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 | 36aedc90 | 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 | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 366 | }; |
| 367 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 368 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 369 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 370 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 371 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 372 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 373 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 374 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 375 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 376 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 377 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 378 | }; |
| 379 | |
| 380 | /* policy for the key default flags */ |
| 381 | static const struct nla_policy |
| 382 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 383 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 384 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 385 | }; |
| 386 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 387 | /* policy for WoWLAN attributes */ |
| 388 | static const struct nla_policy |
| 389 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 390 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 391 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 392 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 393 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 394 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 395 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 396 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 397 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 398 | }; |
| 399 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 400 | /* policy for GTK rekey offload attributes */ |
| 401 | static const struct nla_policy |
| 402 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 403 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 404 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 405 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 406 | }; |
| 407 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 408 | static const struct nla_policy |
| 409 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 410 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 411 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 412 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 413 | }; |
| 414 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 415 | /* ifidx get helper */ |
| 416 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 417 | { |
| 418 | int res; |
| 419 | |
| 420 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 421 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 422 | nl80211_policy); |
| 423 | if (res) |
| 424 | return res; |
| 425 | |
| 426 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 427 | return -EINVAL; |
| 428 | |
| 429 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 430 | if (!res) |
| 431 | return -EINVAL; |
| 432 | return res; |
| 433 | } |
| 434 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 435 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 436 | struct netlink_callback *cb, |
| 437 | struct cfg80211_registered_device **rdev, |
| 438 | struct net_device **dev) |
| 439 | { |
| 440 | int ifidx = cb->args[0]; |
| 441 | int err; |
| 442 | |
| 443 | if (!ifidx) |
| 444 | ifidx = nl80211_get_ifidx(cb); |
| 445 | if (ifidx < 0) |
| 446 | return ifidx; |
| 447 | |
| 448 | cb->args[0] = ifidx; |
| 449 | |
| 450 | rtnl_lock(); |
| 451 | |
| 452 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 453 | if (!*dev) { |
| 454 | err = -ENODEV; |
| 455 | goto out_rtnl; |
| 456 | } |
| 457 | |
| 458 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 459 | if (IS_ERR(*rdev)) { |
| 460 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 461 | goto out_rtnl; |
| 462 | } |
| 463 | |
| 464 | return 0; |
| 465 | out_rtnl: |
| 466 | rtnl_unlock(); |
| 467 | return err; |
| 468 | } |
| 469 | |
| 470 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 471 | { |
| 472 | cfg80211_unlock_rdev(rdev); |
| 473 | rtnl_unlock(); |
| 474 | } |
| 475 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 476 | /* IE validation */ |
| 477 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 478 | { |
| 479 | const u8 *pos; |
| 480 | int len; |
| 481 | |
| 482 | if (!attr) |
| 483 | return true; |
| 484 | |
| 485 | pos = nla_data(attr); |
| 486 | len = nla_len(attr); |
| 487 | |
| 488 | while (len) { |
| 489 | u8 elemlen; |
| 490 | |
| 491 | if (len < 2) |
| 492 | return false; |
| 493 | len -= 2; |
| 494 | |
| 495 | elemlen = pos[1]; |
| 496 | if (elemlen > len) |
| 497 | return false; |
| 498 | |
| 499 | len -= elemlen; |
| 500 | pos += 2 + elemlen; |
| 501 | } |
| 502 | |
| 503 | return true; |
| 504 | } |
| 505 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 506 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 507 | 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] | 508 | int flags, u8 cmd) |
| 509 | { |
| 510 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 511 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 512 | } |
| 513 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 514 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 515 | struct ieee80211_channel *chan) |
| 516 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 517 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 518 | chan->center_freq)) |
| 519 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 520 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 521 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 522 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 523 | goto nla_put_failure; |
| 524 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 525 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 526 | goto nla_put_failure; |
| 527 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 528 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 529 | goto nla_put_failure; |
| 530 | if ((chan->flags & IEEE80211_CHAN_RADAR) && |
| 531 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 532 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 533 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 534 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 535 | DBM_TO_MBM(chan->max_power))) |
| 536 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 537 | |
| 538 | return 0; |
| 539 | |
| 540 | nla_put_failure: |
| 541 | return -ENOBUFS; |
| 542 | } |
| 543 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 544 | /* netlink command implementations */ |
| 545 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 546 | struct key_parse { |
| 547 | struct key_params p; |
| 548 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 549 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 550 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 551 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 552 | }; |
| 553 | |
| 554 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 555 | { |
| 556 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 557 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 558 | nl80211_key_policy); |
| 559 | if (err) |
| 560 | return err; |
| 561 | |
| 562 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 563 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 564 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 565 | if (k->def) { |
| 566 | k->def_uni = true; |
| 567 | k->def_multi = true; |
| 568 | } |
| 569 | if (k->defmgmt) |
| 570 | k->def_multi = true; |
| 571 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 572 | if (tb[NL80211_KEY_IDX]) |
| 573 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 574 | |
| 575 | if (tb[NL80211_KEY_DATA]) { |
| 576 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 577 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 578 | } |
| 579 | |
| 580 | if (tb[NL80211_KEY_SEQ]) { |
| 581 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 582 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 583 | } |
| 584 | |
| 585 | if (tb[NL80211_KEY_CIPHER]) |
| 586 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 587 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 588 | if (tb[NL80211_KEY_TYPE]) { |
| 589 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 590 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 591 | return -EINVAL; |
| 592 | } |
| 593 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 594 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 595 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 596 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 597 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 598 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 599 | if (err) |
| 600 | return err; |
| 601 | |
| 602 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 603 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 604 | } |
| 605 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 610 | { |
| 611 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 612 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 613 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 614 | } |
| 615 | |
| 616 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 617 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 618 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 619 | } |
| 620 | |
| 621 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 622 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 623 | |
| 624 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 625 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 626 | |
| 627 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 628 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 629 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 630 | if (k->def) { |
| 631 | k->def_uni = true; |
| 632 | k->def_multi = true; |
| 633 | } |
| 634 | if (k->defmgmt) |
| 635 | k->def_multi = true; |
| 636 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 637 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 638 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 639 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 640 | return -EINVAL; |
| 641 | } |
| 642 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 643 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 644 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 645 | int err = nla_parse_nested( |
| 646 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 647 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 648 | nl80211_key_default_policy); |
| 649 | if (err) |
| 650 | return err; |
| 651 | |
| 652 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 653 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 654 | } |
| 655 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 660 | { |
| 661 | int err; |
| 662 | |
| 663 | memset(k, 0, sizeof(*k)); |
| 664 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 665 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 666 | |
| 667 | if (info->attrs[NL80211_ATTR_KEY]) |
| 668 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 669 | else |
| 670 | err = nl80211_parse_key_old(info, k); |
| 671 | |
| 672 | if (err) |
| 673 | return err; |
| 674 | |
| 675 | if (k->def && k->defmgmt) |
| 676 | return -EINVAL; |
| 677 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 678 | if (k->defmgmt) { |
| 679 | if (k->def_uni || !k->def_multi) |
| 680 | return -EINVAL; |
| 681 | } |
| 682 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 683 | if (k->idx != -1) { |
| 684 | if (k->defmgmt) { |
| 685 | if (k->idx < 4 || k->idx > 5) |
| 686 | return -EINVAL; |
| 687 | } else if (k->def) { |
| 688 | if (k->idx < 0 || k->idx > 3) |
| 689 | return -EINVAL; |
| 690 | } else { |
| 691 | if (k->idx < 0 || k->idx > 5) |
| 692 | return -EINVAL; |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 699 | static struct cfg80211_cached_keys * |
| 700 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 701 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 702 | { |
| 703 | struct key_parse parse; |
| 704 | struct nlattr *key; |
| 705 | struct cfg80211_cached_keys *result; |
| 706 | int rem, err, def = 0; |
| 707 | |
| 708 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 709 | if (!result) |
| 710 | return ERR_PTR(-ENOMEM); |
| 711 | |
| 712 | result->def = -1; |
| 713 | result->defmgmt = -1; |
| 714 | |
| 715 | nla_for_each_nested(key, keys, rem) { |
| 716 | memset(&parse, 0, sizeof(parse)); |
| 717 | parse.idx = -1; |
| 718 | |
| 719 | err = nl80211_parse_key_new(key, &parse); |
| 720 | if (err) |
| 721 | goto error; |
| 722 | err = -EINVAL; |
| 723 | if (!parse.p.key) |
| 724 | goto error; |
| 725 | if (parse.idx < 0 || parse.idx > 4) |
| 726 | goto error; |
| 727 | if (parse.def) { |
| 728 | if (def) |
| 729 | goto error; |
| 730 | def = 1; |
| 731 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 732 | if (!parse.def_uni || !parse.def_multi) |
| 733 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 734 | } else if (parse.defmgmt) |
| 735 | goto error; |
| 736 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 737 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 738 | if (err) |
| 739 | goto error; |
| 740 | result->params[parse.idx].cipher = parse.p.cipher; |
| 741 | result->params[parse.idx].key_len = parse.p.key_len; |
| 742 | result->params[parse.idx].key = result->data[parse.idx]; |
| 743 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 744 | |
| 745 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 746 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 747 | if (no_ht) |
| 748 | *no_ht = true; |
| 749 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | return result; |
| 753 | error: |
| 754 | kfree(result); |
| 755 | return ERR_PTR(err); |
| 756 | } |
| 757 | |
| 758 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 759 | { |
| 760 | ASSERT_WDEV_LOCK(wdev); |
| 761 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 762 | switch (wdev->iftype) { |
| 763 | case NL80211_IFTYPE_AP: |
| 764 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 765 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 766 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 767 | break; |
| 768 | case NL80211_IFTYPE_ADHOC: |
| 769 | if (!wdev->current_bss) |
| 770 | return -ENOLINK; |
| 771 | break; |
| 772 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 773 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 774 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 775 | return -ENOLINK; |
| 776 | break; |
| 777 | default: |
| 778 | return -EINVAL; |
| 779 | } |
| 780 | |
| 781 | return 0; |
| 782 | } |
| 783 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 784 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 785 | { |
| 786 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 787 | int i; |
| 788 | |
| 789 | if (!nl_modes) |
| 790 | goto nla_put_failure; |
| 791 | |
| 792 | i = 0; |
| 793 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 794 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 795 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 796 | ifmodes >>= 1; |
| 797 | i++; |
| 798 | } |
| 799 | |
| 800 | nla_nest_end(msg, nl_modes); |
| 801 | return 0; |
| 802 | |
| 803 | nla_put_failure: |
| 804 | return -ENOBUFS; |
| 805 | } |
| 806 | |
| 807 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 808 | struct sk_buff *msg) |
| 809 | { |
| 810 | struct nlattr *nl_combis; |
| 811 | int i, j; |
| 812 | |
| 813 | nl_combis = nla_nest_start(msg, |
| 814 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 815 | if (!nl_combis) |
| 816 | goto nla_put_failure; |
| 817 | |
| 818 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 819 | const struct ieee80211_iface_combination *c; |
| 820 | struct nlattr *nl_combi, *nl_limits; |
| 821 | |
| 822 | c = &wiphy->iface_combinations[i]; |
| 823 | |
| 824 | nl_combi = nla_nest_start(msg, i + 1); |
| 825 | if (!nl_combi) |
| 826 | goto nla_put_failure; |
| 827 | |
| 828 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 829 | if (!nl_limits) |
| 830 | goto nla_put_failure; |
| 831 | |
| 832 | for (j = 0; j < c->n_limits; j++) { |
| 833 | struct nlattr *nl_limit; |
| 834 | |
| 835 | nl_limit = nla_nest_start(msg, j + 1); |
| 836 | if (!nl_limit) |
| 837 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 838 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 839 | c->limits[j].max)) |
| 840 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 841 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 842 | c->limits[j].types)) |
| 843 | goto nla_put_failure; |
| 844 | nla_nest_end(msg, nl_limit); |
| 845 | } |
| 846 | |
| 847 | nla_nest_end(msg, nl_limits); |
| 848 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 849 | if (c->beacon_int_infra_match && |
| 850 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 851 | goto nla_put_failure; |
| 852 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 853 | c->num_different_channels) || |
| 854 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 855 | c->max_interfaces)) |
| 856 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 857 | |
| 858 | nla_nest_end(msg, nl_combi); |
| 859 | } |
| 860 | |
| 861 | nla_nest_end(msg, nl_combis); |
| 862 | |
| 863 | return 0; |
| 864 | nla_put_failure: |
| 865 | return -ENOBUFS; |
| 866 | } |
| 867 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 868 | 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] | 869 | struct cfg80211_registered_device *dev) |
| 870 | { |
| 871 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 872 | struct nlattr *nl_bands, *nl_band; |
| 873 | struct nlattr *nl_freqs, *nl_freq; |
| 874 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 875 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 876 | enum ieee80211_band band; |
| 877 | struct ieee80211_channel *chan; |
| 878 | struct ieee80211_rate *rate; |
| 879 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 880 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 881 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 882 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 883 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 884 | if (!hdr) |
| 885 | return -1; |
| 886 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 887 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
| 888 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || |
| 889 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 890 | cfg80211_rdev_list_generation) || |
| 891 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 892 | dev->wiphy.retry_short) || |
| 893 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 894 | dev->wiphy.retry_long) || |
| 895 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 896 | dev->wiphy.frag_threshold) || |
| 897 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 898 | dev->wiphy.rts_threshold) || |
| 899 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 900 | dev->wiphy.coverage_class) || |
| 901 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 902 | dev->wiphy.max_scan_ssids) || |
| 903 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 904 | dev->wiphy.max_sched_scan_ssids) || |
| 905 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 906 | dev->wiphy.max_scan_ie_len) || |
| 907 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 908 | dev->wiphy.max_sched_scan_ie_len) || |
| 909 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 910 | dev->wiphy.max_match_sets)) |
| 911 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 912 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 913 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 914 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 915 | goto nla_put_failure; |
| 916 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 917 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 918 | goto nla_put_failure; |
| 919 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 920 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 921 | goto nla_put_failure; |
| 922 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 923 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 924 | goto nla_put_failure; |
| 925 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 926 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 927 | goto nla_put_failure; |
| 928 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 929 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 930 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 931 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 932 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 933 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 934 | dev->wiphy.cipher_suites)) |
| 935 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 936 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 937 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 938 | dev->wiphy.max_num_pmkids)) |
| 939 | goto nla_put_failure; |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 940 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 941 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 942 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 943 | goto nla_put_failure; |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 944 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 945 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 946 | dev->wiphy.available_antennas_tx) || |
| 947 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 948 | dev->wiphy.available_antennas_rx)) |
| 949 | goto nla_put_failure; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 950 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 951 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 952 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 953 | dev->wiphy.probe_resp_offload)) |
| 954 | goto nla_put_failure; |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 955 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 956 | if ((dev->wiphy.available_antennas_tx || |
| 957 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 958 | u32 tx_ant = 0, rx_ant = 0; |
| 959 | int res; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 960 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 961 | if (!res) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 962 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 963 | tx_ant) || |
| 964 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 965 | rx_ant)) |
| 966 | goto nla_put_failure; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 970 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 971 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 972 | goto nla_put_failure; |
| 973 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 974 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 975 | if (!nl_bands) |
| 976 | goto nla_put_failure; |
| 977 | |
| 978 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 979 | if (!dev->wiphy.bands[band]) |
| 980 | continue; |
| 981 | |
| 982 | nl_band = nla_nest_start(msg, band); |
| 983 | if (!nl_band) |
| 984 | goto nla_put_failure; |
| 985 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 986 | /* add HT info */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 987 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
| 988 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 989 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 990 | &dev->wiphy.bands[band]->ht_cap.mcs) || |
| 991 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 992 | dev->wiphy.bands[band]->ht_cap.cap) || |
| 993 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 994 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || |
| 995 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 996 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) |
| 997 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 998 | |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 999 | /* add VHT info */ |
| 1000 | if (dev->wiphy.bands[band]->vht_cap.vht_supported && |
| 1001 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1002 | sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs), |
| 1003 | &dev->wiphy.bands[band]->vht_cap.vht_mcs) || |
| 1004 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1005 | dev->wiphy.bands[band]->vht_cap.cap))) |
| 1006 | goto nla_put_failure; |
| 1007 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1008 | /* add frequencies */ |
| 1009 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 1010 | if (!nl_freqs) |
| 1011 | goto nla_put_failure; |
| 1012 | |
| 1013 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 1014 | nl_freq = nla_nest_start(msg, i); |
| 1015 | if (!nl_freq) |
| 1016 | goto nla_put_failure; |
| 1017 | |
| 1018 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1019 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1020 | if (nl80211_msg_put_channel(msg, chan)) |
| 1021 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1022 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1023 | nla_nest_end(msg, nl_freq); |
| 1024 | } |
| 1025 | |
| 1026 | nla_nest_end(msg, nl_freqs); |
| 1027 | |
| 1028 | /* add bitrates */ |
| 1029 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1030 | if (!nl_rates) |
| 1031 | goto nla_put_failure; |
| 1032 | |
| 1033 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 1034 | nl_rate = nla_nest_start(msg, i); |
| 1035 | if (!nl_rate) |
| 1036 | goto nla_put_failure; |
| 1037 | |
| 1038 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1039 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1040 | rate->bitrate)) |
| 1041 | goto nla_put_failure; |
| 1042 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1043 | nla_put_flag(msg, |
| 1044 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1045 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1046 | |
| 1047 | nla_nest_end(msg, nl_rate); |
| 1048 | } |
| 1049 | |
| 1050 | nla_nest_end(msg, nl_rates); |
| 1051 | |
| 1052 | nla_nest_end(msg, nl_band); |
| 1053 | } |
| 1054 | nla_nest_end(msg, nl_bands); |
| 1055 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1056 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1057 | if (!nl_cmds) |
| 1058 | goto nla_put_failure; |
| 1059 | |
| 1060 | i = 0; |
| 1061 | #define CMD(op, n) \ |
| 1062 | do { \ |
| 1063 | if (dev->ops->op) { \ |
| 1064 | i++; \ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1065 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1066 | goto nla_put_failure; \ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1067 | } \ |
| 1068 | } while (0) |
| 1069 | |
| 1070 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1071 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1072 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1073 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1074 | CMD(add_station, NEW_STATION); |
| 1075 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 1076 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1077 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1078 | CMD(auth, AUTHENTICATE); |
| 1079 | CMD(assoc, ASSOCIATE); |
| 1080 | CMD(deauth, DEAUTHENTICATE); |
| 1081 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1082 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1083 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1084 | CMD(set_pmksa, SET_PMKSA); |
| 1085 | CMD(del_pmksa, DEL_PMKSA); |
| 1086 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1087 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1088 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 1089 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1090 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1091 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 1092 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1093 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1094 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1095 | goto nla_put_failure; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1096 | } |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1097 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1098 | dev->ops->join_mesh) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1099 | i++; |
| 1100 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1101 | goto nla_put_failure; |
| 1102 | } |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1103 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 1104 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1105 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1106 | CMD(tdls_oper, TDLS_OPER); |
| 1107 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 1108 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1109 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 1110 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1111 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1112 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1113 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1114 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1115 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1116 | } |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1117 | CMD(start_p2p_device, START_P2P_DEVICE); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 1118 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1119 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1120 | #ifdef CONFIG_NL80211_TESTMODE |
| 1121 | CMD(testmode_cmd, TESTMODE); |
| 1122 | #endif |
| 1123 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1124 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1125 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1126 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1127 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1128 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1129 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1132 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1133 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1134 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1135 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1136 | } |
| 1137 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1138 | nla_nest_end(msg, nl_cmds); |
| 1139 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1140 | if (dev->ops->remain_on_channel && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1141 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1142 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1143 | dev->wiphy.max_remain_on_channel_duration)) |
| 1144 | goto nla_put_failure; |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 1145 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1146 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1147 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1148 | goto nla_put_failure; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1149 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1150 | if (mgmt_stypes) { |
| 1151 | u16 stypes; |
| 1152 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1153 | enum nl80211_iftype ift; |
| 1154 | |
| 1155 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1156 | if (!nl_ifs) |
| 1157 | goto nla_put_failure; |
| 1158 | |
| 1159 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1160 | nl_ftypes = nla_nest_start(msg, ift); |
| 1161 | if (!nl_ftypes) |
| 1162 | goto nla_put_failure; |
| 1163 | i = 0; |
| 1164 | stypes = mgmt_stypes[ift].tx; |
| 1165 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1166 | if ((stypes & 1) && |
| 1167 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1168 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1169 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1170 | stypes >>= 1; |
| 1171 | i++; |
| 1172 | } |
| 1173 | nla_nest_end(msg, nl_ftypes); |
| 1174 | } |
| 1175 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1176 | nla_nest_end(msg, nl_ifs); |
| 1177 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1178 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1179 | if (!nl_ifs) |
| 1180 | goto nla_put_failure; |
| 1181 | |
| 1182 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1183 | nl_ftypes = nla_nest_start(msg, ift); |
| 1184 | if (!nl_ftypes) |
| 1185 | goto nla_put_failure; |
| 1186 | i = 0; |
| 1187 | stypes = mgmt_stypes[ift].rx; |
| 1188 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1189 | if ((stypes & 1) && |
| 1190 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1191 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1192 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1193 | stypes >>= 1; |
| 1194 | i++; |
| 1195 | } |
| 1196 | nla_nest_end(msg, nl_ftypes); |
| 1197 | } |
| 1198 | nla_nest_end(msg, nl_ifs); |
| 1199 | } |
| 1200 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1201 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1202 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 1203 | struct nlattr *nl_wowlan; |
| 1204 | |
| 1205 | nl_wowlan = nla_nest_start(msg, |
| 1206 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1207 | if (!nl_wowlan) |
| 1208 | goto nla_put_failure; |
| 1209 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1210 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 1211 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1212 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1213 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1214 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1215 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1216 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1217 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1218 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1219 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1220 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1221 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1222 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1223 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1224 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1225 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1226 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1227 | if (dev->wiphy.wowlan.n_patterns) { |
| 1228 | struct nl80211_wowlan_pattern_support pat = { |
| 1229 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1230 | .min_pattern_len = |
| 1231 | dev->wiphy.wowlan.pattern_min_len, |
| 1232 | .max_pattern_len = |
| 1233 | dev->wiphy.wowlan.pattern_max_len, |
| 1234 | }; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1235 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1236 | sizeof(pat), &pat)) |
| 1237 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | nla_nest_end(msg, nl_wowlan); |
| 1241 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1242 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1243 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1244 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1245 | dev->wiphy.software_iftypes)) |
| 1246 | goto nla_put_failure; |
| 1247 | |
| 1248 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1249 | goto nla_put_failure; |
| 1250 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1251 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1252 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1253 | dev->wiphy.ap_sme_capa)) |
| 1254 | goto nla_put_failure; |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1255 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1256 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
| 1257 | dev->wiphy.features)) |
| 1258 | goto nla_put_failure; |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1259 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1260 | if (dev->wiphy.ht_capa_mod_mask && |
| 1261 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1262 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1263 | dev->wiphy.ht_capa_mod_mask)) |
| 1264 | goto nla_put_failure; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1265 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1266 | return genlmsg_end(msg, hdr); |
| 1267 | |
| 1268 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1269 | genlmsg_cancel(msg, hdr); |
| 1270 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1274 | { |
| 1275 | int idx = 0; |
| 1276 | int start = cb->args[0]; |
| 1277 | struct cfg80211_registered_device *dev; |
| 1278 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1279 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1280 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1281 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1282 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1283 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1284 | continue; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1285 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1286 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1287 | dev) < 0) { |
| 1288 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1289 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1290 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1291 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1292 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1293 | |
| 1294 | cb->args[0] = idx; |
| 1295 | |
| 1296 | return skb->len; |
| 1297 | } |
| 1298 | |
| 1299 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1300 | { |
| 1301 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1302 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1303 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1304 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1305 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1306 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1307 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1308 | 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] | 1309 | nlmsg_free(msg); |
| 1310 | return -ENOBUFS; |
| 1311 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1312 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1313 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1314 | } |
| 1315 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1316 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1317 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1318 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1319 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1320 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1321 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1322 | }; |
| 1323 | |
| 1324 | static int parse_txq_params(struct nlattr *tb[], |
| 1325 | struct ieee80211_txq_params *txq_params) |
| 1326 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1327 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1328 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1329 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1330 | return -EINVAL; |
| 1331 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1332 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1333 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1334 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1335 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1336 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1337 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1338 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1339 | return -EINVAL; |
| 1340 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1341 | return 0; |
| 1342 | } |
| 1343 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1344 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1345 | { |
| 1346 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1347 | * You can only set the channel explicitly for WDS interfaces, |
| 1348 | * all others have their channel managed via their respective |
| 1349 | * "establish a connection" command (connect, join, ...) |
| 1350 | * |
| 1351 | * For AP/GO and mesh mode, the channel can be set with the |
| 1352 | * channel userspace API, but is only stored and passed to the |
| 1353 | * low-level driver when the AP starts or the mesh is joined. |
| 1354 | * This is for backward compatibility, userspace can also give |
| 1355 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1356 | * |
| 1357 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1358 | * whatever else is going on, so they have their own special |
| 1359 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1360 | */ |
| 1361 | return !wdev || |
| 1362 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1363 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1364 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1365 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1366 | } |
| 1367 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1368 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1369 | struct genl_info *info, |
| 1370 | struct cfg80211_chan_def *chandef) |
| 1371 | { |
| 1372 | struct ieee80211_sta_ht_cap *ht_cap; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1373 | struct ieee80211_sta_vht_cap *vht_cap; |
| 1374 | u32 control_freq, width; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1375 | |
| 1376 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1377 | return -EINVAL; |
| 1378 | |
| 1379 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1380 | |
| 1381 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1382 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1383 | chandef->center_freq1 = control_freq; |
| 1384 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1385 | |
| 1386 | /* Primary channel not allowed */ |
| 1387 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1388 | return -EINVAL; |
| 1389 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1390 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1391 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1392 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1393 | chantype = nla_get_u32( |
| 1394 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1395 | |
| 1396 | switch (chantype) { |
| 1397 | case NL80211_CHAN_NO_HT: |
| 1398 | case NL80211_CHAN_HT20: |
| 1399 | case NL80211_CHAN_HT40PLUS: |
| 1400 | case NL80211_CHAN_HT40MINUS: |
| 1401 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1402 | chantype); |
| 1403 | break; |
| 1404 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1405 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1406 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1407 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1408 | chandef->width = |
| 1409 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1410 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1411 | chandef->center_freq1 = |
| 1412 | nla_get_u32( |
| 1413 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1414 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1415 | chandef->center_freq2 = |
| 1416 | nla_get_u32( |
| 1417 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1418 | } |
| 1419 | |
| 1420 | ht_cap = &rdev->wiphy.bands[chandef->chan->band]->ht_cap; |
| 1421 | vht_cap = &rdev->wiphy.bands[chandef->chan->band]->vht_cap; |
| 1422 | |
| 1423 | if (!cfg80211_chan_def_valid(chandef)) |
| 1424 | return -EINVAL; |
| 1425 | |
| 1426 | switch (chandef->width) { |
| 1427 | case NL80211_CHAN_WIDTH_20: |
| 1428 | if (!ht_cap->ht_supported) |
| 1429 | return -EINVAL; |
| 1430 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1431 | width = 20; |
| 1432 | break; |
| 1433 | case NL80211_CHAN_WIDTH_40: |
| 1434 | width = 40; |
| 1435 | /* quick early regulatory check */ |
| 1436 | if (chandef->center_freq1 < control_freq && |
| 1437 | chandef->chan->flags & IEEE80211_CHAN_NO_HT40MINUS) |
| 1438 | return -EINVAL; |
| 1439 | if (chandef->center_freq1 > control_freq && |
| 1440 | chandef->chan->flags & IEEE80211_CHAN_NO_HT40PLUS) |
| 1441 | return -EINVAL; |
| 1442 | if (!ht_cap->ht_supported) |
| 1443 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1444 | if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) || |
| 1445 | ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT) |
| 1446 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1447 | break; |
| 1448 | case NL80211_CHAN_WIDTH_80: |
| 1449 | width = 80; |
| 1450 | if (!vht_cap->vht_supported) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1451 | return -EINVAL; |
| 1452 | break; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1453 | case NL80211_CHAN_WIDTH_80P80: |
| 1454 | width = 80; |
| 1455 | if (!vht_cap->vht_supported) |
| 1456 | return -EINVAL; |
| 1457 | if (!(vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)) |
| 1458 | return -EINVAL; |
| 1459 | break; |
| 1460 | case NL80211_CHAN_WIDTH_160: |
| 1461 | width = 160; |
| 1462 | if (!vht_cap->vht_supported) |
| 1463 | return -EINVAL; |
| 1464 | if (!(vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)) |
| 1465 | return -EINVAL; |
| 1466 | break; |
| 1467 | default: |
| 1468 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1469 | } |
| 1470 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1471 | if (!cfg80211_secondary_chans_ok(&rdev->wiphy, chandef->center_freq1, |
| 1472 | width, IEEE80211_CHAN_DISABLED)) |
| 1473 | return -EINVAL; |
| 1474 | if (chandef->center_freq2 && |
| 1475 | !cfg80211_secondary_chans_ok(&rdev->wiphy, chandef->center_freq2, |
| 1476 | width, IEEE80211_CHAN_DISABLED)) |
| 1477 | return -EINVAL; |
| 1478 | |
| 1479 | /* TODO: missing regulatory check on bandwidth */ |
| 1480 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1481 | return 0; |
| 1482 | } |
| 1483 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1484 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1485 | struct wireless_dev *wdev, |
| 1486 | struct genl_info *info) |
| 1487 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1488 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1489 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1490 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1491 | |
| 1492 | if (wdev) |
| 1493 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1494 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1495 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1496 | return -EOPNOTSUPP; |
| 1497 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1498 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1499 | if (result) |
| 1500 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1501 | |
| 1502 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1503 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1504 | case NL80211_IFTYPE_AP: |
| 1505 | case NL80211_IFTYPE_P2P_GO: |
| 1506 | if (wdev->beacon_interval) { |
| 1507 | result = -EBUSY; |
| 1508 | break; |
| 1509 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1510 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1511 | result = -EINVAL; |
| 1512 | break; |
| 1513 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1514 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1515 | result = 0; |
| 1516 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1517 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1518 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1519 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1520 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1521 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1522 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1523 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1524 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1525 | } |
| 1526 | mutex_unlock(&rdev->devlist_mtx); |
| 1527 | |
| 1528 | return result; |
| 1529 | } |
| 1530 | |
| 1531 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1532 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1534 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1535 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1536 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1537 | } |
| 1538 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1539 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1540 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1541 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1542 | struct net_device *dev = info->user_ptr[1]; |
| 1543 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1544 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1545 | |
| 1546 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1547 | return -EINVAL; |
| 1548 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1549 | if (netif_running(dev)) |
| 1550 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1551 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1552 | if (!rdev->ops->set_wds_peer) |
| 1553 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1554 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1555 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1556 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1557 | |
| 1558 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1559 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1563 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1564 | { |
| 1565 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1566 | struct net_device *netdev = NULL; |
| 1567 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1568 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1569 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1570 | u32 changed; |
| 1571 | u8 retry_short = 0, retry_long = 0; |
| 1572 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1573 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1574 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1575 | /* |
| 1576 | * Try to find the wiphy and netdev. Normally this |
| 1577 | * function shouldn't need the netdev, but this is |
| 1578 | * done for backward compatibility -- previously |
| 1579 | * setting the channel was done per wiphy, but now |
| 1580 | * it is per netdev. Previous userland like hostapd |
| 1581 | * also passed a netdev to set_wiphy, so that it is |
| 1582 | * possible to let that go to the right netdev! |
| 1583 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1584 | mutex_lock(&cfg80211_mutex); |
| 1585 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1586 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1587 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1588 | |
| 1589 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1590 | if (netdev && netdev->ieee80211_ptr) { |
| 1591 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1592 | mutex_lock(&rdev->mtx); |
| 1593 | } else |
| 1594 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1595 | } |
| 1596 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1597 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1598 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1599 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1600 | if (IS_ERR(rdev)) { |
| 1601 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1602 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1603 | } |
| 1604 | wdev = NULL; |
| 1605 | netdev = NULL; |
| 1606 | result = 0; |
| 1607 | |
| 1608 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1609 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1610 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1611 | |
| 1612 | /* |
| 1613 | * end workaround code, by now the rdev is available |
| 1614 | * and locked, and wdev may or may not be NULL. |
| 1615 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1616 | |
| 1617 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1618 | result = cfg80211_dev_rename( |
| 1619 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1620 | |
| 1621 | mutex_unlock(&cfg80211_mutex); |
| 1622 | |
| 1623 | if (result) |
| 1624 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1625 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1626 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1627 | struct ieee80211_txq_params txq_params; |
| 1628 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1629 | |
| 1630 | if (!rdev->ops->set_txq_params) { |
| 1631 | result = -EOPNOTSUPP; |
| 1632 | goto bad_res; |
| 1633 | } |
| 1634 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1635 | if (!netdev) { |
| 1636 | result = -EINVAL; |
| 1637 | goto bad_res; |
| 1638 | } |
| 1639 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1640 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1641 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1642 | result = -EINVAL; |
| 1643 | goto bad_res; |
| 1644 | } |
| 1645 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1646 | if (!netif_running(netdev)) { |
| 1647 | result = -ENETDOWN; |
| 1648 | goto bad_res; |
| 1649 | } |
| 1650 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1651 | nla_for_each_nested(nl_txq_params, |
| 1652 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1653 | rem_txq_params) { |
| 1654 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1655 | nla_data(nl_txq_params), |
| 1656 | nla_len(nl_txq_params), |
| 1657 | txq_params_policy); |
| 1658 | result = parse_txq_params(tb, &txq_params); |
| 1659 | if (result) |
| 1660 | goto bad_res; |
| 1661 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1662 | result = rdev_set_txq_params(rdev, netdev, |
| 1663 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1664 | if (result) |
| 1665 | goto bad_res; |
| 1666 | } |
| 1667 | } |
| 1668 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1669 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1670 | result = __nl80211_set_channel(rdev, |
| 1671 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1672 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1673 | if (result) |
| 1674 | goto bad_res; |
| 1675 | } |
| 1676 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1677 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1678 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1679 | enum nl80211_tx_power_setting type; |
| 1680 | int idx, mbm = 0; |
| 1681 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1682 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1683 | txp_wdev = NULL; |
| 1684 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1685 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1686 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1687 | goto bad_res; |
| 1688 | } |
| 1689 | |
| 1690 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1691 | type = nla_get_u32(info->attrs[idx]); |
| 1692 | |
| 1693 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1694 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1695 | result = -EINVAL; |
| 1696 | goto bad_res; |
| 1697 | } |
| 1698 | |
| 1699 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1700 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1701 | mbm = nla_get_u32(info->attrs[idx]); |
| 1702 | } |
| 1703 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1704 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1705 | if (result) |
| 1706 | goto bad_res; |
| 1707 | } |
| 1708 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1709 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1710 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1711 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1712 | if ((!rdev->wiphy.available_antennas_tx && |
| 1713 | !rdev->wiphy.available_antennas_rx) || |
| 1714 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1715 | result = -EOPNOTSUPP; |
| 1716 | goto bad_res; |
| 1717 | } |
| 1718 | |
| 1719 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1720 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1721 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1722 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1723 | * available antenna masks, except for the "all" mask */ |
| 1724 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1725 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1726 | result = -EINVAL; |
| 1727 | goto bad_res; |
| 1728 | } |
| 1729 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1730 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1731 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1732 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1733 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1734 | if (result) |
| 1735 | goto bad_res; |
| 1736 | } |
| 1737 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1738 | changed = 0; |
| 1739 | |
| 1740 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1741 | retry_short = nla_get_u8( |
| 1742 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1743 | if (retry_short == 0) { |
| 1744 | result = -EINVAL; |
| 1745 | goto bad_res; |
| 1746 | } |
| 1747 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1748 | } |
| 1749 | |
| 1750 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1751 | retry_long = nla_get_u8( |
| 1752 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1753 | if (retry_long == 0) { |
| 1754 | result = -EINVAL; |
| 1755 | goto bad_res; |
| 1756 | } |
| 1757 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1758 | } |
| 1759 | |
| 1760 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1761 | frag_threshold = nla_get_u32( |
| 1762 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1763 | if (frag_threshold < 256) { |
| 1764 | result = -EINVAL; |
| 1765 | goto bad_res; |
| 1766 | } |
| 1767 | if (frag_threshold != (u32) -1) { |
| 1768 | /* |
| 1769 | * Fragments (apart from the last one) are required to |
| 1770 | * have even length. Make the fragmentation code |
| 1771 | * simpler by stripping LSB should someone try to use |
| 1772 | * odd threshold value. |
| 1773 | */ |
| 1774 | frag_threshold &= ~0x1; |
| 1775 | } |
| 1776 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1777 | } |
| 1778 | |
| 1779 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1780 | rts_threshold = nla_get_u32( |
| 1781 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1782 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1783 | } |
| 1784 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1785 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1786 | coverage_class = nla_get_u8( |
| 1787 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1788 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1789 | } |
| 1790 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1791 | if (changed) { |
| 1792 | u8 old_retry_short, old_retry_long; |
| 1793 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1794 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1795 | |
| 1796 | if (!rdev->ops->set_wiphy_params) { |
| 1797 | result = -EOPNOTSUPP; |
| 1798 | goto bad_res; |
| 1799 | } |
| 1800 | |
| 1801 | old_retry_short = rdev->wiphy.retry_short; |
| 1802 | old_retry_long = rdev->wiphy.retry_long; |
| 1803 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1804 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1805 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1806 | |
| 1807 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1808 | rdev->wiphy.retry_short = retry_short; |
| 1809 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1810 | rdev->wiphy.retry_long = retry_long; |
| 1811 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1812 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1813 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1814 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1815 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1816 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1817 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1818 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1819 | if (result) { |
| 1820 | rdev->wiphy.retry_short = old_retry_short; |
| 1821 | rdev->wiphy.retry_long = old_retry_long; |
| 1822 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1823 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1824 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1825 | } |
| 1826 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1827 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1828 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1829 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1830 | if (netdev) |
| 1831 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1832 | return result; |
| 1833 | } |
| 1834 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1835 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1836 | { |
| 1837 | return (u64)wdev->identifier | |
| 1838 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1839 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1840 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1841 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 1842 | struct cfg80211_chan_def *chandef) |
| 1843 | { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1844 | WARN_ON(!cfg80211_chan_def_valid(chandef)); |
| 1845 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1846 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1847 | chandef->chan->center_freq)) |
| 1848 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1849 | switch (chandef->width) { |
| 1850 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1851 | case NL80211_CHAN_WIDTH_20: |
| 1852 | case NL80211_CHAN_WIDTH_40: |
| 1853 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1854 | cfg80211_get_chandef_type(chandef))) |
| 1855 | return -ENOBUFS; |
| 1856 | break; |
| 1857 | default: |
| 1858 | break; |
| 1859 | } |
| 1860 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 1861 | return -ENOBUFS; |
| 1862 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 1863 | return -ENOBUFS; |
| 1864 | if (chandef->center_freq2 && |
| 1865 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1866 | return -ENOBUFS; |
| 1867 | return 0; |
| 1868 | } |
| 1869 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1870 | 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] | 1871 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1872 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1873 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1874 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1875 | void *hdr; |
| 1876 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1877 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1878 | if (!hdr) |
| 1879 | return -1; |
| 1880 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1881 | if (dev && |
| 1882 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1883 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1884 | goto nla_put_failure; |
| 1885 | |
| 1886 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1887 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1888 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1889 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1890 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1891 | rdev->devlist_generation ^ |
| 1892 | (cfg80211_rdev_list_generation << 2))) |
| 1893 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1894 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1895 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1896 | int ret; |
| 1897 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1898 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1899 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 1900 | if (ret == 0) { |
| 1901 | if (nl80211_send_chandef(msg, &chandef)) |
| 1902 | goto nla_put_failure; |
| 1903 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1904 | } |
| 1905 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 1906 | if (wdev->ssid_len) { |
| 1907 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 1908 | goto nla_put_failure; |
| 1909 | } |
| 1910 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1911 | return genlmsg_end(msg, hdr); |
| 1912 | |
| 1913 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1914 | genlmsg_cancel(msg, hdr); |
| 1915 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1919 | { |
| 1920 | int wp_idx = 0; |
| 1921 | int if_idx = 0; |
| 1922 | int wp_start = cb->args[0]; |
| 1923 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1924 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1925 | struct wireless_dev *wdev; |
| 1926 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1927 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1928 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1929 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1930 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1931 | if (wp_idx < wp_start) { |
| 1932 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1933 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1934 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1935 | if_idx = 0; |
| 1936 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1937 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1938 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1939 | if (if_idx < if_start) { |
| 1940 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1941 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1942 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1943 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1944 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1945 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1946 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1947 | goto out; |
| 1948 | } |
| 1949 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1950 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1951 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1952 | |
| 1953 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1954 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1955 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1956 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1957 | |
| 1958 | cb->args[0] = wp_idx; |
| 1959 | cb->args[1] = if_idx; |
| 1960 | |
| 1961 | return skb->len; |
| 1962 | } |
| 1963 | |
| 1964 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1965 | { |
| 1966 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1967 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1968 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1969 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1970 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1971 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1972 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1973 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1974 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1975 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1976 | nlmsg_free(msg); |
| 1977 | return -ENOBUFS; |
| 1978 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1979 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1980 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1981 | } |
| 1982 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1983 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1984 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1985 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1986 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1987 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1988 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1989 | }; |
| 1990 | |
| 1991 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1992 | { |
| 1993 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1994 | int flag; |
| 1995 | |
| 1996 | *mntrflags = 0; |
| 1997 | |
| 1998 | if (!nla) |
| 1999 | return -EINVAL; |
| 2000 | |
| 2001 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2002 | nla, mntr_flags_policy)) |
| 2003 | return -EINVAL; |
| 2004 | |
| 2005 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2006 | if (flags[flag]) |
| 2007 | *mntrflags |= (1<<flag); |
| 2008 | |
| 2009 | return 0; |
| 2010 | } |
| 2011 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2012 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2013 | struct net_device *netdev, u8 use_4addr, |
| 2014 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2015 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2016 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2017 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2018 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2019 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2020 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2021 | |
| 2022 | switch (iftype) { |
| 2023 | case NL80211_IFTYPE_AP_VLAN: |
| 2024 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2025 | return 0; |
| 2026 | break; |
| 2027 | case NL80211_IFTYPE_STATION: |
| 2028 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2029 | return 0; |
| 2030 | break; |
| 2031 | default: |
| 2032 | break; |
| 2033 | } |
| 2034 | |
| 2035 | return -EOPNOTSUPP; |
| 2036 | } |
| 2037 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2038 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2039 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2040 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2041 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2042 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2043 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2044 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2045 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2046 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2047 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2048 | memset(¶ms, 0, sizeof(params)); |
| 2049 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2050 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2051 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2052 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2053 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2054 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2055 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2056 | if (ntype > NL80211_IFTYPE_MAX) |
| 2057 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2058 | } |
| 2059 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2060 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2061 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2062 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2063 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2064 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2065 | if (netif_running(dev)) |
| 2066 | return -EBUSY; |
| 2067 | |
| 2068 | wdev_lock(wdev); |
| 2069 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2070 | IEEE80211_MAX_MESH_ID_LEN); |
| 2071 | wdev->mesh_id_up_len = |
| 2072 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2073 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2074 | wdev->mesh_id_up_len); |
| 2075 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2076 | } |
| 2077 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2078 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2079 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2080 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2081 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2082 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2083 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2084 | } else { |
| 2085 | params.use_4addr = -1; |
| 2086 | } |
| 2087 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2088 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2089 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2090 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2091 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2092 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2093 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2094 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2095 | |
| 2096 | flags = &_flags; |
| 2097 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2098 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2099 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2100 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2101 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2102 | else |
| 2103 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2104 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2105 | if (!err && params.use_4addr != -1) |
| 2106 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2107 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2108 | return err; |
| 2109 | } |
| 2110 | |
| 2111 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2112 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2113 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2114 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2115 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2116 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2117 | int err; |
| 2118 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2119 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2120 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2121 | memset(¶ms, 0, sizeof(params)); |
| 2122 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2123 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2124 | return -EINVAL; |
| 2125 | |
| 2126 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2127 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2128 | if (type > NL80211_IFTYPE_MAX) |
| 2129 | return -EINVAL; |
| 2130 | } |
| 2131 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2132 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2133 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2134 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2135 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2136 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2137 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2138 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2139 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2140 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2141 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2142 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2143 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2144 | if (!msg) |
| 2145 | return -ENOMEM; |
| 2146 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2147 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2148 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2149 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2150 | wdev = rdev_add_virtual_intf(rdev, |
| 2151 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2152 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2153 | if (IS_ERR(wdev)) { |
| 2154 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2155 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2156 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2157 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2158 | switch (type) { |
| 2159 | case NL80211_IFTYPE_MESH_POINT: |
| 2160 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2161 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2162 | wdev_lock(wdev); |
| 2163 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2164 | IEEE80211_MAX_MESH_ID_LEN); |
| 2165 | wdev->mesh_id_up_len = |
| 2166 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2167 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2168 | wdev->mesh_id_up_len); |
| 2169 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2170 | break; |
| 2171 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2172 | /* |
| 2173 | * P2P Device doesn't have a netdev, so doesn't go |
| 2174 | * through the netdev notifier and must be added here |
| 2175 | */ |
| 2176 | mutex_init(&wdev->mtx); |
| 2177 | INIT_LIST_HEAD(&wdev->event_list); |
| 2178 | spin_lock_init(&wdev->event_lock); |
| 2179 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2180 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2181 | |
| 2182 | mutex_lock(&rdev->devlist_mtx); |
| 2183 | wdev->identifier = ++rdev->wdev_id; |
| 2184 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2185 | rdev->devlist_generation++; |
| 2186 | mutex_unlock(&rdev->devlist_mtx); |
| 2187 | break; |
| 2188 | default: |
| 2189 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2190 | } |
| 2191 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2192 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2193 | rdev, wdev) < 0) { |
| 2194 | nlmsg_free(msg); |
| 2195 | return -ENOBUFS; |
| 2196 | } |
| 2197 | |
| 2198 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2202 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2203 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2204 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2205 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2206 | if (!rdev->ops->del_virtual_intf) |
| 2207 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2208 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2209 | /* |
| 2210 | * If we remove a wireless device without a netdev then clear |
| 2211 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2212 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2213 | * since the wdev has been freed, unlike with a netdev where |
| 2214 | * we need the dev_put() for the netdev to really be freed. |
| 2215 | */ |
| 2216 | if (!wdev->netdev) |
| 2217 | info->user_ptr[1] = NULL; |
| 2218 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2219 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2220 | } |
| 2221 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2222 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2223 | { |
| 2224 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2225 | struct net_device *dev = info->user_ptr[1]; |
| 2226 | u16 noack_map; |
| 2227 | |
| 2228 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2229 | return -EINVAL; |
| 2230 | |
| 2231 | if (!rdev->ops->set_noack_map) |
| 2232 | return -EOPNOTSUPP; |
| 2233 | |
| 2234 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2235 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2236 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2237 | } |
| 2238 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2239 | struct get_key_cookie { |
| 2240 | struct sk_buff *msg; |
| 2241 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2242 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2243 | }; |
| 2244 | |
| 2245 | static void get_key_callback(void *c, struct key_params *params) |
| 2246 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2247 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2248 | struct get_key_cookie *cookie = c; |
| 2249 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2250 | if ((params->key && |
| 2251 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2252 | params->key_len, params->key)) || |
| 2253 | (params->seq && |
| 2254 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2255 | params->seq_len, params->seq)) || |
| 2256 | (params->cipher && |
| 2257 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2258 | params->cipher))) |
| 2259 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2260 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2261 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2262 | if (!key) |
| 2263 | goto nla_put_failure; |
| 2264 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2265 | if ((params->key && |
| 2266 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2267 | params->key_len, params->key)) || |
| 2268 | (params->seq && |
| 2269 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2270 | params->seq_len, params->seq)) || |
| 2271 | (params->cipher && |
| 2272 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2273 | params->cipher))) |
| 2274 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2275 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2276 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2277 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2278 | |
| 2279 | nla_nest_end(cookie->msg, key); |
| 2280 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2281 | return; |
| 2282 | nla_put_failure: |
| 2283 | cookie->error = 1; |
| 2284 | } |
| 2285 | |
| 2286 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2287 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2288 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2289 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2290 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2291 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2292 | const u8 *mac_addr = NULL; |
| 2293 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2294 | struct get_key_cookie cookie = { |
| 2295 | .error = 0, |
| 2296 | }; |
| 2297 | void *hdr; |
| 2298 | struct sk_buff *msg; |
| 2299 | |
| 2300 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2301 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2302 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2303 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2304 | return -EINVAL; |
| 2305 | |
| 2306 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2307 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2308 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2309 | pairwise = !!mac_addr; |
| 2310 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2311 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2312 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2313 | return -EINVAL; |
| 2314 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2315 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2316 | return -EINVAL; |
| 2317 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2318 | } |
| 2319 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2320 | if (!rdev->ops->get_key) |
| 2321 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2322 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2323 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2324 | if (!msg) |
| 2325 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2326 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2327 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2328 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2329 | if (IS_ERR(hdr)) |
| 2330 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2331 | |
| 2332 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2333 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2334 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2335 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2336 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2337 | goto nla_put_failure; |
| 2338 | if (mac_addr && |
| 2339 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2340 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2341 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2342 | if (pairwise && mac_addr && |
| 2343 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2344 | return -ENOENT; |
| 2345 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2346 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2347 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2348 | |
| 2349 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2350 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2351 | |
| 2352 | if (cookie.error) |
| 2353 | goto nla_put_failure; |
| 2354 | |
| 2355 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2356 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2357 | |
| 2358 | nla_put_failure: |
| 2359 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2360 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2361 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2362 | return err; |
| 2363 | } |
| 2364 | |
| 2365 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2366 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2367 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2368 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2369 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2370 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2371 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2372 | err = nl80211_parse_key(info, &key); |
| 2373 | if (err) |
| 2374 | return err; |
| 2375 | |
| 2376 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2377 | return -EINVAL; |
| 2378 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2379 | /* only support setting default key */ |
| 2380 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2381 | return -EINVAL; |
| 2382 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2383 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2384 | |
| 2385 | if (key.def) { |
| 2386 | if (!rdev->ops->set_default_key) { |
| 2387 | err = -EOPNOTSUPP; |
| 2388 | goto out; |
| 2389 | } |
| 2390 | |
| 2391 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2392 | if (err) |
| 2393 | goto out; |
| 2394 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2395 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2396 | key.def_uni, key.def_multi); |
| 2397 | |
| 2398 | if (err) |
| 2399 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2400 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2401 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2402 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2403 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2404 | } else { |
| 2405 | if (key.def_uni || !key.def_multi) { |
| 2406 | err = -EINVAL; |
| 2407 | goto out; |
| 2408 | } |
| 2409 | |
| 2410 | if (!rdev->ops->set_default_mgmt_key) { |
| 2411 | err = -EOPNOTSUPP; |
| 2412 | goto out; |
| 2413 | } |
| 2414 | |
| 2415 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2416 | if (err) |
| 2417 | goto out; |
| 2418 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2419 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2420 | if (err) |
| 2421 | goto out; |
| 2422 | |
| 2423 | #ifdef CONFIG_CFG80211_WEXT |
| 2424 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2425 | #endif |
| 2426 | } |
| 2427 | |
| 2428 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2429 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2430 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2431 | return err; |
| 2432 | } |
| 2433 | |
| 2434 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2435 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2436 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2437 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2438 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2439 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2440 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2441 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2442 | err = nl80211_parse_key(info, &key); |
| 2443 | if (err) |
| 2444 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2445 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2446 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2447 | return -EINVAL; |
| 2448 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2449 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2450 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2451 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2452 | if (key.type == -1) { |
| 2453 | if (mac_addr) |
| 2454 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2455 | else |
| 2456 | key.type = NL80211_KEYTYPE_GROUP; |
| 2457 | } |
| 2458 | |
| 2459 | /* for now */ |
| 2460 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2461 | key.type != NL80211_KEYTYPE_GROUP) |
| 2462 | return -EINVAL; |
| 2463 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2464 | if (!rdev->ops->add_key) |
| 2465 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2466 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2467 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2468 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2469 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2470 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2471 | |
| 2472 | wdev_lock(dev->ieee80211_ptr); |
| 2473 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2474 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2475 | err = rdev_add_key(rdev, dev, key.idx, |
| 2476 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2477 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2478 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2479 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2480 | return err; |
| 2481 | } |
| 2482 | |
| 2483 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2484 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2485 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2486 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2487 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2488 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2489 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2490 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2491 | err = nl80211_parse_key(info, &key); |
| 2492 | if (err) |
| 2493 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2494 | |
| 2495 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2496 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2497 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2498 | if (key.type == -1) { |
| 2499 | if (mac_addr) |
| 2500 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2501 | else |
| 2502 | key.type = NL80211_KEYTYPE_GROUP; |
| 2503 | } |
| 2504 | |
| 2505 | /* for now */ |
| 2506 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2507 | key.type != NL80211_KEYTYPE_GROUP) |
| 2508 | return -EINVAL; |
| 2509 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2510 | if (!rdev->ops->del_key) |
| 2511 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2512 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2513 | wdev_lock(dev->ieee80211_ptr); |
| 2514 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2515 | |
| 2516 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2517 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2518 | err = -ENOENT; |
| 2519 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2520 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2521 | err = rdev_del_key(rdev, dev, key.idx, |
| 2522 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2523 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2524 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2525 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2526 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2527 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2528 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2529 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2530 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2531 | } |
| 2532 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2533 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2534 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2535 | return err; |
| 2536 | } |
| 2537 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2538 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2539 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2540 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2541 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2542 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2543 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2544 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2545 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2546 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2547 | return -EINVAL; |
| 2548 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2549 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2550 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2551 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2552 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2553 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2554 | if (!bcn->head_len) |
| 2555 | return -EINVAL; |
| 2556 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2560 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2561 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2562 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2563 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2564 | } |
| 2565 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2566 | if (!haveinfo) |
| 2567 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2568 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2569 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2570 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2571 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2575 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2576 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2577 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2578 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2579 | } |
| 2580 | |
| 2581 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2582 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2583 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2584 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2585 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2586 | } |
| 2587 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2588 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2589 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2590 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2591 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2592 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2593 | } |
| 2594 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2595 | return 0; |
| 2596 | } |
| 2597 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2598 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2599 | struct cfg80211_ap_settings *params) |
| 2600 | { |
| 2601 | struct wireless_dev *wdev; |
| 2602 | bool ret = false; |
| 2603 | |
| 2604 | mutex_lock(&rdev->devlist_mtx); |
| 2605 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2606 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2607 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2608 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2609 | continue; |
| 2610 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2611 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2612 | continue; |
| 2613 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2614 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2615 | ret = true; |
| 2616 | break; |
| 2617 | } |
| 2618 | |
| 2619 | mutex_unlock(&rdev->devlist_mtx); |
| 2620 | |
| 2621 | return ret; |
| 2622 | } |
| 2623 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2624 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2625 | enum nl80211_auth_type auth_type, |
| 2626 | enum nl80211_commands cmd) |
| 2627 | { |
| 2628 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2629 | return false; |
| 2630 | |
| 2631 | switch (cmd) { |
| 2632 | case NL80211_CMD_AUTHENTICATE: |
| 2633 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2634 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2635 | return false; |
| 2636 | return true; |
| 2637 | case NL80211_CMD_CONNECT: |
| 2638 | case NL80211_CMD_START_AP: |
| 2639 | /* SAE not supported yet */ |
| 2640 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2641 | return false; |
| 2642 | return true; |
| 2643 | default: |
| 2644 | return false; |
| 2645 | } |
| 2646 | } |
| 2647 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2648 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2649 | { |
| 2650 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2651 | struct net_device *dev = info->user_ptr[1]; |
| 2652 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2653 | struct cfg80211_ap_settings params; |
| 2654 | int err; |
| 2655 | |
| 2656 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2657 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2658 | return -EOPNOTSUPP; |
| 2659 | |
| 2660 | if (!rdev->ops->start_ap) |
| 2661 | return -EOPNOTSUPP; |
| 2662 | |
| 2663 | if (wdev->beacon_interval) |
| 2664 | return -EALREADY; |
| 2665 | |
| 2666 | memset(¶ms, 0, sizeof(params)); |
| 2667 | |
| 2668 | /* these are required for START_AP */ |
| 2669 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2670 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2671 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2672 | return -EINVAL; |
| 2673 | |
| 2674 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2675 | if (err) |
| 2676 | return err; |
| 2677 | |
| 2678 | params.beacon_interval = |
| 2679 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2680 | params.dtim_period = |
| 2681 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2682 | |
| 2683 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2684 | if (err) |
| 2685 | return err; |
| 2686 | |
| 2687 | /* |
| 2688 | * In theory, some of these attributes should be required here |
| 2689 | * but since they were not used when the command was originally |
| 2690 | * added, keep them optional for old user space programs to let |
| 2691 | * them continue to work with drivers that do not need the |
| 2692 | * additional information -- drivers must check! |
| 2693 | */ |
| 2694 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2695 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2696 | params.ssid_len = |
| 2697 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2698 | if (params.ssid_len == 0 || |
| 2699 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2700 | return -EINVAL; |
| 2701 | } |
| 2702 | |
| 2703 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2704 | params.hidden_ssid = nla_get_u32( |
| 2705 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2706 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2707 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2708 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2709 | return -EINVAL; |
| 2710 | } |
| 2711 | |
| 2712 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2713 | |
| 2714 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2715 | params.auth_type = nla_get_u32( |
| 2716 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2717 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 2718 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2719 | return -EINVAL; |
| 2720 | } else |
| 2721 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2722 | |
| 2723 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2724 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2725 | if (err) |
| 2726 | return err; |
| 2727 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2728 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2729 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2730 | return -EOPNOTSUPP; |
| 2731 | params.inactivity_timeout = nla_get_u16( |
| 2732 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2733 | } |
| 2734 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2735 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2736 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 2737 | if (err) |
| 2738 | return err; |
| 2739 | } else if (wdev->preset_chandef.chan) { |
| 2740 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2741 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2742 | return -EINVAL; |
| 2743 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2744 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2745 | return -EINVAL; |
| 2746 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2747 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2748 | err = cfg80211_can_use_chan(rdev, wdev, params.chandef.chan, |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2749 | CHAN_MODE_SHARED); |
| 2750 | mutex_unlock(&rdev->devlist_mtx); |
| 2751 | |
| 2752 | if (err) |
| 2753 | return err; |
| 2754 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2755 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2756 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2757 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2758 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2759 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 2760 | wdev->ssid_len = params.ssid_len; |
| 2761 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2762 | } |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2763 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2764 | } |
| 2765 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2766 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2767 | { |
| 2768 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2769 | struct net_device *dev = info->user_ptr[1]; |
| 2770 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2771 | struct cfg80211_beacon_data params; |
| 2772 | int err; |
| 2773 | |
| 2774 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2775 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2776 | return -EOPNOTSUPP; |
| 2777 | |
| 2778 | if (!rdev->ops->change_beacon) |
| 2779 | return -EOPNOTSUPP; |
| 2780 | |
| 2781 | if (!wdev->beacon_interval) |
| 2782 | return -EINVAL; |
| 2783 | |
| 2784 | err = nl80211_parse_beacon(info, ¶ms); |
| 2785 | if (err) |
| 2786 | return err; |
| 2787 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2788 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | 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] | 2792 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2793 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2794 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2795 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2796 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2797 | } |
| 2798 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2799 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2800 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2801 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2802 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2803 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2804 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2805 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2806 | }; |
| 2807 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2808 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2809 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2810 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2811 | { |
| 2812 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2813 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2814 | int flag; |
| 2815 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2816 | /* |
| 2817 | * Try parsing the new attribute first so userspace |
| 2818 | * can specify both for older kernels. |
| 2819 | */ |
| 2820 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2821 | if (nla) { |
| 2822 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2823 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2824 | sta_flags = nla_data(nla); |
| 2825 | params->sta_flags_mask = sta_flags->mask; |
| 2826 | params->sta_flags_set = sta_flags->set; |
| 2827 | if ((params->sta_flags_mask | |
| 2828 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2829 | return -EINVAL; |
| 2830 | return 0; |
| 2831 | } |
| 2832 | |
| 2833 | /* if present, parse the old attribute */ |
| 2834 | |
| 2835 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2836 | if (!nla) |
| 2837 | return 0; |
| 2838 | |
| 2839 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2840 | nla, sta_flags_policy)) |
| 2841 | return -EINVAL; |
| 2842 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2843 | /* |
| 2844 | * Only allow certain flags for interface types so that |
| 2845 | * other attributes are silently ignored. Remember that |
| 2846 | * this is backward compatibility code with old userspace |
| 2847 | * and shouldn't be hit in other cases anyway. |
| 2848 | */ |
| 2849 | switch (iftype) { |
| 2850 | case NL80211_IFTYPE_AP: |
| 2851 | case NL80211_IFTYPE_AP_VLAN: |
| 2852 | case NL80211_IFTYPE_P2P_GO: |
| 2853 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2854 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2855 | BIT(NL80211_STA_FLAG_WME) | |
| 2856 | BIT(NL80211_STA_FLAG_MFP); |
| 2857 | break; |
| 2858 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2859 | case NL80211_IFTYPE_STATION: |
| 2860 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2861 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2862 | break; |
| 2863 | case NL80211_IFTYPE_MESH_POINT: |
| 2864 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2865 | BIT(NL80211_STA_FLAG_MFP) | |
| 2866 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2867 | default: |
| 2868 | return -EINVAL; |
| 2869 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2870 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2871 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 2872 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2873 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2874 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2875 | /* no longer support new API additions in old API */ |
| 2876 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 2877 | return -EINVAL; |
| 2878 | } |
| 2879 | } |
| 2880 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2881 | return 0; |
| 2882 | } |
| 2883 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2884 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2885 | int attr) |
| 2886 | { |
| 2887 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2888 | u32 bitrate; |
| 2889 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2890 | |
| 2891 | rate = nla_nest_start(msg, attr); |
| 2892 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 2893 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2894 | |
| 2895 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2896 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2897 | /* report 16-bit bitrate only if we can */ |
| 2898 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 2899 | if (bitrate > 0 && |
| 2900 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 2901 | return false; |
| 2902 | if (bitrate_compat > 0 && |
| 2903 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 2904 | return false; |
| 2905 | |
| 2906 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 2907 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 2908 | return false; |
| 2909 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 2910 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 2911 | return false; |
| 2912 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 2913 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 2914 | return false; |
| 2915 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 2916 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 2917 | return false; |
| 2918 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 2919 | return false; |
| 2920 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 2921 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 2922 | return false; |
| 2923 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 2924 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 2925 | return false; |
| 2926 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 2927 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 2928 | return false; |
| 2929 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 2930 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 2931 | return false; |
| 2932 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 2933 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 2934 | return false; |
| 2935 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2936 | |
| 2937 | nla_nest_end(msg, rate); |
| 2938 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2939 | } |
| 2940 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2941 | 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] | 2942 | int flags, |
| 2943 | struct cfg80211_registered_device *rdev, |
| 2944 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2945 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2946 | { |
| 2947 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2948 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2949 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2950 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2951 | if (!hdr) |
| 2952 | return -1; |
| 2953 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2954 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2955 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 2956 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 2957 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2958 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2959 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2960 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2961 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2962 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 2963 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2964 | sinfo->connected_time)) |
| 2965 | goto nla_put_failure; |
| 2966 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 2967 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2968 | sinfo->inactive_time)) |
| 2969 | goto nla_put_failure; |
| 2970 | if ((sinfo->filled & STATION_INFO_RX_BYTES) && |
| 2971 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2972 | sinfo->rx_bytes)) |
| 2973 | goto nla_put_failure; |
| 2974 | if ((sinfo->filled & STATION_INFO_TX_BYTES) && |
| 2975 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2976 | sinfo->tx_bytes)) |
| 2977 | goto nla_put_failure; |
| 2978 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 2979 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 2980 | goto nla_put_failure; |
| 2981 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 2982 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 2983 | goto nla_put_failure; |
| 2984 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 2985 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2986 | sinfo->plink_state)) |
| 2987 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2988 | switch (rdev->wiphy.signal_type) { |
| 2989 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2990 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 2991 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 2992 | sinfo->signal)) |
| 2993 | goto nla_put_failure; |
| 2994 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 2995 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2996 | sinfo->signal_avg)) |
| 2997 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2998 | break; |
| 2999 | default: |
| 3000 | break; |
| 3001 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3002 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3003 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3004 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3005 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3006 | } |
| 3007 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3008 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3009 | NL80211_STA_INFO_RX_BITRATE)) |
| 3010 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3011 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3012 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3013 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3014 | sinfo->rx_packets)) |
| 3015 | goto nla_put_failure; |
| 3016 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3017 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3018 | sinfo->tx_packets)) |
| 3019 | goto nla_put_failure; |
| 3020 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3021 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3022 | sinfo->tx_retries)) |
| 3023 | goto nla_put_failure; |
| 3024 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3025 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3026 | sinfo->tx_failed)) |
| 3027 | goto nla_put_failure; |
| 3028 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3029 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3030 | sinfo->beacon_loss_count)) |
| 3031 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3032 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3033 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3034 | if (!bss_param) |
| 3035 | goto nla_put_failure; |
| 3036 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3037 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3038 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3039 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3040 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3041 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3042 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3043 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3044 | sinfo->bss_param.dtim_period) || |
| 3045 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3046 | sinfo->bss_param.beacon_interval)) |
| 3047 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3048 | |
| 3049 | nla_nest_end(msg, bss_param); |
| 3050 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3051 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3052 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3053 | sizeof(struct nl80211_sta_flag_update), |
| 3054 | &sinfo->sta_flags)) |
| 3055 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3056 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3057 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3058 | sinfo->t_offset)) |
| 3059 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3060 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3061 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3062 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3063 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3064 | sinfo->assoc_req_ies)) |
| 3065 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3066 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3067 | return genlmsg_end(msg, hdr); |
| 3068 | |
| 3069 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3070 | genlmsg_cancel(msg, hdr); |
| 3071 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3072 | } |
| 3073 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3074 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3075 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3076 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3077 | struct station_info sinfo; |
| 3078 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3079 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3080 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3081 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3082 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3083 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3084 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3085 | if (err) |
| 3086 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3087 | |
| 3088 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3089 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3090 | goto out_err; |
| 3091 | } |
| 3092 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3093 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3094 | memset(&sinfo, 0, sizeof(sinfo)); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3095 | err = rdev_dump_station(dev, netdev, sta_idx, |
| 3096 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3097 | if (err == -ENOENT) |
| 3098 | break; |
| 3099 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3100 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3101 | |
| 3102 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3103 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3104 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3105 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3106 | &sinfo) < 0) |
| 3107 | goto out; |
| 3108 | |
| 3109 | sta_idx++; |
| 3110 | } |
| 3111 | |
| 3112 | |
| 3113 | out: |
| 3114 | cb->args[1] = sta_idx; |
| 3115 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3116 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3117 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3118 | |
| 3119 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3120 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3121 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3122 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3123 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3124 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3125 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3126 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3127 | struct sk_buff *msg; |
| 3128 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3129 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3130 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3131 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3132 | |
| 3133 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3134 | return -EINVAL; |
| 3135 | |
| 3136 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3137 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3138 | if (!rdev->ops->get_station) |
| 3139 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3140 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3141 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3142 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3143 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3144 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3145 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3146 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3147 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3148 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3149 | 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] | 3150 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3151 | nlmsg_free(msg); |
| 3152 | return -ENOBUFS; |
| 3153 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3154 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3155 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3159 | * 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] | 3160 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3161 | static struct net_device *get_vlan(struct genl_info *info, |
| 3162 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3163 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3164 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3165 | struct net_device *v; |
| 3166 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3167 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3168 | if (!vlanattr) |
| 3169 | return NULL; |
| 3170 | |
| 3171 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3172 | if (!v) |
| 3173 | return ERR_PTR(-ENODEV); |
| 3174 | |
| 3175 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3176 | ret = -EINVAL; |
| 3177 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3178 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3179 | |
| 3180 | if (!netif_running(v)) { |
| 3181 | ret = -ENETDOWN; |
| 3182 | goto error; |
| 3183 | } |
| 3184 | |
| 3185 | return v; |
| 3186 | error: |
| 3187 | dev_put(v); |
| 3188 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3192 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3193 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3194 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3195 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3196 | struct station_parameters params; |
| 3197 | u8 *mac_addr = NULL; |
| 3198 | |
| 3199 | memset(¶ms, 0, sizeof(params)); |
| 3200 | |
| 3201 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 3202 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3203 | |
| 3204 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3205 | return -EINVAL; |
| 3206 | |
| 3207 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3208 | return -EINVAL; |
| 3209 | |
| 3210 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3211 | |
| 3212 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3213 | params.supported_rates = |
| 3214 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3215 | params.supported_rates_len = |
| 3216 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3217 | } |
| 3218 | |
| 3219 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3220 | params.listen_interval = |
| 3221 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 3222 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3223 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3224 | params.ht_capa = |
| 3225 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3226 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3227 | if (!rdev->ops->change_station) |
| 3228 | return -EOPNOTSUPP; |
| 3229 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3230 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3231 | return -EINVAL; |
| 3232 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3233 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3234 | params.plink_action = |
| 3235 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3236 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3237 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3238 | params.plink_state = |
| 3239 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3240 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3241 | switch (dev->ieee80211_ptr->iftype) { |
| 3242 | case NL80211_IFTYPE_AP: |
| 3243 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3244 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3245 | /* disallow mesh-specific things */ |
| 3246 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3247 | return -EINVAL; |
| 3248 | |
| 3249 | /* TDLS can't be set, ... */ |
| 3250 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3251 | return -EINVAL; |
| 3252 | /* |
| 3253 | * ... but don't bother the driver with it. This works around |
| 3254 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3255 | * TLDS_PEER flag in the mask even for AP mode. |
| 3256 | */ |
| 3257 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3258 | |
| 3259 | /* accept only the listed bits */ |
| 3260 | if (params.sta_flags_mask & |
| 3261 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3262 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3263 | BIT(NL80211_STA_FLAG_WME) | |
| 3264 | BIT(NL80211_STA_FLAG_MFP))) |
| 3265 | return -EINVAL; |
| 3266 | |
| 3267 | /* must be last in here for error handling */ |
| 3268 | params.vlan = get_vlan(info, rdev); |
| 3269 | if (IS_ERR(params.vlan)) |
| 3270 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3271 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3272 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3273 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3274 | /* |
| 3275 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3276 | * but silently ignore attempts to change it since we |
| 3277 | * don't have state here to verify that it doesn't try |
| 3278 | * to change the flag. |
| 3279 | */ |
| 3280 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3281 | /* fall through */ |
| 3282 | case NL80211_IFTYPE_ADHOC: |
| 3283 | /* disallow things sta doesn't support */ |
| 3284 | if (params.plink_action) |
| 3285 | return -EINVAL; |
| 3286 | if (params.ht_capa) |
| 3287 | return -EINVAL; |
| 3288 | if (params.listen_interval >= 0) |
| 3289 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3290 | /* reject any changes other than AUTHORIZED */ |
| 3291 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3292 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3293 | break; |
| 3294 | case NL80211_IFTYPE_MESH_POINT: |
| 3295 | /* disallow things mesh doesn't support */ |
| 3296 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3297 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3298 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3299 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3300 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3301 | return -EINVAL; |
| 3302 | /* |
| 3303 | * No special handling for TDLS here -- the userspace |
| 3304 | * mesh code doesn't have this bug. |
| 3305 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3306 | if (params.sta_flags_mask & |
| 3307 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3308 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3309 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3310 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3311 | break; |
| 3312 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3313 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3314 | } |
| 3315 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3316 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3317 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3318 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3319 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3320 | if (params.vlan) |
| 3321 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3322 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3323 | return err; |
| 3324 | } |
| 3325 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3326 | static struct nla_policy |
| 3327 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3328 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3329 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3330 | }; |
| 3331 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3332 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3333 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3334 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3335 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3336 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3337 | struct station_parameters params; |
| 3338 | u8 *mac_addr = NULL; |
| 3339 | |
| 3340 | memset(¶ms, 0, sizeof(params)); |
| 3341 | |
| 3342 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3343 | return -EINVAL; |
| 3344 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3345 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3346 | return -EINVAL; |
| 3347 | |
| 3348 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3349 | return -EINVAL; |
| 3350 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3351 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3352 | return -EINVAL; |
| 3353 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3354 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3355 | params.supported_rates = |
| 3356 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3357 | params.supported_rates_len = |
| 3358 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3359 | params.listen_interval = |
| 3360 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3361 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3362 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3363 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3364 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3365 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3366 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3367 | params.ht_capa = |
| 3368 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3369 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3370 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3371 | params.vht_capa = |
| 3372 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3373 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3374 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3375 | params.plink_action = |
| 3376 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3377 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3378 | if (!rdev->ops->add_station) |
| 3379 | return -EOPNOTSUPP; |
| 3380 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3381 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3382 | return -EINVAL; |
| 3383 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3384 | switch (dev->ieee80211_ptr->iftype) { |
| 3385 | case NL80211_IFTYPE_AP: |
| 3386 | case NL80211_IFTYPE_AP_VLAN: |
| 3387 | case NL80211_IFTYPE_P2P_GO: |
| 3388 | /* parse WME attributes if sta is WME capable */ |
| 3389 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3390 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3391 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3392 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3393 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3394 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3395 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3396 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3397 | nl80211_sta_wme_policy); |
| 3398 | if (err) |
| 3399 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3400 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3401 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3402 | params.uapsd_queues = |
| 3403 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3404 | if (params.uapsd_queues & |
| 3405 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3406 | return -EINVAL; |
| 3407 | |
| 3408 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3409 | params.max_sp = |
| 3410 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3411 | |
| 3412 | if (params.max_sp & |
| 3413 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3414 | return -EINVAL; |
| 3415 | |
| 3416 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3417 | } |
| 3418 | /* TDLS peers cannot be added */ |
| 3419 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3420 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3421 | /* but don't bother the driver with it */ |
| 3422 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3423 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3424 | /* must be last in here for error handling */ |
| 3425 | params.vlan = get_vlan(info, rdev); |
| 3426 | if (IS_ERR(params.vlan)) |
| 3427 | return PTR_ERR(params.vlan); |
| 3428 | break; |
| 3429 | case NL80211_IFTYPE_MESH_POINT: |
| 3430 | /* TDLS peers cannot be added */ |
| 3431 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3432 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3433 | break; |
| 3434 | case NL80211_IFTYPE_STATION: |
| 3435 | /* Only TDLS peers can be added */ |
| 3436 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3437 | return -EINVAL; |
| 3438 | /* Can only add if TDLS ... */ |
| 3439 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3440 | return -EOPNOTSUPP; |
| 3441 | /* ... with external setup is supported */ |
| 3442 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3443 | return -EOPNOTSUPP; |
| 3444 | break; |
| 3445 | default: |
| 3446 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [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_add_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 | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3455 | return err; |
| 3456 | } |
| 3457 | |
| 3458 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3459 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3460 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3461 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3462 | u8 *mac_addr = NULL; |
| 3463 | |
| 3464 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3465 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3466 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3467 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3468 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3469 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3470 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3471 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3472 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3473 | if (!rdev->ops->del_station) |
| 3474 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3475 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3476 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3477 | } |
| 3478 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3479 | 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] | 3480 | int flags, struct net_device *dev, |
| 3481 | u8 *dst, u8 *next_hop, |
| 3482 | struct mpath_info *pinfo) |
| 3483 | { |
| 3484 | void *hdr; |
| 3485 | struct nlattr *pinfoattr; |
| 3486 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3487 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3488 | if (!hdr) |
| 3489 | return -1; |
| 3490 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3491 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3492 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3493 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3494 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3495 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3496 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3497 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3498 | if (!pinfoattr) |
| 3499 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3500 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3501 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3502 | pinfo->frame_qlen)) |
| 3503 | goto nla_put_failure; |
| 3504 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3505 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3506 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3507 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3508 | pinfo->metric)) || |
| 3509 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3510 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3511 | pinfo->exptime)) || |
| 3512 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3513 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3514 | pinfo->flags)) || |
| 3515 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3516 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3517 | pinfo->discovery_timeout)) || |
| 3518 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3519 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3520 | pinfo->discovery_retries))) |
| 3521 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3522 | |
| 3523 | nla_nest_end(msg, pinfoattr); |
| 3524 | |
| 3525 | return genlmsg_end(msg, hdr); |
| 3526 | |
| 3527 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3528 | genlmsg_cancel(msg, hdr); |
| 3529 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3533 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3534 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3535 | struct mpath_info pinfo; |
| 3536 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3537 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3538 | u8 dst[ETH_ALEN]; |
| 3539 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3540 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3541 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3542 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3543 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3544 | if (err) |
| 3545 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3546 | |
| 3547 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3548 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3549 | goto out_err; |
| 3550 | } |
| 3551 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3552 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3553 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3554 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3555 | } |
| 3556 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3557 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3558 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 3559 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3560 | if (err == -ENOENT) |
| 3561 | break; |
| 3562 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3563 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3564 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3565 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3566 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3567 | netdev, dst, next_hop, |
| 3568 | &pinfo) < 0) |
| 3569 | goto out; |
| 3570 | |
| 3571 | path_idx++; |
| 3572 | } |
| 3573 | |
| 3574 | |
| 3575 | out: |
| 3576 | cb->args[1] = path_idx; |
| 3577 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3578 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3579 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3580 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3581 | } |
| 3582 | |
| 3583 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3584 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3585 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3586 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3587 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3588 | struct mpath_info pinfo; |
| 3589 | struct sk_buff *msg; |
| 3590 | u8 *dst = NULL; |
| 3591 | u8 next_hop[ETH_ALEN]; |
| 3592 | |
| 3593 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3594 | |
| 3595 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3596 | return -EINVAL; |
| 3597 | |
| 3598 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3599 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3600 | if (!rdev->ops->get_mpath) |
| 3601 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3602 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3603 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3604 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3605 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3606 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3607 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3608 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3609 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3610 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3611 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3612 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3613 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3614 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3615 | dev, dst, next_hop, &pinfo) < 0) { |
| 3616 | nlmsg_free(msg); |
| 3617 | return -ENOBUFS; |
| 3618 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3619 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3620 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3624 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3625 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3626 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3627 | u8 *dst = NULL; |
| 3628 | u8 *next_hop = NULL; |
| 3629 | |
| 3630 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3631 | return -EINVAL; |
| 3632 | |
| 3633 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3634 | return -EINVAL; |
| 3635 | |
| 3636 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3637 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3638 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3639 | if (!rdev->ops->change_mpath) |
| 3640 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3641 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3642 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3643 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3644 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3645 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3646 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3647 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3648 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3649 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3650 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3651 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3652 | u8 *dst = NULL; |
| 3653 | u8 *next_hop = NULL; |
| 3654 | |
| 3655 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3656 | return -EINVAL; |
| 3657 | |
| 3658 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3659 | return -EINVAL; |
| 3660 | |
| 3661 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3662 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3663 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3664 | if (!rdev->ops->add_mpath) |
| 3665 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3666 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3667 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3668 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3669 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3670 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3674 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3675 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3676 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3677 | u8 *dst = NULL; |
| 3678 | |
| 3679 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3680 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3681 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3682 | if (!rdev->ops->del_mpath) |
| 3683 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3684 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3685 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3686 | } |
| 3687 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3688 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3689 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3690 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3691 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3692 | struct bss_parameters params; |
| 3693 | |
| 3694 | memset(¶ms, 0, sizeof(params)); |
| 3695 | /* default to not changing parameters */ |
| 3696 | params.use_cts_prot = -1; |
| 3697 | params.use_short_preamble = -1; |
| 3698 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3699 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3700 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3701 | |
| 3702 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3703 | params.use_cts_prot = |
| 3704 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3705 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3706 | params.use_short_preamble = |
| 3707 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3708 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3709 | params.use_short_slot_time = |
| 3710 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3711 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3712 | params.basic_rates = |
| 3713 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3714 | params.basic_rates_len = |
| 3715 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3716 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3717 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3718 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3719 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3720 | params.ht_opmode = |
| 3721 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3722 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3723 | if (!rdev->ops->change_bss) |
| 3724 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3725 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3726 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3727 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3728 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3729 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3730 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3731 | } |
| 3732 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3733 | 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] | 3734 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3735 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3736 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3737 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3738 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3739 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3740 | }; |
| 3741 | |
| 3742 | static int parse_reg_rule(struct nlattr *tb[], |
| 3743 | struct ieee80211_reg_rule *reg_rule) |
| 3744 | { |
| 3745 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3746 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3747 | |
| 3748 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3749 | return -EINVAL; |
| 3750 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3751 | return -EINVAL; |
| 3752 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3753 | return -EINVAL; |
| 3754 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3755 | return -EINVAL; |
| 3756 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3757 | return -EINVAL; |
| 3758 | |
| 3759 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3760 | |
| 3761 | freq_range->start_freq_khz = |
| 3762 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3763 | freq_range->end_freq_khz = |
| 3764 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3765 | freq_range->max_bandwidth_khz = |
| 3766 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3767 | |
| 3768 | power_rule->max_eirp = |
| 3769 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3770 | |
| 3771 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3772 | power_rule->max_antenna_gain = |
| 3773 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3774 | |
| 3775 | return 0; |
| 3776 | } |
| 3777 | |
| 3778 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3779 | { |
| 3780 | int r; |
| 3781 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3782 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3783 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3784 | /* |
| 3785 | * You should only get this when cfg80211 hasn't yet initialized |
| 3786 | * completely when built-in to the kernel right between the time |
| 3787 | * window between nl80211_init() and regulatory_init(), if that is |
| 3788 | * even possible. |
| 3789 | */ |
| 3790 | mutex_lock(&cfg80211_mutex); |
| 3791 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3792 | mutex_unlock(&cfg80211_mutex); |
| 3793 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3794 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3795 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3796 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3797 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3798 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3799 | |
| 3800 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3801 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3802 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 3803 | user_reg_hint_type = |
| 3804 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 3805 | else |
| 3806 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 3807 | |
| 3808 | switch (user_reg_hint_type) { |
| 3809 | case NL80211_USER_REG_HINT_USER: |
| 3810 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 3811 | break; |
| 3812 | default: |
| 3813 | return -EINVAL; |
| 3814 | } |
| 3815 | |
| 3816 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3817 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3818 | return r; |
| 3819 | } |
| 3820 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3821 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3822 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3823 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3824 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3825 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3826 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3827 | struct mesh_config cur_params; |
| 3828 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3829 | void *hdr; |
| 3830 | struct nlattr *pinfoattr; |
| 3831 | struct sk_buff *msg; |
| 3832 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3833 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3834 | return -EOPNOTSUPP; |
| 3835 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3836 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3837 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3838 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3839 | wdev_lock(wdev); |
| 3840 | /* If not connected, get default parameters */ |
| 3841 | if (!wdev->mesh_id_len) |
| 3842 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3843 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3844 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3845 | wdev_unlock(wdev); |
| 3846 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3847 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3848 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3849 | |
| 3850 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3851 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3852 | if (!msg) |
| 3853 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3854 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3855 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3856 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3857 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3858 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3859 | if (!pinfoattr) |
| 3860 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3861 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3862 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3863 | cur_params.dot11MeshRetryTimeout) || |
| 3864 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3865 | cur_params.dot11MeshConfirmTimeout) || |
| 3866 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3867 | cur_params.dot11MeshHoldingTimeout) || |
| 3868 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3869 | cur_params.dot11MeshMaxPeerLinks) || |
| 3870 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3871 | cur_params.dot11MeshMaxRetries) || |
| 3872 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 3873 | cur_params.dot11MeshTTL) || |
| 3874 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3875 | cur_params.element_ttl) || |
| 3876 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3877 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3878 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3879 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3880 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3881 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 3882 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3883 | cur_params.path_refresh_time) || |
| 3884 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3885 | cur_params.min_discovery_timeout) || |
| 3886 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3887 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 3888 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3889 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 3890 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3891 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 3892 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3893 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 3894 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3895 | cur_params.dot11MeshHWMPRootMode) || |
| 3896 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3897 | cur_params.dot11MeshHWMPRannInterval) || |
| 3898 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3899 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 3900 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 3901 | cur_params.dot11MeshForwarding) || |
| 3902 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3903 | cur_params.rssi_threshold) || |
| 3904 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3905 | cur_params.ht_opmode) || |
| 3906 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3907 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 3908 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3909 | cur_params.dot11MeshHWMProotInterval) || |
| 3910 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3911 | cur_params.dot11MeshHWMPconfirmationInterval)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3912 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3913 | nla_nest_end(msg, pinfoattr); |
| 3914 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3915 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3916 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3917 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3918 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3919 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3920 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3921 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3922 | } |
| 3923 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3924 | 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] | 3925 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3926 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3927 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3928 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3929 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3930 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3931 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3932 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3933 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3934 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3935 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3936 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3937 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3938 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3939 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3940 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3941 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3942 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3943 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3944 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3945 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 3946 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3947 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 3948 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3949 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3950 | }; |
| 3951 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3952 | static const struct nla_policy |
| 3953 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3954 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3955 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3956 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3957 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3958 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3959 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3960 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3961 | }; |
| 3962 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3963 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3964 | struct mesh_config *cfg, |
| 3965 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3966 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3967 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3968 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3969 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3970 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3971 | do {\ |
| 3972 | if (table[attr_num]) {\ |
| 3973 | cfg->param = nla_fn(table[attr_num]); \ |
| 3974 | mask |= (1 << (attr_num - 1)); \ |
| 3975 | } \ |
| 3976 | } while (0);\ |
| 3977 | |
| 3978 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3979 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3980 | return -EINVAL; |
| 3981 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3982 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3983 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3984 | return -EINVAL; |
| 3985 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3986 | /* This makes sure that there aren't more than 32 mesh config |
| 3987 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3988 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3989 | |
| 3990 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3991 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3992 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3993 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3994 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3995 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3996 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3997 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3998 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3999 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4000 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4001 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4002 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4003 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4004 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4005 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4006 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4007 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4008 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4009 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4010 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4011 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4012 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4013 | nla_get_u8); |
| 4014 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask, |
| 4015 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4016 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4017 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4018 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4019 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4020 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4021 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4022 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4023 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4024 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4025 | nla_get_u16); |
| 4026 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask, |
| 4027 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4028 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4029 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4030 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4031 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4032 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4033 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4034 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4035 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4036 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
| 4037 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4038 | nla_get_u16); |
| 4039 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 4040 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 4041 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 4042 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4043 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4044 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4045 | dot11MeshGateAnnouncementProtocol, mask, |
| 4046 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4047 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4048 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4049 | mask, NL80211_MESHCONF_FORWARDING, |
| 4050 | nla_get_u8); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 4051 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4052 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4053 | nla_get_u32); |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4054 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4055 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4056 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4057 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
| 4058 | mask, |
| 4059 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4060 | nla_get_u32); |
| 4061 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, |
| 4062 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4063 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4064 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 4065 | dot11MeshHWMPconfirmationInterval, mask, |
| 4066 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4067 | nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4068 | if (mask_out) |
| 4069 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4070 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4071 | return 0; |
| 4072 | |
| 4073 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4074 | } |
| 4075 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4076 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4077 | struct mesh_setup *setup) |
| 4078 | { |
| 4079 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4080 | |
| 4081 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4082 | return -EINVAL; |
| 4083 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4084 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4085 | nl80211_mesh_setup_params_policy)) |
| 4086 | return -EINVAL; |
| 4087 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4088 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4089 | setup->sync_method = |
| 4090 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4091 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4092 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4093 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4094 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4095 | setup->path_sel_proto = |
| 4096 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4097 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4098 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4099 | |
| 4100 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4101 | setup->path_metric = |
| 4102 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4103 | IEEE80211_PATH_METRIC_VENDOR : |
| 4104 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4105 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4106 | |
| 4107 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4108 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4109 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4110 | if (!is_valid_ie_attr(ieattr)) |
| 4111 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4112 | setup->ie = nla_data(ieattr); |
| 4113 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4114 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4115 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4116 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4117 | |
| 4118 | return 0; |
| 4119 | } |
| 4120 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4121 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4122 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4123 | { |
| 4124 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4125 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4126 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4127 | struct mesh_config cfg; |
| 4128 | u32 mask; |
| 4129 | int err; |
| 4130 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4131 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4132 | return -EOPNOTSUPP; |
| 4133 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4134 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4135 | return -EOPNOTSUPP; |
| 4136 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4137 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4138 | if (err) |
| 4139 | return err; |
| 4140 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4141 | wdev_lock(wdev); |
| 4142 | if (!wdev->mesh_id_len) |
| 4143 | err = -ENOLINK; |
| 4144 | |
| 4145 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4146 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4147 | |
| 4148 | wdev_unlock(wdev); |
| 4149 | |
| 4150 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4151 | } |
| 4152 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4153 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4154 | { |
| 4155 | struct sk_buff *msg; |
| 4156 | void *hdr = NULL; |
| 4157 | struct nlattr *nl_reg_rules; |
| 4158 | unsigned int i; |
| 4159 | int err = -EINVAL; |
| 4160 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4161 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4162 | |
| 4163 | if (!cfg80211_regdomain) |
| 4164 | goto out; |
| 4165 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4166 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4167 | if (!msg) { |
| 4168 | err = -ENOBUFS; |
| 4169 | goto out; |
| 4170 | } |
| 4171 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4172 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4173 | NL80211_CMD_GET_REG); |
| 4174 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4175 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4176 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4177 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 4178 | cfg80211_regdomain->alpha2) || |
| 4179 | (cfg80211_regdomain->dfs_region && |
| 4180 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, |
| 4181 | cfg80211_regdomain->dfs_region))) |
| 4182 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4183 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4184 | if (reg_last_request_cell_base() && |
| 4185 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4186 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4187 | goto nla_put_failure; |
| 4188 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4189 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4190 | if (!nl_reg_rules) |
| 4191 | goto nla_put_failure; |
| 4192 | |
| 4193 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 4194 | struct nlattr *nl_reg_rule; |
| 4195 | const struct ieee80211_reg_rule *reg_rule; |
| 4196 | const struct ieee80211_freq_range *freq_range; |
| 4197 | const struct ieee80211_power_rule *power_rule; |
| 4198 | |
| 4199 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 4200 | freq_range = ®_rule->freq_range; |
| 4201 | power_rule = ®_rule->power_rule; |
| 4202 | |
| 4203 | nl_reg_rule = nla_nest_start(msg, i); |
| 4204 | if (!nl_reg_rule) |
| 4205 | goto nla_put_failure; |
| 4206 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4207 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4208 | reg_rule->flags) || |
| 4209 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4210 | freq_range->start_freq_khz) || |
| 4211 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4212 | freq_range->end_freq_khz) || |
| 4213 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4214 | freq_range->max_bandwidth_khz) || |
| 4215 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4216 | power_rule->max_antenna_gain) || |
| 4217 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4218 | power_rule->max_eirp)) |
| 4219 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4220 | |
| 4221 | nla_nest_end(msg, nl_reg_rule); |
| 4222 | } |
| 4223 | |
| 4224 | nla_nest_end(msg, nl_reg_rules); |
| 4225 | |
| 4226 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4227 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4228 | goto out; |
| 4229 | |
| 4230 | nla_put_failure: |
| 4231 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4232 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4233 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4234 | err = -EMSGSIZE; |
| 4235 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4236 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4237 | return err; |
| 4238 | } |
| 4239 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4240 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4241 | { |
| 4242 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4243 | struct nlattr *nl_reg_rule; |
| 4244 | char *alpha2 = NULL; |
| 4245 | int rem_reg_rules = 0, r = 0; |
| 4246 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4247 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4248 | struct ieee80211_regdomain *rd = NULL; |
| 4249 | |
| 4250 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4251 | return -EINVAL; |
| 4252 | |
| 4253 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4254 | return -EINVAL; |
| 4255 | |
| 4256 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4257 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4258 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4259 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4260 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4261 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4262 | rem_reg_rules) { |
| 4263 | num_rules++; |
| 4264 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4265 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4266 | } |
| 4267 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4268 | mutex_lock(&cfg80211_mutex); |
| 4269 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4270 | if (!reg_is_valid_request(alpha2)) { |
| 4271 | r = -EINVAL; |
| 4272 | goto bad_reg; |
| 4273 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4274 | |
| 4275 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 4276 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 4277 | |
| 4278 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4279 | if (!rd) { |
| 4280 | r = -ENOMEM; |
| 4281 | goto bad_reg; |
| 4282 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4283 | |
| 4284 | rd->n_reg_rules = num_rules; |
| 4285 | rd->alpha2[0] = alpha2[0]; |
| 4286 | rd->alpha2[1] = alpha2[1]; |
| 4287 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4288 | /* |
| 4289 | * Disable DFS master mode if the DFS region was |
| 4290 | * not supported or known on this kernel. |
| 4291 | */ |
| 4292 | if (reg_supported_dfs_region(dfs_region)) |
| 4293 | rd->dfs_region = dfs_region; |
| 4294 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4295 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4296 | rem_reg_rules) { |
| 4297 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 4298 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4299 | reg_rule_policy); |
| 4300 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4301 | if (r) |
| 4302 | goto bad_reg; |
| 4303 | |
| 4304 | rule_idx++; |
| 4305 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4306 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4307 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4308 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4309 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | BUG_ON(rule_idx != num_rules); |
| 4313 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4314 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4315 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4316 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4317 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4318 | return r; |
| 4319 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4320 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4321 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4322 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4323 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4324 | } |
| 4325 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4326 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4327 | { |
| 4328 | struct nlattr *attr1, *attr2; |
| 4329 | int n_channels = 0, tmp1, tmp2; |
| 4330 | |
| 4331 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4332 | n_channels++; |
| 4333 | /* |
| 4334 | * Some hardware has a limited channel list for |
| 4335 | * scanning, and it is pretty much nonsensical |
| 4336 | * to scan for a channel twice, so disallow that |
| 4337 | * and don't require drivers to check that the |
| 4338 | * channel list they get isn't longer than what |
| 4339 | * they can scan, as long as they can scan all |
| 4340 | * the channels they registered at once. |
| 4341 | */ |
| 4342 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4343 | if (attr1 != attr2 && |
| 4344 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4345 | return 0; |
| 4346 | } |
| 4347 | |
| 4348 | return n_channels; |
| 4349 | } |
| 4350 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4351 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4352 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4353 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4354 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4355 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4356 | struct nlattr *attr; |
| 4357 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4358 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4359 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4360 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4361 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4362 | return -EINVAL; |
| 4363 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4364 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4365 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4366 | if (!rdev->ops->scan) |
| 4367 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4368 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4369 | if (rdev->scan_req) |
| 4370 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4371 | |
| 4372 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4373 | n_channels = validate_scan_freqs( |
| 4374 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4375 | if (!n_channels) |
| 4376 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4377 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4378 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4379 | n_channels = 0; |
| 4380 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4381 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4382 | if (wiphy->bands[band]) |
| 4383 | n_channels += wiphy->bands[band]->n_channels; |
| 4384 | } |
| 4385 | |
| 4386 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4387 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4388 | n_ssids++; |
| 4389 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4390 | if (n_ssids > wiphy->max_scan_ssids) |
| 4391 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4392 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4393 | if (info->attrs[NL80211_ATTR_IE]) |
| 4394 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4395 | else |
| 4396 | ie_len = 0; |
| 4397 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4398 | if (ie_len > wiphy->max_scan_ie_len) |
| 4399 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4400 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4401 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4402 | + sizeof(*request->ssids) * n_ssids |
| 4403 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4404 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4405 | if (!request) |
| 4406 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4407 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4408 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4409 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4410 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4411 | if (ie_len) { |
| 4412 | if (request->ssids) |
| 4413 | request->ie = (void *)(request->ssids + n_ssids); |
| 4414 | else |
| 4415 | request->ie = (void *)(request->channels + n_channels); |
| 4416 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4417 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4418 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4419 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4420 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4421 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4422 | struct ieee80211_channel *chan; |
| 4423 | |
| 4424 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4425 | |
| 4426 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4427 | err = -EINVAL; |
| 4428 | goto out_free; |
| 4429 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4430 | |
| 4431 | /* ignore disabled channels */ |
| 4432 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4433 | continue; |
| 4434 | |
| 4435 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4436 | i++; |
| 4437 | } |
| 4438 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4439 | enum ieee80211_band band; |
| 4440 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4441 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4442 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4443 | int j; |
| 4444 | if (!wiphy->bands[band]) |
| 4445 | continue; |
| 4446 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4447 | struct ieee80211_channel *chan; |
| 4448 | |
| 4449 | chan = &wiphy->bands[band]->channels[j]; |
| 4450 | |
| 4451 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4452 | continue; |
| 4453 | |
| 4454 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4455 | i++; |
| 4456 | } |
| 4457 | } |
| 4458 | } |
| 4459 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4460 | if (!i) { |
| 4461 | err = -EINVAL; |
| 4462 | goto out_free; |
| 4463 | } |
| 4464 | |
| 4465 | request->n_channels = i; |
| 4466 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4467 | i = 0; |
| 4468 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4469 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4470 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4471 | err = -EINVAL; |
| 4472 | goto out_free; |
| 4473 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4474 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4475 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4476 | i++; |
| 4477 | } |
| 4478 | } |
| 4479 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4480 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4481 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4482 | memcpy((void *)request->ie, |
| 4483 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4484 | request->ie_len); |
| 4485 | } |
| 4486 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4487 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4488 | if (wiphy->bands[i]) |
| 4489 | request->rates[i] = |
| 4490 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4491 | |
| 4492 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4493 | nla_for_each_nested(attr, |
| 4494 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4495 | tmp) { |
| 4496 | enum ieee80211_band band = nla_type(attr); |
| 4497 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4498 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4499 | err = -EINVAL; |
| 4500 | goto out_free; |
| 4501 | } |
| 4502 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4503 | nla_data(attr), |
| 4504 | nla_len(attr), |
| 4505 | &request->rates[band]); |
| 4506 | if (err) |
| 4507 | goto out_free; |
| 4508 | } |
| 4509 | } |
| 4510 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4511 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4512 | request->flags = nla_get_u32( |
| 4513 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4514 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4515 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4516 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4517 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4518 | err = -EOPNOTSUPP; |
| 4519 | goto out_free; |
| 4520 | } |
| 4521 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4522 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4523 | request->no_cck = |
| 4524 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4525 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4526 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4527 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4528 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4529 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4530 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4531 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4532 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4533 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4534 | nl80211_send_scan_start(rdev, wdev); |
| 4535 | if (wdev->netdev) |
| 4536 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4537 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4538 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4539 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4540 | kfree(request); |
| 4541 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4542 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4543 | return err; |
| 4544 | } |
| 4545 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4546 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4547 | struct genl_info *info) |
| 4548 | { |
| 4549 | struct cfg80211_sched_scan_request *request; |
| 4550 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4551 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4552 | struct nlattr *attr; |
| 4553 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4554 | 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] | 4555 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4556 | enum ieee80211_band band; |
| 4557 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4558 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4559 | |
| 4560 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4561 | !rdev->ops->sched_scan_start) |
| 4562 | return -EOPNOTSUPP; |
| 4563 | |
| 4564 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4565 | return -EINVAL; |
| 4566 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4567 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4568 | return -EINVAL; |
| 4569 | |
| 4570 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4571 | if (interval == 0) |
| 4572 | return -EINVAL; |
| 4573 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4574 | wiphy = &rdev->wiphy; |
| 4575 | |
| 4576 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4577 | n_channels = validate_scan_freqs( |
| 4578 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4579 | if (!n_channels) |
| 4580 | return -EINVAL; |
| 4581 | } else { |
| 4582 | n_channels = 0; |
| 4583 | |
| 4584 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4585 | if (wiphy->bands[band]) |
| 4586 | n_channels += wiphy->bands[band]->n_channels; |
| 4587 | } |
| 4588 | |
| 4589 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4590 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4591 | tmp) |
| 4592 | n_ssids++; |
| 4593 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4594 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4595 | return -EINVAL; |
| 4596 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4597 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4598 | nla_for_each_nested(attr, |
| 4599 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4600 | tmp) |
| 4601 | n_match_sets++; |
| 4602 | |
| 4603 | if (n_match_sets > wiphy->max_match_sets) |
| 4604 | return -EINVAL; |
| 4605 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4606 | if (info->attrs[NL80211_ATTR_IE]) |
| 4607 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4608 | else |
| 4609 | ie_len = 0; |
| 4610 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4611 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4612 | return -EINVAL; |
| 4613 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4614 | mutex_lock(&rdev->sched_scan_mtx); |
| 4615 | |
| 4616 | if (rdev->sched_scan_req) { |
| 4617 | err = -EINPROGRESS; |
| 4618 | goto out; |
| 4619 | } |
| 4620 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4621 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4622 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4623 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4624 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4625 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4626 | if (!request) { |
| 4627 | err = -ENOMEM; |
| 4628 | goto out; |
| 4629 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4630 | |
| 4631 | if (n_ssids) |
| 4632 | request->ssids = (void *)&request->channels[n_channels]; |
| 4633 | request->n_ssids = n_ssids; |
| 4634 | if (ie_len) { |
| 4635 | if (request->ssids) |
| 4636 | request->ie = (void *)(request->ssids + n_ssids); |
| 4637 | else |
| 4638 | request->ie = (void *)(request->channels + n_channels); |
| 4639 | } |
| 4640 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4641 | if (n_match_sets) { |
| 4642 | if (request->ie) |
| 4643 | request->match_sets = (void *)(request->ie + ie_len); |
| 4644 | else if (request->ssids) |
| 4645 | request->match_sets = |
| 4646 | (void *)(request->ssids + n_ssids); |
| 4647 | else |
| 4648 | request->match_sets = |
| 4649 | (void *)(request->channels + n_channels); |
| 4650 | } |
| 4651 | request->n_match_sets = n_match_sets; |
| 4652 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4653 | i = 0; |
| 4654 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4655 | /* user specified, bail out if channel not found */ |
| 4656 | nla_for_each_nested(attr, |
| 4657 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4658 | tmp) { |
| 4659 | struct ieee80211_channel *chan; |
| 4660 | |
| 4661 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4662 | |
| 4663 | if (!chan) { |
| 4664 | err = -EINVAL; |
| 4665 | goto out_free; |
| 4666 | } |
| 4667 | |
| 4668 | /* ignore disabled channels */ |
| 4669 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4670 | continue; |
| 4671 | |
| 4672 | request->channels[i] = chan; |
| 4673 | i++; |
| 4674 | } |
| 4675 | } else { |
| 4676 | /* all channels */ |
| 4677 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4678 | int j; |
| 4679 | if (!wiphy->bands[band]) |
| 4680 | continue; |
| 4681 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4682 | struct ieee80211_channel *chan; |
| 4683 | |
| 4684 | chan = &wiphy->bands[band]->channels[j]; |
| 4685 | |
| 4686 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4687 | continue; |
| 4688 | |
| 4689 | request->channels[i] = chan; |
| 4690 | i++; |
| 4691 | } |
| 4692 | } |
| 4693 | } |
| 4694 | |
| 4695 | if (!i) { |
| 4696 | err = -EINVAL; |
| 4697 | goto out_free; |
| 4698 | } |
| 4699 | |
| 4700 | request->n_channels = i; |
| 4701 | |
| 4702 | i = 0; |
| 4703 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4704 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4705 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4706 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4707 | err = -EINVAL; |
| 4708 | goto out_free; |
| 4709 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4710 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4711 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4712 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4713 | i++; |
| 4714 | } |
| 4715 | } |
| 4716 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4717 | i = 0; |
| 4718 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4719 | nla_for_each_nested(attr, |
| 4720 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4721 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4722 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4723 | |
| 4724 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4725 | nla_data(attr), nla_len(attr), |
| 4726 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 4727 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4728 | if (ssid) { |
| 4729 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4730 | err = -EINVAL; |
| 4731 | goto out_free; |
| 4732 | } |
| 4733 | memcpy(request->match_sets[i].ssid.ssid, |
| 4734 | nla_data(ssid), nla_len(ssid)); |
| 4735 | request->match_sets[i].ssid.ssid_len = |
| 4736 | nla_len(ssid); |
| 4737 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4738 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 4739 | if (rssi) |
| 4740 | request->rssi_thold = nla_get_u32(rssi); |
| 4741 | else |
| 4742 | request->rssi_thold = |
| 4743 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4744 | i++; |
| 4745 | } |
| 4746 | } |
| 4747 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4748 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4749 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4750 | memcpy((void *)request->ie, |
| 4751 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4752 | request->ie_len); |
| 4753 | } |
| 4754 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4755 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4756 | request->flags = nla_get_u32( |
| 4757 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4758 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4759 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4760 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4761 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4762 | err = -EOPNOTSUPP; |
| 4763 | goto out_free; |
| 4764 | } |
| 4765 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4766 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4767 | request->dev = dev; |
| 4768 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4769 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4770 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4771 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4772 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4773 | if (!err) { |
| 4774 | rdev->sched_scan_req = request; |
| 4775 | nl80211_send_sched_scan(rdev, dev, |
| 4776 | NL80211_CMD_START_SCHED_SCAN); |
| 4777 | goto out; |
| 4778 | } |
| 4779 | |
| 4780 | out_free: |
| 4781 | kfree(request); |
| 4782 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4783 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4784 | return err; |
| 4785 | } |
| 4786 | |
| 4787 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4788 | struct genl_info *info) |
| 4789 | { |
| 4790 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4791 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4792 | |
| 4793 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4794 | !rdev->ops->sched_scan_stop) |
| 4795 | return -EOPNOTSUPP; |
| 4796 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4797 | mutex_lock(&rdev->sched_scan_mtx); |
| 4798 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4799 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4800 | |
| 4801 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4802 | } |
| 4803 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4804 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4805 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4806 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4807 | struct wireless_dev *wdev, |
| 4808 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4809 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4810 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4811 | void *hdr; |
| 4812 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4813 | |
| 4814 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4815 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4816 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4817 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4818 | if (!hdr) |
| 4819 | return -1; |
| 4820 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4821 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4822 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4823 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 4824 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 4825 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4826 | |
| 4827 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4828 | if (!bss) |
| 4829 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4830 | if ((!is_zero_ether_addr(res->bssid) && |
| 4831 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) || |
| 4832 | (res->information_elements && res->len_information_elements && |
| 4833 | nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4834 | res->len_information_elements, |
| 4835 | res->information_elements)) || |
| 4836 | (res->beacon_ies && res->len_beacon_ies && |
| 4837 | res->beacon_ies != res->information_elements && |
| 4838 | nla_put(msg, NL80211_BSS_BEACON_IES, |
| 4839 | res->len_beacon_ies, res->beacon_ies))) |
| 4840 | goto nla_put_failure; |
| 4841 | if (res->tsf && |
| 4842 | nla_put_u64(msg, NL80211_BSS_TSF, res->tsf)) |
| 4843 | goto nla_put_failure; |
| 4844 | if (res->beacon_interval && |
| 4845 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 4846 | goto nla_put_failure; |
| 4847 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 4848 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 4849 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4850 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 4851 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4852 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4853 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4854 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4855 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 4856 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4857 | break; |
| 4858 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4859 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 4860 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4861 | break; |
| 4862 | default: |
| 4863 | break; |
| 4864 | } |
| 4865 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4866 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4867 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4868 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4869 | if (intbss == wdev->current_bss && |
| 4870 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4871 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 4872 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4873 | break; |
| 4874 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4875 | if (intbss == wdev->current_bss && |
| 4876 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4877 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 4878 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4879 | break; |
| 4880 | default: |
| 4881 | break; |
| 4882 | } |
| 4883 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4884 | nla_nest_end(msg, bss); |
| 4885 | |
| 4886 | return genlmsg_end(msg, hdr); |
| 4887 | |
| 4888 | nla_put_failure: |
| 4889 | genlmsg_cancel(msg, hdr); |
| 4890 | return -EMSGSIZE; |
| 4891 | } |
| 4892 | |
| 4893 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4894 | struct netlink_callback *cb) |
| 4895 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4896 | struct cfg80211_registered_device *rdev; |
| 4897 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4898 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4899 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4900 | int start = cb->args[1], idx = 0; |
| 4901 | int err; |
| 4902 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4903 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4904 | if (err) |
| 4905 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4906 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4907 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4908 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4909 | wdev_lock(wdev); |
| 4910 | spin_lock_bh(&rdev->bss_lock); |
| 4911 | cfg80211_bss_expire(rdev); |
| 4912 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4913 | cb->seq = rdev->bss_generation; |
| 4914 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4915 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4916 | if (++idx <= start) |
| 4917 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4918 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4919 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4920 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4921 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4922 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4923 | } |
| 4924 | } |
| 4925 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4926 | spin_unlock_bh(&rdev->bss_lock); |
| 4927 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4928 | |
| 4929 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4930 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4931 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4932 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4933 | } |
| 4934 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4935 | 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] | 4936 | int flags, struct net_device *dev, |
| 4937 | struct survey_info *survey) |
| 4938 | { |
| 4939 | void *hdr; |
| 4940 | struct nlattr *infoattr; |
| 4941 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4942 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4943 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4944 | if (!hdr) |
| 4945 | return -ENOMEM; |
| 4946 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4947 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 4948 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4949 | |
| 4950 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4951 | if (!infoattr) |
| 4952 | goto nla_put_failure; |
| 4953 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4954 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4955 | survey->channel->center_freq)) |
| 4956 | goto nla_put_failure; |
| 4957 | |
| 4958 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 4959 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 4960 | goto nla_put_failure; |
| 4961 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 4962 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 4963 | goto nla_put_failure; |
| 4964 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 4965 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4966 | survey->channel_time)) |
| 4967 | goto nla_put_failure; |
| 4968 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 4969 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4970 | survey->channel_time_busy)) |
| 4971 | goto nla_put_failure; |
| 4972 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 4973 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4974 | survey->channel_time_ext_busy)) |
| 4975 | goto nla_put_failure; |
| 4976 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 4977 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4978 | survey->channel_time_rx)) |
| 4979 | goto nla_put_failure; |
| 4980 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 4981 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4982 | survey->channel_time_tx)) |
| 4983 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4984 | |
| 4985 | nla_nest_end(msg, infoattr); |
| 4986 | |
| 4987 | return genlmsg_end(msg, hdr); |
| 4988 | |
| 4989 | nla_put_failure: |
| 4990 | genlmsg_cancel(msg, hdr); |
| 4991 | return -EMSGSIZE; |
| 4992 | } |
| 4993 | |
| 4994 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4995 | struct netlink_callback *cb) |
| 4996 | { |
| 4997 | struct survey_info survey; |
| 4998 | struct cfg80211_registered_device *dev; |
| 4999 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5000 | int survey_idx = cb->args[1]; |
| 5001 | int res; |
| 5002 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5003 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 5004 | if (res) |
| 5005 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5006 | |
| 5007 | if (!dev->ops->dump_survey) { |
| 5008 | res = -EOPNOTSUPP; |
| 5009 | goto out_err; |
| 5010 | } |
| 5011 | |
| 5012 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5013 | struct ieee80211_channel *chan; |
| 5014 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5015 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5016 | if (res == -ENOENT) |
| 5017 | break; |
| 5018 | if (res) |
| 5019 | goto out_err; |
| 5020 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5021 | /* Survey without a channel doesn't make sense */ |
| 5022 | if (!survey.channel) { |
| 5023 | res = -EINVAL; |
| 5024 | goto out; |
| 5025 | } |
| 5026 | |
| 5027 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5028 | survey.channel->center_freq); |
| 5029 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5030 | survey_idx++; |
| 5031 | continue; |
| 5032 | } |
| 5033 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5034 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5035 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5036 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5037 | netdev, |
| 5038 | &survey) < 0) |
| 5039 | goto out; |
| 5040 | survey_idx++; |
| 5041 | } |
| 5042 | |
| 5043 | out: |
| 5044 | cb->args[1] = survey_idx; |
| 5045 | res = skb->len; |
| 5046 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5047 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5048 | return res; |
| 5049 | } |
| 5050 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5051 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5052 | { |
| 5053 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5054 | NL80211_WPA_VERSION_2)); |
| 5055 | } |
| 5056 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5057 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5058 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5059 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5060 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5061 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5062 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5063 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5064 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5065 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5066 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5067 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5068 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5069 | return -EINVAL; |
| 5070 | |
| 5071 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5072 | return -EINVAL; |
| 5073 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5074 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5075 | return -EINVAL; |
| 5076 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5077 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5078 | return -EINVAL; |
| 5079 | |
| 5080 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5081 | return -EINVAL; |
| 5082 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5083 | err = nl80211_parse_key(info, &key); |
| 5084 | if (err) |
| 5085 | return err; |
| 5086 | |
| 5087 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5088 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5089 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5090 | if (!key.p.key || !key.p.key_len) |
| 5091 | return -EINVAL; |
| 5092 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5093 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5094 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5095 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5096 | return -EINVAL; |
| 5097 | if (key.idx > 4) |
| 5098 | return -EINVAL; |
| 5099 | } else { |
| 5100 | key.p.key_len = 0; |
| 5101 | key.p.key = NULL; |
| 5102 | } |
| 5103 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5104 | if (key.idx >= 0) { |
| 5105 | int i; |
| 5106 | bool ok = false; |
| 5107 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5108 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5109 | ok = true; |
| 5110 | break; |
| 5111 | } |
| 5112 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5113 | if (!ok) |
| 5114 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5115 | } |
| 5116 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5117 | if (!rdev->ops->auth) |
| 5118 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5119 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5120 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5121 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5122 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5123 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5124 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5125 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5126 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5127 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5128 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5129 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5130 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5131 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5132 | |
| 5133 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5134 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5135 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5136 | } |
| 5137 | |
| 5138 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5139 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5140 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5141 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5142 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5143 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5144 | return -EINVAL; |
| 5145 | |
| 5146 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5147 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5148 | return -EINVAL; |
| 5149 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5150 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5151 | /* need to include at least Auth Transaction and Status Code */ |
| 5152 | if (sae_data_len < 4) |
| 5153 | return -EINVAL; |
| 5154 | } |
| 5155 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5156 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5157 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5158 | /* |
| 5159 | * Since we no longer track auth state, ignore |
| 5160 | * requests to only change local state. |
| 5161 | */ |
| 5162 | if (local_state_change) |
| 5163 | return 0; |
| 5164 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5165 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5166 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5167 | key.p.key, key.p.key_len, key.idx, |
| 5168 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5169 | } |
| 5170 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5171 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5172 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5173 | struct cfg80211_crypto_settings *settings, |
| 5174 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5175 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5176 | memset(settings, 0, sizeof(*settings)); |
| 5177 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5178 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5179 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5180 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5181 | u16 proto; |
| 5182 | proto = nla_get_u16( |
| 5183 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5184 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5185 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5186 | proto != ETH_P_PAE) |
| 5187 | return -EINVAL; |
| 5188 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5189 | settings->control_port_no_encrypt = true; |
| 5190 | } else |
| 5191 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5192 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5193 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5194 | void *data; |
| 5195 | int len, i; |
| 5196 | |
| 5197 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5198 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5199 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5200 | |
| 5201 | if (len % sizeof(u32)) |
| 5202 | return -EINVAL; |
| 5203 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5204 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5205 | return -EINVAL; |
| 5206 | |
| 5207 | memcpy(settings->ciphers_pairwise, data, len); |
| 5208 | |
| 5209 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5210 | if (!cfg80211_supported_cipher_suite( |
| 5211 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5212 | settings->ciphers_pairwise[i])) |
| 5213 | return -EINVAL; |
| 5214 | } |
| 5215 | |
| 5216 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5217 | settings->cipher_group = |
| 5218 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5219 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5220 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5221 | return -EINVAL; |
| 5222 | } |
| 5223 | |
| 5224 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5225 | settings->wpa_versions = |
| 5226 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5227 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5228 | return -EINVAL; |
| 5229 | } |
| 5230 | |
| 5231 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5232 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5233 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5234 | |
| 5235 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5236 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5237 | settings->n_akm_suites = len / sizeof(u32); |
| 5238 | |
| 5239 | if (len % sizeof(u32)) |
| 5240 | return -EINVAL; |
| 5241 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5242 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5243 | return -EINVAL; |
| 5244 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5245 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | return 0; |
| 5249 | } |
| 5250 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5251 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5252 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5253 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5254 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5255 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5256 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5257 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5258 | int err, ssid_len, ie_len = 0; |
| 5259 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5260 | u32 flags = 0; |
| 5261 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5262 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5263 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5264 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5265 | return -EINVAL; |
| 5266 | |
| 5267 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5268 | !info->attrs[NL80211_ATTR_SSID] || |
| 5269 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5270 | return -EINVAL; |
| 5271 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5272 | if (!rdev->ops->assoc) |
| 5273 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5274 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5275 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5276 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5277 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5278 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5279 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5280 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5281 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5282 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5283 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5284 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5285 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5286 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5287 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5288 | |
| 5289 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5290 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5291 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5292 | } |
| 5293 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5294 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5295 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5296 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5297 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5298 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5299 | else if (mfp != NL80211_MFP_NO) |
| 5300 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5301 | } |
| 5302 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5303 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5304 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5305 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5306 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5307 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5308 | |
| 5309 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5310 | ht_capa_mask = |
| 5311 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5312 | |
| 5313 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5314 | if (!ht_capa_mask) |
| 5315 | return -EINVAL; |
| 5316 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5317 | } |
| 5318 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5319 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5320 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5321 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5322 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5323 | &crypto, flags, ht_capa, |
| 5324 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5325 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5326 | return err; |
| 5327 | } |
| 5328 | |
| 5329 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5330 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5331 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5332 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5333 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5334 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5335 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5336 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5337 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5338 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5339 | return -EINVAL; |
| 5340 | |
| 5341 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5342 | return -EINVAL; |
| 5343 | |
| 5344 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5345 | return -EINVAL; |
| 5346 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5347 | if (!rdev->ops->deauth) |
| 5348 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5349 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5350 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5351 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5352 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5353 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5354 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5355 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5356 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5357 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5358 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5359 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5360 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5361 | |
| 5362 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5363 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5364 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5365 | } |
| 5366 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5367 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5368 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5369 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5370 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5371 | } |
| 5372 | |
| 5373 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5374 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5375 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5376 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5377 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5378 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5379 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5380 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5381 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5382 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5383 | return -EINVAL; |
| 5384 | |
| 5385 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5386 | return -EINVAL; |
| 5387 | |
| 5388 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5389 | return -EINVAL; |
| 5390 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5391 | if (!rdev->ops->disassoc) |
| 5392 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5393 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5394 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5395 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5396 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5397 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5398 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5399 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5400 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5401 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5402 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5403 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5404 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5405 | |
| 5406 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5407 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5408 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5409 | } |
| 5410 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5411 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5412 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5413 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5414 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5415 | } |
| 5416 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5417 | static bool |
| 5418 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5419 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5420 | int rateval) |
| 5421 | { |
| 5422 | struct wiphy *wiphy = &rdev->wiphy; |
| 5423 | bool found = false; |
| 5424 | int band, i; |
| 5425 | |
| 5426 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5427 | struct ieee80211_supported_band *sband; |
| 5428 | |
| 5429 | sband = wiphy->bands[band]; |
| 5430 | if (!sband) |
| 5431 | continue; |
| 5432 | |
| 5433 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5434 | if (sband->bitrates[i].bitrate == rateval) { |
| 5435 | mcast_rate[band] = i + 1; |
| 5436 | found = true; |
| 5437 | break; |
| 5438 | } |
| 5439 | } |
| 5440 | } |
| 5441 | |
| 5442 | return found; |
| 5443 | } |
| 5444 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5445 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5446 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5447 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5448 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5449 | struct cfg80211_ibss_params ibss; |
| 5450 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5451 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5452 | int err; |
| 5453 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5454 | memset(&ibss, 0, sizeof(ibss)); |
| 5455 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5456 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5457 | return -EINVAL; |
| 5458 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5459 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5460 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5461 | return -EINVAL; |
| 5462 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5463 | ibss.beacon_interval = 100; |
| 5464 | |
| 5465 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5466 | ibss.beacon_interval = |
| 5467 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5468 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5469 | return -EINVAL; |
| 5470 | } |
| 5471 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5472 | if (!rdev->ops->join_ibss) |
| 5473 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5474 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5475 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5476 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5477 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5478 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5479 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5480 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5481 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5482 | |
| 5483 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5484 | return -EINVAL; |
| 5485 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5486 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5487 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5488 | |
| 5489 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5490 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5491 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5492 | } |
| 5493 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5494 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 5495 | if (err) |
| 5496 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5497 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5498 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5499 | return -EINVAL; |
| 5500 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5501 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 5502 | return -EINVAL; |
| 5503 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 5504 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 5505 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5506 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5507 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5508 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5509 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5510 | u8 *rates = |
| 5511 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5512 | int n_rates = |
| 5513 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5514 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5515 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5516 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5517 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5518 | &ibss.basic_rates); |
| 5519 | if (err) |
| 5520 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5521 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5522 | |
| 5523 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5524 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5525 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5526 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5527 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5528 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5529 | bool no_ht = false; |
| 5530 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5531 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5532 | info->attrs[NL80211_ATTR_KEYS], |
| 5533 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5534 | if (IS_ERR(connkeys)) |
| 5535 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5536 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 5537 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 5538 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5539 | kfree(connkeys); |
| 5540 | return -EINVAL; |
| 5541 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5542 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5543 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5544 | ibss.control_port = |
| 5545 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5546 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5547 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5548 | if (err) |
| 5549 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5550 | return err; |
| 5551 | } |
| 5552 | |
| 5553 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5554 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5555 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5556 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5557 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5558 | if (!rdev->ops->leave_ibss) |
| 5559 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5560 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5561 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5562 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5563 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5564 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5565 | } |
| 5566 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 5567 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 5568 | { |
| 5569 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5570 | struct net_device *dev = info->user_ptr[1]; |
| 5571 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 5572 | u32 nla_rate; |
| 5573 | int err; |
| 5574 | |
| 5575 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5576 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5577 | return -EOPNOTSUPP; |
| 5578 | |
| 5579 | if (!rdev->ops->set_mcast_rate) |
| 5580 | return -EOPNOTSUPP; |
| 5581 | |
| 5582 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 5583 | |
| 5584 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 5585 | return -EINVAL; |
| 5586 | |
| 5587 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 5588 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 5589 | return -EINVAL; |
| 5590 | |
| 5591 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 5592 | |
| 5593 | return err; |
| 5594 | } |
| 5595 | |
| 5596 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5597 | #ifdef CONFIG_NL80211_TESTMODE |
| 5598 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5599 | .name = "testmode", |
| 5600 | }; |
| 5601 | |
| 5602 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5603 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5604 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5605 | int err; |
| 5606 | |
| 5607 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5608 | return -EINVAL; |
| 5609 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5610 | err = -EOPNOTSUPP; |
| 5611 | if (rdev->ops->testmode_cmd) { |
| 5612 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5613 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5614 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5615 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5616 | rdev->testmode_info = NULL; |
| 5617 | } |
| 5618 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5619 | return err; |
| 5620 | } |
| 5621 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5622 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5623 | struct netlink_callback *cb) |
| 5624 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5625 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5626 | int err; |
| 5627 | long phy_idx; |
| 5628 | void *data = NULL; |
| 5629 | int data_len = 0; |
| 5630 | |
| 5631 | if (cb->args[0]) { |
| 5632 | /* |
| 5633 | * 0 is a valid index, but not valid for args[0], |
| 5634 | * so we need to offset by 1. |
| 5635 | */ |
| 5636 | phy_idx = cb->args[0] - 1; |
| 5637 | } else { |
| 5638 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5639 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5640 | nl80211_policy); |
| 5641 | if (err) |
| 5642 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5643 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5644 | mutex_lock(&cfg80211_mutex); |
| 5645 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 5646 | nl80211_fam.attrbuf); |
| 5647 | if (IS_ERR(rdev)) { |
| 5648 | mutex_unlock(&cfg80211_mutex); |
| 5649 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5650 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5651 | phy_idx = rdev->wiphy_idx; |
| 5652 | rdev = NULL; |
| 5653 | mutex_unlock(&cfg80211_mutex); |
| 5654 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5655 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 5656 | cb->args[1] = |
| 5657 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 5658 | } |
| 5659 | |
| 5660 | if (cb->args[1]) { |
| 5661 | data = nla_data((void *)cb->args[1]); |
| 5662 | data_len = nla_len((void *)cb->args[1]); |
| 5663 | } |
| 5664 | |
| 5665 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5666 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 5667 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5668 | mutex_unlock(&cfg80211_mutex); |
| 5669 | return -ENOENT; |
| 5670 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5671 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5672 | mutex_unlock(&cfg80211_mutex); |
| 5673 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5674 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5675 | err = -EOPNOTSUPP; |
| 5676 | goto out_err; |
| 5677 | } |
| 5678 | |
| 5679 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5680 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5681 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5682 | NL80211_CMD_TESTMODE); |
| 5683 | struct nlattr *tmdata; |
| 5684 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5685 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5686 | genlmsg_cancel(skb, hdr); |
| 5687 | break; |
| 5688 | } |
| 5689 | |
| 5690 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5691 | if (!tmdata) { |
| 5692 | genlmsg_cancel(skb, hdr); |
| 5693 | break; |
| 5694 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5695 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5696 | nla_nest_end(skb, tmdata); |
| 5697 | |
| 5698 | if (err == -ENOBUFS || err == -ENOENT) { |
| 5699 | genlmsg_cancel(skb, hdr); |
| 5700 | break; |
| 5701 | } else if (err) { |
| 5702 | genlmsg_cancel(skb, hdr); |
| 5703 | goto out_err; |
| 5704 | } |
| 5705 | |
| 5706 | genlmsg_end(skb, hdr); |
| 5707 | } |
| 5708 | |
| 5709 | err = skb->len; |
| 5710 | /* see above */ |
| 5711 | cb->args[0] = phy_idx + 1; |
| 5712 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5713 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5714 | return err; |
| 5715 | } |
| 5716 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5717 | static struct sk_buff * |
| 5718 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5719 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5720 | { |
| 5721 | struct sk_buff *skb; |
| 5722 | void *hdr; |
| 5723 | struct nlattr *data; |
| 5724 | |
| 5725 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5726 | if (!skb) |
| 5727 | return NULL; |
| 5728 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5729 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5730 | if (!hdr) { |
| 5731 | kfree_skb(skb); |
| 5732 | return NULL; |
| 5733 | } |
| 5734 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5735 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 5736 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5737 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5738 | |
| 5739 | ((void **)skb->cb)[0] = rdev; |
| 5740 | ((void **)skb->cb)[1] = hdr; |
| 5741 | ((void **)skb->cb)[2] = data; |
| 5742 | |
| 5743 | return skb; |
| 5744 | |
| 5745 | nla_put_failure: |
| 5746 | kfree_skb(skb); |
| 5747 | return NULL; |
| 5748 | } |
| 5749 | |
| 5750 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5751 | int approxlen) |
| 5752 | { |
| 5753 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5754 | |
| 5755 | if (WARN_ON(!rdev->testmode_info)) |
| 5756 | return NULL; |
| 5757 | |
| 5758 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5759 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5760 | rdev->testmode_info->snd_seq, |
| 5761 | GFP_KERNEL); |
| 5762 | } |
| 5763 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5764 | |
| 5765 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5766 | { |
| 5767 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5768 | void *hdr = ((void **)skb->cb)[1]; |
| 5769 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5770 | |
| 5771 | if (WARN_ON(!rdev->testmode_info)) { |
| 5772 | kfree_skb(skb); |
| 5773 | return -EINVAL; |
| 5774 | } |
| 5775 | |
| 5776 | nla_nest_end(skb, data); |
| 5777 | genlmsg_end(skb, hdr); |
| 5778 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5779 | } |
| 5780 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5781 | |
| 5782 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5783 | int approxlen, gfp_t gfp) |
| 5784 | { |
| 5785 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5786 | |
| 5787 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5788 | } |
| 5789 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5790 | |
| 5791 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5792 | { |
| 5793 | void *hdr = ((void **)skb->cb)[1]; |
| 5794 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5795 | |
| 5796 | nla_nest_end(skb, data); |
| 5797 | genlmsg_end(skb, hdr); |
| 5798 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5799 | } |
| 5800 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5801 | #endif |
| 5802 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5803 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5804 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5805 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5806 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5807 | struct cfg80211_connect_params connect; |
| 5808 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5809 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5810 | int err; |
| 5811 | |
| 5812 | memset(&connect, 0, sizeof(connect)); |
| 5813 | |
| 5814 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5815 | return -EINVAL; |
| 5816 | |
| 5817 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5818 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5819 | return -EINVAL; |
| 5820 | |
| 5821 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5822 | connect.auth_type = |
| 5823 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5824 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 5825 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5826 | return -EINVAL; |
| 5827 | } else |
| 5828 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5829 | |
| 5830 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5831 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5832 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5833 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5834 | if (err) |
| 5835 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5836 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5837 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5838 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5839 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5840 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5841 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5842 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 5843 | connect.bg_scan_period = -1; |
| 5844 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 5845 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 5846 | connect.bg_scan_period = |
| 5847 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 5848 | } |
| 5849 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5850 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5851 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5852 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5853 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5854 | |
| 5855 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5856 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5857 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5858 | } |
| 5859 | |
| 5860 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5861 | connect.channel = |
| 5862 | ieee80211_get_channel(wiphy, |
| 5863 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5864 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5865 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5866 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5867 | } |
| 5868 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5869 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5870 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5871 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5872 | if (IS_ERR(connkeys)) |
| 5873 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5874 | } |
| 5875 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5876 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5877 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5878 | |
| 5879 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5880 | memcpy(&connect.ht_capa_mask, |
| 5881 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5882 | sizeof(connect.ht_capa_mask)); |
| 5883 | |
| 5884 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5885 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 5886 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5887 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5888 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5889 | memcpy(&connect.ht_capa, |
| 5890 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5891 | sizeof(connect.ht_capa)); |
| 5892 | } |
| 5893 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5894 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5895 | if (err) |
| 5896 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5897 | return err; |
| 5898 | } |
| 5899 | |
| 5900 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5901 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5903 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5904 | u16 reason; |
| 5905 | |
| 5906 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5907 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5908 | else |
| 5909 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5910 | |
| 5911 | if (reason == 0) |
| 5912 | return -EINVAL; |
| 5913 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5914 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5915 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5916 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5917 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5918 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5919 | } |
| 5920 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5921 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5922 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5923 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5924 | struct net *net; |
| 5925 | int err; |
| 5926 | u32 pid; |
| 5927 | |
| 5928 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5929 | return -EINVAL; |
| 5930 | |
| 5931 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5932 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5933 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5934 | if (IS_ERR(net)) |
| 5935 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5936 | |
| 5937 | err = 0; |
| 5938 | |
| 5939 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5940 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5941 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5942 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5943 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5944 | return err; |
| 5945 | } |
| 5946 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5947 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5948 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5949 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5950 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5951 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5952 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5953 | struct cfg80211_pmksa pmksa; |
| 5954 | |
| 5955 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5956 | |
| 5957 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5958 | return -EINVAL; |
| 5959 | |
| 5960 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5961 | return -EINVAL; |
| 5962 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5963 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5964 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5965 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5966 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5967 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5968 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5969 | |
| 5970 | switch (info->genlhdr->cmd) { |
| 5971 | case NL80211_CMD_SET_PMKSA: |
| 5972 | rdev_ops = rdev->ops->set_pmksa; |
| 5973 | break; |
| 5974 | case NL80211_CMD_DEL_PMKSA: |
| 5975 | rdev_ops = rdev->ops->del_pmksa; |
| 5976 | break; |
| 5977 | default: |
| 5978 | WARN_ON(1); |
| 5979 | break; |
| 5980 | } |
| 5981 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5982 | if (!rdev_ops) |
| 5983 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5984 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5985 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5989 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5990 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5991 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5992 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5993 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5994 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5995 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5996 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5997 | if (!rdev->ops->flush_pmksa) |
| 5998 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5999 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6000 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6001 | } |
| 6002 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6003 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6004 | { |
| 6005 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6006 | struct net_device *dev = info->user_ptr[1]; |
| 6007 | u8 action_code, dialog_token; |
| 6008 | u16 status_code; |
| 6009 | u8 *peer; |
| 6010 | |
| 6011 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6012 | !rdev->ops->tdls_mgmt) |
| 6013 | return -EOPNOTSUPP; |
| 6014 | |
| 6015 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6016 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6017 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6018 | !info->attrs[NL80211_ATTR_IE] || |
| 6019 | !info->attrs[NL80211_ATTR_MAC]) |
| 6020 | return -EINVAL; |
| 6021 | |
| 6022 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6023 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6024 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6025 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6026 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6027 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6028 | dialog_token, status_code, |
| 6029 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6030 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6031 | } |
| 6032 | |
| 6033 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6034 | { |
| 6035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6036 | struct net_device *dev = info->user_ptr[1]; |
| 6037 | enum nl80211_tdls_operation operation; |
| 6038 | u8 *peer; |
| 6039 | |
| 6040 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6041 | !rdev->ops->tdls_oper) |
| 6042 | return -EOPNOTSUPP; |
| 6043 | |
| 6044 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6045 | !info->attrs[NL80211_ATTR_MAC]) |
| 6046 | return -EINVAL; |
| 6047 | |
| 6048 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6049 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6050 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6051 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6052 | } |
| 6053 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6054 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6055 | struct genl_info *info) |
| 6056 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6057 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6058 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6059 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6060 | struct sk_buff *msg; |
| 6061 | void *hdr; |
| 6062 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6063 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6064 | int err; |
| 6065 | |
| 6066 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6067 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6068 | return -EINVAL; |
| 6069 | |
| 6070 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6071 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6072 | if (!rdev->ops->remain_on_channel || |
| 6073 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6074 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6075 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6076 | /* |
| 6077 | * We should be on that channel for at least a minimum amount of |
| 6078 | * time (10ms) but no longer than the driver supports. |
| 6079 | */ |
| 6080 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6081 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6082 | return -EINVAL; |
| 6083 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6084 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6085 | if (err) |
| 6086 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6087 | |
| 6088 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6089 | if (!msg) |
| 6090 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6091 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6092 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6093 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6094 | |
| 6095 | if (IS_ERR(hdr)) { |
| 6096 | err = PTR_ERR(hdr); |
| 6097 | goto free_msg; |
| 6098 | } |
| 6099 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6100 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6101 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6102 | |
| 6103 | if (err) |
| 6104 | goto free_msg; |
| 6105 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6106 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6107 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6108 | |
| 6109 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6110 | |
| 6111 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6112 | |
| 6113 | nla_put_failure: |
| 6114 | err = -ENOBUFS; |
| 6115 | free_msg: |
| 6116 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6117 | return err; |
| 6118 | } |
| 6119 | |
| 6120 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6121 | struct genl_info *info) |
| 6122 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6123 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6124 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6125 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6126 | |
| 6127 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6128 | return -EINVAL; |
| 6129 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6130 | if (!rdev->ops->cancel_remain_on_channel) |
| 6131 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6132 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6133 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6134 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6135 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6136 | } |
| 6137 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6138 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6139 | u8 *rates, u8 rates_len) |
| 6140 | { |
| 6141 | u8 i; |
| 6142 | u32 mask = 0; |
| 6143 | |
| 6144 | for (i = 0; i < rates_len; i++) { |
| 6145 | int rate = (rates[i] & 0x7f) * 5; |
| 6146 | int ridx; |
| 6147 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6148 | struct ieee80211_rate *srate = |
| 6149 | &sband->bitrates[ridx]; |
| 6150 | if (rate == srate->bitrate) { |
| 6151 | mask |= 1 << ridx; |
| 6152 | break; |
| 6153 | } |
| 6154 | } |
| 6155 | if (ridx == sband->n_bitrates) |
| 6156 | return 0; /* rate not found */ |
| 6157 | } |
| 6158 | |
| 6159 | return mask; |
| 6160 | } |
| 6161 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6162 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6163 | u8 *rates, u8 rates_len, |
| 6164 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6165 | { |
| 6166 | u8 i; |
| 6167 | |
| 6168 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6169 | |
| 6170 | for (i = 0; i < rates_len; i++) { |
| 6171 | int ridx, rbit; |
| 6172 | |
| 6173 | ridx = rates[i] / 8; |
| 6174 | rbit = BIT(rates[i] % 8); |
| 6175 | |
| 6176 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6177 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6178 | return false; |
| 6179 | |
| 6180 | /* check availability */ |
| 6181 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6182 | mcs[ridx] |= rbit; |
| 6183 | else |
| 6184 | return false; |
| 6185 | } |
| 6186 | |
| 6187 | return true; |
| 6188 | } |
| 6189 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6190 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6191 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6192 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6193 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6194 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6195 | }; |
| 6196 | |
| 6197 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6198 | struct genl_info *info) |
| 6199 | { |
| 6200 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6201 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6202 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6203 | int rem, i; |
| 6204 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6205 | struct nlattr *tx_rates; |
| 6206 | struct ieee80211_supported_band *sband; |
| 6207 | |
| 6208 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6209 | return -EINVAL; |
| 6210 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6211 | if (!rdev->ops->set_bitrate_mask) |
| 6212 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6213 | |
| 6214 | memset(&mask, 0, sizeof(mask)); |
| 6215 | /* Default to all rates enabled */ |
| 6216 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6217 | sband = rdev->wiphy.bands[i]; |
| 6218 | mask.control[i].legacy = |
| 6219 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6220 | if (sband) |
| 6221 | memcpy(mask.control[i].mcs, |
| 6222 | sband->ht_cap.mcs.rx_mask, |
| 6223 | sizeof(mask.control[i].mcs)); |
| 6224 | else |
| 6225 | memset(mask.control[i].mcs, 0, |
| 6226 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6227 | } |
| 6228 | |
| 6229 | /* |
| 6230 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6231 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6232 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6233 | 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] | 6234 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6235 | { |
| 6236 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6237 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6238 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6239 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6240 | if (sband == NULL) |
| 6241 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6242 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6243 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6244 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6245 | mask.control[band].legacy = rateset_to_mask( |
| 6246 | sband, |
| 6247 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6248 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6249 | if ((mask.control[band].legacy == 0) && |
| 6250 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6251 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6252 | } |
| 6253 | if (tb[NL80211_TXRATE_MCS]) { |
| 6254 | if (!ht_rateset_to_mask( |
| 6255 | sband, |
| 6256 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6257 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6258 | mask.control[band].mcs)) |
| 6259 | return -EINVAL; |
| 6260 | } |
| 6261 | |
| 6262 | if (mask.control[band].legacy == 0) { |
| 6263 | /* don't allow empty legacy rates if HT |
| 6264 | * is not even supported. */ |
| 6265 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6266 | return -EINVAL; |
| 6267 | |
| 6268 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6269 | if (mask.control[band].mcs[i]) |
| 6270 | break; |
| 6271 | |
| 6272 | /* legacy and mcs rates may not be both empty */ |
| 6273 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6274 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6275 | } |
| 6276 | } |
| 6277 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6278 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6279 | } |
| 6280 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6281 | 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] | 6282 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6283 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6284 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6285 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6286 | |
| 6287 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6288 | return -EINVAL; |
| 6289 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6290 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6291 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6292 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6293 | switch (wdev->iftype) { |
| 6294 | case NL80211_IFTYPE_STATION: |
| 6295 | case NL80211_IFTYPE_ADHOC: |
| 6296 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6297 | case NL80211_IFTYPE_AP: |
| 6298 | case NL80211_IFTYPE_AP_VLAN: |
| 6299 | case NL80211_IFTYPE_MESH_POINT: |
| 6300 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6301 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6302 | break; |
| 6303 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6304 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6305 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6306 | |
| 6307 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6308 | if (!rdev->ops->mgmt_tx) |
| 6309 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6310 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6311 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6312 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6313 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6314 | } |
| 6315 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6316 | 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] | 6317 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6318 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6319 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6320 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6321 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6322 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6323 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6324 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6325 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6326 | bool offchan, no_cck, dont_wait_for_ack; |
| 6327 | |
| 6328 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6329 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6330 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6331 | return -EINVAL; |
| 6332 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6333 | if (!rdev->ops->mgmt_tx) |
| 6334 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6335 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6336 | switch (wdev->iftype) { |
| 6337 | case NL80211_IFTYPE_STATION: |
| 6338 | case NL80211_IFTYPE_ADHOC: |
| 6339 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6340 | case NL80211_IFTYPE_AP: |
| 6341 | case NL80211_IFTYPE_AP_VLAN: |
| 6342 | case NL80211_IFTYPE_MESH_POINT: |
| 6343 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6344 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6345 | break; |
| 6346 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6347 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6348 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6349 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6350 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6351 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6352 | return -EINVAL; |
| 6353 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6354 | |
| 6355 | /* |
| 6356 | * We should wait on the channel for at least a minimum amount |
| 6357 | * of time (10ms) but no longer than the driver supports. |
| 6358 | */ |
| 6359 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6360 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6361 | return -EINVAL; |
| 6362 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6363 | } |
| 6364 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6365 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6366 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6367 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6368 | return -EINVAL; |
| 6369 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6370 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6371 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6372 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6373 | if (err) |
| 6374 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6375 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6376 | if (!dont_wait_for_ack) { |
| 6377 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6378 | if (!msg) |
| 6379 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6380 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6381 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6382 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6383 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6384 | if (IS_ERR(hdr)) { |
| 6385 | err = PTR_ERR(hdr); |
| 6386 | goto free_msg; |
| 6387 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6388 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6389 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6390 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6391 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6392 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6393 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6394 | if (err) |
| 6395 | goto free_msg; |
| 6396 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6397 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6398 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6399 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6400 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6401 | genlmsg_end(msg, hdr); |
| 6402 | return genlmsg_reply(msg, info); |
| 6403 | } |
| 6404 | |
| 6405 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6406 | |
| 6407 | nla_put_failure: |
| 6408 | err = -ENOBUFS; |
| 6409 | free_msg: |
| 6410 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6411 | return err; |
| 6412 | } |
| 6413 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6414 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6415 | { |
| 6416 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6417 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6418 | u64 cookie; |
| 6419 | |
| 6420 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6421 | return -EINVAL; |
| 6422 | |
| 6423 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6424 | return -EOPNOTSUPP; |
| 6425 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6426 | switch (wdev->iftype) { |
| 6427 | case NL80211_IFTYPE_STATION: |
| 6428 | case NL80211_IFTYPE_ADHOC: |
| 6429 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6430 | case NL80211_IFTYPE_AP: |
| 6431 | case NL80211_IFTYPE_AP_VLAN: |
| 6432 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6433 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6434 | break; |
| 6435 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6436 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6437 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6438 | |
| 6439 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6440 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6441 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6442 | } |
| 6443 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6444 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6445 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6446 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6447 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6448 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6449 | u8 ps_state; |
| 6450 | bool state; |
| 6451 | int err; |
| 6452 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6453 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6454 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6455 | |
| 6456 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6457 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6458 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6459 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6460 | |
| 6461 | wdev = dev->ieee80211_ptr; |
| 6462 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6463 | if (!rdev->ops->set_power_mgmt) |
| 6464 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6465 | |
| 6466 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6467 | |
| 6468 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6469 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6470 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6471 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6472 | if (!err) |
| 6473 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6474 | return err; |
| 6475 | } |
| 6476 | |
| 6477 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6478 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6479 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6480 | enum nl80211_ps_state ps_state; |
| 6481 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6482 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6483 | struct sk_buff *msg; |
| 6484 | void *hdr; |
| 6485 | int err; |
| 6486 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6487 | wdev = dev->ieee80211_ptr; |
| 6488 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6489 | if (!rdev->ops->set_power_mgmt) |
| 6490 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6491 | |
| 6492 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6493 | if (!msg) |
| 6494 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6495 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6496 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6497 | NL80211_CMD_GET_POWER_SAVE); |
| 6498 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6499 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6500 | goto free_msg; |
| 6501 | } |
| 6502 | |
| 6503 | if (wdev->ps) |
| 6504 | ps_state = NL80211_PS_ENABLED; |
| 6505 | else |
| 6506 | ps_state = NL80211_PS_DISABLED; |
| 6507 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6508 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6509 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6510 | |
| 6511 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6512 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6513 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6514 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6515 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6516 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6517 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6518 | return err; |
| 6519 | } |
| 6520 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6521 | static struct nla_policy |
| 6522 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6523 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6524 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6525 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6526 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 6527 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 6528 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6529 | }; |
| 6530 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6531 | static int nl80211_set_cqm_txe(struct genl_info *info, |
| 6532 | u32 rate, u32 pkts, u32 intvl) |
| 6533 | { |
| 6534 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6535 | struct wireless_dev *wdev; |
| 6536 | struct net_device *dev = info->user_ptr[1]; |
| 6537 | |
| 6538 | if ((rate < 0 || rate > 100) || |
| 6539 | (intvl < 0 || intvl > NL80211_CQM_TXE_MAX_INTVL)) |
| 6540 | return -EINVAL; |
| 6541 | |
| 6542 | wdev = dev->ieee80211_ptr; |
| 6543 | |
| 6544 | if (!rdev->ops->set_cqm_txe_config) |
| 6545 | return -EOPNOTSUPP; |
| 6546 | |
| 6547 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 6548 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6549 | return -EOPNOTSUPP; |
| 6550 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6551 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6552 | } |
| 6553 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6554 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6555 | s32 threshold, u32 hysteresis) |
| 6556 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6557 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6558 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6559 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6560 | |
| 6561 | if (threshold > 0) |
| 6562 | return -EINVAL; |
| 6563 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6564 | wdev = dev->ieee80211_ptr; |
| 6565 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6566 | if (!rdev->ops->set_cqm_rssi_config) |
| 6567 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6568 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6569 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6570 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6571 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6572 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6573 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6574 | } |
| 6575 | |
| 6576 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6577 | { |
| 6578 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6579 | struct nlattr *cqm; |
| 6580 | int err; |
| 6581 | |
| 6582 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6583 | if (!cqm) { |
| 6584 | err = -EINVAL; |
| 6585 | goto out; |
| 6586 | } |
| 6587 | |
| 6588 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6589 | nl80211_attr_cqm_policy); |
| 6590 | if (err) |
| 6591 | goto out; |
| 6592 | |
| 6593 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6594 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6595 | s32 threshold; |
| 6596 | u32 hysteresis; |
| 6597 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6598 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6599 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6600 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 6601 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 6602 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 6603 | u32 rate, pkts, intvl; |
| 6604 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 6605 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 6606 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 6607 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6608 | } else |
| 6609 | err = -EINVAL; |
| 6610 | |
| 6611 | out: |
| 6612 | return err; |
| 6613 | } |
| 6614 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6615 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6616 | { |
| 6617 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6618 | struct net_device *dev = info->user_ptr[1]; |
| 6619 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6620 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6621 | int err; |
| 6622 | |
| 6623 | /* start with default */ |
| 6624 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6625 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6626 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6627 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6628 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6629 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6630 | if (err) |
| 6631 | return err; |
| 6632 | } |
| 6633 | |
| 6634 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6635 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 6636 | return -EINVAL; |
| 6637 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6638 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6639 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6640 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 6641 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6642 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 6643 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6644 | return -EINVAL; |
| 6645 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6646 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 6647 | /* parse additional setup parameters if given */ |
| 6648 | err = nl80211_parse_mesh_setup(info, &setup); |
| 6649 | if (err) |
| 6650 | return err; |
| 6651 | } |
| 6652 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6653 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6654 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 6655 | if (err) |
| 6656 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6657 | } else { |
| 6658 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6659 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6660 | } |
| 6661 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6662 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6663 | } |
| 6664 | |
| 6665 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6666 | { |
| 6667 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6668 | struct net_device *dev = info->user_ptr[1]; |
| 6669 | |
| 6670 | return cfg80211_leave_mesh(rdev, dev); |
| 6671 | } |
| 6672 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6673 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6674 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6675 | { |
| 6676 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6677 | struct sk_buff *msg; |
| 6678 | void *hdr; |
| 6679 | |
| 6680 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6681 | return -EOPNOTSUPP; |
| 6682 | |
| 6683 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6684 | if (!msg) |
| 6685 | return -ENOMEM; |
| 6686 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6687 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6688 | NL80211_CMD_GET_WOWLAN); |
| 6689 | if (!hdr) |
| 6690 | goto nla_put_failure; |
| 6691 | |
| 6692 | if (rdev->wowlan) { |
| 6693 | struct nlattr *nl_wowlan; |
| 6694 | |
| 6695 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 6696 | if (!nl_wowlan) |
| 6697 | goto nla_put_failure; |
| 6698 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6699 | if ((rdev->wowlan->any && |
| 6700 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 6701 | (rdev->wowlan->disconnect && |
| 6702 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 6703 | (rdev->wowlan->magic_pkt && |
| 6704 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 6705 | (rdev->wowlan->gtk_rekey_failure && |
| 6706 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 6707 | (rdev->wowlan->eap_identity_req && |
| 6708 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 6709 | (rdev->wowlan->four_way_handshake && |
| 6710 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 6711 | (rdev->wowlan->rfkill_release && |
| 6712 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 6713 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6714 | if (rdev->wowlan->n_patterns) { |
| 6715 | struct nlattr *nl_pats, *nl_pat; |
| 6716 | int i, pat_len; |
| 6717 | |
| 6718 | nl_pats = nla_nest_start(msg, |
| 6719 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 6720 | if (!nl_pats) |
| 6721 | goto nla_put_failure; |
| 6722 | |
| 6723 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 6724 | nl_pat = nla_nest_start(msg, i + 1); |
| 6725 | if (!nl_pat) |
| 6726 | goto nla_put_failure; |
| 6727 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6728 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 6729 | DIV_ROUND_UP(pat_len, 8), |
| 6730 | rdev->wowlan->patterns[i].mask) || |
| 6731 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 6732 | pat_len, |
| 6733 | rdev->wowlan->patterns[i].pattern)) |
| 6734 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6735 | nla_nest_end(msg, nl_pat); |
| 6736 | } |
| 6737 | nla_nest_end(msg, nl_pats); |
| 6738 | } |
| 6739 | |
| 6740 | nla_nest_end(msg, nl_wowlan); |
| 6741 | } |
| 6742 | |
| 6743 | genlmsg_end(msg, hdr); |
| 6744 | return genlmsg_reply(msg, info); |
| 6745 | |
| 6746 | nla_put_failure: |
| 6747 | nlmsg_free(msg); |
| 6748 | return -ENOBUFS; |
| 6749 | } |
| 6750 | |
| 6751 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6752 | { |
| 6753 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6754 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6755 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6756 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6757 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 6758 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6759 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6760 | |
| 6761 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6762 | return -EOPNOTSUPP; |
| 6763 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6764 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 6765 | cfg80211_rdev_free_wowlan(rdev); |
| 6766 | rdev->wowlan = NULL; |
| 6767 | goto set_wakeup; |
| 6768 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6769 | |
| 6770 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 6771 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6772 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6773 | nl80211_wowlan_policy); |
| 6774 | if (err) |
| 6775 | return err; |
| 6776 | |
| 6777 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 6778 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 6779 | return -EINVAL; |
| 6780 | new_triggers.any = true; |
| 6781 | } |
| 6782 | |
| 6783 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 6784 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 6785 | return -EINVAL; |
| 6786 | new_triggers.disconnect = true; |
| 6787 | } |
| 6788 | |
| 6789 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 6790 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 6791 | return -EINVAL; |
| 6792 | new_triggers.magic_pkt = true; |
| 6793 | } |
| 6794 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 6795 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 6796 | return -EINVAL; |
| 6797 | |
| 6798 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 6799 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 6800 | return -EINVAL; |
| 6801 | new_triggers.gtk_rekey_failure = true; |
| 6802 | } |
| 6803 | |
| 6804 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 6805 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 6806 | return -EINVAL; |
| 6807 | new_triggers.eap_identity_req = true; |
| 6808 | } |
| 6809 | |
| 6810 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 6811 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 6812 | return -EINVAL; |
| 6813 | new_triggers.four_way_handshake = true; |
| 6814 | } |
| 6815 | |
| 6816 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 6817 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 6818 | return -EINVAL; |
| 6819 | new_triggers.rfkill_release = true; |
| 6820 | } |
| 6821 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6822 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 6823 | struct nlattr *pat; |
| 6824 | int n_patterns = 0; |
| 6825 | int rem, pat_len, mask_len; |
| 6826 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6827 | |
| 6828 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6829 | rem) |
| 6830 | n_patterns++; |
| 6831 | if (n_patterns > wowlan->n_patterns) |
| 6832 | return -EINVAL; |
| 6833 | |
| 6834 | new_triggers.patterns = kcalloc(n_patterns, |
| 6835 | sizeof(new_triggers.patterns[0]), |
| 6836 | GFP_KERNEL); |
| 6837 | if (!new_triggers.patterns) |
| 6838 | return -ENOMEM; |
| 6839 | |
| 6840 | new_triggers.n_patterns = n_patterns; |
| 6841 | i = 0; |
| 6842 | |
| 6843 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6844 | rem) { |
| 6845 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6846 | nla_data(pat), nla_len(pat), NULL); |
| 6847 | err = -EINVAL; |
| 6848 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6849 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6850 | goto error; |
| 6851 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6852 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6853 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6854 | mask_len) |
| 6855 | goto error; |
| 6856 | if (pat_len > wowlan->pattern_max_len || |
| 6857 | pat_len < wowlan->pattern_min_len) |
| 6858 | goto error; |
| 6859 | |
| 6860 | new_triggers.patterns[i].mask = |
| 6861 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6862 | if (!new_triggers.patterns[i].mask) { |
| 6863 | err = -ENOMEM; |
| 6864 | goto error; |
| 6865 | } |
| 6866 | new_triggers.patterns[i].pattern = |
| 6867 | new_triggers.patterns[i].mask + mask_len; |
| 6868 | memcpy(new_triggers.patterns[i].mask, |
| 6869 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6870 | mask_len); |
| 6871 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6872 | memcpy(new_triggers.patterns[i].pattern, |
| 6873 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6874 | pat_len); |
| 6875 | i++; |
| 6876 | } |
| 6877 | } |
| 6878 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6879 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 6880 | if (!ntrig) { |
| 6881 | err = -ENOMEM; |
| 6882 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6883 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6884 | cfg80211_rdev_free_wowlan(rdev); |
| 6885 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6886 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6887 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6888 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6889 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6890 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6891 | return 0; |
| 6892 | error: |
| 6893 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6894 | kfree(new_triggers.patterns[i].mask); |
| 6895 | kfree(new_triggers.patterns); |
| 6896 | return err; |
| 6897 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6898 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6899 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6900 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6901 | { |
| 6902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6903 | struct net_device *dev = info->user_ptr[1]; |
| 6904 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6905 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6906 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6907 | int err; |
| 6908 | |
| 6909 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6910 | return -EINVAL; |
| 6911 | |
| 6912 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6913 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6914 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6915 | nl80211_rekey_policy); |
| 6916 | if (err) |
| 6917 | return err; |
| 6918 | |
| 6919 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6920 | return -ERANGE; |
| 6921 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6922 | return -ERANGE; |
| 6923 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6924 | return -ERANGE; |
| 6925 | |
| 6926 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6927 | NL80211_KEK_LEN); |
| 6928 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6929 | NL80211_KCK_LEN); |
| 6930 | memcpy(rekey_data.replay_ctr, |
| 6931 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6932 | NL80211_REPLAY_CTR_LEN); |
| 6933 | |
| 6934 | wdev_lock(wdev); |
| 6935 | if (!wdev->current_bss) { |
| 6936 | err = -ENOTCONN; |
| 6937 | goto out; |
| 6938 | } |
| 6939 | |
| 6940 | if (!rdev->ops->set_rekey_data) { |
| 6941 | err = -EOPNOTSUPP; |
| 6942 | goto out; |
| 6943 | } |
| 6944 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6945 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6946 | out: |
| 6947 | wdev_unlock(wdev); |
| 6948 | return err; |
| 6949 | } |
| 6950 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6951 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6952 | struct genl_info *info) |
| 6953 | { |
| 6954 | struct net_device *dev = info->user_ptr[1]; |
| 6955 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6956 | |
| 6957 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6958 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6959 | return -EINVAL; |
| 6960 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6961 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6962 | return -EBUSY; |
| 6963 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6964 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6965 | return 0; |
| 6966 | } |
| 6967 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6968 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6969 | struct genl_info *info) |
| 6970 | { |
| 6971 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6972 | struct net_device *dev = info->user_ptr[1]; |
| 6973 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6974 | struct sk_buff *msg; |
| 6975 | void *hdr; |
| 6976 | const u8 *addr; |
| 6977 | u64 cookie; |
| 6978 | int err; |
| 6979 | |
| 6980 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6981 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6982 | return -EOPNOTSUPP; |
| 6983 | |
| 6984 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6985 | return -EINVAL; |
| 6986 | |
| 6987 | if (!rdev->ops->probe_client) |
| 6988 | return -EOPNOTSUPP; |
| 6989 | |
| 6990 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6991 | if (!msg) |
| 6992 | return -ENOMEM; |
| 6993 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6994 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6995 | NL80211_CMD_PROBE_CLIENT); |
| 6996 | |
| 6997 | if (IS_ERR(hdr)) { |
| 6998 | err = PTR_ERR(hdr); |
| 6999 | goto free_msg; |
| 7000 | } |
| 7001 | |
| 7002 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7003 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7004 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7005 | if (err) |
| 7006 | goto free_msg; |
| 7007 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7008 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7009 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7010 | |
| 7011 | genlmsg_end(msg, hdr); |
| 7012 | |
| 7013 | return genlmsg_reply(msg, info); |
| 7014 | |
| 7015 | nla_put_failure: |
| 7016 | err = -ENOBUFS; |
| 7017 | free_msg: |
| 7018 | nlmsg_free(msg); |
| 7019 | return err; |
| 7020 | } |
| 7021 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7022 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 7023 | { |
| 7024 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7025 | struct cfg80211_beacon_registration *reg, *nreg; |
| 7026 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7027 | |
| 7028 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 7029 | return -EOPNOTSUPP; |
| 7030 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7031 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 7032 | if (!nreg) |
| 7033 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7034 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7035 | /* First, check if already registered. */ |
| 7036 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 7037 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 7038 | if (reg->nlportid == info->snd_portid) { |
| 7039 | rv = -EALREADY; |
| 7040 | goto out_err; |
| 7041 | } |
| 7042 | } |
| 7043 | /* Add it to the list */ |
| 7044 | nreg->nlportid = info->snd_portid; |
| 7045 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 7046 | |
| 7047 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7048 | |
| 7049 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7050 | out_err: |
| 7051 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 7052 | kfree(nreg); |
| 7053 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7054 | } |
| 7055 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7056 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7057 | { |
| 7058 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7059 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7060 | int err; |
| 7061 | |
| 7062 | if (!rdev->ops->start_p2p_device) |
| 7063 | return -EOPNOTSUPP; |
| 7064 | |
| 7065 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7066 | return -EOPNOTSUPP; |
| 7067 | |
| 7068 | if (wdev->p2p_started) |
| 7069 | return 0; |
| 7070 | |
| 7071 | mutex_lock(&rdev->devlist_mtx); |
| 7072 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 7073 | mutex_unlock(&rdev->devlist_mtx); |
| 7074 | if (err) |
| 7075 | return err; |
| 7076 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7077 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7078 | if (err) |
| 7079 | return err; |
| 7080 | |
| 7081 | wdev->p2p_started = true; |
| 7082 | mutex_lock(&rdev->devlist_mtx); |
| 7083 | rdev->opencount++; |
| 7084 | mutex_unlock(&rdev->devlist_mtx); |
| 7085 | |
| 7086 | return 0; |
| 7087 | } |
| 7088 | |
| 7089 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7090 | { |
| 7091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7092 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7093 | |
| 7094 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7095 | return -EOPNOTSUPP; |
| 7096 | |
| 7097 | if (!rdev->ops->stop_p2p_device) |
| 7098 | return -EOPNOTSUPP; |
| 7099 | |
| 7100 | if (!wdev->p2p_started) |
| 7101 | return 0; |
| 7102 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7103 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7104 | wdev->p2p_started = false; |
| 7105 | |
| 7106 | mutex_lock(&rdev->devlist_mtx); |
| 7107 | rdev->opencount--; |
| 7108 | mutex_unlock(&rdev->devlist_mtx); |
| 7109 | |
| 7110 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 7111 | rdev->scan_req->aborted = true; |
| 7112 | ___cfg80211_scan_done(rdev, true); |
| 7113 | } |
| 7114 | |
| 7115 | return 0; |
| 7116 | } |
| 7117 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7118 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 7119 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 7120 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7121 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 7122 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 7123 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7124 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7125 | /* 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] | 7126 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 7127 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7128 | |
| 7129 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7130 | struct genl_info *info) |
| 7131 | { |
| 7132 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7133 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7134 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7135 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 7136 | |
| 7137 | if (rtnl) |
| 7138 | rtnl_lock(); |
| 7139 | |
| 7140 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 7141 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7142 | if (IS_ERR(rdev)) { |
| 7143 | if (rtnl) |
| 7144 | rtnl_unlock(); |
| 7145 | return PTR_ERR(rdev); |
| 7146 | } |
| 7147 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7148 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7149 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7150 | mutex_lock(&cfg80211_mutex); |
| 7151 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7152 | info->attrs); |
| 7153 | if (IS_ERR(wdev)) { |
| 7154 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7155 | if (rtnl) |
| 7156 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7157 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7158 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7159 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7160 | dev = wdev->netdev; |
| 7161 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7162 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7163 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7164 | if (!dev) { |
| 7165 | mutex_unlock(&cfg80211_mutex); |
| 7166 | if (rtnl) |
| 7167 | rtnl_unlock(); |
| 7168 | return -EINVAL; |
| 7169 | } |
| 7170 | |
| 7171 | info->user_ptr[1] = dev; |
| 7172 | } else { |
| 7173 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7174 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7175 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7176 | if (dev) { |
| 7177 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7178 | !netif_running(dev)) { |
| 7179 | mutex_unlock(&cfg80211_mutex); |
| 7180 | if (rtnl) |
| 7181 | rtnl_unlock(); |
| 7182 | return -ENETDOWN; |
| 7183 | } |
| 7184 | |
| 7185 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7186 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7187 | if (!wdev->p2p_started) { |
| 7188 | mutex_unlock(&cfg80211_mutex); |
| 7189 | if (rtnl) |
| 7190 | rtnl_unlock(); |
| 7191 | return -ENETDOWN; |
| 7192 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7193 | } |
| 7194 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7195 | cfg80211_lock_rdev(rdev); |
| 7196 | |
| 7197 | mutex_unlock(&cfg80211_mutex); |
| 7198 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7199 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7200 | } |
| 7201 | |
| 7202 | return 0; |
| 7203 | } |
| 7204 | |
| 7205 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7206 | struct genl_info *info) |
| 7207 | { |
| 7208 | if (info->user_ptr[0]) |
| 7209 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7210 | if (info->user_ptr[1]) { |
| 7211 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7212 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7213 | |
| 7214 | if (wdev->netdev) |
| 7215 | dev_put(wdev->netdev); |
| 7216 | } else { |
| 7217 | dev_put(info->user_ptr[1]); |
| 7218 | } |
| 7219 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7220 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7221 | rtnl_unlock(); |
| 7222 | } |
| 7223 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7224 | static struct genl_ops nl80211_ops[] = { |
| 7225 | { |
| 7226 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7227 | .doit = nl80211_get_wiphy, |
| 7228 | .dumpit = nl80211_dump_wiphy, |
| 7229 | .policy = nl80211_policy, |
| 7230 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7231 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7232 | }, |
| 7233 | { |
| 7234 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7235 | .doit = nl80211_set_wiphy, |
| 7236 | .policy = nl80211_policy, |
| 7237 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7238 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7239 | }, |
| 7240 | { |
| 7241 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7242 | .doit = nl80211_get_interface, |
| 7243 | .dumpit = nl80211_dump_interface, |
| 7244 | .policy = nl80211_policy, |
| 7245 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7246 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7247 | }, |
| 7248 | { |
| 7249 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7250 | .doit = nl80211_set_interface, |
| 7251 | .policy = nl80211_policy, |
| 7252 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7253 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7254 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7255 | }, |
| 7256 | { |
| 7257 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7258 | .doit = nl80211_new_interface, |
| 7259 | .policy = nl80211_policy, |
| 7260 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7261 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7262 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7263 | }, |
| 7264 | { |
| 7265 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7266 | .doit = nl80211_del_interface, |
| 7267 | .policy = nl80211_policy, |
| 7268 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7269 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7270 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7271 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7272 | { |
| 7273 | .cmd = NL80211_CMD_GET_KEY, |
| 7274 | .doit = nl80211_get_key, |
| 7275 | .policy = nl80211_policy, |
| 7276 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7277 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7278 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7279 | }, |
| 7280 | { |
| 7281 | .cmd = NL80211_CMD_SET_KEY, |
| 7282 | .doit = nl80211_set_key, |
| 7283 | .policy = nl80211_policy, |
| 7284 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7285 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7286 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7287 | }, |
| 7288 | { |
| 7289 | .cmd = NL80211_CMD_NEW_KEY, |
| 7290 | .doit = nl80211_new_key, |
| 7291 | .policy = nl80211_policy, |
| 7292 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7293 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7294 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7295 | }, |
| 7296 | { |
| 7297 | .cmd = NL80211_CMD_DEL_KEY, |
| 7298 | .doit = nl80211_del_key, |
| 7299 | .policy = nl80211_policy, |
| 7300 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7301 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7302 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7303 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7304 | { |
| 7305 | .cmd = NL80211_CMD_SET_BEACON, |
| 7306 | .policy = nl80211_policy, |
| 7307 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7308 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7309 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7310 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7311 | }, |
| 7312 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7313 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7314 | .policy = nl80211_policy, |
| 7315 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7316 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7317 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7318 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7319 | }, |
| 7320 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7321 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7322 | .policy = nl80211_policy, |
| 7323 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7324 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7325 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7326 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7327 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7328 | { |
| 7329 | .cmd = NL80211_CMD_GET_STATION, |
| 7330 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7331 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7332 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7333 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7334 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7335 | }, |
| 7336 | { |
| 7337 | .cmd = NL80211_CMD_SET_STATION, |
| 7338 | .doit = nl80211_set_station, |
| 7339 | .policy = nl80211_policy, |
| 7340 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7341 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7342 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7343 | }, |
| 7344 | { |
| 7345 | .cmd = NL80211_CMD_NEW_STATION, |
| 7346 | .doit = nl80211_new_station, |
| 7347 | .policy = nl80211_policy, |
| 7348 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7349 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7350 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7351 | }, |
| 7352 | { |
| 7353 | .cmd = NL80211_CMD_DEL_STATION, |
| 7354 | .doit = nl80211_del_station, |
| 7355 | .policy = nl80211_policy, |
| 7356 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7357 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7358 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7359 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7360 | { |
| 7361 | .cmd = NL80211_CMD_GET_MPATH, |
| 7362 | .doit = nl80211_get_mpath, |
| 7363 | .dumpit = nl80211_dump_mpath, |
| 7364 | .policy = nl80211_policy, |
| 7365 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7366 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7367 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7368 | }, |
| 7369 | { |
| 7370 | .cmd = NL80211_CMD_SET_MPATH, |
| 7371 | .doit = nl80211_set_mpath, |
| 7372 | .policy = nl80211_policy, |
| 7373 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7374 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7375 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7376 | }, |
| 7377 | { |
| 7378 | .cmd = NL80211_CMD_NEW_MPATH, |
| 7379 | .doit = nl80211_new_mpath, |
| 7380 | .policy = nl80211_policy, |
| 7381 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7382 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7383 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7384 | }, |
| 7385 | { |
| 7386 | .cmd = NL80211_CMD_DEL_MPATH, |
| 7387 | .doit = nl80211_del_mpath, |
| 7388 | .policy = nl80211_policy, |
| 7389 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7390 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7391 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7392 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7393 | { |
| 7394 | .cmd = NL80211_CMD_SET_BSS, |
| 7395 | .doit = nl80211_set_bss, |
| 7396 | .policy = nl80211_policy, |
| 7397 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7398 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7399 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7400 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7401 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7402 | .cmd = NL80211_CMD_GET_REG, |
| 7403 | .doit = nl80211_get_reg, |
| 7404 | .policy = nl80211_policy, |
| 7405 | /* can be retrieved by unprivileged users */ |
| 7406 | }, |
| 7407 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7408 | .cmd = NL80211_CMD_SET_REG, |
| 7409 | .doit = nl80211_set_reg, |
| 7410 | .policy = nl80211_policy, |
| 7411 | .flags = GENL_ADMIN_PERM, |
| 7412 | }, |
| 7413 | { |
| 7414 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 7415 | .doit = nl80211_req_set_reg, |
| 7416 | .policy = nl80211_policy, |
| 7417 | .flags = GENL_ADMIN_PERM, |
| 7418 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7419 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7420 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 7421 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7422 | .policy = nl80211_policy, |
| 7423 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7424 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7425 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7426 | }, |
| 7427 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7428 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 7429 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7430 | .policy = nl80211_policy, |
| 7431 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7432 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7433 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7434 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 7435 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7436 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 7437 | .doit = nl80211_trigger_scan, |
| 7438 | .policy = nl80211_policy, |
| 7439 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7440 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7441 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7442 | }, |
| 7443 | { |
| 7444 | .cmd = NL80211_CMD_GET_SCAN, |
| 7445 | .policy = nl80211_policy, |
| 7446 | .dumpit = nl80211_dump_scan, |
| 7447 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7448 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7449 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 7450 | .doit = nl80211_start_sched_scan, |
| 7451 | .policy = nl80211_policy, |
| 7452 | .flags = GENL_ADMIN_PERM, |
| 7453 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7454 | NL80211_FLAG_NEED_RTNL, |
| 7455 | }, |
| 7456 | { |
| 7457 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 7458 | .doit = nl80211_stop_sched_scan, |
| 7459 | .policy = nl80211_policy, |
| 7460 | .flags = GENL_ADMIN_PERM, |
| 7461 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7462 | NL80211_FLAG_NEED_RTNL, |
| 7463 | }, |
| 7464 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7465 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 7466 | .doit = nl80211_authenticate, |
| 7467 | .policy = nl80211_policy, |
| 7468 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7469 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7470 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7471 | }, |
| 7472 | { |
| 7473 | .cmd = NL80211_CMD_ASSOCIATE, |
| 7474 | .doit = nl80211_associate, |
| 7475 | .policy = nl80211_policy, |
| 7476 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7477 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7478 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7479 | }, |
| 7480 | { |
| 7481 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 7482 | .doit = nl80211_deauthenticate, |
| 7483 | .policy = nl80211_policy, |
| 7484 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7485 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7486 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7487 | }, |
| 7488 | { |
| 7489 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 7490 | .doit = nl80211_disassociate, |
| 7491 | .policy = nl80211_policy, |
| 7492 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7493 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7494 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7495 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7496 | { |
| 7497 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 7498 | .doit = nl80211_join_ibss, |
| 7499 | .policy = nl80211_policy, |
| 7500 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7501 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7502 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7503 | }, |
| 7504 | { |
| 7505 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 7506 | .doit = nl80211_leave_ibss, |
| 7507 | .policy = nl80211_policy, |
| 7508 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7509 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7510 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7511 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7512 | #ifdef CONFIG_NL80211_TESTMODE |
| 7513 | { |
| 7514 | .cmd = NL80211_CMD_TESTMODE, |
| 7515 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7516 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7517 | .policy = nl80211_policy, |
| 7518 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7519 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7520 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7521 | }, |
| 7522 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7523 | { |
| 7524 | .cmd = NL80211_CMD_CONNECT, |
| 7525 | .doit = nl80211_connect, |
| 7526 | .policy = nl80211_policy, |
| 7527 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7528 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7529 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7530 | }, |
| 7531 | { |
| 7532 | .cmd = NL80211_CMD_DISCONNECT, |
| 7533 | .doit = nl80211_disconnect, |
| 7534 | .policy = nl80211_policy, |
| 7535 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7536 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7537 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7538 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7539 | { |
| 7540 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 7541 | .doit = nl80211_wiphy_netns, |
| 7542 | .policy = nl80211_policy, |
| 7543 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7544 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7545 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7546 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7547 | { |
| 7548 | .cmd = NL80211_CMD_GET_SURVEY, |
| 7549 | .policy = nl80211_policy, |
| 7550 | .dumpit = nl80211_dump_survey, |
| 7551 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7552 | { |
| 7553 | .cmd = NL80211_CMD_SET_PMKSA, |
| 7554 | .doit = nl80211_setdel_pmksa, |
| 7555 | .policy = nl80211_policy, |
| 7556 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7557 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7558 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7559 | }, |
| 7560 | { |
| 7561 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 7562 | .doit = nl80211_setdel_pmksa, |
| 7563 | .policy = nl80211_policy, |
| 7564 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7565 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7566 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7567 | }, |
| 7568 | { |
| 7569 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 7570 | .doit = nl80211_flush_pmksa, |
| 7571 | .policy = nl80211_policy, |
| 7572 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7573 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7574 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7575 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7576 | { |
| 7577 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7578 | .doit = nl80211_remain_on_channel, |
| 7579 | .policy = nl80211_policy, |
| 7580 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7581 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7582 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7583 | }, |
| 7584 | { |
| 7585 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7586 | .doit = nl80211_cancel_remain_on_channel, |
| 7587 | .policy = nl80211_policy, |
| 7588 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7589 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7590 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7591 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7592 | { |
| 7593 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 7594 | .doit = nl80211_set_tx_bitrate_mask, |
| 7595 | .policy = nl80211_policy, |
| 7596 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7597 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7598 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7599 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7600 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7601 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 7602 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7603 | .policy = nl80211_policy, |
| 7604 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7605 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7606 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7607 | }, |
| 7608 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7609 | .cmd = NL80211_CMD_FRAME, |
| 7610 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7611 | .policy = nl80211_policy, |
| 7612 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7613 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7614 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7615 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7616 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7617 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 7618 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 7619 | .policy = nl80211_policy, |
| 7620 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7621 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7622 | NL80211_FLAG_NEED_RTNL, |
| 7623 | }, |
| 7624 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7625 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 7626 | .doit = nl80211_set_power_save, |
| 7627 | .policy = nl80211_policy, |
| 7628 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7629 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7630 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7631 | }, |
| 7632 | { |
| 7633 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 7634 | .doit = nl80211_get_power_save, |
| 7635 | .policy = nl80211_policy, |
| 7636 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7637 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7638 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7639 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7640 | { |
| 7641 | .cmd = NL80211_CMD_SET_CQM, |
| 7642 | .doit = nl80211_set_cqm, |
| 7643 | .policy = nl80211_policy, |
| 7644 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7645 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7646 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7647 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7648 | { |
| 7649 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 7650 | .doit = nl80211_set_channel, |
| 7651 | .policy = nl80211_policy, |
| 7652 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7653 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7654 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7655 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7656 | { |
| 7657 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 7658 | .doit = nl80211_set_wds_peer, |
| 7659 | .policy = nl80211_policy, |
| 7660 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 7661 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7662 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7663 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7664 | { |
| 7665 | .cmd = NL80211_CMD_JOIN_MESH, |
| 7666 | .doit = nl80211_join_mesh, |
| 7667 | .policy = nl80211_policy, |
| 7668 | .flags = GENL_ADMIN_PERM, |
| 7669 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7670 | NL80211_FLAG_NEED_RTNL, |
| 7671 | }, |
| 7672 | { |
| 7673 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 7674 | .doit = nl80211_leave_mesh, |
| 7675 | .policy = nl80211_policy, |
| 7676 | .flags = GENL_ADMIN_PERM, |
| 7677 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7678 | NL80211_FLAG_NEED_RTNL, |
| 7679 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7680 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7681 | { |
| 7682 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 7683 | .doit = nl80211_get_wowlan, |
| 7684 | .policy = nl80211_policy, |
| 7685 | /* can be retrieved by unprivileged users */ |
| 7686 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7687 | NL80211_FLAG_NEED_RTNL, |
| 7688 | }, |
| 7689 | { |
| 7690 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 7691 | .doit = nl80211_set_wowlan, |
| 7692 | .policy = nl80211_policy, |
| 7693 | .flags = GENL_ADMIN_PERM, |
| 7694 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7695 | NL80211_FLAG_NEED_RTNL, |
| 7696 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7697 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7698 | { |
| 7699 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 7700 | .doit = nl80211_set_rekey_data, |
| 7701 | .policy = nl80211_policy, |
| 7702 | .flags = GENL_ADMIN_PERM, |
| 7703 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7704 | NL80211_FLAG_NEED_RTNL, |
| 7705 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7706 | { |
| 7707 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 7708 | .doit = nl80211_tdls_mgmt, |
| 7709 | .policy = nl80211_policy, |
| 7710 | .flags = GENL_ADMIN_PERM, |
| 7711 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7712 | NL80211_FLAG_NEED_RTNL, |
| 7713 | }, |
| 7714 | { |
| 7715 | .cmd = NL80211_CMD_TDLS_OPER, |
| 7716 | .doit = nl80211_tdls_oper, |
| 7717 | .policy = nl80211_policy, |
| 7718 | .flags = GENL_ADMIN_PERM, |
| 7719 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7720 | NL80211_FLAG_NEED_RTNL, |
| 7721 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7722 | { |
| 7723 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 7724 | .doit = nl80211_register_unexpected_frame, |
| 7725 | .policy = nl80211_policy, |
| 7726 | .flags = GENL_ADMIN_PERM, |
| 7727 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7728 | NL80211_FLAG_NEED_RTNL, |
| 7729 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7730 | { |
| 7731 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 7732 | .doit = nl80211_probe_client, |
| 7733 | .policy = nl80211_policy, |
| 7734 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7735 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7736 | NL80211_FLAG_NEED_RTNL, |
| 7737 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7738 | { |
| 7739 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 7740 | .doit = nl80211_register_beacons, |
| 7741 | .policy = nl80211_policy, |
| 7742 | .flags = GENL_ADMIN_PERM, |
| 7743 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7744 | NL80211_FLAG_NEED_RTNL, |
| 7745 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 7746 | { |
| 7747 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 7748 | .doit = nl80211_set_noack_map, |
| 7749 | .policy = nl80211_policy, |
| 7750 | .flags = GENL_ADMIN_PERM, |
| 7751 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7752 | NL80211_FLAG_NEED_RTNL, |
| 7753 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7754 | { |
| 7755 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 7756 | .doit = nl80211_start_p2p_device, |
| 7757 | .policy = nl80211_policy, |
| 7758 | .flags = GENL_ADMIN_PERM, |
| 7759 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 7760 | NL80211_FLAG_NEED_RTNL, |
| 7761 | }, |
| 7762 | { |
| 7763 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 7764 | .doit = nl80211_stop_p2p_device, |
| 7765 | .policy = nl80211_policy, |
| 7766 | .flags = GENL_ADMIN_PERM, |
| 7767 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 7768 | NL80211_FLAG_NEED_RTNL, |
| 7769 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7770 | { |
| 7771 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 7772 | .doit = nl80211_set_mcast_rate, |
| 7773 | .policy = nl80211_policy, |
| 7774 | .flags = GENL_ADMIN_PERM, |
| 7775 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7776 | NL80211_FLAG_NEED_RTNL, |
| 7777 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7778 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7779 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7780 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 7781 | .name = "mlme", |
| 7782 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7783 | |
| 7784 | /* multicast groups */ |
| 7785 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 7786 | .name = "config", |
| 7787 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7788 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 7789 | .name = "scan", |
| 7790 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7791 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 7792 | .name = "regulatory", |
| 7793 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7794 | |
| 7795 | /* notification functions */ |
| 7796 | |
| 7797 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 7798 | { |
| 7799 | struct sk_buff *msg; |
| 7800 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7801 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7802 | if (!msg) |
| 7803 | return; |
| 7804 | |
| 7805 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 7806 | nlmsg_free(msg); |
| 7807 | return; |
| 7808 | } |
| 7809 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7810 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7811 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7812 | } |
| 7813 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7814 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 7815 | struct cfg80211_registered_device *rdev) |
| 7816 | { |
| 7817 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 7818 | struct nlattr *nest; |
| 7819 | int i; |
| 7820 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7821 | ASSERT_RDEV_LOCK(rdev); |
| 7822 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7823 | if (WARN_ON(!req)) |
| 7824 | return 0; |
| 7825 | |
| 7826 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 7827 | if (!nest) |
| 7828 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7829 | for (i = 0; i < req->n_ssids; i++) { |
| 7830 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 7831 | goto nla_put_failure; |
| 7832 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7833 | nla_nest_end(msg, nest); |
| 7834 | |
| 7835 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 7836 | if (!nest) |
| 7837 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7838 | for (i = 0; i < req->n_channels; i++) { |
| 7839 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 7840 | goto nla_put_failure; |
| 7841 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7842 | nla_nest_end(msg, nest); |
| 7843 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7844 | if (req->ie && |
| 7845 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 7846 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7847 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7848 | if (req->flags) |
| 7849 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 7850 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7851 | return 0; |
| 7852 | nla_put_failure: |
| 7853 | return -ENOBUFS; |
| 7854 | } |
| 7855 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7856 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 7857 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7858 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7859 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7860 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7861 | { |
| 7862 | void *hdr; |
| 7863 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7864 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7865 | if (!hdr) |
| 7866 | return -1; |
| 7867 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7868 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7869 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 7870 | wdev->netdev->ifindex)) || |
| 7871 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7872 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7873 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7874 | /* ignore errors and send incomplete event anyway */ |
| 7875 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7876 | |
| 7877 | return genlmsg_end(msg, hdr); |
| 7878 | |
| 7879 | nla_put_failure: |
| 7880 | genlmsg_cancel(msg, hdr); |
| 7881 | return -EMSGSIZE; |
| 7882 | } |
| 7883 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7884 | static int |
| 7885 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 7886 | struct cfg80211_registered_device *rdev, |
| 7887 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7888 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7889 | { |
| 7890 | void *hdr; |
| 7891 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7892 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7893 | if (!hdr) |
| 7894 | return -1; |
| 7895 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7896 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7897 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7898 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7899 | |
| 7900 | return genlmsg_end(msg, hdr); |
| 7901 | |
| 7902 | nla_put_failure: |
| 7903 | genlmsg_cancel(msg, hdr); |
| 7904 | return -EMSGSIZE; |
| 7905 | } |
| 7906 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7907 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7908 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7909 | { |
| 7910 | struct sk_buff *msg; |
| 7911 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 7912 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7913 | if (!msg) |
| 7914 | return; |
| 7915 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7916 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7917 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 7918 | nlmsg_free(msg); |
| 7919 | return; |
| 7920 | } |
| 7921 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7922 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7923 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7924 | } |
| 7925 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7926 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7927 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7928 | { |
| 7929 | struct sk_buff *msg; |
| 7930 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7931 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7932 | if (!msg) |
| 7933 | return; |
| 7934 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7935 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7936 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7937 | nlmsg_free(msg); |
| 7938 | return; |
| 7939 | } |
| 7940 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7941 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7942 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7943 | } |
| 7944 | |
| 7945 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7946 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7947 | { |
| 7948 | struct sk_buff *msg; |
| 7949 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7950 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7951 | if (!msg) |
| 7952 | return; |
| 7953 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7954 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7955 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7956 | nlmsg_free(msg); |
| 7957 | return; |
| 7958 | } |
| 7959 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7960 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7961 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7962 | } |
| 7963 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7964 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 7965 | struct net_device *netdev) |
| 7966 | { |
| 7967 | struct sk_buff *msg; |
| 7968 | |
| 7969 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7970 | if (!msg) |
| 7971 | return; |
| 7972 | |
| 7973 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7974 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 7975 | nlmsg_free(msg); |
| 7976 | return; |
| 7977 | } |
| 7978 | |
| 7979 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7980 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7981 | } |
| 7982 | |
| 7983 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 7984 | struct net_device *netdev, u32 cmd) |
| 7985 | { |
| 7986 | struct sk_buff *msg; |
| 7987 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 7988 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7989 | if (!msg) |
| 7990 | return; |
| 7991 | |
| 7992 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 7993 | nlmsg_free(msg); |
| 7994 | return; |
| 7995 | } |
| 7996 | |
| 7997 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7998 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7999 | } |
| 8000 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8001 | /* |
| 8002 | * This can happen on global regulatory changes or device specific settings |
| 8003 | * based on custom world regulatory domains. |
| 8004 | */ |
| 8005 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 8006 | { |
| 8007 | struct sk_buff *msg; |
| 8008 | void *hdr; |
| 8009 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8010 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8011 | if (!msg) |
| 8012 | return; |
| 8013 | |
| 8014 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 8015 | if (!hdr) { |
| 8016 | nlmsg_free(msg); |
| 8017 | return; |
| 8018 | } |
| 8019 | |
| 8020 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8021 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 8022 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8023 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8024 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 8025 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8026 | NL80211_REGDOM_TYPE_WORLD)) |
| 8027 | goto nla_put_failure; |
| 8028 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 8029 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8030 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 8031 | goto nla_put_failure; |
| 8032 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 8033 | request->intersect) { |
| 8034 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8035 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 8036 | goto nla_put_failure; |
| 8037 | } else { |
| 8038 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8039 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 8040 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 8041 | request->alpha2)) |
| 8042 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8043 | } |
| 8044 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8045 | if (wiphy_idx_valid(request->wiphy_idx) && |
| 8046 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 8047 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8048 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8049 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8050 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8051 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8052 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8053 | GFP_ATOMIC); |
| 8054 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8055 | |
| 8056 | return; |
| 8057 | |
| 8058 | nla_put_failure: |
| 8059 | genlmsg_cancel(msg, hdr); |
| 8060 | nlmsg_free(msg); |
| 8061 | } |
| 8062 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8063 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 8064 | struct net_device *netdev, |
| 8065 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8066 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8067 | { |
| 8068 | struct sk_buff *msg; |
| 8069 | void *hdr; |
| 8070 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8071 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8072 | if (!msg) |
| 8073 | return; |
| 8074 | |
| 8075 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8076 | if (!hdr) { |
| 8077 | nlmsg_free(msg); |
| 8078 | return; |
| 8079 | } |
| 8080 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8081 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8082 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8083 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8084 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8085 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8086 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8087 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8088 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8089 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8090 | return; |
| 8091 | |
| 8092 | nla_put_failure: |
| 8093 | genlmsg_cancel(msg, hdr); |
| 8094 | nlmsg_free(msg); |
| 8095 | } |
| 8096 | |
| 8097 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8098 | struct net_device *netdev, const u8 *buf, |
| 8099 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8100 | { |
| 8101 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8102 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8103 | } |
| 8104 | |
| 8105 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 8106 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8107 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8108 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8109 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8110 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8111 | } |
| 8112 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8113 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8114 | struct net_device *netdev, const u8 *buf, |
| 8115 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8116 | { |
| 8117 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8118 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8119 | } |
| 8120 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8121 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 8122 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8123 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8124 | { |
| 8125 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8126 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8127 | } |
| 8128 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 8129 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 8130 | struct net_device *netdev, const u8 *buf, |
| 8131 | size_t len, gfp_t gfp) |
| 8132 | { |
| 8133 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8134 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 8135 | } |
| 8136 | |
| 8137 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 8138 | struct net_device *netdev, const u8 *buf, |
| 8139 | size_t len, gfp_t gfp) |
| 8140 | { |
| 8141 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8142 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 8143 | } |
| 8144 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 8145 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 8146 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8147 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8148 | { |
| 8149 | struct sk_buff *msg; |
| 8150 | void *hdr; |
| 8151 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8152 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8153 | if (!msg) |
| 8154 | return; |
| 8155 | |
| 8156 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8157 | if (!hdr) { |
| 8158 | nlmsg_free(msg); |
| 8159 | return; |
| 8160 | } |
| 8161 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8162 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8163 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8164 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8165 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8166 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8167 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8168 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8169 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8170 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8171 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8172 | return; |
| 8173 | |
| 8174 | nla_put_failure: |
| 8175 | genlmsg_cancel(msg, hdr); |
| 8176 | nlmsg_free(msg); |
| 8177 | } |
| 8178 | |
| 8179 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8180 | struct net_device *netdev, const u8 *addr, |
| 8181 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8182 | { |
| 8183 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8184 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8185 | } |
| 8186 | |
| 8187 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8188 | struct net_device *netdev, const u8 *addr, |
| 8189 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8190 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8191 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8192 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8193 | } |
| 8194 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8195 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8196 | struct net_device *netdev, const u8 *bssid, |
| 8197 | const u8 *req_ie, size_t req_ie_len, |
| 8198 | const u8 *resp_ie, size_t resp_ie_len, |
| 8199 | u16 status, gfp_t gfp) |
| 8200 | { |
| 8201 | struct sk_buff *msg; |
| 8202 | void *hdr; |
| 8203 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8204 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8205 | if (!msg) |
| 8206 | return; |
| 8207 | |
| 8208 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8209 | if (!hdr) { |
| 8210 | nlmsg_free(msg); |
| 8211 | return; |
| 8212 | } |
| 8213 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8214 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8215 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8216 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8217 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8218 | (req_ie && |
| 8219 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8220 | (resp_ie && |
| 8221 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8222 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8223 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8224 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8225 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8226 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8227 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8228 | return; |
| 8229 | |
| 8230 | nla_put_failure: |
| 8231 | genlmsg_cancel(msg, hdr); |
| 8232 | nlmsg_free(msg); |
| 8233 | |
| 8234 | } |
| 8235 | |
| 8236 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8237 | struct net_device *netdev, const u8 *bssid, |
| 8238 | const u8 *req_ie, size_t req_ie_len, |
| 8239 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8240 | { |
| 8241 | struct sk_buff *msg; |
| 8242 | void *hdr; |
| 8243 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8244 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8245 | if (!msg) |
| 8246 | return; |
| 8247 | |
| 8248 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8249 | if (!hdr) { |
| 8250 | nlmsg_free(msg); |
| 8251 | return; |
| 8252 | } |
| 8253 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8254 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8255 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8256 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8257 | (req_ie && |
| 8258 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8259 | (resp_ie && |
| 8260 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8261 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8262 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8263 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8264 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8265 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8266 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8267 | return; |
| 8268 | |
| 8269 | nla_put_failure: |
| 8270 | genlmsg_cancel(msg, hdr); |
| 8271 | nlmsg_free(msg); |
| 8272 | |
| 8273 | } |
| 8274 | |
| 8275 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 8276 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8277 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8278 | { |
| 8279 | struct sk_buff *msg; |
| 8280 | void *hdr; |
| 8281 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8282 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8283 | if (!msg) |
| 8284 | return; |
| 8285 | |
| 8286 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 8287 | if (!hdr) { |
| 8288 | nlmsg_free(msg); |
| 8289 | return; |
| 8290 | } |
| 8291 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8292 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8293 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8294 | (from_ap && reason && |
| 8295 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 8296 | (from_ap && |
| 8297 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 8298 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 8299 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8300 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8301 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8302 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8303 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8304 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8305 | return; |
| 8306 | |
| 8307 | nla_put_failure: |
| 8308 | genlmsg_cancel(msg, hdr); |
| 8309 | nlmsg_free(msg); |
| 8310 | |
| 8311 | } |
| 8312 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8313 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 8314 | struct net_device *netdev, const u8 *bssid, |
| 8315 | gfp_t gfp) |
| 8316 | { |
| 8317 | struct sk_buff *msg; |
| 8318 | void *hdr; |
| 8319 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8320 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8321 | if (!msg) |
| 8322 | return; |
| 8323 | |
| 8324 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 8325 | if (!hdr) { |
| 8326 | nlmsg_free(msg); |
| 8327 | return; |
| 8328 | } |
| 8329 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8330 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8331 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8332 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8333 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8334 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8335 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8336 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8337 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8338 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8339 | return; |
| 8340 | |
| 8341 | nla_put_failure: |
| 8342 | genlmsg_cancel(msg, hdr); |
| 8343 | nlmsg_free(msg); |
| 8344 | } |
| 8345 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8346 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 8347 | struct net_device *netdev, |
| 8348 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 8349 | gfp_t gfp) |
| 8350 | { |
| 8351 | struct sk_buff *msg; |
| 8352 | void *hdr; |
| 8353 | |
| 8354 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8355 | if (!msg) |
| 8356 | return; |
| 8357 | |
| 8358 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 8359 | if (!hdr) { |
| 8360 | nlmsg_free(msg); |
| 8361 | return; |
| 8362 | } |
| 8363 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8364 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8365 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8366 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 8367 | (ie_len && ie && |
| 8368 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 8369 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8370 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8371 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8372 | |
| 8373 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8374 | nl80211_mlme_mcgrp.id, gfp); |
| 8375 | return; |
| 8376 | |
| 8377 | nla_put_failure: |
| 8378 | genlmsg_cancel(msg, hdr); |
| 8379 | nlmsg_free(msg); |
| 8380 | } |
| 8381 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8382 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 8383 | struct net_device *netdev, const u8 *addr, |
| 8384 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8385 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8386 | { |
| 8387 | struct sk_buff *msg; |
| 8388 | void *hdr; |
| 8389 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8390 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8391 | if (!msg) |
| 8392 | return; |
| 8393 | |
| 8394 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 8395 | if (!hdr) { |
| 8396 | nlmsg_free(msg); |
| 8397 | return; |
| 8398 | } |
| 8399 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8400 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8401 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8402 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 8403 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 8404 | (key_id != -1 && |
| 8405 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 8406 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 8407 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8408 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8409 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8410 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8411 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8412 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8413 | return; |
| 8414 | |
| 8415 | nla_put_failure: |
| 8416 | genlmsg_cancel(msg, hdr); |
| 8417 | nlmsg_free(msg); |
| 8418 | } |
| 8419 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8420 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 8421 | struct ieee80211_channel *channel_before, |
| 8422 | struct ieee80211_channel *channel_after) |
| 8423 | { |
| 8424 | struct sk_buff *msg; |
| 8425 | void *hdr; |
| 8426 | struct nlattr *nl_freq; |
| 8427 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8428 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8429 | if (!msg) |
| 8430 | return; |
| 8431 | |
| 8432 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 8433 | if (!hdr) { |
| 8434 | nlmsg_free(msg); |
| 8435 | return; |
| 8436 | } |
| 8437 | |
| 8438 | /* |
| 8439 | * Since we are applying the beacon hint to a wiphy we know its |
| 8440 | * wiphy_idx is valid |
| 8441 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8442 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 8443 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8444 | |
| 8445 | /* Before */ |
| 8446 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 8447 | if (!nl_freq) |
| 8448 | goto nla_put_failure; |
| 8449 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 8450 | goto nla_put_failure; |
| 8451 | nla_nest_end(msg, nl_freq); |
| 8452 | |
| 8453 | /* After */ |
| 8454 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 8455 | if (!nl_freq) |
| 8456 | goto nla_put_failure; |
| 8457 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 8458 | goto nla_put_failure; |
| 8459 | nla_nest_end(msg, nl_freq); |
| 8460 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8461 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8462 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8463 | rcu_read_lock(); |
| 8464 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 8465 | GFP_ATOMIC); |
| 8466 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8467 | |
| 8468 | return; |
| 8469 | |
| 8470 | nla_put_failure: |
| 8471 | genlmsg_cancel(msg, hdr); |
| 8472 | nlmsg_free(msg); |
| 8473 | } |
| 8474 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8475 | static void nl80211_send_remain_on_chan_event( |
| 8476 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8477 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8478 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8479 | unsigned int duration, gfp_t gfp) |
| 8480 | { |
| 8481 | struct sk_buff *msg; |
| 8482 | void *hdr; |
| 8483 | |
| 8484 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8485 | if (!msg) |
| 8486 | return; |
| 8487 | |
| 8488 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8489 | if (!hdr) { |
| 8490 | nlmsg_free(msg); |
| 8491 | return; |
| 8492 | } |
| 8493 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8494 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8495 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8496 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 8497 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8498 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8499 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 8500 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8501 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8502 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8503 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8504 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 8505 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 8506 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8507 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8508 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8509 | |
| 8510 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8511 | nl80211_mlme_mcgrp.id, gfp); |
| 8512 | return; |
| 8513 | |
| 8514 | nla_put_failure: |
| 8515 | genlmsg_cancel(msg, hdr); |
| 8516 | nlmsg_free(msg); |
| 8517 | } |
| 8518 | |
| 8519 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8520 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8521 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8522 | unsigned int duration, gfp_t gfp) |
| 8523 | { |
| 8524 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8525 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8526 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8527 | } |
| 8528 | |
| 8529 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8530 | struct cfg80211_registered_device *rdev, |
| 8531 | struct wireless_dev *wdev, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8532 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8533 | { |
| 8534 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8535 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8536 | } |
| 8537 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8538 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 8539 | struct net_device *dev, const u8 *mac_addr, |
| 8540 | struct station_info *sinfo, gfp_t gfp) |
| 8541 | { |
| 8542 | struct sk_buff *msg; |
| 8543 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8544 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8545 | if (!msg) |
| 8546 | return; |
| 8547 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 8548 | if (nl80211_send_station(msg, 0, 0, 0, |
| 8549 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8550 | nlmsg_free(msg); |
| 8551 | return; |
| 8552 | } |
| 8553 | |
| 8554 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8555 | nl80211_mlme_mcgrp.id, gfp); |
| 8556 | } |
| 8557 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8558 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 8559 | struct net_device *dev, const u8 *mac_addr, |
| 8560 | gfp_t gfp) |
| 8561 | { |
| 8562 | struct sk_buff *msg; |
| 8563 | void *hdr; |
| 8564 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8565 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8566 | if (!msg) |
| 8567 | return; |
| 8568 | |
| 8569 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 8570 | if (!hdr) { |
| 8571 | nlmsg_free(msg); |
| 8572 | return; |
| 8573 | } |
| 8574 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8575 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8576 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 8577 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8578 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8579 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8580 | |
| 8581 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8582 | nl80211_mlme_mcgrp.id, gfp); |
| 8583 | return; |
| 8584 | |
| 8585 | nla_put_failure: |
| 8586 | genlmsg_cancel(msg, hdr); |
| 8587 | nlmsg_free(msg); |
| 8588 | } |
| 8589 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 8590 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 8591 | struct net_device *dev, const u8 *mac_addr, |
| 8592 | enum nl80211_connect_failed_reason reason, |
| 8593 | gfp_t gfp) |
| 8594 | { |
| 8595 | struct sk_buff *msg; |
| 8596 | void *hdr; |
| 8597 | |
| 8598 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8599 | if (!msg) |
| 8600 | return; |
| 8601 | |
| 8602 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 8603 | if (!hdr) { |
| 8604 | nlmsg_free(msg); |
| 8605 | return; |
| 8606 | } |
| 8607 | |
| 8608 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8609 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 8610 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 8611 | goto nla_put_failure; |
| 8612 | |
| 8613 | genlmsg_end(msg, hdr); |
| 8614 | |
| 8615 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8616 | nl80211_mlme_mcgrp.id, gfp); |
| 8617 | return; |
| 8618 | |
| 8619 | nla_put_failure: |
| 8620 | genlmsg_cancel(msg, hdr); |
| 8621 | nlmsg_free(msg); |
| 8622 | } |
| 8623 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8624 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 8625 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8626 | { |
| 8627 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8628 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8629 | struct sk_buff *msg; |
| 8630 | void *hdr; |
| 8631 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8632 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8633 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8634 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8635 | return false; |
| 8636 | |
| 8637 | msg = nlmsg_new(100, gfp); |
| 8638 | if (!msg) |
| 8639 | return true; |
| 8640 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8641 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8642 | if (!hdr) { |
| 8643 | nlmsg_free(msg); |
| 8644 | return true; |
| 8645 | } |
| 8646 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8647 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8648 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8649 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8650 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8651 | |
| 8652 | err = genlmsg_end(msg, hdr); |
| 8653 | if (err < 0) { |
| 8654 | nlmsg_free(msg); |
| 8655 | return true; |
| 8656 | } |
| 8657 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8658 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8659 | return true; |
| 8660 | |
| 8661 | nla_put_failure: |
| 8662 | genlmsg_cancel(msg, hdr); |
| 8663 | nlmsg_free(msg); |
| 8664 | return true; |
| 8665 | } |
| 8666 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8667 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 8668 | { |
| 8669 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 8670 | addr, gfp); |
| 8671 | } |
| 8672 | |
| 8673 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 8674 | const u8 *addr, gfp_t gfp) |
| 8675 | { |
| 8676 | return __nl80211_unexpected_frame(dev, |
| 8677 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 8678 | addr, gfp); |
| 8679 | } |
| 8680 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8681 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8682 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8683 | int freq, int sig_dbm, |
| 8684 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8685 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8686 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8687 | struct sk_buff *msg; |
| 8688 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8689 | |
| 8690 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8691 | if (!msg) |
| 8692 | return -ENOMEM; |
| 8693 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8694 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8695 | if (!hdr) { |
| 8696 | nlmsg_free(msg); |
| 8697 | return -ENOMEM; |
| 8698 | } |
| 8699 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8700 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8701 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8702 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8703 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8704 | (sig_dbm && |
| 8705 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8706 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8707 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8708 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8709 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8710 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8711 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8712 | |
| 8713 | nla_put_failure: |
| 8714 | genlmsg_cancel(msg, hdr); |
| 8715 | nlmsg_free(msg); |
| 8716 | return -ENOBUFS; |
| 8717 | } |
| 8718 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8719 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8720 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8721 | const u8 *buf, size_t len, bool ack, |
| 8722 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8723 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8724 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8725 | struct sk_buff *msg; |
| 8726 | void *hdr; |
| 8727 | |
| 8728 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8729 | if (!msg) |
| 8730 | return; |
| 8731 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8732 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8733 | if (!hdr) { |
| 8734 | nlmsg_free(msg); |
| 8735 | return; |
| 8736 | } |
| 8737 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8738 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8739 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8740 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8741 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 8742 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8743 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8744 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8745 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8746 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8747 | |
| 8748 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 8749 | return; |
| 8750 | |
| 8751 | nla_put_failure: |
| 8752 | genlmsg_cancel(msg, hdr); |
| 8753 | nlmsg_free(msg); |
| 8754 | } |
| 8755 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8756 | void |
| 8757 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 8758 | struct net_device *netdev, |
| 8759 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 8760 | gfp_t gfp) |
| 8761 | { |
| 8762 | struct sk_buff *msg; |
| 8763 | struct nlattr *pinfoattr; |
| 8764 | void *hdr; |
| 8765 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8766 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8767 | if (!msg) |
| 8768 | return; |
| 8769 | |
| 8770 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8771 | if (!hdr) { |
| 8772 | nlmsg_free(msg); |
| 8773 | return; |
| 8774 | } |
| 8775 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8776 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8777 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8778 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8779 | |
| 8780 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8781 | if (!pinfoattr) |
| 8782 | goto nla_put_failure; |
| 8783 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8784 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 8785 | rssi_event)) |
| 8786 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8787 | |
| 8788 | nla_nest_end(msg, pinfoattr); |
| 8789 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8790 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8791 | |
| 8792 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8793 | nl80211_mlme_mcgrp.id, gfp); |
| 8794 | return; |
| 8795 | |
| 8796 | nla_put_failure: |
| 8797 | genlmsg_cancel(msg, hdr); |
| 8798 | nlmsg_free(msg); |
| 8799 | } |
| 8800 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8801 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 8802 | struct net_device *netdev, const u8 *bssid, |
| 8803 | const u8 *replay_ctr, gfp_t gfp) |
| 8804 | { |
| 8805 | struct sk_buff *msg; |
| 8806 | struct nlattr *rekey_attr; |
| 8807 | void *hdr; |
| 8808 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8809 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8810 | if (!msg) |
| 8811 | return; |
| 8812 | |
| 8813 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 8814 | if (!hdr) { |
| 8815 | nlmsg_free(msg); |
| 8816 | return; |
| 8817 | } |
| 8818 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8819 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8820 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8821 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8822 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8823 | |
| 8824 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 8825 | if (!rekey_attr) |
| 8826 | goto nla_put_failure; |
| 8827 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8828 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 8829 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 8830 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8831 | |
| 8832 | nla_nest_end(msg, rekey_attr); |
| 8833 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8834 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8835 | |
| 8836 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8837 | nl80211_mlme_mcgrp.id, gfp); |
| 8838 | return; |
| 8839 | |
| 8840 | nla_put_failure: |
| 8841 | genlmsg_cancel(msg, hdr); |
| 8842 | nlmsg_free(msg); |
| 8843 | } |
| 8844 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8845 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 8846 | struct net_device *netdev, int index, |
| 8847 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 8848 | { |
| 8849 | struct sk_buff *msg; |
| 8850 | struct nlattr *attr; |
| 8851 | void *hdr; |
| 8852 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8853 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8854 | if (!msg) |
| 8855 | return; |
| 8856 | |
| 8857 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 8858 | if (!hdr) { |
| 8859 | nlmsg_free(msg); |
| 8860 | return; |
| 8861 | } |
| 8862 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8863 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8864 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8865 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8866 | |
| 8867 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 8868 | if (!attr) |
| 8869 | goto nla_put_failure; |
| 8870 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8871 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 8872 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 8873 | (preauth && |
| 8874 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 8875 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8876 | |
| 8877 | nla_nest_end(msg, attr); |
| 8878 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8879 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8880 | |
| 8881 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8882 | nl80211_mlme_mcgrp.id, gfp); |
| 8883 | return; |
| 8884 | |
| 8885 | nla_put_failure: |
| 8886 | genlmsg_cancel(msg, hdr); |
| 8887 | nlmsg_free(msg); |
| 8888 | } |
| 8889 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8890 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8891 | struct net_device *netdev, |
| 8892 | struct cfg80211_chan_def *chandef, gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8893 | { |
| 8894 | struct sk_buff *msg; |
| 8895 | void *hdr; |
| 8896 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8897 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8898 | if (!msg) |
| 8899 | return; |
| 8900 | |
| 8901 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 8902 | if (!hdr) { |
| 8903 | nlmsg_free(msg); |
| 8904 | return; |
| 8905 | } |
| 8906 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8907 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8908 | goto nla_put_failure; |
| 8909 | |
| 8910 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 8911 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8912 | |
| 8913 | genlmsg_end(msg, hdr); |
| 8914 | |
| 8915 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8916 | nl80211_mlme_mcgrp.id, gfp); |
| 8917 | return; |
| 8918 | |
| 8919 | nla_put_failure: |
| 8920 | genlmsg_cancel(msg, hdr); |
| 8921 | nlmsg_free(msg); |
| 8922 | } |
| 8923 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8924 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8925 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 8926 | struct net_device *netdev, const u8 *peer, |
| 8927 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 8928 | { |
| 8929 | struct sk_buff *msg; |
| 8930 | struct nlattr *pinfoattr; |
| 8931 | void *hdr; |
| 8932 | |
| 8933 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8934 | if (!msg) |
| 8935 | return; |
| 8936 | |
| 8937 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8938 | if (!hdr) { |
| 8939 | nlmsg_free(msg); |
| 8940 | return; |
| 8941 | } |
| 8942 | |
| 8943 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8944 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8945 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8946 | goto nla_put_failure; |
| 8947 | |
| 8948 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8949 | if (!pinfoattr) |
| 8950 | goto nla_put_failure; |
| 8951 | |
| 8952 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 8953 | goto nla_put_failure; |
| 8954 | |
| 8955 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 8956 | goto nla_put_failure; |
| 8957 | |
| 8958 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 8959 | goto nla_put_failure; |
| 8960 | |
| 8961 | nla_nest_end(msg, pinfoattr); |
| 8962 | |
| 8963 | genlmsg_end(msg, hdr); |
| 8964 | |
| 8965 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8966 | nl80211_mlme_mcgrp.id, gfp); |
| 8967 | return; |
| 8968 | |
| 8969 | nla_put_failure: |
| 8970 | genlmsg_cancel(msg, hdr); |
| 8971 | nlmsg_free(msg); |
| 8972 | } |
| 8973 | |
| 8974 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8975 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 8976 | struct net_device *netdev, const u8 *peer, |
| 8977 | u32 num_packets, gfp_t gfp) |
| 8978 | { |
| 8979 | struct sk_buff *msg; |
| 8980 | struct nlattr *pinfoattr; |
| 8981 | void *hdr; |
| 8982 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8983 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8984 | if (!msg) |
| 8985 | return; |
| 8986 | |
| 8987 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8988 | if (!hdr) { |
| 8989 | nlmsg_free(msg); |
| 8990 | return; |
| 8991 | } |
| 8992 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8993 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8994 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8995 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8996 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8997 | |
| 8998 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8999 | if (!pinfoattr) |
| 9000 | goto nla_put_failure; |
| 9001 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9002 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 9003 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9004 | |
| 9005 | nla_nest_end(msg, pinfoattr); |
| 9006 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9007 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9008 | |
| 9009 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9010 | nl80211_mlme_mcgrp.id, gfp); |
| 9011 | return; |
| 9012 | |
| 9013 | nla_put_failure: |
| 9014 | genlmsg_cancel(msg, hdr); |
| 9015 | nlmsg_free(msg); |
| 9016 | } |
| 9017 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9018 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 9019 | u64 cookie, bool acked, gfp_t gfp) |
| 9020 | { |
| 9021 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9022 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9023 | struct sk_buff *msg; |
| 9024 | void *hdr; |
| 9025 | int err; |
| 9026 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9027 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 9028 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9029 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9030 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9031 | if (!msg) |
| 9032 | return; |
| 9033 | |
| 9034 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 9035 | if (!hdr) { |
| 9036 | nlmsg_free(msg); |
| 9037 | return; |
| 9038 | } |
| 9039 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9040 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9041 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9042 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9043 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9044 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9045 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9046 | |
| 9047 | err = genlmsg_end(msg, hdr); |
| 9048 | if (err < 0) { |
| 9049 | nlmsg_free(msg); |
| 9050 | return; |
| 9051 | } |
| 9052 | |
| 9053 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9054 | nl80211_mlme_mcgrp.id, gfp); |
| 9055 | return; |
| 9056 | |
| 9057 | nla_put_failure: |
| 9058 | genlmsg_cancel(msg, hdr); |
| 9059 | nlmsg_free(msg); |
| 9060 | } |
| 9061 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 9062 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9063 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 9064 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9065 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9066 | { |
| 9067 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9068 | struct sk_buff *msg; |
| 9069 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9070 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9071 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9072 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 9073 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9074 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9075 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9076 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 9077 | if (!msg) { |
| 9078 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9079 | return; |
| 9080 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9081 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9082 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 9083 | if (!hdr) |
| 9084 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9085 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9086 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9087 | (freq && |
| 9088 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9089 | (sig_dbm && |
| 9090 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9091 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 9092 | goto nla_put_failure; |
| 9093 | |
| 9094 | genlmsg_end(msg, hdr); |
| 9095 | |
| 9096 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9097 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9098 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9099 | return; |
| 9100 | |
| 9101 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9102 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9103 | if (hdr) |
| 9104 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9105 | nlmsg_free(msg); |
| 9106 | } |
| 9107 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 9108 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 9109 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 9110 | enum nl80211_tdls_operation oper, |
| 9111 | u16 reason_code, gfp_t gfp) |
| 9112 | { |
| 9113 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9114 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9115 | struct sk_buff *msg; |
| 9116 | void *hdr; |
| 9117 | int err; |
| 9118 | |
| 9119 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 9120 | reason_code); |
| 9121 | |
| 9122 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9123 | if (!msg) |
| 9124 | return; |
| 9125 | |
| 9126 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 9127 | if (!hdr) { |
| 9128 | nlmsg_free(msg); |
| 9129 | return; |
| 9130 | } |
| 9131 | |
| 9132 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9133 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9134 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 9135 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 9136 | (reason_code > 0 && |
| 9137 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 9138 | goto nla_put_failure; |
| 9139 | |
| 9140 | err = genlmsg_end(msg, hdr); |
| 9141 | if (err < 0) { |
| 9142 | nlmsg_free(msg); |
| 9143 | return; |
| 9144 | } |
| 9145 | |
| 9146 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9147 | nl80211_mlme_mcgrp.id, gfp); |
| 9148 | return; |
| 9149 | |
| 9150 | nla_put_failure: |
| 9151 | genlmsg_cancel(msg, hdr); |
| 9152 | nlmsg_free(msg); |
| 9153 | } |
| 9154 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 9155 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9156 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 9157 | unsigned long state, |
| 9158 | void *_notify) |
| 9159 | { |
| 9160 | struct netlink_notify *notify = _notify; |
| 9161 | struct cfg80211_registered_device *rdev; |
| 9162 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9163 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9164 | |
| 9165 | if (state != NETLINK_URELEASE) |
| 9166 | return NOTIFY_DONE; |
| 9167 | |
| 9168 | rcu_read_lock(); |
| 9169 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9170 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9171 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9172 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9173 | |
| 9174 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9175 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 9176 | list) { |
| 9177 | if (reg->nlportid == notify->portid) { |
| 9178 | list_del(®->list); |
| 9179 | kfree(reg); |
| 9180 | break; |
| 9181 | } |
| 9182 | } |
| 9183 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9184 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9185 | |
| 9186 | rcu_read_unlock(); |
| 9187 | |
| 9188 | return NOTIFY_DONE; |
| 9189 | } |
| 9190 | |
| 9191 | static struct notifier_block nl80211_netlink_notifier = { |
| 9192 | .notifier_call = nl80211_netlink_notify, |
| 9193 | }; |
| 9194 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9195 | /* initialisation/exit functions */ |
| 9196 | |
| 9197 | int nl80211_init(void) |
| 9198 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9199 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9200 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9201 | err = genl_register_family_with_ops(&nl80211_fam, |
| 9202 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9203 | if (err) |
| 9204 | return err; |
| 9205 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9206 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 9207 | if (err) |
| 9208 | goto err_out; |
| 9209 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9210 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 9211 | if (err) |
| 9212 | goto err_out; |
| 9213 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9214 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 9215 | if (err) |
| 9216 | goto err_out; |
| 9217 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9218 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 9219 | if (err) |
| 9220 | goto err_out; |
| 9221 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9222 | #ifdef CONFIG_NL80211_TESTMODE |
| 9223 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 9224 | if (err) |
| 9225 | goto err_out; |
| 9226 | #endif |
| 9227 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9228 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 9229 | if (err) |
| 9230 | goto err_out; |
| 9231 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9232 | return 0; |
| 9233 | err_out: |
| 9234 | genl_unregister_family(&nl80211_fam); |
| 9235 | return err; |
| 9236 | } |
| 9237 | |
| 9238 | void nl80211_exit(void) |
| 9239 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9240 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9241 | genl_unregister_family(&nl80211_fam); |
| 9242 | } |