Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | #include "core.h" |
| 23 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 24 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 25 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 26 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 27 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 28 | struct genl_info *info, |
| 29 | struct cfg80211_crypto_settings *settings, |
| 30 | int cipher_limit); |
| 31 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 32 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 33 | struct genl_info *info); |
| 34 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 35 | struct genl_info *info); |
| 36 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | /* the netlink family */ |
| 38 | static struct genl_family nl80211_fam = { |
| 39 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 40 | .name = "nl80211", /* have users key off the name instead */ |
| 41 | .hdrsize = 0, /* no private header */ |
| 42 | .version = 1, /* no particular meaning now */ |
| 43 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 44 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 45 | .pre_doit = nl80211_pre_doit, |
| 46 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 49 | /* returns ERR_PTR values */ |
| 50 | static struct wireless_dev * |
| 51 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 52 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 53 | struct cfg80211_registered_device *rdev; |
| 54 | struct wireless_dev *result = NULL; |
| 55 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 56 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 57 | u64 wdev_id; |
| 58 | int wiphy_idx = -1; |
| 59 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 60 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 61 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 62 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 63 | if (!have_ifidx && !have_wdev_id) |
| 64 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 65 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 66 | if (have_ifidx) |
| 67 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 68 | if (have_wdev_id) { |
| 69 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 70 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 73 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 74 | struct wireless_dev *wdev; |
| 75 | |
| 76 | if (wiphy_net(&rdev->wiphy) != netns) |
| 77 | continue; |
| 78 | |
| 79 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 80 | continue; |
| 81 | |
| 82 | mutex_lock(&rdev->devlist_mtx); |
| 83 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 84 | if (have_ifidx && wdev->netdev && |
| 85 | wdev->netdev->ifindex == ifidx) { |
| 86 | result = wdev; |
| 87 | break; |
| 88 | } |
| 89 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 90 | result = wdev; |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | mutex_unlock(&rdev->devlist_mtx); |
| 95 | |
| 96 | if (result) |
| 97 | break; |
| 98 | } |
| 99 | |
| 100 | if (result) |
| 101 | return result; |
| 102 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 103 | } |
| 104 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 105 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 106 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 107 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 108 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 109 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 110 | |
| 111 | assert_cfg80211_lock(); |
| 112 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 113 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 114 | !attrs[NL80211_ATTR_IFINDEX] && |
| 115 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 116 | return ERR_PTR(-EINVAL); |
| 117 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 118 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 119 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 120 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 121 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 122 | if (attrs[NL80211_ATTR_WDEV]) { |
| 123 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 124 | struct wireless_dev *wdev; |
| 125 | bool found = false; |
| 126 | |
| 127 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 128 | if (tmp) { |
| 129 | /* make sure wdev exists */ |
| 130 | mutex_lock(&tmp->devlist_mtx); |
| 131 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 132 | if (wdev->identifier != (u32)wdev_id) |
| 133 | continue; |
| 134 | found = true; |
| 135 | break; |
| 136 | } |
| 137 | mutex_unlock(&tmp->devlist_mtx); |
| 138 | |
| 139 | if (!found) |
| 140 | tmp = NULL; |
| 141 | |
| 142 | if (rdev && tmp != rdev) |
| 143 | return ERR_PTR(-EINVAL); |
| 144 | rdev = tmp; |
| 145 | } |
| 146 | } |
| 147 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 148 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 149 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 150 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 151 | if (netdev) { |
| 152 | if (netdev->ieee80211_ptr) |
| 153 | tmp = wiphy_to_dev( |
| 154 | netdev->ieee80211_ptr->wiphy); |
| 155 | else |
| 156 | tmp = NULL; |
| 157 | |
| 158 | dev_put(netdev); |
| 159 | |
| 160 | /* not wireless device -- return error */ |
| 161 | if (!tmp) |
| 162 | return ERR_PTR(-EINVAL); |
| 163 | |
| 164 | /* mismatch -- return error */ |
| 165 | if (rdev && tmp != rdev) |
| 166 | return ERR_PTR(-EINVAL); |
| 167 | |
| 168 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 169 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 170 | } |
| 171 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 172 | if (!rdev) |
| 173 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 174 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 175 | if (netns != wiphy_net(&rdev->wiphy)) |
| 176 | return ERR_PTR(-ENODEV); |
| 177 | |
| 178 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* |
| 182 | * This function returns a pointer to the driver |
| 183 | * that the genl_info item that is passed refers to. |
| 184 | * If successful, it returns non-NULL and also locks |
| 185 | * the driver's mutex! |
| 186 | * |
| 187 | * This means that you need to call cfg80211_unlock_rdev() |
| 188 | * before being allowed to acquire &cfg80211_mutex! |
| 189 | * |
| 190 | * This is necessary because we need to lock the global |
| 191 | * mutex to get an item off the list safely, and then |
| 192 | * we lock the rdev mutex so it doesn't go away under us. |
| 193 | * |
| 194 | * We don't want to keep cfg80211_mutex locked |
| 195 | * for all the time in order to allow requests on |
| 196 | * other interfaces to go through at the same time. |
| 197 | * |
| 198 | * The result of this can be a PTR_ERR and hence must |
| 199 | * be checked with IS_ERR() for errors. |
| 200 | */ |
| 201 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 202 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 203 | { |
| 204 | struct cfg80211_registered_device *rdev; |
| 205 | |
| 206 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 207 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 208 | |
| 209 | /* if it is not an error we grab the lock on |
| 210 | * it to assure it won't be going away while |
| 211 | * we operate on it */ |
| 212 | if (!IS_ERR(rdev)) |
| 213 | mutex_lock(&rdev->mtx); |
| 214 | |
| 215 | mutex_unlock(&cfg80211_mutex); |
| 216 | |
| 217 | return rdev; |
| 218 | } |
| 219 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 220 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 221 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 222 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 223 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 224 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 225 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 226 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 227 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 229 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 230 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 232 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 233 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 234 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 235 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 236 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 238 | |
| 239 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 240 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 242 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 243 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 244 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 245 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 246 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 247 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 248 | .len = WLAN_MAX_KEY_LEN }, |
| 249 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 250 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 251 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 252 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 253 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 254 | |
| 255 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 256 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 257 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 258 | .len = IEEE80211_MAX_DATA_LEN }, |
| 259 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 260 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 262 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 263 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 264 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 265 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 266 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 268 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 269 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 270 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 271 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 272 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 273 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 274 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 275 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 276 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 277 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 278 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 279 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 280 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 281 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 282 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 283 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 284 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 285 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 286 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 287 | |
| 288 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 289 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 290 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 291 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 292 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 293 | |
| 294 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 295 | .len = IEEE80211_MAX_SSID_LEN }, |
| 296 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 297 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 298 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 299 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_STA_FLAGS2] = { |
| 302 | .len = sizeof(struct nl80211_sta_flag_update), |
| 303 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 304 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 306 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 308 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 309 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 311 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 313 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 314 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 315 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 318 | .len = IEEE80211_MAX_DATA_LEN }, |
| 319 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 320 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 322 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 323 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 324 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 325 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 327 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 328 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 329 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 330 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 331 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 333 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 335 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 336 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 337 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 339 | .len = IEEE80211_MAX_DATA_LEN }, |
| 340 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 341 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 342 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 343 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 344 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 345 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 346 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 347 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 348 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 349 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 350 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 351 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 352 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 353 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 354 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 355 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 356 | .len = NL80211_HT_CAPABILITY_LEN |
| 357 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 358 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 359 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 360 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 361 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 362 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 363 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 364 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 365 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 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 | 5e76023 | 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 | 5e76023 | 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 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame^] | 1423 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1424 | return -EINVAL; |
| 1425 | |
| 1426 | switch (chandef->width) { |
| 1427 | case NL80211_CHAN_WIDTH_20: |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1428 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1429 | width = 20; |
| 1430 | break; |
| 1431 | case NL80211_CHAN_WIDTH_40: |
| 1432 | width = 40; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1433 | break; |
| 1434 | case NL80211_CHAN_WIDTH_80: |
| 1435 | width = 80; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1436 | break; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1437 | case NL80211_CHAN_WIDTH_80P80: |
| 1438 | width = 80; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1439 | break; |
| 1440 | case NL80211_CHAN_WIDTH_160: |
| 1441 | width = 160; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1442 | break; |
| 1443 | default: |
| 1444 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1445 | } |
| 1446 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame^] | 1447 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1448 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1449 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1450 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1451 | return 0; |
| 1452 | } |
| 1453 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1454 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1455 | struct wireless_dev *wdev, |
| 1456 | struct genl_info *info) |
| 1457 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1458 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1459 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1460 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1461 | |
| 1462 | if (wdev) |
| 1463 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1464 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1465 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1466 | return -EOPNOTSUPP; |
| 1467 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1468 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1469 | if (result) |
| 1470 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1471 | |
| 1472 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1473 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1474 | case NL80211_IFTYPE_AP: |
| 1475 | case NL80211_IFTYPE_P2P_GO: |
| 1476 | if (wdev->beacon_interval) { |
| 1477 | result = -EBUSY; |
| 1478 | break; |
| 1479 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1480 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1481 | result = -EINVAL; |
| 1482 | break; |
| 1483 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1484 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1485 | result = 0; |
| 1486 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1487 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1488 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1489 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1490 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1491 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1492 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1493 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1494 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1495 | } |
| 1496 | mutex_unlock(&rdev->devlist_mtx); |
| 1497 | |
| 1498 | return result; |
| 1499 | } |
| 1500 | |
| 1501 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1502 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1503 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1504 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1505 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1506 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1507 | } |
| 1508 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1509 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1510 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1511 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1512 | struct net_device *dev = info->user_ptr[1]; |
| 1513 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1514 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1515 | |
| 1516 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1517 | return -EINVAL; |
| 1518 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1519 | if (netif_running(dev)) |
| 1520 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1521 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1522 | if (!rdev->ops->set_wds_peer) |
| 1523 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1524 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1525 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1526 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1527 | |
| 1528 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1529 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1533 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1534 | { |
| 1535 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1536 | struct net_device *netdev = NULL; |
| 1537 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1538 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1539 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1540 | u32 changed; |
| 1541 | u8 retry_short = 0, retry_long = 0; |
| 1542 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1543 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1544 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1545 | /* |
| 1546 | * Try to find the wiphy and netdev. Normally this |
| 1547 | * function shouldn't need the netdev, but this is |
| 1548 | * done for backward compatibility -- previously |
| 1549 | * setting the channel was done per wiphy, but now |
| 1550 | * it is per netdev. Previous userland like hostapd |
| 1551 | * also passed a netdev to set_wiphy, so that it is |
| 1552 | * possible to let that go to the right netdev! |
| 1553 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1554 | mutex_lock(&cfg80211_mutex); |
| 1555 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1556 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1557 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1558 | |
| 1559 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1560 | if (netdev && netdev->ieee80211_ptr) { |
| 1561 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1562 | mutex_lock(&rdev->mtx); |
| 1563 | } else |
| 1564 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1565 | } |
| 1566 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1567 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1568 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1569 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1570 | if (IS_ERR(rdev)) { |
| 1571 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1572 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1573 | } |
| 1574 | wdev = NULL; |
| 1575 | netdev = NULL; |
| 1576 | result = 0; |
| 1577 | |
| 1578 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1579 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1580 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1581 | |
| 1582 | /* |
| 1583 | * end workaround code, by now the rdev is available |
| 1584 | * and locked, and wdev may or may not be NULL. |
| 1585 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1586 | |
| 1587 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1588 | result = cfg80211_dev_rename( |
| 1589 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1590 | |
| 1591 | mutex_unlock(&cfg80211_mutex); |
| 1592 | |
| 1593 | if (result) |
| 1594 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1595 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1596 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1597 | struct ieee80211_txq_params txq_params; |
| 1598 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1599 | |
| 1600 | if (!rdev->ops->set_txq_params) { |
| 1601 | result = -EOPNOTSUPP; |
| 1602 | goto bad_res; |
| 1603 | } |
| 1604 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1605 | if (!netdev) { |
| 1606 | result = -EINVAL; |
| 1607 | goto bad_res; |
| 1608 | } |
| 1609 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1610 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1611 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1612 | result = -EINVAL; |
| 1613 | goto bad_res; |
| 1614 | } |
| 1615 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1616 | if (!netif_running(netdev)) { |
| 1617 | result = -ENETDOWN; |
| 1618 | goto bad_res; |
| 1619 | } |
| 1620 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1621 | nla_for_each_nested(nl_txq_params, |
| 1622 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1623 | rem_txq_params) { |
| 1624 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1625 | nla_data(nl_txq_params), |
| 1626 | nla_len(nl_txq_params), |
| 1627 | txq_params_policy); |
| 1628 | result = parse_txq_params(tb, &txq_params); |
| 1629 | if (result) |
| 1630 | goto bad_res; |
| 1631 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1632 | result = rdev_set_txq_params(rdev, netdev, |
| 1633 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1634 | if (result) |
| 1635 | goto bad_res; |
| 1636 | } |
| 1637 | } |
| 1638 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1639 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1640 | result = __nl80211_set_channel(rdev, |
| 1641 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1642 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1643 | if (result) |
| 1644 | goto bad_res; |
| 1645 | } |
| 1646 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1647 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1648 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1649 | enum nl80211_tx_power_setting type; |
| 1650 | int idx, mbm = 0; |
| 1651 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1652 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1653 | txp_wdev = NULL; |
| 1654 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1655 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1656 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1657 | goto bad_res; |
| 1658 | } |
| 1659 | |
| 1660 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1661 | type = nla_get_u32(info->attrs[idx]); |
| 1662 | |
| 1663 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1664 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1665 | result = -EINVAL; |
| 1666 | goto bad_res; |
| 1667 | } |
| 1668 | |
| 1669 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1670 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1671 | mbm = nla_get_u32(info->attrs[idx]); |
| 1672 | } |
| 1673 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1674 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1675 | if (result) |
| 1676 | goto bad_res; |
| 1677 | } |
| 1678 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1679 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1680 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1681 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1682 | if ((!rdev->wiphy.available_antennas_tx && |
| 1683 | !rdev->wiphy.available_antennas_rx) || |
| 1684 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1685 | result = -EOPNOTSUPP; |
| 1686 | goto bad_res; |
| 1687 | } |
| 1688 | |
| 1689 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1690 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1691 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1692 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1693 | * available antenna masks, except for the "all" mask */ |
| 1694 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1695 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1696 | result = -EINVAL; |
| 1697 | goto bad_res; |
| 1698 | } |
| 1699 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1700 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1701 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1702 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1703 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1704 | if (result) |
| 1705 | goto bad_res; |
| 1706 | } |
| 1707 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1708 | changed = 0; |
| 1709 | |
| 1710 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1711 | retry_short = nla_get_u8( |
| 1712 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1713 | if (retry_short == 0) { |
| 1714 | result = -EINVAL; |
| 1715 | goto bad_res; |
| 1716 | } |
| 1717 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1718 | } |
| 1719 | |
| 1720 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1721 | retry_long = nla_get_u8( |
| 1722 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1723 | if (retry_long == 0) { |
| 1724 | result = -EINVAL; |
| 1725 | goto bad_res; |
| 1726 | } |
| 1727 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1728 | } |
| 1729 | |
| 1730 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1731 | frag_threshold = nla_get_u32( |
| 1732 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1733 | if (frag_threshold < 256) { |
| 1734 | result = -EINVAL; |
| 1735 | goto bad_res; |
| 1736 | } |
| 1737 | if (frag_threshold != (u32) -1) { |
| 1738 | /* |
| 1739 | * Fragments (apart from the last one) are required to |
| 1740 | * have even length. Make the fragmentation code |
| 1741 | * simpler by stripping LSB should someone try to use |
| 1742 | * odd threshold value. |
| 1743 | */ |
| 1744 | frag_threshold &= ~0x1; |
| 1745 | } |
| 1746 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1747 | } |
| 1748 | |
| 1749 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1750 | rts_threshold = nla_get_u32( |
| 1751 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1752 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1753 | } |
| 1754 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1755 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1756 | coverage_class = nla_get_u8( |
| 1757 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1758 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1759 | } |
| 1760 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1761 | if (changed) { |
| 1762 | u8 old_retry_short, old_retry_long; |
| 1763 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1764 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1765 | |
| 1766 | if (!rdev->ops->set_wiphy_params) { |
| 1767 | result = -EOPNOTSUPP; |
| 1768 | goto bad_res; |
| 1769 | } |
| 1770 | |
| 1771 | old_retry_short = rdev->wiphy.retry_short; |
| 1772 | old_retry_long = rdev->wiphy.retry_long; |
| 1773 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1774 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1775 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1776 | |
| 1777 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1778 | rdev->wiphy.retry_short = retry_short; |
| 1779 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1780 | rdev->wiphy.retry_long = retry_long; |
| 1781 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1782 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1783 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1784 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1785 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1786 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1787 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1788 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1789 | if (result) { |
| 1790 | rdev->wiphy.retry_short = old_retry_short; |
| 1791 | rdev->wiphy.retry_long = old_retry_long; |
| 1792 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1793 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1794 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1795 | } |
| 1796 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1797 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1798 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1799 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1800 | if (netdev) |
| 1801 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1802 | return result; |
| 1803 | } |
| 1804 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1805 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1806 | { |
| 1807 | return (u64)wdev->identifier | |
| 1808 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1809 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1810 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1811 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 1812 | struct cfg80211_chan_def *chandef) |
| 1813 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame^] | 1814 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1815 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1816 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1817 | chandef->chan->center_freq)) |
| 1818 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1819 | switch (chandef->width) { |
| 1820 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1821 | case NL80211_CHAN_WIDTH_20: |
| 1822 | case NL80211_CHAN_WIDTH_40: |
| 1823 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1824 | cfg80211_get_chandef_type(chandef))) |
| 1825 | return -ENOBUFS; |
| 1826 | break; |
| 1827 | default: |
| 1828 | break; |
| 1829 | } |
| 1830 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 1831 | return -ENOBUFS; |
| 1832 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 1833 | return -ENOBUFS; |
| 1834 | if (chandef->center_freq2 && |
| 1835 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1836 | return -ENOBUFS; |
| 1837 | return 0; |
| 1838 | } |
| 1839 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1840 | 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] | 1841 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1842 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1843 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1844 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1845 | void *hdr; |
| 1846 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1847 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1848 | if (!hdr) |
| 1849 | return -1; |
| 1850 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1851 | if (dev && |
| 1852 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1853 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1854 | goto nla_put_failure; |
| 1855 | |
| 1856 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1857 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1858 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1859 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1860 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1861 | rdev->devlist_generation ^ |
| 1862 | (cfg80211_rdev_list_generation << 2))) |
| 1863 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1864 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1865 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1866 | int ret; |
| 1867 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1868 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1869 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 1870 | if (ret == 0) { |
| 1871 | if (nl80211_send_chandef(msg, &chandef)) |
| 1872 | goto nla_put_failure; |
| 1873 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1874 | } |
| 1875 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 1876 | if (wdev->ssid_len) { |
| 1877 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 1878 | goto nla_put_failure; |
| 1879 | } |
| 1880 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1881 | return genlmsg_end(msg, hdr); |
| 1882 | |
| 1883 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1884 | genlmsg_cancel(msg, hdr); |
| 1885 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1889 | { |
| 1890 | int wp_idx = 0; |
| 1891 | int if_idx = 0; |
| 1892 | int wp_start = cb->args[0]; |
| 1893 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1894 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1895 | struct wireless_dev *wdev; |
| 1896 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1897 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1898 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1899 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1900 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1901 | if (wp_idx < wp_start) { |
| 1902 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1903 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1904 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1905 | if_idx = 0; |
| 1906 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1907 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1908 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1909 | if (if_idx < if_start) { |
| 1910 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1911 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1912 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1913 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1914 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1915 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1916 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1917 | goto out; |
| 1918 | } |
| 1919 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1920 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1921 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1922 | |
| 1923 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1924 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1925 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1926 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1927 | |
| 1928 | cb->args[0] = wp_idx; |
| 1929 | cb->args[1] = if_idx; |
| 1930 | |
| 1931 | return skb->len; |
| 1932 | } |
| 1933 | |
| 1934 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1935 | { |
| 1936 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1937 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1938 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1939 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1940 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1941 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1942 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1943 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1944 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1945 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1946 | nlmsg_free(msg); |
| 1947 | return -ENOBUFS; |
| 1948 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1949 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1950 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1951 | } |
| 1952 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1953 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1954 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1955 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1956 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1957 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1958 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1959 | }; |
| 1960 | |
| 1961 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1962 | { |
| 1963 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1964 | int flag; |
| 1965 | |
| 1966 | *mntrflags = 0; |
| 1967 | |
| 1968 | if (!nla) |
| 1969 | return -EINVAL; |
| 1970 | |
| 1971 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1972 | nla, mntr_flags_policy)) |
| 1973 | return -EINVAL; |
| 1974 | |
| 1975 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1976 | if (flags[flag]) |
| 1977 | *mntrflags |= (1<<flag); |
| 1978 | |
| 1979 | return 0; |
| 1980 | } |
| 1981 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1982 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1983 | struct net_device *netdev, u8 use_4addr, |
| 1984 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1985 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1986 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1987 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1988 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1989 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1990 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1991 | |
| 1992 | switch (iftype) { |
| 1993 | case NL80211_IFTYPE_AP_VLAN: |
| 1994 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1995 | return 0; |
| 1996 | break; |
| 1997 | case NL80211_IFTYPE_STATION: |
| 1998 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1999 | return 0; |
| 2000 | break; |
| 2001 | default: |
| 2002 | break; |
| 2003 | } |
| 2004 | |
| 2005 | return -EOPNOTSUPP; |
| 2006 | } |
| 2007 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2008 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2009 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2010 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2011 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2012 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2013 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2014 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2015 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2016 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2017 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2018 | memset(¶ms, 0, sizeof(params)); |
| 2019 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2020 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2021 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2022 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2023 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2024 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2025 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2026 | if (ntype > NL80211_IFTYPE_MAX) |
| 2027 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2028 | } |
| 2029 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2030 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2031 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2032 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2033 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2034 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2035 | if (netif_running(dev)) |
| 2036 | return -EBUSY; |
| 2037 | |
| 2038 | wdev_lock(wdev); |
| 2039 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2040 | IEEE80211_MAX_MESH_ID_LEN); |
| 2041 | wdev->mesh_id_up_len = |
| 2042 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2043 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2044 | wdev->mesh_id_up_len); |
| 2045 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2046 | } |
| 2047 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2048 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2049 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2050 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2051 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2052 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2053 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2054 | } else { |
| 2055 | params.use_4addr = -1; |
| 2056 | } |
| 2057 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2058 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2059 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2060 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2061 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2062 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2063 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2064 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2065 | |
| 2066 | flags = &_flags; |
| 2067 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2068 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2069 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2070 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2071 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2072 | else |
| 2073 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2074 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2075 | if (!err && params.use_4addr != -1) |
| 2076 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2077 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2078 | return err; |
| 2079 | } |
| 2080 | |
| 2081 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2082 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2083 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2084 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2085 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2086 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2087 | int err; |
| 2088 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2089 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2090 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2091 | memset(¶ms, 0, sizeof(params)); |
| 2092 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2093 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2094 | return -EINVAL; |
| 2095 | |
| 2096 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2097 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2098 | if (type > NL80211_IFTYPE_MAX) |
| 2099 | return -EINVAL; |
| 2100 | } |
| 2101 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2102 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2103 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2104 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2105 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2106 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2107 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2108 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2109 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2110 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2111 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2112 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2113 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2114 | if (!msg) |
| 2115 | return -ENOMEM; |
| 2116 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2117 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2118 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2119 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2120 | wdev = rdev_add_virtual_intf(rdev, |
| 2121 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2122 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2123 | if (IS_ERR(wdev)) { |
| 2124 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2125 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2126 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2127 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2128 | switch (type) { |
| 2129 | case NL80211_IFTYPE_MESH_POINT: |
| 2130 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2131 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2132 | wdev_lock(wdev); |
| 2133 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2134 | IEEE80211_MAX_MESH_ID_LEN); |
| 2135 | wdev->mesh_id_up_len = |
| 2136 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2137 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2138 | wdev->mesh_id_up_len); |
| 2139 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2140 | break; |
| 2141 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2142 | /* |
| 2143 | * P2P Device doesn't have a netdev, so doesn't go |
| 2144 | * through the netdev notifier and must be added here |
| 2145 | */ |
| 2146 | mutex_init(&wdev->mtx); |
| 2147 | INIT_LIST_HEAD(&wdev->event_list); |
| 2148 | spin_lock_init(&wdev->event_lock); |
| 2149 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2150 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2151 | |
| 2152 | mutex_lock(&rdev->devlist_mtx); |
| 2153 | wdev->identifier = ++rdev->wdev_id; |
| 2154 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2155 | rdev->devlist_generation++; |
| 2156 | mutex_unlock(&rdev->devlist_mtx); |
| 2157 | break; |
| 2158 | default: |
| 2159 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2160 | } |
| 2161 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2162 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2163 | rdev, wdev) < 0) { |
| 2164 | nlmsg_free(msg); |
| 2165 | return -ENOBUFS; |
| 2166 | } |
| 2167 | |
| 2168 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2172 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2173 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2174 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2175 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2176 | if (!rdev->ops->del_virtual_intf) |
| 2177 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2178 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2179 | /* |
| 2180 | * If we remove a wireless device without a netdev then clear |
| 2181 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2182 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2183 | * since the wdev has been freed, unlike with a netdev where |
| 2184 | * we need the dev_put() for the netdev to really be freed. |
| 2185 | */ |
| 2186 | if (!wdev->netdev) |
| 2187 | info->user_ptr[1] = NULL; |
| 2188 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2189 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2190 | } |
| 2191 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2192 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2193 | { |
| 2194 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2195 | struct net_device *dev = info->user_ptr[1]; |
| 2196 | u16 noack_map; |
| 2197 | |
| 2198 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2199 | return -EINVAL; |
| 2200 | |
| 2201 | if (!rdev->ops->set_noack_map) |
| 2202 | return -EOPNOTSUPP; |
| 2203 | |
| 2204 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2205 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2206 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2207 | } |
| 2208 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2209 | struct get_key_cookie { |
| 2210 | struct sk_buff *msg; |
| 2211 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2212 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2213 | }; |
| 2214 | |
| 2215 | static void get_key_callback(void *c, struct key_params *params) |
| 2216 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2217 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2218 | struct get_key_cookie *cookie = c; |
| 2219 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2220 | if ((params->key && |
| 2221 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2222 | params->key_len, params->key)) || |
| 2223 | (params->seq && |
| 2224 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2225 | params->seq_len, params->seq)) || |
| 2226 | (params->cipher && |
| 2227 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2228 | params->cipher))) |
| 2229 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2230 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2231 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2232 | if (!key) |
| 2233 | goto nla_put_failure; |
| 2234 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2235 | if ((params->key && |
| 2236 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2237 | params->key_len, params->key)) || |
| 2238 | (params->seq && |
| 2239 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2240 | params->seq_len, params->seq)) || |
| 2241 | (params->cipher && |
| 2242 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2243 | params->cipher))) |
| 2244 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2245 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2246 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2247 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2248 | |
| 2249 | nla_nest_end(cookie->msg, key); |
| 2250 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2251 | return; |
| 2252 | nla_put_failure: |
| 2253 | cookie->error = 1; |
| 2254 | } |
| 2255 | |
| 2256 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2257 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2258 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2259 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2260 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2261 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2262 | const u8 *mac_addr = NULL; |
| 2263 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2264 | struct get_key_cookie cookie = { |
| 2265 | .error = 0, |
| 2266 | }; |
| 2267 | void *hdr; |
| 2268 | struct sk_buff *msg; |
| 2269 | |
| 2270 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2271 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2272 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2273 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2274 | return -EINVAL; |
| 2275 | |
| 2276 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2277 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2278 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2279 | pairwise = !!mac_addr; |
| 2280 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2281 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2282 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2283 | return -EINVAL; |
| 2284 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2285 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2286 | return -EINVAL; |
| 2287 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2288 | } |
| 2289 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2290 | if (!rdev->ops->get_key) |
| 2291 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2292 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2293 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2294 | if (!msg) |
| 2295 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2296 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2297 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2298 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2299 | if (IS_ERR(hdr)) |
| 2300 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2301 | |
| 2302 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2303 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2304 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2305 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2306 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2307 | goto nla_put_failure; |
| 2308 | if (mac_addr && |
| 2309 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2310 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2311 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2312 | if (pairwise && mac_addr && |
| 2313 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2314 | return -ENOENT; |
| 2315 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2316 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2317 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2318 | |
| 2319 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2320 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2321 | |
| 2322 | if (cookie.error) |
| 2323 | goto nla_put_failure; |
| 2324 | |
| 2325 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2326 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2327 | |
| 2328 | nla_put_failure: |
| 2329 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2330 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2331 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2332 | return err; |
| 2333 | } |
| 2334 | |
| 2335 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2336 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2337 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2338 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2339 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2340 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2341 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2342 | err = nl80211_parse_key(info, &key); |
| 2343 | if (err) |
| 2344 | return err; |
| 2345 | |
| 2346 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2347 | return -EINVAL; |
| 2348 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2349 | /* only support setting default key */ |
| 2350 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2351 | return -EINVAL; |
| 2352 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2353 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2354 | |
| 2355 | if (key.def) { |
| 2356 | if (!rdev->ops->set_default_key) { |
| 2357 | err = -EOPNOTSUPP; |
| 2358 | goto out; |
| 2359 | } |
| 2360 | |
| 2361 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2362 | if (err) |
| 2363 | goto out; |
| 2364 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2365 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2366 | key.def_uni, key.def_multi); |
| 2367 | |
| 2368 | if (err) |
| 2369 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2370 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2371 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2372 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2373 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2374 | } else { |
| 2375 | if (key.def_uni || !key.def_multi) { |
| 2376 | err = -EINVAL; |
| 2377 | goto out; |
| 2378 | } |
| 2379 | |
| 2380 | if (!rdev->ops->set_default_mgmt_key) { |
| 2381 | err = -EOPNOTSUPP; |
| 2382 | goto out; |
| 2383 | } |
| 2384 | |
| 2385 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2386 | if (err) |
| 2387 | goto out; |
| 2388 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2389 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2390 | if (err) |
| 2391 | goto out; |
| 2392 | |
| 2393 | #ifdef CONFIG_CFG80211_WEXT |
| 2394 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2395 | #endif |
| 2396 | } |
| 2397 | |
| 2398 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2399 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2400 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2401 | return err; |
| 2402 | } |
| 2403 | |
| 2404 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2405 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2406 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2407 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2408 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2409 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2410 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2411 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2412 | err = nl80211_parse_key(info, &key); |
| 2413 | if (err) |
| 2414 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2415 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2416 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2417 | return -EINVAL; |
| 2418 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2419 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2420 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2421 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2422 | if (key.type == -1) { |
| 2423 | if (mac_addr) |
| 2424 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2425 | else |
| 2426 | key.type = NL80211_KEYTYPE_GROUP; |
| 2427 | } |
| 2428 | |
| 2429 | /* for now */ |
| 2430 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2431 | key.type != NL80211_KEYTYPE_GROUP) |
| 2432 | return -EINVAL; |
| 2433 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2434 | if (!rdev->ops->add_key) |
| 2435 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2436 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2437 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2438 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2439 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2440 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2441 | |
| 2442 | wdev_lock(dev->ieee80211_ptr); |
| 2443 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2444 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2445 | err = rdev_add_key(rdev, dev, key.idx, |
| 2446 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2447 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2448 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2449 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2450 | return err; |
| 2451 | } |
| 2452 | |
| 2453 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2454 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2455 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2456 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2457 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2458 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2459 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2460 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2461 | err = nl80211_parse_key(info, &key); |
| 2462 | if (err) |
| 2463 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2464 | |
| 2465 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2466 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2467 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2468 | if (key.type == -1) { |
| 2469 | if (mac_addr) |
| 2470 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2471 | else |
| 2472 | key.type = NL80211_KEYTYPE_GROUP; |
| 2473 | } |
| 2474 | |
| 2475 | /* for now */ |
| 2476 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2477 | key.type != NL80211_KEYTYPE_GROUP) |
| 2478 | return -EINVAL; |
| 2479 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2480 | if (!rdev->ops->del_key) |
| 2481 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2482 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2483 | wdev_lock(dev->ieee80211_ptr); |
| 2484 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2485 | |
| 2486 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2487 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2488 | err = -ENOENT; |
| 2489 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2490 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2491 | err = rdev_del_key(rdev, dev, key.idx, |
| 2492 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2493 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2494 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2495 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2496 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2497 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2498 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2499 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2500 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2501 | } |
| 2502 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2503 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2504 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2505 | return err; |
| 2506 | } |
| 2507 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2508 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2509 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2510 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2511 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2512 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2513 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2514 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2515 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2516 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2517 | return -EINVAL; |
| 2518 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2519 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2520 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2521 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2522 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2523 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2524 | if (!bcn->head_len) |
| 2525 | return -EINVAL; |
| 2526 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2530 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2531 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2532 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2533 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2534 | } |
| 2535 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2536 | if (!haveinfo) |
| 2537 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2538 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2539 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2540 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2541 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2545 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2546 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2547 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2548 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2549 | } |
| 2550 | |
| 2551 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2552 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2553 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2554 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2555 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2556 | } |
| 2557 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2558 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2559 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2560 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2561 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2562 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2563 | } |
| 2564 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2565 | return 0; |
| 2566 | } |
| 2567 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2568 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2569 | struct cfg80211_ap_settings *params) |
| 2570 | { |
| 2571 | struct wireless_dev *wdev; |
| 2572 | bool ret = false; |
| 2573 | |
| 2574 | mutex_lock(&rdev->devlist_mtx); |
| 2575 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2576 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2577 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2578 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2579 | continue; |
| 2580 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2581 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2582 | continue; |
| 2583 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2584 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2585 | ret = true; |
| 2586 | break; |
| 2587 | } |
| 2588 | |
| 2589 | mutex_unlock(&rdev->devlist_mtx); |
| 2590 | |
| 2591 | return ret; |
| 2592 | } |
| 2593 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2594 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2595 | enum nl80211_auth_type auth_type, |
| 2596 | enum nl80211_commands cmd) |
| 2597 | { |
| 2598 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2599 | return false; |
| 2600 | |
| 2601 | switch (cmd) { |
| 2602 | case NL80211_CMD_AUTHENTICATE: |
| 2603 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2604 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2605 | return false; |
| 2606 | return true; |
| 2607 | case NL80211_CMD_CONNECT: |
| 2608 | case NL80211_CMD_START_AP: |
| 2609 | /* SAE not supported yet */ |
| 2610 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2611 | return false; |
| 2612 | return true; |
| 2613 | default: |
| 2614 | return false; |
| 2615 | } |
| 2616 | } |
| 2617 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2618 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2619 | { |
| 2620 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2621 | struct net_device *dev = info->user_ptr[1]; |
| 2622 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2623 | struct cfg80211_ap_settings params; |
| 2624 | int err; |
| 2625 | |
| 2626 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2627 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2628 | return -EOPNOTSUPP; |
| 2629 | |
| 2630 | if (!rdev->ops->start_ap) |
| 2631 | return -EOPNOTSUPP; |
| 2632 | |
| 2633 | if (wdev->beacon_interval) |
| 2634 | return -EALREADY; |
| 2635 | |
| 2636 | memset(¶ms, 0, sizeof(params)); |
| 2637 | |
| 2638 | /* these are required for START_AP */ |
| 2639 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2640 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2641 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2642 | return -EINVAL; |
| 2643 | |
| 2644 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2645 | if (err) |
| 2646 | return err; |
| 2647 | |
| 2648 | params.beacon_interval = |
| 2649 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2650 | params.dtim_period = |
| 2651 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2652 | |
| 2653 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2654 | if (err) |
| 2655 | return err; |
| 2656 | |
| 2657 | /* |
| 2658 | * In theory, some of these attributes should be required here |
| 2659 | * but since they were not used when the command was originally |
| 2660 | * added, keep them optional for old user space programs to let |
| 2661 | * them continue to work with drivers that do not need the |
| 2662 | * additional information -- drivers must check! |
| 2663 | */ |
| 2664 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2665 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2666 | params.ssid_len = |
| 2667 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2668 | if (params.ssid_len == 0 || |
| 2669 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2670 | return -EINVAL; |
| 2671 | } |
| 2672 | |
| 2673 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2674 | params.hidden_ssid = nla_get_u32( |
| 2675 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2676 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2677 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2678 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2679 | return -EINVAL; |
| 2680 | } |
| 2681 | |
| 2682 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2683 | |
| 2684 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2685 | params.auth_type = nla_get_u32( |
| 2686 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2687 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 2688 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2689 | return -EINVAL; |
| 2690 | } else |
| 2691 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2692 | |
| 2693 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2694 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2695 | if (err) |
| 2696 | return err; |
| 2697 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2698 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2699 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2700 | return -EOPNOTSUPP; |
| 2701 | params.inactivity_timeout = nla_get_u16( |
| 2702 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2703 | } |
| 2704 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2705 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2706 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 2707 | if (err) |
| 2708 | return err; |
| 2709 | } else if (wdev->preset_chandef.chan) { |
| 2710 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2711 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2712 | return -EINVAL; |
| 2713 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2714 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2715 | return -EINVAL; |
| 2716 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2717 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2718 | err = cfg80211_can_use_chan(rdev, wdev, params.chandef.chan, |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2719 | CHAN_MODE_SHARED); |
| 2720 | mutex_unlock(&rdev->devlist_mtx); |
| 2721 | |
| 2722 | if (err) |
| 2723 | return err; |
| 2724 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2725 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2726 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2727 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2728 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2729 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 2730 | wdev->ssid_len = params.ssid_len; |
| 2731 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2732 | } |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2733 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2734 | } |
| 2735 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2736 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2737 | { |
| 2738 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2739 | struct net_device *dev = info->user_ptr[1]; |
| 2740 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2741 | struct cfg80211_beacon_data params; |
| 2742 | int err; |
| 2743 | |
| 2744 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2745 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2746 | return -EOPNOTSUPP; |
| 2747 | |
| 2748 | if (!rdev->ops->change_beacon) |
| 2749 | return -EOPNOTSUPP; |
| 2750 | |
| 2751 | if (!wdev->beacon_interval) |
| 2752 | return -EINVAL; |
| 2753 | |
| 2754 | err = nl80211_parse_beacon(info, ¶ms); |
| 2755 | if (err) |
| 2756 | return err; |
| 2757 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2758 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | 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] | 2762 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2764 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2765 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2766 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2767 | } |
| 2768 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2769 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2770 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2771 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2772 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2773 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2774 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2775 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2776 | }; |
| 2777 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2778 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2779 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2780 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2781 | { |
| 2782 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2783 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2784 | int flag; |
| 2785 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2786 | /* |
| 2787 | * Try parsing the new attribute first so userspace |
| 2788 | * can specify both for older kernels. |
| 2789 | */ |
| 2790 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2791 | if (nla) { |
| 2792 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2793 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2794 | sta_flags = nla_data(nla); |
| 2795 | params->sta_flags_mask = sta_flags->mask; |
| 2796 | params->sta_flags_set = sta_flags->set; |
| 2797 | if ((params->sta_flags_mask | |
| 2798 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2799 | return -EINVAL; |
| 2800 | return 0; |
| 2801 | } |
| 2802 | |
| 2803 | /* if present, parse the old attribute */ |
| 2804 | |
| 2805 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2806 | if (!nla) |
| 2807 | return 0; |
| 2808 | |
| 2809 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2810 | nla, sta_flags_policy)) |
| 2811 | return -EINVAL; |
| 2812 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2813 | /* |
| 2814 | * Only allow certain flags for interface types so that |
| 2815 | * other attributes are silently ignored. Remember that |
| 2816 | * this is backward compatibility code with old userspace |
| 2817 | * and shouldn't be hit in other cases anyway. |
| 2818 | */ |
| 2819 | switch (iftype) { |
| 2820 | case NL80211_IFTYPE_AP: |
| 2821 | case NL80211_IFTYPE_AP_VLAN: |
| 2822 | case NL80211_IFTYPE_P2P_GO: |
| 2823 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2824 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2825 | BIT(NL80211_STA_FLAG_WME) | |
| 2826 | BIT(NL80211_STA_FLAG_MFP); |
| 2827 | break; |
| 2828 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2829 | case NL80211_IFTYPE_STATION: |
| 2830 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2831 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2832 | break; |
| 2833 | case NL80211_IFTYPE_MESH_POINT: |
| 2834 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2835 | BIT(NL80211_STA_FLAG_MFP) | |
| 2836 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2837 | default: |
| 2838 | return -EINVAL; |
| 2839 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2840 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2841 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 2842 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2843 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2844 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2845 | /* no longer support new API additions in old API */ |
| 2846 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 2847 | return -EINVAL; |
| 2848 | } |
| 2849 | } |
| 2850 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2851 | return 0; |
| 2852 | } |
| 2853 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2854 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2855 | int attr) |
| 2856 | { |
| 2857 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2858 | u32 bitrate; |
| 2859 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2860 | |
| 2861 | rate = nla_nest_start(msg, attr); |
| 2862 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 2863 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2864 | |
| 2865 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2866 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2867 | /* report 16-bit bitrate only if we can */ |
| 2868 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 2869 | if (bitrate > 0 && |
| 2870 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 2871 | return false; |
| 2872 | if (bitrate_compat > 0 && |
| 2873 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 2874 | return false; |
| 2875 | |
| 2876 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 2877 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 2878 | return false; |
| 2879 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 2880 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 2881 | return false; |
| 2882 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 2883 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 2884 | return false; |
| 2885 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 2886 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 2887 | return false; |
| 2888 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 2889 | return false; |
| 2890 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 2891 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 2892 | return false; |
| 2893 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 2894 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 2895 | return false; |
| 2896 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 2897 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 2898 | return false; |
| 2899 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 2900 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 2901 | return false; |
| 2902 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 2903 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 2904 | return false; |
| 2905 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2906 | |
| 2907 | nla_nest_end(msg, rate); |
| 2908 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2909 | } |
| 2910 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2911 | 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] | 2912 | int flags, |
| 2913 | struct cfg80211_registered_device *rdev, |
| 2914 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2915 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2916 | { |
| 2917 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2918 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2919 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2920 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2921 | if (!hdr) |
| 2922 | return -1; |
| 2923 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2924 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2925 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 2926 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 2927 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2928 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2929 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2930 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2931 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2932 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 2933 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2934 | sinfo->connected_time)) |
| 2935 | goto nla_put_failure; |
| 2936 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 2937 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2938 | sinfo->inactive_time)) |
| 2939 | goto nla_put_failure; |
| 2940 | if ((sinfo->filled & STATION_INFO_RX_BYTES) && |
| 2941 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2942 | sinfo->rx_bytes)) |
| 2943 | goto nla_put_failure; |
| 2944 | if ((sinfo->filled & STATION_INFO_TX_BYTES) && |
| 2945 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2946 | sinfo->tx_bytes)) |
| 2947 | goto nla_put_failure; |
| 2948 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 2949 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 2950 | goto nla_put_failure; |
| 2951 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 2952 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 2953 | goto nla_put_failure; |
| 2954 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 2955 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2956 | sinfo->plink_state)) |
| 2957 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2958 | switch (rdev->wiphy.signal_type) { |
| 2959 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2960 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 2961 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 2962 | sinfo->signal)) |
| 2963 | goto nla_put_failure; |
| 2964 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 2965 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2966 | sinfo->signal_avg)) |
| 2967 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2968 | break; |
| 2969 | default: |
| 2970 | break; |
| 2971 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2972 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2973 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2974 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2975 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2976 | } |
| 2977 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2978 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2979 | NL80211_STA_INFO_RX_BITRATE)) |
| 2980 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2981 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2982 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 2983 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2984 | sinfo->rx_packets)) |
| 2985 | goto nla_put_failure; |
| 2986 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 2987 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2988 | sinfo->tx_packets)) |
| 2989 | goto nla_put_failure; |
| 2990 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 2991 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2992 | sinfo->tx_retries)) |
| 2993 | goto nla_put_failure; |
| 2994 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 2995 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2996 | sinfo->tx_failed)) |
| 2997 | goto nla_put_failure; |
| 2998 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 2999 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3000 | sinfo->beacon_loss_count)) |
| 3001 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3002 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3003 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3004 | if (!bss_param) |
| 3005 | goto nla_put_failure; |
| 3006 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3007 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3008 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3009 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3010 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3011 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3012 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3013 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3014 | sinfo->bss_param.dtim_period) || |
| 3015 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3016 | sinfo->bss_param.beacon_interval)) |
| 3017 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3018 | |
| 3019 | nla_nest_end(msg, bss_param); |
| 3020 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3021 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3022 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3023 | sizeof(struct nl80211_sta_flag_update), |
| 3024 | &sinfo->sta_flags)) |
| 3025 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3026 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3027 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3028 | sinfo->t_offset)) |
| 3029 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3030 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3031 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3032 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3033 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3034 | sinfo->assoc_req_ies)) |
| 3035 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3036 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3037 | return genlmsg_end(msg, hdr); |
| 3038 | |
| 3039 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3040 | genlmsg_cancel(msg, hdr); |
| 3041 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3042 | } |
| 3043 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3044 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3045 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3046 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3047 | struct station_info sinfo; |
| 3048 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3049 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3050 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3051 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3052 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3053 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3054 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3055 | if (err) |
| 3056 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3057 | |
| 3058 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3059 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3060 | goto out_err; |
| 3061 | } |
| 3062 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3063 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3064 | memset(&sinfo, 0, sizeof(sinfo)); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3065 | err = rdev_dump_station(dev, netdev, sta_idx, |
| 3066 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3067 | if (err == -ENOENT) |
| 3068 | break; |
| 3069 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3070 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3071 | |
| 3072 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3073 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3074 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3075 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3076 | &sinfo) < 0) |
| 3077 | goto out; |
| 3078 | |
| 3079 | sta_idx++; |
| 3080 | } |
| 3081 | |
| 3082 | |
| 3083 | out: |
| 3084 | cb->args[1] = sta_idx; |
| 3085 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3086 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3087 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3088 | |
| 3089 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3090 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3091 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3092 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3093 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3094 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3095 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3096 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3097 | struct sk_buff *msg; |
| 3098 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3099 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3100 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3101 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3102 | |
| 3103 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3104 | return -EINVAL; |
| 3105 | |
| 3106 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3107 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3108 | if (!rdev->ops->get_station) |
| 3109 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3110 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3111 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3112 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3113 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3114 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3115 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3116 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3117 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3118 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3119 | 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] | 3120 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3121 | nlmsg_free(msg); |
| 3122 | return -ENOBUFS; |
| 3123 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3124 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3125 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3129 | * 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] | 3130 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3131 | static struct net_device *get_vlan(struct genl_info *info, |
| 3132 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3133 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3134 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3135 | struct net_device *v; |
| 3136 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3137 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3138 | if (!vlanattr) |
| 3139 | return NULL; |
| 3140 | |
| 3141 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3142 | if (!v) |
| 3143 | return ERR_PTR(-ENODEV); |
| 3144 | |
| 3145 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3146 | ret = -EINVAL; |
| 3147 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3148 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3149 | |
| 3150 | if (!netif_running(v)) { |
| 3151 | ret = -ENETDOWN; |
| 3152 | goto error; |
| 3153 | } |
| 3154 | |
| 3155 | return v; |
| 3156 | error: |
| 3157 | dev_put(v); |
| 3158 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3162 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3163 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3164 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3165 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3166 | struct station_parameters params; |
| 3167 | u8 *mac_addr = NULL; |
| 3168 | |
| 3169 | memset(¶ms, 0, sizeof(params)); |
| 3170 | |
| 3171 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 3172 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3173 | |
| 3174 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3175 | return -EINVAL; |
| 3176 | |
| 3177 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3178 | return -EINVAL; |
| 3179 | |
| 3180 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3181 | |
| 3182 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3183 | params.supported_rates = |
| 3184 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3185 | params.supported_rates_len = |
| 3186 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3187 | } |
| 3188 | |
| 3189 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3190 | params.listen_interval = |
| 3191 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 3192 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3193 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3194 | params.ht_capa = |
| 3195 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3196 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3197 | if (!rdev->ops->change_station) |
| 3198 | return -EOPNOTSUPP; |
| 3199 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3200 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3201 | return -EINVAL; |
| 3202 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3203 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3204 | params.plink_action = |
| 3205 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3206 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3207 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3208 | params.plink_state = |
| 3209 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3210 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3211 | switch (dev->ieee80211_ptr->iftype) { |
| 3212 | case NL80211_IFTYPE_AP: |
| 3213 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3214 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3215 | /* disallow mesh-specific things */ |
| 3216 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3217 | return -EINVAL; |
| 3218 | |
| 3219 | /* TDLS can't be set, ... */ |
| 3220 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3221 | return -EINVAL; |
| 3222 | /* |
| 3223 | * ... but don't bother the driver with it. This works around |
| 3224 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3225 | * TLDS_PEER flag in the mask even for AP mode. |
| 3226 | */ |
| 3227 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3228 | |
| 3229 | /* accept only the listed bits */ |
| 3230 | if (params.sta_flags_mask & |
| 3231 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3232 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3233 | BIT(NL80211_STA_FLAG_WME) | |
| 3234 | BIT(NL80211_STA_FLAG_MFP))) |
| 3235 | return -EINVAL; |
| 3236 | |
| 3237 | /* must be last in here for error handling */ |
| 3238 | params.vlan = get_vlan(info, rdev); |
| 3239 | if (IS_ERR(params.vlan)) |
| 3240 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3241 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3242 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3243 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3244 | /* |
| 3245 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3246 | * but silently ignore attempts to change it since we |
| 3247 | * don't have state here to verify that it doesn't try |
| 3248 | * to change the flag. |
| 3249 | */ |
| 3250 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3251 | /* fall through */ |
| 3252 | case NL80211_IFTYPE_ADHOC: |
| 3253 | /* disallow things sta doesn't support */ |
| 3254 | if (params.plink_action) |
| 3255 | return -EINVAL; |
| 3256 | if (params.ht_capa) |
| 3257 | return -EINVAL; |
| 3258 | if (params.listen_interval >= 0) |
| 3259 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3260 | /* reject any changes other than AUTHORIZED */ |
| 3261 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3262 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3263 | break; |
| 3264 | case NL80211_IFTYPE_MESH_POINT: |
| 3265 | /* disallow things mesh doesn't support */ |
| 3266 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3267 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3268 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3269 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3270 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3271 | return -EINVAL; |
| 3272 | /* |
| 3273 | * No special handling for TDLS here -- the userspace |
| 3274 | * mesh code doesn't have this bug. |
| 3275 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3276 | if (params.sta_flags_mask & |
| 3277 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3278 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3279 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3280 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3281 | break; |
| 3282 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3283 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3284 | } |
| 3285 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3286 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3287 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3288 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3289 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3290 | if (params.vlan) |
| 3291 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3292 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3293 | return err; |
| 3294 | } |
| 3295 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3296 | static struct nla_policy |
| 3297 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3298 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3299 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3300 | }; |
| 3301 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3302 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3303 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3304 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3305 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3306 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3307 | struct station_parameters params; |
| 3308 | u8 *mac_addr = NULL; |
| 3309 | |
| 3310 | memset(¶ms, 0, sizeof(params)); |
| 3311 | |
| 3312 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3313 | return -EINVAL; |
| 3314 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3315 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3316 | return -EINVAL; |
| 3317 | |
| 3318 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3319 | return -EINVAL; |
| 3320 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3321 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3322 | return -EINVAL; |
| 3323 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3324 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3325 | params.supported_rates = |
| 3326 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3327 | params.supported_rates_len = |
| 3328 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3329 | params.listen_interval = |
| 3330 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3331 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3332 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3333 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3334 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3335 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3336 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3337 | params.ht_capa = |
| 3338 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3339 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3340 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3341 | params.vht_capa = |
| 3342 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3343 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3344 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3345 | params.plink_action = |
| 3346 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3347 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3348 | if (!rdev->ops->add_station) |
| 3349 | return -EOPNOTSUPP; |
| 3350 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3351 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3352 | return -EINVAL; |
| 3353 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3354 | switch (dev->ieee80211_ptr->iftype) { |
| 3355 | case NL80211_IFTYPE_AP: |
| 3356 | case NL80211_IFTYPE_AP_VLAN: |
| 3357 | case NL80211_IFTYPE_P2P_GO: |
| 3358 | /* parse WME attributes if sta is WME capable */ |
| 3359 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3360 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3361 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3362 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3363 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3364 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3365 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3366 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3367 | nl80211_sta_wme_policy); |
| 3368 | if (err) |
| 3369 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3370 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3371 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3372 | params.uapsd_queues = |
| 3373 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3374 | if (params.uapsd_queues & |
| 3375 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3376 | return -EINVAL; |
| 3377 | |
| 3378 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3379 | params.max_sp = |
| 3380 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3381 | |
| 3382 | if (params.max_sp & |
| 3383 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3384 | return -EINVAL; |
| 3385 | |
| 3386 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3387 | } |
| 3388 | /* TDLS peers cannot be added */ |
| 3389 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3390 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3391 | /* but don't bother the driver with it */ |
| 3392 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3393 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3394 | /* must be last in here for error handling */ |
| 3395 | params.vlan = get_vlan(info, rdev); |
| 3396 | if (IS_ERR(params.vlan)) |
| 3397 | return PTR_ERR(params.vlan); |
| 3398 | break; |
| 3399 | case NL80211_IFTYPE_MESH_POINT: |
| 3400 | /* TDLS peers cannot be added */ |
| 3401 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3402 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3403 | break; |
| 3404 | case NL80211_IFTYPE_STATION: |
| 3405 | /* Only TDLS peers can be added */ |
| 3406 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3407 | return -EINVAL; |
| 3408 | /* Can only add if TDLS ... */ |
| 3409 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3410 | return -EOPNOTSUPP; |
| 3411 | /* ... with external setup is supported */ |
| 3412 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3413 | return -EOPNOTSUPP; |
| 3414 | break; |
| 3415 | default: |
| 3416 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3417 | } |
| 3418 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3419 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3420 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3421 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3422 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3423 | if (params.vlan) |
| 3424 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3425 | return err; |
| 3426 | } |
| 3427 | |
| 3428 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3429 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3431 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3432 | u8 *mac_addr = NULL; |
| 3433 | |
| 3434 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3435 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3436 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3437 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3438 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3439 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3440 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3441 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3442 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3443 | if (!rdev->ops->del_station) |
| 3444 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3445 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3446 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3447 | } |
| 3448 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3449 | 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] | 3450 | int flags, struct net_device *dev, |
| 3451 | u8 *dst, u8 *next_hop, |
| 3452 | struct mpath_info *pinfo) |
| 3453 | { |
| 3454 | void *hdr; |
| 3455 | struct nlattr *pinfoattr; |
| 3456 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3457 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3458 | if (!hdr) |
| 3459 | return -1; |
| 3460 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3461 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3462 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3463 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3464 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3465 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3466 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3467 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3468 | if (!pinfoattr) |
| 3469 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3470 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3471 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3472 | pinfo->frame_qlen)) |
| 3473 | goto nla_put_failure; |
| 3474 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3475 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3476 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3477 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3478 | pinfo->metric)) || |
| 3479 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3480 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3481 | pinfo->exptime)) || |
| 3482 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3483 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3484 | pinfo->flags)) || |
| 3485 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3486 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3487 | pinfo->discovery_timeout)) || |
| 3488 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3489 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3490 | pinfo->discovery_retries))) |
| 3491 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3492 | |
| 3493 | nla_nest_end(msg, pinfoattr); |
| 3494 | |
| 3495 | return genlmsg_end(msg, hdr); |
| 3496 | |
| 3497 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3498 | genlmsg_cancel(msg, hdr); |
| 3499 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3503 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3504 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3505 | struct mpath_info pinfo; |
| 3506 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3507 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3508 | u8 dst[ETH_ALEN]; |
| 3509 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3510 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3511 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3512 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3513 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3514 | if (err) |
| 3515 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3516 | |
| 3517 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3518 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3519 | goto out_err; |
| 3520 | } |
| 3521 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3522 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3523 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3524 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3525 | } |
| 3526 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3527 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3528 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 3529 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3530 | if (err == -ENOENT) |
| 3531 | break; |
| 3532 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3533 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3534 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3535 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3536 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3537 | netdev, dst, next_hop, |
| 3538 | &pinfo) < 0) |
| 3539 | goto out; |
| 3540 | |
| 3541 | path_idx++; |
| 3542 | } |
| 3543 | |
| 3544 | |
| 3545 | out: |
| 3546 | cb->args[1] = path_idx; |
| 3547 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3548 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3549 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3550 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3551 | } |
| 3552 | |
| 3553 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3554 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3555 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3556 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3557 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3558 | struct mpath_info pinfo; |
| 3559 | struct sk_buff *msg; |
| 3560 | u8 *dst = NULL; |
| 3561 | u8 next_hop[ETH_ALEN]; |
| 3562 | |
| 3563 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3564 | |
| 3565 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3566 | return -EINVAL; |
| 3567 | |
| 3568 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3569 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3570 | if (!rdev->ops->get_mpath) |
| 3571 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3572 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3573 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3574 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3575 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3576 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3577 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3578 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3579 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3580 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3581 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3582 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3583 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3584 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3585 | dev, dst, next_hop, &pinfo) < 0) { |
| 3586 | nlmsg_free(msg); |
| 3587 | return -ENOBUFS; |
| 3588 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3589 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3590 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3594 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3595 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3596 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3597 | u8 *dst = NULL; |
| 3598 | u8 *next_hop = NULL; |
| 3599 | |
| 3600 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3601 | return -EINVAL; |
| 3602 | |
| 3603 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3604 | return -EINVAL; |
| 3605 | |
| 3606 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3607 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3608 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3609 | if (!rdev->ops->change_mpath) |
| 3610 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3611 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3612 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3613 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3614 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3615 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3616 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3617 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3618 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3619 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3620 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3621 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3622 | u8 *dst = NULL; |
| 3623 | u8 *next_hop = NULL; |
| 3624 | |
| 3625 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3626 | return -EINVAL; |
| 3627 | |
| 3628 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3629 | return -EINVAL; |
| 3630 | |
| 3631 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3632 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3633 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3634 | if (!rdev->ops->add_mpath) |
| 3635 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3636 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3637 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3638 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3639 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3640 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3644 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3645 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3646 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3647 | u8 *dst = NULL; |
| 3648 | |
| 3649 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3650 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3651 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3652 | if (!rdev->ops->del_mpath) |
| 3653 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3654 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3655 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3656 | } |
| 3657 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3658 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3659 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3660 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3661 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3662 | struct bss_parameters params; |
| 3663 | |
| 3664 | memset(¶ms, 0, sizeof(params)); |
| 3665 | /* default to not changing parameters */ |
| 3666 | params.use_cts_prot = -1; |
| 3667 | params.use_short_preamble = -1; |
| 3668 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3669 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3670 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3671 | |
| 3672 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3673 | params.use_cts_prot = |
| 3674 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3675 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3676 | params.use_short_preamble = |
| 3677 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3678 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3679 | params.use_short_slot_time = |
| 3680 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3681 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3682 | params.basic_rates = |
| 3683 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3684 | params.basic_rates_len = |
| 3685 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3686 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3687 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3688 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3689 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3690 | params.ht_opmode = |
| 3691 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3692 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3693 | if (!rdev->ops->change_bss) |
| 3694 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3695 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3696 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3697 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3698 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3699 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3700 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3701 | } |
| 3702 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3703 | 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] | 3704 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3705 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3706 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3707 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3708 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3709 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3710 | }; |
| 3711 | |
| 3712 | static int parse_reg_rule(struct nlattr *tb[], |
| 3713 | struct ieee80211_reg_rule *reg_rule) |
| 3714 | { |
| 3715 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3716 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3717 | |
| 3718 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3719 | return -EINVAL; |
| 3720 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3721 | return -EINVAL; |
| 3722 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3723 | return -EINVAL; |
| 3724 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3725 | return -EINVAL; |
| 3726 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3727 | return -EINVAL; |
| 3728 | |
| 3729 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3730 | |
| 3731 | freq_range->start_freq_khz = |
| 3732 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3733 | freq_range->end_freq_khz = |
| 3734 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3735 | freq_range->max_bandwidth_khz = |
| 3736 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3737 | |
| 3738 | power_rule->max_eirp = |
| 3739 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3740 | |
| 3741 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3742 | power_rule->max_antenna_gain = |
| 3743 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3744 | |
| 3745 | return 0; |
| 3746 | } |
| 3747 | |
| 3748 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3749 | { |
| 3750 | int r; |
| 3751 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3752 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3753 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3754 | /* |
| 3755 | * You should only get this when cfg80211 hasn't yet initialized |
| 3756 | * completely when built-in to the kernel right between the time |
| 3757 | * window between nl80211_init() and regulatory_init(), if that is |
| 3758 | * even possible. |
| 3759 | */ |
| 3760 | mutex_lock(&cfg80211_mutex); |
| 3761 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3762 | mutex_unlock(&cfg80211_mutex); |
| 3763 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3764 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3765 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3766 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3767 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3768 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3769 | |
| 3770 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3771 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3772 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 3773 | user_reg_hint_type = |
| 3774 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 3775 | else |
| 3776 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 3777 | |
| 3778 | switch (user_reg_hint_type) { |
| 3779 | case NL80211_USER_REG_HINT_USER: |
| 3780 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 3781 | break; |
| 3782 | default: |
| 3783 | return -EINVAL; |
| 3784 | } |
| 3785 | |
| 3786 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3787 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3788 | return r; |
| 3789 | } |
| 3790 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3791 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3792 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3793 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3795 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3796 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3797 | struct mesh_config cur_params; |
| 3798 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3799 | void *hdr; |
| 3800 | struct nlattr *pinfoattr; |
| 3801 | struct sk_buff *msg; |
| 3802 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3803 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3804 | return -EOPNOTSUPP; |
| 3805 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3806 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3807 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3808 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3809 | wdev_lock(wdev); |
| 3810 | /* If not connected, get default parameters */ |
| 3811 | if (!wdev->mesh_id_len) |
| 3812 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3813 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3814 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3815 | wdev_unlock(wdev); |
| 3816 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3817 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3818 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3819 | |
| 3820 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3821 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3822 | if (!msg) |
| 3823 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3824 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3825 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3826 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3827 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3828 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3829 | if (!pinfoattr) |
| 3830 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3831 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3832 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3833 | cur_params.dot11MeshRetryTimeout) || |
| 3834 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3835 | cur_params.dot11MeshConfirmTimeout) || |
| 3836 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3837 | cur_params.dot11MeshHoldingTimeout) || |
| 3838 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3839 | cur_params.dot11MeshMaxPeerLinks) || |
| 3840 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3841 | cur_params.dot11MeshMaxRetries) || |
| 3842 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 3843 | cur_params.dot11MeshTTL) || |
| 3844 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3845 | cur_params.element_ttl) || |
| 3846 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3847 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3848 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3849 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3850 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3851 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 3852 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3853 | cur_params.path_refresh_time) || |
| 3854 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3855 | cur_params.min_discovery_timeout) || |
| 3856 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3857 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 3858 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3859 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 3860 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3861 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 3862 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3863 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 3864 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3865 | cur_params.dot11MeshHWMPRootMode) || |
| 3866 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3867 | cur_params.dot11MeshHWMPRannInterval) || |
| 3868 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3869 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 3870 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 3871 | cur_params.dot11MeshForwarding) || |
| 3872 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3873 | cur_params.rssi_threshold) || |
| 3874 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3875 | cur_params.ht_opmode) || |
| 3876 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3877 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 3878 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3879 | cur_params.dot11MeshHWMProotInterval) || |
| 3880 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3881 | cur_params.dot11MeshHWMPconfirmationInterval)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3882 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3883 | nla_nest_end(msg, pinfoattr); |
| 3884 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3885 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3886 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3887 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3888 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3889 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3890 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3891 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3892 | } |
| 3893 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3894 | 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] | 3895 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3896 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3897 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3898 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3899 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3900 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3901 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3902 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3903 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3904 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3905 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3906 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3907 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3908 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3909 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3910 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3911 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3912 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3913 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3914 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3915 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 3916 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3917 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 3918 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3919 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3920 | }; |
| 3921 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3922 | static const struct nla_policy |
| 3923 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3924 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3925 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3926 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3927 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3928 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3929 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3930 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3931 | }; |
| 3932 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3933 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3934 | struct mesh_config *cfg, |
| 3935 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3936 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3937 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3938 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3939 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3940 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3941 | do {\ |
| 3942 | if (table[attr_num]) {\ |
| 3943 | cfg->param = nla_fn(table[attr_num]); \ |
| 3944 | mask |= (1 << (attr_num - 1)); \ |
| 3945 | } \ |
| 3946 | } while (0);\ |
| 3947 | |
| 3948 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3949 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3950 | return -EINVAL; |
| 3951 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3952 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3953 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3954 | return -EINVAL; |
| 3955 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3956 | /* This makes sure that there aren't more than 32 mesh config |
| 3957 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3958 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3959 | |
| 3960 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3961 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3962 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3963 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3964 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3965 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3966 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3967 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3968 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3969 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3970 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3971 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3972 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3973 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3974 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 3975 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3976 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3977 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3978 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3979 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 3980 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3981 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3982 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3983 | nla_get_u8); |
| 3984 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask, |
| 3985 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3986 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3987 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3988 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3989 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3990 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3991 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3992 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3993 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3994 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3995 | nla_get_u16); |
| 3996 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask, |
| 3997 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3998 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3999 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4000 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4001 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4002 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4003 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4004 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4005 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4006 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
| 4007 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4008 | nla_get_u16); |
| 4009 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 4010 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 4011 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 4012 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4013 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4014 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4015 | dot11MeshGateAnnouncementProtocol, mask, |
| 4016 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4017 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4018 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4019 | mask, NL80211_MESHCONF_FORWARDING, |
| 4020 | nla_get_u8); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 4021 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4022 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4023 | nla_get_u32); |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4024 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4025 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4026 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4027 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
| 4028 | mask, |
| 4029 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4030 | nla_get_u32); |
| 4031 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, |
| 4032 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4033 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4034 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 4035 | dot11MeshHWMPconfirmationInterval, mask, |
| 4036 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4037 | nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4038 | if (mask_out) |
| 4039 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4040 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4041 | return 0; |
| 4042 | |
| 4043 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4044 | } |
| 4045 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4046 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4047 | struct mesh_setup *setup) |
| 4048 | { |
| 4049 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4050 | |
| 4051 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4052 | return -EINVAL; |
| 4053 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4054 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4055 | nl80211_mesh_setup_params_policy)) |
| 4056 | return -EINVAL; |
| 4057 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4058 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4059 | setup->sync_method = |
| 4060 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4061 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4062 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4063 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4064 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4065 | setup->path_sel_proto = |
| 4066 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4067 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4068 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4069 | |
| 4070 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4071 | setup->path_metric = |
| 4072 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4073 | IEEE80211_PATH_METRIC_VENDOR : |
| 4074 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4075 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4076 | |
| 4077 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4078 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4079 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4080 | if (!is_valid_ie_attr(ieattr)) |
| 4081 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4082 | setup->ie = nla_data(ieattr); |
| 4083 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4084 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4085 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4086 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4087 | |
| 4088 | return 0; |
| 4089 | } |
| 4090 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4091 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4092 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4093 | { |
| 4094 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4095 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4096 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4097 | struct mesh_config cfg; |
| 4098 | u32 mask; |
| 4099 | int err; |
| 4100 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4101 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4102 | return -EOPNOTSUPP; |
| 4103 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4104 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4105 | return -EOPNOTSUPP; |
| 4106 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4107 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4108 | if (err) |
| 4109 | return err; |
| 4110 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4111 | wdev_lock(wdev); |
| 4112 | if (!wdev->mesh_id_len) |
| 4113 | err = -ENOLINK; |
| 4114 | |
| 4115 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4116 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4117 | |
| 4118 | wdev_unlock(wdev); |
| 4119 | |
| 4120 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4121 | } |
| 4122 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4123 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4124 | { |
| 4125 | struct sk_buff *msg; |
| 4126 | void *hdr = NULL; |
| 4127 | struct nlattr *nl_reg_rules; |
| 4128 | unsigned int i; |
| 4129 | int err = -EINVAL; |
| 4130 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4131 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4132 | |
| 4133 | if (!cfg80211_regdomain) |
| 4134 | goto out; |
| 4135 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4136 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4137 | if (!msg) { |
| 4138 | err = -ENOBUFS; |
| 4139 | goto out; |
| 4140 | } |
| 4141 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4142 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4143 | NL80211_CMD_GET_REG); |
| 4144 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4145 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4146 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4147 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 4148 | cfg80211_regdomain->alpha2) || |
| 4149 | (cfg80211_regdomain->dfs_region && |
| 4150 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, |
| 4151 | cfg80211_regdomain->dfs_region))) |
| 4152 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4153 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4154 | if (reg_last_request_cell_base() && |
| 4155 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4156 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4157 | goto nla_put_failure; |
| 4158 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4159 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4160 | if (!nl_reg_rules) |
| 4161 | goto nla_put_failure; |
| 4162 | |
| 4163 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 4164 | struct nlattr *nl_reg_rule; |
| 4165 | const struct ieee80211_reg_rule *reg_rule; |
| 4166 | const struct ieee80211_freq_range *freq_range; |
| 4167 | const struct ieee80211_power_rule *power_rule; |
| 4168 | |
| 4169 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 4170 | freq_range = ®_rule->freq_range; |
| 4171 | power_rule = ®_rule->power_rule; |
| 4172 | |
| 4173 | nl_reg_rule = nla_nest_start(msg, i); |
| 4174 | if (!nl_reg_rule) |
| 4175 | goto nla_put_failure; |
| 4176 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4177 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4178 | reg_rule->flags) || |
| 4179 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4180 | freq_range->start_freq_khz) || |
| 4181 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4182 | freq_range->end_freq_khz) || |
| 4183 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4184 | freq_range->max_bandwidth_khz) || |
| 4185 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4186 | power_rule->max_antenna_gain) || |
| 4187 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4188 | power_rule->max_eirp)) |
| 4189 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4190 | |
| 4191 | nla_nest_end(msg, nl_reg_rule); |
| 4192 | } |
| 4193 | |
| 4194 | nla_nest_end(msg, nl_reg_rules); |
| 4195 | |
| 4196 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4197 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4198 | goto out; |
| 4199 | |
| 4200 | nla_put_failure: |
| 4201 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4202 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4203 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4204 | err = -EMSGSIZE; |
| 4205 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4206 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4207 | return err; |
| 4208 | } |
| 4209 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4210 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4211 | { |
| 4212 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4213 | struct nlattr *nl_reg_rule; |
| 4214 | char *alpha2 = NULL; |
| 4215 | int rem_reg_rules = 0, r = 0; |
| 4216 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4217 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4218 | struct ieee80211_regdomain *rd = NULL; |
| 4219 | |
| 4220 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4221 | return -EINVAL; |
| 4222 | |
| 4223 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4224 | return -EINVAL; |
| 4225 | |
| 4226 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4227 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4228 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4229 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4230 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4231 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4232 | rem_reg_rules) { |
| 4233 | num_rules++; |
| 4234 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4235 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4236 | } |
| 4237 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4238 | mutex_lock(&cfg80211_mutex); |
| 4239 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4240 | if (!reg_is_valid_request(alpha2)) { |
| 4241 | r = -EINVAL; |
| 4242 | goto bad_reg; |
| 4243 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4244 | |
| 4245 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 4246 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 4247 | |
| 4248 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4249 | if (!rd) { |
| 4250 | r = -ENOMEM; |
| 4251 | goto bad_reg; |
| 4252 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4253 | |
| 4254 | rd->n_reg_rules = num_rules; |
| 4255 | rd->alpha2[0] = alpha2[0]; |
| 4256 | rd->alpha2[1] = alpha2[1]; |
| 4257 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4258 | /* |
| 4259 | * Disable DFS master mode if the DFS region was |
| 4260 | * not supported or known on this kernel. |
| 4261 | */ |
| 4262 | if (reg_supported_dfs_region(dfs_region)) |
| 4263 | rd->dfs_region = dfs_region; |
| 4264 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4265 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4266 | rem_reg_rules) { |
| 4267 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 4268 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4269 | reg_rule_policy); |
| 4270 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4271 | if (r) |
| 4272 | goto bad_reg; |
| 4273 | |
| 4274 | rule_idx++; |
| 4275 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4276 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4277 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4278 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4279 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4280 | } |
| 4281 | |
| 4282 | BUG_ON(rule_idx != num_rules); |
| 4283 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4284 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4285 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4286 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4287 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4288 | return r; |
| 4289 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4290 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4291 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4292 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4293 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4294 | } |
| 4295 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4296 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4297 | { |
| 4298 | struct nlattr *attr1, *attr2; |
| 4299 | int n_channels = 0, tmp1, tmp2; |
| 4300 | |
| 4301 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4302 | n_channels++; |
| 4303 | /* |
| 4304 | * Some hardware has a limited channel list for |
| 4305 | * scanning, and it is pretty much nonsensical |
| 4306 | * to scan for a channel twice, so disallow that |
| 4307 | * and don't require drivers to check that the |
| 4308 | * channel list they get isn't longer than what |
| 4309 | * they can scan, as long as they can scan all |
| 4310 | * the channels they registered at once. |
| 4311 | */ |
| 4312 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4313 | if (attr1 != attr2 && |
| 4314 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4315 | return 0; |
| 4316 | } |
| 4317 | |
| 4318 | return n_channels; |
| 4319 | } |
| 4320 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4321 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4322 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4323 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4324 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4325 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4326 | struct nlattr *attr; |
| 4327 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4328 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4329 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4330 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4331 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4332 | return -EINVAL; |
| 4333 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4334 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4335 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4336 | if (!rdev->ops->scan) |
| 4337 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4338 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4339 | if (rdev->scan_req) |
| 4340 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4341 | |
| 4342 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4343 | n_channels = validate_scan_freqs( |
| 4344 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4345 | if (!n_channels) |
| 4346 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4347 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4348 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4349 | n_channels = 0; |
| 4350 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4351 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4352 | if (wiphy->bands[band]) |
| 4353 | n_channels += wiphy->bands[band]->n_channels; |
| 4354 | } |
| 4355 | |
| 4356 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4357 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4358 | n_ssids++; |
| 4359 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4360 | if (n_ssids > wiphy->max_scan_ssids) |
| 4361 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4362 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4363 | if (info->attrs[NL80211_ATTR_IE]) |
| 4364 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4365 | else |
| 4366 | ie_len = 0; |
| 4367 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4368 | if (ie_len > wiphy->max_scan_ie_len) |
| 4369 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4370 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4371 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4372 | + sizeof(*request->ssids) * n_ssids |
| 4373 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4374 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4375 | if (!request) |
| 4376 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4377 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4378 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4379 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4380 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4381 | if (ie_len) { |
| 4382 | if (request->ssids) |
| 4383 | request->ie = (void *)(request->ssids + n_ssids); |
| 4384 | else |
| 4385 | request->ie = (void *)(request->channels + n_channels); |
| 4386 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4387 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4388 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4389 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4390 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4391 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4392 | struct ieee80211_channel *chan; |
| 4393 | |
| 4394 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4395 | |
| 4396 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4397 | err = -EINVAL; |
| 4398 | goto out_free; |
| 4399 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4400 | |
| 4401 | /* ignore disabled channels */ |
| 4402 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4403 | continue; |
| 4404 | |
| 4405 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4406 | i++; |
| 4407 | } |
| 4408 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4409 | enum ieee80211_band band; |
| 4410 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4411 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4412 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4413 | int j; |
| 4414 | if (!wiphy->bands[band]) |
| 4415 | continue; |
| 4416 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4417 | struct ieee80211_channel *chan; |
| 4418 | |
| 4419 | chan = &wiphy->bands[band]->channels[j]; |
| 4420 | |
| 4421 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4422 | continue; |
| 4423 | |
| 4424 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4425 | i++; |
| 4426 | } |
| 4427 | } |
| 4428 | } |
| 4429 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4430 | if (!i) { |
| 4431 | err = -EINVAL; |
| 4432 | goto out_free; |
| 4433 | } |
| 4434 | |
| 4435 | request->n_channels = i; |
| 4436 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4437 | i = 0; |
| 4438 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4439 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4440 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4441 | err = -EINVAL; |
| 4442 | goto out_free; |
| 4443 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4444 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4445 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4446 | i++; |
| 4447 | } |
| 4448 | } |
| 4449 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4450 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4451 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4452 | memcpy((void *)request->ie, |
| 4453 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4454 | request->ie_len); |
| 4455 | } |
| 4456 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4457 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4458 | if (wiphy->bands[i]) |
| 4459 | request->rates[i] = |
| 4460 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4461 | |
| 4462 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4463 | nla_for_each_nested(attr, |
| 4464 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4465 | tmp) { |
| 4466 | enum ieee80211_band band = nla_type(attr); |
| 4467 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4468 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4469 | err = -EINVAL; |
| 4470 | goto out_free; |
| 4471 | } |
| 4472 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4473 | nla_data(attr), |
| 4474 | nla_len(attr), |
| 4475 | &request->rates[band]); |
| 4476 | if (err) |
| 4477 | goto out_free; |
| 4478 | } |
| 4479 | } |
| 4480 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4481 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4482 | request->flags = nla_get_u32( |
| 4483 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4484 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4485 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4486 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4487 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4488 | err = -EOPNOTSUPP; |
| 4489 | goto out_free; |
| 4490 | } |
| 4491 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4492 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4493 | request->no_cck = |
| 4494 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4495 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4496 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4497 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4498 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4499 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4500 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4501 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4502 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4503 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4504 | nl80211_send_scan_start(rdev, wdev); |
| 4505 | if (wdev->netdev) |
| 4506 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4507 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4508 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4509 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4510 | kfree(request); |
| 4511 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4512 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4513 | return err; |
| 4514 | } |
| 4515 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4516 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4517 | struct genl_info *info) |
| 4518 | { |
| 4519 | struct cfg80211_sched_scan_request *request; |
| 4520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4521 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4522 | struct nlattr *attr; |
| 4523 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4524 | 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] | 4525 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4526 | enum ieee80211_band band; |
| 4527 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4528 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4529 | |
| 4530 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4531 | !rdev->ops->sched_scan_start) |
| 4532 | return -EOPNOTSUPP; |
| 4533 | |
| 4534 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4535 | return -EINVAL; |
| 4536 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4537 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4538 | return -EINVAL; |
| 4539 | |
| 4540 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4541 | if (interval == 0) |
| 4542 | return -EINVAL; |
| 4543 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4544 | wiphy = &rdev->wiphy; |
| 4545 | |
| 4546 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4547 | n_channels = validate_scan_freqs( |
| 4548 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4549 | if (!n_channels) |
| 4550 | return -EINVAL; |
| 4551 | } else { |
| 4552 | n_channels = 0; |
| 4553 | |
| 4554 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4555 | if (wiphy->bands[band]) |
| 4556 | n_channels += wiphy->bands[band]->n_channels; |
| 4557 | } |
| 4558 | |
| 4559 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4560 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4561 | tmp) |
| 4562 | n_ssids++; |
| 4563 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4564 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4565 | return -EINVAL; |
| 4566 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4567 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4568 | nla_for_each_nested(attr, |
| 4569 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4570 | tmp) |
| 4571 | n_match_sets++; |
| 4572 | |
| 4573 | if (n_match_sets > wiphy->max_match_sets) |
| 4574 | return -EINVAL; |
| 4575 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4576 | if (info->attrs[NL80211_ATTR_IE]) |
| 4577 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4578 | else |
| 4579 | ie_len = 0; |
| 4580 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4581 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4582 | return -EINVAL; |
| 4583 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4584 | mutex_lock(&rdev->sched_scan_mtx); |
| 4585 | |
| 4586 | if (rdev->sched_scan_req) { |
| 4587 | err = -EINPROGRESS; |
| 4588 | goto out; |
| 4589 | } |
| 4590 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4591 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4592 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4593 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4594 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4595 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4596 | if (!request) { |
| 4597 | err = -ENOMEM; |
| 4598 | goto out; |
| 4599 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4600 | |
| 4601 | if (n_ssids) |
| 4602 | request->ssids = (void *)&request->channels[n_channels]; |
| 4603 | request->n_ssids = n_ssids; |
| 4604 | if (ie_len) { |
| 4605 | if (request->ssids) |
| 4606 | request->ie = (void *)(request->ssids + n_ssids); |
| 4607 | else |
| 4608 | request->ie = (void *)(request->channels + n_channels); |
| 4609 | } |
| 4610 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4611 | if (n_match_sets) { |
| 4612 | if (request->ie) |
| 4613 | request->match_sets = (void *)(request->ie + ie_len); |
| 4614 | else if (request->ssids) |
| 4615 | request->match_sets = |
| 4616 | (void *)(request->ssids + n_ssids); |
| 4617 | else |
| 4618 | request->match_sets = |
| 4619 | (void *)(request->channels + n_channels); |
| 4620 | } |
| 4621 | request->n_match_sets = n_match_sets; |
| 4622 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4623 | i = 0; |
| 4624 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4625 | /* user specified, bail out if channel not found */ |
| 4626 | nla_for_each_nested(attr, |
| 4627 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4628 | tmp) { |
| 4629 | struct ieee80211_channel *chan; |
| 4630 | |
| 4631 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4632 | |
| 4633 | if (!chan) { |
| 4634 | err = -EINVAL; |
| 4635 | goto out_free; |
| 4636 | } |
| 4637 | |
| 4638 | /* ignore disabled channels */ |
| 4639 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4640 | continue; |
| 4641 | |
| 4642 | request->channels[i] = chan; |
| 4643 | i++; |
| 4644 | } |
| 4645 | } else { |
| 4646 | /* all channels */ |
| 4647 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4648 | int j; |
| 4649 | if (!wiphy->bands[band]) |
| 4650 | continue; |
| 4651 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4652 | struct ieee80211_channel *chan; |
| 4653 | |
| 4654 | chan = &wiphy->bands[band]->channels[j]; |
| 4655 | |
| 4656 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4657 | continue; |
| 4658 | |
| 4659 | request->channels[i] = chan; |
| 4660 | i++; |
| 4661 | } |
| 4662 | } |
| 4663 | } |
| 4664 | |
| 4665 | if (!i) { |
| 4666 | err = -EINVAL; |
| 4667 | goto out_free; |
| 4668 | } |
| 4669 | |
| 4670 | request->n_channels = i; |
| 4671 | |
| 4672 | i = 0; |
| 4673 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4674 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4675 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4676 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4677 | err = -EINVAL; |
| 4678 | goto out_free; |
| 4679 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4680 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4681 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4682 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4683 | i++; |
| 4684 | } |
| 4685 | } |
| 4686 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4687 | i = 0; |
| 4688 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4689 | nla_for_each_nested(attr, |
| 4690 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4691 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4692 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4693 | |
| 4694 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4695 | nla_data(attr), nla_len(attr), |
| 4696 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 4697 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4698 | if (ssid) { |
| 4699 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4700 | err = -EINVAL; |
| 4701 | goto out_free; |
| 4702 | } |
| 4703 | memcpy(request->match_sets[i].ssid.ssid, |
| 4704 | nla_data(ssid), nla_len(ssid)); |
| 4705 | request->match_sets[i].ssid.ssid_len = |
| 4706 | nla_len(ssid); |
| 4707 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4708 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 4709 | if (rssi) |
| 4710 | request->rssi_thold = nla_get_u32(rssi); |
| 4711 | else |
| 4712 | request->rssi_thold = |
| 4713 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4714 | i++; |
| 4715 | } |
| 4716 | } |
| 4717 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4718 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4719 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4720 | memcpy((void *)request->ie, |
| 4721 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4722 | request->ie_len); |
| 4723 | } |
| 4724 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4725 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4726 | request->flags = nla_get_u32( |
| 4727 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4728 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4729 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4730 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4731 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4732 | err = -EOPNOTSUPP; |
| 4733 | goto out_free; |
| 4734 | } |
| 4735 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4736 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4737 | request->dev = dev; |
| 4738 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4739 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4740 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4741 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4742 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4743 | if (!err) { |
| 4744 | rdev->sched_scan_req = request; |
| 4745 | nl80211_send_sched_scan(rdev, dev, |
| 4746 | NL80211_CMD_START_SCHED_SCAN); |
| 4747 | goto out; |
| 4748 | } |
| 4749 | |
| 4750 | out_free: |
| 4751 | kfree(request); |
| 4752 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4753 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4754 | return err; |
| 4755 | } |
| 4756 | |
| 4757 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4758 | struct genl_info *info) |
| 4759 | { |
| 4760 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4761 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4762 | |
| 4763 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4764 | !rdev->ops->sched_scan_stop) |
| 4765 | return -EOPNOTSUPP; |
| 4766 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4767 | mutex_lock(&rdev->sched_scan_mtx); |
| 4768 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4769 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4770 | |
| 4771 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4772 | } |
| 4773 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4774 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4775 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4776 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4777 | struct wireless_dev *wdev, |
| 4778 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4779 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4780 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4781 | void *hdr; |
| 4782 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4783 | |
| 4784 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4785 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4786 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4787 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4788 | if (!hdr) |
| 4789 | return -1; |
| 4790 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4791 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4792 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4793 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 4794 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 4795 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4796 | |
| 4797 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4798 | if (!bss) |
| 4799 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4800 | if ((!is_zero_ether_addr(res->bssid) && |
| 4801 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) || |
| 4802 | (res->information_elements && res->len_information_elements && |
| 4803 | nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4804 | res->len_information_elements, |
| 4805 | res->information_elements)) || |
| 4806 | (res->beacon_ies && res->len_beacon_ies && |
| 4807 | res->beacon_ies != res->information_elements && |
| 4808 | nla_put(msg, NL80211_BSS_BEACON_IES, |
| 4809 | res->len_beacon_ies, res->beacon_ies))) |
| 4810 | goto nla_put_failure; |
| 4811 | if (res->tsf && |
| 4812 | nla_put_u64(msg, NL80211_BSS_TSF, res->tsf)) |
| 4813 | goto nla_put_failure; |
| 4814 | if (res->beacon_interval && |
| 4815 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 4816 | goto nla_put_failure; |
| 4817 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 4818 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 4819 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4820 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 4821 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4822 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4823 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4824 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4825 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 4826 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4827 | break; |
| 4828 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4829 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 4830 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4831 | break; |
| 4832 | default: |
| 4833 | break; |
| 4834 | } |
| 4835 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4836 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4837 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4838 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4839 | if (intbss == wdev->current_bss && |
| 4840 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4841 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 4842 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4843 | break; |
| 4844 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4845 | if (intbss == wdev->current_bss && |
| 4846 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4847 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 4848 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4849 | break; |
| 4850 | default: |
| 4851 | break; |
| 4852 | } |
| 4853 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4854 | nla_nest_end(msg, bss); |
| 4855 | |
| 4856 | return genlmsg_end(msg, hdr); |
| 4857 | |
| 4858 | nla_put_failure: |
| 4859 | genlmsg_cancel(msg, hdr); |
| 4860 | return -EMSGSIZE; |
| 4861 | } |
| 4862 | |
| 4863 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4864 | struct netlink_callback *cb) |
| 4865 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4866 | struct cfg80211_registered_device *rdev; |
| 4867 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4868 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4869 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4870 | int start = cb->args[1], idx = 0; |
| 4871 | int err; |
| 4872 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4873 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4874 | if (err) |
| 4875 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4876 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4877 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4878 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4879 | wdev_lock(wdev); |
| 4880 | spin_lock_bh(&rdev->bss_lock); |
| 4881 | cfg80211_bss_expire(rdev); |
| 4882 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4883 | cb->seq = rdev->bss_generation; |
| 4884 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4885 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4886 | if (++idx <= start) |
| 4887 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4888 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4889 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4890 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4891 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4892 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4893 | } |
| 4894 | } |
| 4895 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4896 | spin_unlock_bh(&rdev->bss_lock); |
| 4897 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4898 | |
| 4899 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4900 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4901 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4902 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4903 | } |
| 4904 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4905 | 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] | 4906 | int flags, struct net_device *dev, |
| 4907 | struct survey_info *survey) |
| 4908 | { |
| 4909 | void *hdr; |
| 4910 | struct nlattr *infoattr; |
| 4911 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4912 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4913 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4914 | if (!hdr) |
| 4915 | return -ENOMEM; |
| 4916 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4917 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 4918 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4919 | |
| 4920 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4921 | if (!infoattr) |
| 4922 | goto nla_put_failure; |
| 4923 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4924 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4925 | survey->channel->center_freq)) |
| 4926 | goto nla_put_failure; |
| 4927 | |
| 4928 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 4929 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 4930 | goto nla_put_failure; |
| 4931 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 4932 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 4933 | goto nla_put_failure; |
| 4934 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 4935 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4936 | survey->channel_time)) |
| 4937 | goto nla_put_failure; |
| 4938 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 4939 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4940 | survey->channel_time_busy)) |
| 4941 | goto nla_put_failure; |
| 4942 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 4943 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4944 | survey->channel_time_ext_busy)) |
| 4945 | goto nla_put_failure; |
| 4946 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 4947 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4948 | survey->channel_time_rx)) |
| 4949 | goto nla_put_failure; |
| 4950 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 4951 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4952 | survey->channel_time_tx)) |
| 4953 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4954 | |
| 4955 | nla_nest_end(msg, infoattr); |
| 4956 | |
| 4957 | return genlmsg_end(msg, hdr); |
| 4958 | |
| 4959 | nla_put_failure: |
| 4960 | genlmsg_cancel(msg, hdr); |
| 4961 | return -EMSGSIZE; |
| 4962 | } |
| 4963 | |
| 4964 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4965 | struct netlink_callback *cb) |
| 4966 | { |
| 4967 | struct survey_info survey; |
| 4968 | struct cfg80211_registered_device *dev; |
| 4969 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4970 | int survey_idx = cb->args[1]; |
| 4971 | int res; |
| 4972 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4973 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4974 | if (res) |
| 4975 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4976 | |
| 4977 | if (!dev->ops->dump_survey) { |
| 4978 | res = -EOPNOTSUPP; |
| 4979 | goto out_err; |
| 4980 | } |
| 4981 | |
| 4982 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4983 | struct ieee80211_channel *chan; |
| 4984 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4985 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4986 | if (res == -ENOENT) |
| 4987 | break; |
| 4988 | if (res) |
| 4989 | goto out_err; |
| 4990 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4991 | /* Survey without a channel doesn't make sense */ |
| 4992 | if (!survey.channel) { |
| 4993 | res = -EINVAL; |
| 4994 | goto out; |
| 4995 | } |
| 4996 | |
| 4997 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4998 | survey.channel->center_freq); |
| 4999 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5000 | survey_idx++; |
| 5001 | continue; |
| 5002 | } |
| 5003 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5004 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5005 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5006 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5007 | netdev, |
| 5008 | &survey) < 0) |
| 5009 | goto out; |
| 5010 | survey_idx++; |
| 5011 | } |
| 5012 | |
| 5013 | out: |
| 5014 | cb->args[1] = survey_idx; |
| 5015 | res = skb->len; |
| 5016 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5017 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5018 | return res; |
| 5019 | } |
| 5020 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5021 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5022 | { |
| 5023 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5024 | NL80211_WPA_VERSION_2)); |
| 5025 | } |
| 5026 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5027 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5028 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5029 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5030 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5031 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5032 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5033 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5034 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5035 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5036 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5037 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5038 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5039 | return -EINVAL; |
| 5040 | |
| 5041 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5042 | return -EINVAL; |
| 5043 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5044 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5045 | return -EINVAL; |
| 5046 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5047 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5048 | return -EINVAL; |
| 5049 | |
| 5050 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5051 | return -EINVAL; |
| 5052 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5053 | err = nl80211_parse_key(info, &key); |
| 5054 | if (err) |
| 5055 | return err; |
| 5056 | |
| 5057 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5058 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5059 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5060 | if (!key.p.key || !key.p.key_len) |
| 5061 | return -EINVAL; |
| 5062 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5063 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5064 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5065 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5066 | return -EINVAL; |
| 5067 | if (key.idx > 4) |
| 5068 | return -EINVAL; |
| 5069 | } else { |
| 5070 | key.p.key_len = 0; |
| 5071 | key.p.key = NULL; |
| 5072 | } |
| 5073 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5074 | if (key.idx >= 0) { |
| 5075 | int i; |
| 5076 | bool ok = false; |
| 5077 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5078 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5079 | ok = true; |
| 5080 | break; |
| 5081 | } |
| 5082 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5083 | if (!ok) |
| 5084 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5085 | } |
| 5086 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5087 | if (!rdev->ops->auth) |
| 5088 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5089 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5090 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5091 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5092 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5093 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5094 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5095 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5096 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5097 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5098 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5099 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5100 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5101 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5102 | |
| 5103 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5104 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5105 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5106 | } |
| 5107 | |
| 5108 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5109 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5110 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5111 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5112 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5113 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5114 | return -EINVAL; |
| 5115 | |
| 5116 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5117 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5118 | return -EINVAL; |
| 5119 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5120 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5121 | /* need to include at least Auth Transaction and Status Code */ |
| 5122 | if (sae_data_len < 4) |
| 5123 | return -EINVAL; |
| 5124 | } |
| 5125 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5126 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5127 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5128 | /* |
| 5129 | * Since we no longer track auth state, ignore |
| 5130 | * requests to only change local state. |
| 5131 | */ |
| 5132 | if (local_state_change) |
| 5133 | return 0; |
| 5134 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5135 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5136 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5137 | key.p.key, key.p.key_len, key.idx, |
| 5138 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5139 | } |
| 5140 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5141 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5142 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5143 | struct cfg80211_crypto_settings *settings, |
| 5144 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5145 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5146 | memset(settings, 0, sizeof(*settings)); |
| 5147 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5148 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5149 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5150 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5151 | u16 proto; |
| 5152 | proto = nla_get_u16( |
| 5153 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5154 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5155 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5156 | proto != ETH_P_PAE) |
| 5157 | return -EINVAL; |
| 5158 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5159 | settings->control_port_no_encrypt = true; |
| 5160 | } else |
| 5161 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5162 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5163 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5164 | void *data; |
| 5165 | int len, i; |
| 5166 | |
| 5167 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5168 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5169 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5170 | |
| 5171 | if (len % sizeof(u32)) |
| 5172 | return -EINVAL; |
| 5173 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5174 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5175 | return -EINVAL; |
| 5176 | |
| 5177 | memcpy(settings->ciphers_pairwise, data, len); |
| 5178 | |
| 5179 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5180 | if (!cfg80211_supported_cipher_suite( |
| 5181 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5182 | settings->ciphers_pairwise[i])) |
| 5183 | return -EINVAL; |
| 5184 | } |
| 5185 | |
| 5186 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5187 | settings->cipher_group = |
| 5188 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5189 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5190 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5191 | return -EINVAL; |
| 5192 | } |
| 5193 | |
| 5194 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5195 | settings->wpa_versions = |
| 5196 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5197 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5198 | return -EINVAL; |
| 5199 | } |
| 5200 | |
| 5201 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5202 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5203 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5204 | |
| 5205 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5206 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5207 | settings->n_akm_suites = len / sizeof(u32); |
| 5208 | |
| 5209 | if (len % sizeof(u32)) |
| 5210 | return -EINVAL; |
| 5211 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5212 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5213 | return -EINVAL; |
| 5214 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5215 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5216 | } |
| 5217 | |
| 5218 | return 0; |
| 5219 | } |
| 5220 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5221 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5222 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5223 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5224 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5225 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5226 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5227 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5228 | int err, ssid_len, ie_len = 0; |
| 5229 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5230 | u32 flags = 0; |
| 5231 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5232 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5233 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5234 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5235 | return -EINVAL; |
| 5236 | |
| 5237 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5238 | !info->attrs[NL80211_ATTR_SSID] || |
| 5239 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5240 | return -EINVAL; |
| 5241 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5242 | if (!rdev->ops->assoc) |
| 5243 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5244 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5245 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5246 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5247 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5248 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5249 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5250 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5251 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5252 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5253 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5254 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5255 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5256 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5257 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5258 | |
| 5259 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5260 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5261 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5262 | } |
| 5263 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5264 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5265 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5266 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5267 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5268 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5269 | else if (mfp != NL80211_MFP_NO) |
| 5270 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5271 | } |
| 5272 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5273 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5274 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5275 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5276 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5277 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5278 | |
| 5279 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5280 | ht_capa_mask = |
| 5281 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5282 | |
| 5283 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5284 | if (!ht_capa_mask) |
| 5285 | return -EINVAL; |
| 5286 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5287 | } |
| 5288 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5289 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5290 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5291 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5292 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5293 | &crypto, flags, ht_capa, |
| 5294 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5295 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5296 | return err; |
| 5297 | } |
| 5298 | |
| 5299 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5300 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5301 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5302 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5303 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5304 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5305 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5306 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5307 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5308 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5309 | return -EINVAL; |
| 5310 | |
| 5311 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5312 | return -EINVAL; |
| 5313 | |
| 5314 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5315 | return -EINVAL; |
| 5316 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5317 | if (!rdev->ops->deauth) |
| 5318 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5319 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5320 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5321 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5322 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5323 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5324 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5325 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5326 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5327 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5328 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5329 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5330 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5331 | |
| 5332 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5333 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5334 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5335 | } |
| 5336 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5337 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5338 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5339 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5340 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5341 | } |
| 5342 | |
| 5343 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5344 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5345 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5346 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5347 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5348 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5349 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5350 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5351 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5352 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5353 | return -EINVAL; |
| 5354 | |
| 5355 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5356 | return -EINVAL; |
| 5357 | |
| 5358 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5359 | return -EINVAL; |
| 5360 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5361 | if (!rdev->ops->disassoc) |
| 5362 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5363 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5364 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5365 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5366 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5367 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5368 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5369 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5370 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5371 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5372 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5373 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5374 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5375 | |
| 5376 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5377 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5378 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5379 | } |
| 5380 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5381 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5382 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5383 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5384 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5385 | } |
| 5386 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5387 | static bool |
| 5388 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5389 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5390 | int rateval) |
| 5391 | { |
| 5392 | struct wiphy *wiphy = &rdev->wiphy; |
| 5393 | bool found = false; |
| 5394 | int band, i; |
| 5395 | |
| 5396 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5397 | struct ieee80211_supported_band *sband; |
| 5398 | |
| 5399 | sband = wiphy->bands[band]; |
| 5400 | if (!sband) |
| 5401 | continue; |
| 5402 | |
| 5403 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5404 | if (sband->bitrates[i].bitrate == rateval) { |
| 5405 | mcast_rate[band] = i + 1; |
| 5406 | found = true; |
| 5407 | break; |
| 5408 | } |
| 5409 | } |
| 5410 | } |
| 5411 | |
| 5412 | return found; |
| 5413 | } |
| 5414 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5415 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5416 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5417 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5418 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5419 | struct cfg80211_ibss_params ibss; |
| 5420 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5421 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5422 | int err; |
| 5423 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5424 | memset(&ibss, 0, sizeof(ibss)); |
| 5425 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5426 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5427 | return -EINVAL; |
| 5428 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5429 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5430 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5431 | return -EINVAL; |
| 5432 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5433 | ibss.beacon_interval = 100; |
| 5434 | |
| 5435 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5436 | ibss.beacon_interval = |
| 5437 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5438 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5439 | return -EINVAL; |
| 5440 | } |
| 5441 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5442 | if (!rdev->ops->join_ibss) |
| 5443 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5444 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5445 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5446 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5447 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5448 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5449 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5450 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5451 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5452 | |
| 5453 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5454 | return -EINVAL; |
| 5455 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5456 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5457 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5458 | |
| 5459 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5460 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5461 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5462 | } |
| 5463 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5464 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 5465 | if (err) |
| 5466 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5467 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5468 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5469 | return -EINVAL; |
| 5470 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5471 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 5472 | return -EINVAL; |
| 5473 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 5474 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 5475 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5476 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5477 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5478 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5479 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5480 | u8 *rates = |
| 5481 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5482 | int n_rates = |
| 5483 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5484 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5485 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5486 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5487 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5488 | &ibss.basic_rates); |
| 5489 | if (err) |
| 5490 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5491 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5492 | |
| 5493 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5494 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5495 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5496 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5497 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5498 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5499 | bool no_ht = false; |
| 5500 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5501 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5502 | info->attrs[NL80211_ATTR_KEYS], |
| 5503 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5504 | if (IS_ERR(connkeys)) |
| 5505 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5506 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 5507 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 5508 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5509 | kfree(connkeys); |
| 5510 | return -EINVAL; |
| 5511 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5512 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5513 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5514 | ibss.control_port = |
| 5515 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5516 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5517 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5518 | if (err) |
| 5519 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5520 | return err; |
| 5521 | } |
| 5522 | |
| 5523 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5524 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5525 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5526 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5527 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5528 | if (!rdev->ops->leave_ibss) |
| 5529 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5530 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5531 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5532 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5533 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5534 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5535 | } |
| 5536 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 5537 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 5538 | { |
| 5539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5540 | struct net_device *dev = info->user_ptr[1]; |
| 5541 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 5542 | u32 nla_rate; |
| 5543 | int err; |
| 5544 | |
| 5545 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5546 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5547 | return -EOPNOTSUPP; |
| 5548 | |
| 5549 | if (!rdev->ops->set_mcast_rate) |
| 5550 | return -EOPNOTSUPP; |
| 5551 | |
| 5552 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 5553 | |
| 5554 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 5555 | return -EINVAL; |
| 5556 | |
| 5557 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 5558 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 5559 | return -EINVAL; |
| 5560 | |
| 5561 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 5562 | |
| 5563 | return err; |
| 5564 | } |
| 5565 | |
| 5566 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5567 | #ifdef CONFIG_NL80211_TESTMODE |
| 5568 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5569 | .name = "testmode", |
| 5570 | }; |
| 5571 | |
| 5572 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5573 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5574 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5575 | int err; |
| 5576 | |
| 5577 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5578 | return -EINVAL; |
| 5579 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5580 | err = -EOPNOTSUPP; |
| 5581 | if (rdev->ops->testmode_cmd) { |
| 5582 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5583 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5584 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5585 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5586 | rdev->testmode_info = NULL; |
| 5587 | } |
| 5588 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5589 | return err; |
| 5590 | } |
| 5591 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5592 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5593 | struct netlink_callback *cb) |
| 5594 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5595 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5596 | int err; |
| 5597 | long phy_idx; |
| 5598 | void *data = NULL; |
| 5599 | int data_len = 0; |
| 5600 | |
| 5601 | if (cb->args[0]) { |
| 5602 | /* |
| 5603 | * 0 is a valid index, but not valid for args[0], |
| 5604 | * so we need to offset by 1. |
| 5605 | */ |
| 5606 | phy_idx = cb->args[0] - 1; |
| 5607 | } else { |
| 5608 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5609 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5610 | nl80211_policy); |
| 5611 | if (err) |
| 5612 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5613 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5614 | mutex_lock(&cfg80211_mutex); |
| 5615 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 5616 | nl80211_fam.attrbuf); |
| 5617 | if (IS_ERR(rdev)) { |
| 5618 | mutex_unlock(&cfg80211_mutex); |
| 5619 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5620 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5621 | phy_idx = rdev->wiphy_idx; |
| 5622 | rdev = NULL; |
| 5623 | mutex_unlock(&cfg80211_mutex); |
| 5624 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5625 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 5626 | cb->args[1] = |
| 5627 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 5628 | } |
| 5629 | |
| 5630 | if (cb->args[1]) { |
| 5631 | data = nla_data((void *)cb->args[1]); |
| 5632 | data_len = nla_len((void *)cb->args[1]); |
| 5633 | } |
| 5634 | |
| 5635 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5636 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 5637 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5638 | mutex_unlock(&cfg80211_mutex); |
| 5639 | return -ENOENT; |
| 5640 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5641 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5642 | mutex_unlock(&cfg80211_mutex); |
| 5643 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5644 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5645 | err = -EOPNOTSUPP; |
| 5646 | goto out_err; |
| 5647 | } |
| 5648 | |
| 5649 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5650 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5651 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5652 | NL80211_CMD_TESTMODE); |
| 5653 | struct nlattr *tmdata; |
| 5654 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5655 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5656 | genlmsg_cancel(skb, hdr); |
| 5657 | break; |
| 5658 | } |
| 5659 | |
| 5660 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5661 | if (!tmdata) { |
| 5662 | genlmsg_cancel(skb, hdr); |
| 5663 | break; |
| 5664 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5665 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5666 | nla_nest_end(skb, tmdata); |
| 5667 | |
| 5668 | if (err == -ENOBUFS || err == -ENOENT) { |
| 5669 | genlmsg_cancel(skb, hdr); |
| 5670 | break; |
| 5671 | } else if (err) { |
| 5672 | genlmsg_cancel(skb, hdr); |
| 5673 | goto out_err; |
| 5674 | } |
| 5675 | |
| 5676 | genlmsg_end(skb, hdr); |
| 5677 | } |
| 5678 | |
| 5679 | err = skb->len; |
| 5680 | /* see above */ |
| 5681 | cb->args[0] = phy_idx + 1; |
| 5682 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5683 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5684 | return err; |
| 5685 | } |
| 5686 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5687 | static struct sk_buff * |
| 5688 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5689 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5690 | { |
| 5691 | struct sk_buff *skb; |
| 5692 | void *hdr; |
| 5693 | struct nlattr *data; |
| 5694 | |
| 5695 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5696 | if (!skb) |
| 5697 | return NULL; |
| 5698 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5699 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5700 | if (!hdr) { |
| 5701 | kfree_skb(skb); |
| 5702 | return NULL; |
| 5703 | } |
| 5704 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5705 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 5706 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5707 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5708 | |
| 5709 | ((void **)skb->cb)[0] = rdev; |
| 5710 | ((void **)skb->cb)[1] = hdr; |
| 5711 | ((void **)skb->cb)[2] = data; |
| 5712 | |
| 5713 | return skb; |
| 5714 | |
| 5715 | nla_put_failure: |
| 5716 | kfree_skb(skb); |
| 5717 | return NULL; |
| 5718 | } |
| 5719 | |
| 5720 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5721 | int approxlen) |
| 5722 | { |
| 5723 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5724 | |
| 5725 | if (WARN_ON(!rdev->testmode_info)) |
| 5726 | return NULL; |
| 5727 | |
| 5728 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5729 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5730 | rdev->testmode_info->snd_seq, |
| 5731 | GFP_KERNEL); |
| 5732 | } |
| 5733 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5734 | |
| 5735 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5736 | { |
| 5737 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5738 | void *hdr = ((void **)skb->cb)[1]; |
| 5739 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5740 | |
| 5741 | if (WARN_ON(!rdev->testmode_info)) { |
| 5742 | kfree_skb(skb); |
| 5743 | return -EINVAL; |
| 5744 | } |
| 5745 | |
| 5746 | nla_nest_end(skb, data); |
| 5747 | genlmsg_end(skb, hdr); |
| 5748 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5749 | } |
| 5750 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5751 | |
| 5752 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5753 | int approxlen, gfp_t gfp) |
| 5754 | { |
| 5755 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5756 | |
| 5757 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5758 | } |
| 5759 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5760 | |
| 5761 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5762 | { |
| 5763 | void *hdr = ((void **)skb->cb)[1]; |
| 5764 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5765 | |
| 5766 | nla_nest_end(skb, data); |
| 5767 | genlmsg_end(skb, hdr); |
| 5768 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5769 | } |
| 5770 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5771 | #endif |
| 5772 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5773 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5774 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5775 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5776 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5777 | struct cfg80211_connect_params connect; |
| 5778 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5779 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5780 | int err; |
| 5781 | |
| 5782 | memset(&connect, 0, sizeof(connect)); |
| 5783 | |
| 5784 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5785 | return -EINVAL; |
| 5786 | |
| 5787 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5788 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5789 | return -EINVAL; |
| 5790 | |
| 5791 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5792 | connect.auth_type = |
| 5793 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5794 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 5795 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5796 | return -EINVAL; |
| 5797 | } else |
| 5798 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5799 | |
| 5800 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5801 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5802 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5803 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5804 | if (err) |
| 5805 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5806 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5807 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5808 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5809 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5810 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5811 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5812 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 5813 | connect.bg_scan_period = -1; |
| 5814 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 5815 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 5816 | connect.bg_scan_period = |
| 5817 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 5818 | } |
| 5819 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5820 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5821 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5822 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5823 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5824 | |
| 5825 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5826 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5827 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5828 | } |
| 5829 | |
| 5830 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5831 | connect.channel = |
| 5832 | ieee80211_get_channel(wiphy, |
| 5833 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5834 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5835 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5836 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5837 | } |
| 5838 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5839 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5840 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5841 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5842 | if (IS_ERR(connkeys)) |
| 5843 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5844 | } |
| 5845 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5846 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5847 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5848 | |
| 5849 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5850 | memcpy(&connect.ht_capa_mask, |
| 5851 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5852 | sizeof(connect.ht_capa_mask)); |
| 5853 | |
| 5854 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5855 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 5856 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5857 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5858 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5859 | memcpy(&connect.ht_capa, |
| 5860 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5861 | sizeof(connect.ht_capa)); |
| 5862 | } |
| 5863 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5864 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5865 | if (err) |
| 5866 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5867 | return err; |
| 5868 | } |
| 5869 | |
| 5870 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5871 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5872 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5873 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5874 | u16 reason; |
| 5875 | |
| 5876 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5877 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5878 | else |
| 5879 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5880 | |
| 5881 | if (reason == 0) |
| 5882 | return -EINVAL; |
| 5883 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5884 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5885 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5886 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5887 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5888 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5889 | } |
| 5890 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5891 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5892 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5893 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5894 | struct net *net; |
| 5895 | int err; |
| 5896 | u32 pid; |
| 5897 | |
| 5898 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5899 | return -EINVAL; |
| 5900 | |
| 5901 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5902 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5903 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5904 | if (IS_ERR(net)) |
| 5905 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5906 | |
| 5907 | err = 0; |
| 5908 | |
| 5909 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5910 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5911 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5912 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5913 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5914 | return err; |
| 5915 | } |
| 5916 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5917 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5918 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5920 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5921 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5922 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5923 | struct cfg80211_pmksa pmksa; |
| 5924 | |
| 5925 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5926 | |
| 5927 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5928 | return -EINVAL; |
| 5929 | |
| 5930 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5931 | return -EINVAL; |
| 5932 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5933 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5934 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5935 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5936 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5937 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5938 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5939 | |
| 5940 | switch (info->genlhdr->cmd) { |
| 5941 | case NL80211_CMD_SET_PMKSA: |
| 5942 | rdev_ops = rdev->ops->set_pmksa; |
| 5943 | break; |
| 5944 | case NL80211_CMD_DEL_PMKSA: |
| 5945 | rdev_ops = rdev->ops->del_pmksa; |
| 5946 | break; |
| 5947 | default: |
| 5948 | WARN_ON(1); |
| 5949 | break; |
| 5950 | } |
| 5951 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5952 | if (!rdev_ops) |
| 5953 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5954 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5955 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5956 | } |
| 5957 | |
| 5958 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5959 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5960 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5961 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5962 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5963 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5964 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5965 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5966 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5967 | if (!rdev->ops->flush_pmksa) |
| 5968 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5969 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5970 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5971 | } |
| 5972 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5973 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5974 | { |
| 5975 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5976 | struct net_device *dev = info->user_ptr[1]; |
| 5977 | u8 action_code, dialog_token; |
| 5978 | u16 status_code; |
| 5979 | u8 *peer; |
| 5980 | |
| 5981 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5982 | !rdev->ops->tdls_mgmt) |
| 5983 | return -EOPNOTSUPP; |
| 5984 | |
| 5985 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5986 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5987 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5988 | !info->attrs[NL80211_ATTR_IE] || |
| 5989 | !info->attrs[NL80211_ATTR_MAC]) |
| 5990 | return -EINVAL; |
| 5991 | |
| 5992 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5993 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5994 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5995 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5996 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5997 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 5998 | dialog_token, status_code, |
| 5999 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6000 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6001 | } |
| 6002 | |
| 6003 | static int nl80211_tdls_oper(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 | enum nl80211_tdls_operation operation; |
| 6008 | u8 *peer; |
| 6009 | |
| 6010 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6011 | !rdev->ops->tdls_oper) |
| 6012 | return -EOPNOTSUPP; |
| 6013 | |
| 6014 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6015 | !info->attrs[NL80211_ATTR_MAC]) |
| 6016 | return -EINVAL; |
| 6017 | |
| 6018 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6019 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6020 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6021 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6022 | } |
| 6023 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6024 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6025 | struct genl_info *info) |
| 6026 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6028 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6029 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6030 | struct sk_buff *msg; |
| 6031 | void *hdr; |
| 6032 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6033 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6034 | int err; |
| 6035 | |
| 6036 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6037 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6038 | return -EINVAL; |
| 6039 | |
| 6040 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6041 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6042 | if (!rdev->ops->remain_on_channel || |
| 6043 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6044 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6045 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6046 | /* |
| 6047 | * We should be on that channel for at least a minimum amount of |
| 6048 | * time (10ms) but no longer than the driver supports. |
| 6049 | */ |
| 6050 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6051 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6052 | return -EINVAL; |
| 6053 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6054 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6055 | if (err) |
| 6056 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6057 | |
| 6058 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6059 | if (!msg) |
| 6060 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6061 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6062 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6063 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6064 | |
| 6065 | if (IS_ERR(hdr)) { |
| 6066 | err = PTR_ERR(hdr); |
| 6067 | goto free_msg; |
| 6068 | } |
| 6069 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6070 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6071 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6072 | |
| 6073 | if (err) |
| 6074 | goto free_msg; |
| 6075 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6076 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6077 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6078 | |
| 6079 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6080 | |
| 6081 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6082 | |
| 6083 | nla_put_failure: |
| 6084 | err = -ENOBUFS; |
| 6085 | free_msg: |
| 6086 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6087 | return err; |
| 6088 | } |
| 6089 | |
| 6090 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6091 | struct genl_info *info) |
| 6092 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6094 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6095 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6096 | |
| 6097 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6098 | return -EINVAL; |
| 6099 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6100 | if (!rdev->ops->cancel_remain_on_channel) |
| 6101 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6102 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6103 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6104 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6105 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6106 | } |
| 6107 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6108 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6109 | u8 *rates, u8 rates_len) |
| 6110 | { |
| 6111 | u8 i; |
| 6112 | u32 mask = 0; |
| 6113 | |
| 6114 | for (i = 0; i < rates_len; i++) { |
| 6115 | int rate = (rates[i] & 0x7f) * 5; |
| 6116 | int ridx; |
| 6117 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6118 | struct ieee80211_rate *srate = |
| 6119 | &sband->bitrates[ridx]; |
| 6120 | if (rate == srate->bitrate) { |
| 6121 | mask |= 1 << ridx; |
| 6122 | break; |
| 6123 | } |
| 6124 | } |
| 6125 | if (ridx == sband->n_bitrates) |
| 6126 | return 0; /* rate not found */ |
| 6127 | } |
| 6128 | |
| 6129 | return mask; |
| 6130 | } |
| 6131 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6132 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6133 | u8 *rates, u8 rates_len, |
| 6134 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6135 | { |
| 6136 | u8 i; |
| 6137 | |
| 6138 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6139 | |
| 6140 | for (i = 0; i < rates_len; i++) { |
| 6141 | int ridx, rbit; |
| 6142 | |
| 6143 | ridx = rates[i] / 8; |
| 6144 | rbit = BIT(rates[i] % 8); |
| 6145 | |
| 6146 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6147 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6148 | return false; |
| 6149 | |
| 6150 | /* check availability */ |
| 6151 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6152 | mcs[ridx] |= rbit; |
| 6153 | else |
| 6154 | return false; |
| 6155 | } |
| 6156 | |
| 6157 | return true; |
| 6158 | } |
| 6159 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6160 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6161 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6162 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6163 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6164 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6165 | }; |
| 6166 | |
| 6167 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6168 | struct genl_info *info) |
| 6169 | { |
| 6170 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6171 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6172 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6173 | int rem, i; |
| 6174 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6175 | struct nlattr *tx_rates; |
| 6176 | struct ieee80211_supported_band *sband; |
| 6177 | |
| 6178 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6179 | return -EINVAL; |
| 6180 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6181 | if (!rdev->ops->set_bitrate_mask) |
| 6182 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6183 | |
| 6184 | memset(&mask, 0, sizeof(mask)); |
| 6185 | /* Default to all rates enabled */ |
| 6186 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6187 | sband = rdev->wiphy.bands[i]; |
| 6188 | mask.control[i].legacy = |
| 6189 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6190 | if (sband) |
| 6191 | memcpy(mask.control[i].mcs, |
| 6192 | sband->ht_cap.mcs.rx_mask, |
| 6193 | sizeof(mask.control[i].mcs)); |
| 6194 | else |
| 6195 | memset(mask.control[i].mcs, 0, |
| 6196 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | /* |
| 6200 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6201 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6202 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6203 | 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] | 6204 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6205 | { |
| 6206 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6207 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6208 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6209 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6210 | if (sband == NULL) |
| 6211 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6212 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6213 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6214 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6215 | mask.control[band].legacy = rateset_to_mask( |
| 6216 | sband, |
| 6217 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6218 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6219 | if ((mask.control[band].legacy == 0) && |
| 6220 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6221 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6222 | } |
| 6223 | if (tb[NL80211_TXRATE_MCS]) { |
| 6224 | if (!ht_rateset_to_mask( |
| 6225 | sband, |
| 6226 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6227 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6228 | mask.control[band].mcs)) |
| 6229 | return -EINVAL; |
| 6230 | } |
| 6231 | |
| 6232 | if (mask.control[band].legacy == 0) { |
| 6233 | /* don't allow empty legacy rates if HT |
| 6234 | * is not even supported. */ |
| 6235 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6236 | return -EINVAL; |
| 6237 | |
| 6238 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6239 | if (mask.control[band].mcs[i]) |
| 6240 | break; |
| 6241 | |
| 6242 | /* legacy and mcs rates may not be both empty */ |
| 6243 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6244 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6245 | } |
| 6246 | } |
| 6247 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6248 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6249 | } |
| 6250 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6251 | 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] | 6252 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6253 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6254 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6255 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6256 | |
| 6257 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6258 | return -EINVAL; |
| 6259 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6260 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6261 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6262 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6263 | switch (wdev->iftype) { |
| 6264 | case NL80211_IFTYPE_STATION: |
| 6265 | case NL80211_IFTYPE_ADHOC: |
| 6266 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6267 | case NL80211_IFTYPE_AP: |
| 6268 | case NL80211_IFTYPE_AP_VLAN: |
| 6269 | case NL80211_IFTYPE_MESH_POINT: |
| 6270 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6271 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6272 | break; |
| 6273 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6274 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6275 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6276 | |
| 6277 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6278 | if (!rdev->ops->mgmt_tx) |
| 6279 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6280 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6281 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6282 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6283 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6284 | } |
| 6285 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6286 | 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] | 6287 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6288 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6289 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6290 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6291 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6292 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6293 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6294 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6295 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6296 | bool offchan, no_cck, dont_wait_for_ack; |
| 6297 | |
| 6298 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6299 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6300 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6301 | return -EINVAL; |
| 6302 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6303 | if (!rdev->ops->mgmt_tx) |
| 6304 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6305 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6306 | switch (wdev->iftype) { |
| 6307 | case NL80211_IFTYPE_STATION: |
| 6308 | case NL80211_IFTYPE_ADHOC: |
| 6309 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6310 | case NL80211_IFTYPE_AP: |
| 6311 | case NL80211_IFTYPE_AP_VLAN: |
| 6312 | case NL80211_IFTYPE_MESH_POINT: |
| 6313 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6314 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6315 | break; |
| 6316 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6317 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6318 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6319 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6320 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6321 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6322 | return -EINVAL; |
| 6323 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6324 | |
| 6325 | /* |
| 6326 | * We should wait on the channel for at least a minimum amount |
| 6327 | * of time (10ms) but no longer than the driver supports. |
| 6328 | */ |
| 6329 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6330 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6331 | return -EINVAL; |
| 6332 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6333 | } |
| 6334 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6335 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6336 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6337 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6338 | return -EINVAL; |
| 6339 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6340 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6341 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6342 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6343 | if (err) |
| 6344 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6345 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6346 | if (!dont_wait_for_ack) { |
| 6347 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6348 | if (!msg) |
| 6349 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6350 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6351 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6352 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6353 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6354 | if (IS_ERR(hdr)) { |
| 6355 | err = PTR_ERR(hdr); |
| 6356 | goto free_msg; |
| 6357 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6358 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6359 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6360 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6361 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6362 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6363 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6364 | if (err) |
| 6365 | goto free_msg; |
| 6366 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6367 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6368 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6369 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6370 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6371 | genlmsg_end(msg, hdr); |
| 6372 | return genlmsg_reply(msg, info); |
| 6373 | } |
| 6374 | |
| 6375 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6376 | |
| 6377 | nla_put_failure: |
| 6378 | err = -ENOBUFS; |
| 6379 | free_msg: |
| 6380 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6381 | return err; |
| 6382 | } |
| 6383 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6384 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6385 | { |
| 6386 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6387 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6388 | u64 cookie; |
| 6389 | |
| 6390 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6391 | return -EINVAL; |
| 6392 | |
| 6393 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6394 | return -EOPNOTSUPP; |
| 6395 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6396 | switch (wdev->iftype) { |
| 6397 | case NL80211_IFTYPE_STATION: |
| 6398 | case NL80211_IFTYPE_ADHOC: |
| 6399 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6400 | case NL80211_IFTYPE_AP: |
| 6401 | case NL80211_IFTYPE_AP_VLAN: |
| 6402 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6403 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6404 | break; |
| 6405 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6406 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6407 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6408 | |
| 6409 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6410 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6411 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6412 | } |
| 6413 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6414 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6415 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6416 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6417 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6418 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6419 | u8 ps_state; |
| 6420 | bool state; |
| 6421 | int err; |
| 6422 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6423 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6424 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6425 | |
| 6426 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6427 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6428 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6429 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6430 | |
| 6431 | wdev = dev->ieee80211_ptr; |
| 6432 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6433 | if (!rdev->ops->set_power_mgmt) |
| 6434 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6435 | |
| 6436 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6437 | |
| 6438 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6439 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6440 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6441 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6442 | if (!err) |
| 6443 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6444 | return err; |
| 6445 | } |
| 6446 | |
| 6447 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6448 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6449 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6450 | enum nl80211_ps_state ps_state; |
| 6451 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6452 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6453 | struct sk_buff *msg; |
| 6454 | void *hdr; |
| 6455 | int err; |
| 6456 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6457 | wdev = dev->ieee80211_ptr; |
| 6458 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6459 | if (!rdev->ops->set_power_mgmt) |
| 6460 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6461 | |
| 6462 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6463 | if (!msg) |
| 6464 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6465 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6466 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6467 | NL80211_CMD_GET_POWER_SAVE); |
| 6468 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6469 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6470 | goto free_msg; |
| 6471 | } |
| 6472 | |
| 6473 | if (wdev->ps) |
| 6474 | ps_state = NL80211_PS_ENABLED; |
| 6475 | else |
| 6476 | ps_state = NL80211_PS_DISABLED; |
| 6477 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6478 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6479 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6480 | |
| 6481 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6482 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6483 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6484 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6485 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6486 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6487 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6488 | return err; |
| 6489 | } |
| 6490 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6491 | static struct nla_policy |
| 6492 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6493 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6494 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6495 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6496 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 6497 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 6498 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6499 | }; |
| 6500 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6501 | static int nl80211_set_cqm_txe(struct genl_info *info, |
| 6502 | u32 rate, u32 pkts, u32 intvl) |
| 6503 | { |
| 6504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6505 | struct wireless_dev *wdev; |
| 6506 | struct net_device *dev = info->user_ptr[1]; |
| 6507 | |
| 6508 | if ((rate < 0 || rate > 100) || |
| 6509 | (intvl < 0 || intvl > NL80211_CQM_TXE_MAX_INTVL)) |
| 6510 | return -EINVAL; |
| 6511 | |
| 6512 | wdev = dev->ieee80211_ptr; |
| 6513 | |
| 6514 | if (!rdev->ops->set_cqm_txe_config) |
| 6515 | return -EOPNOTSUPP; |
| 6516 | |
| 6517 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 6518 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6519 | return -EOPNOTSUPP; |
| 6520 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6521 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6522 | } |
| 6523 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6524 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6525 | s32 threshold, u32 hysteresis) |
| 6526 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6527 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6528 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6529 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6530 | |
| 6531 | if (threshold > 0) |
| 6532 | return -EINVAL; |
| 6533 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6534 | wdev = dev->ieee80211_ptr; |
| 6535 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6536 | if (!rdev->ops->set_cqm_rssi_config) |
| 6537 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6538 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6539 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6540 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6541 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6542 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6543 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6544 | } |
| 6545 | |
| 6546 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6547 | { |
| 6548 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6549 | struct nlattr *cqm; |
| 6550 | int err; |
| 6551 | |
| 6552 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6553 | if (!cqm) { |
| 6554 | err = -EINVAL; |
| 6555 | goto out; |
| 6556 | } |
| 6557 | |
| 6558 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6559 | nl80211_attr_cqm_policy); |
| 6560 | if (err) |
| 6561 | goto out; |
| 6562 | |
| 6563 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6564 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6565 | s32 threshold; |
| 6566 | u32 hysteresis; |
| 6567 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6568 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6569 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6570 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 6571 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 6572 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 6573 | u32 rate, pkts, intvl; |
| 6574 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 6575 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 6576 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 6577 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6578 | } else |
| 6579 | err = -EINVAL; |
| 6580 | |
| 6581 | out: |
| 6582 | return err; |
| 6583 | } |
| 6584 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6585 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6586 | { |
| 6587 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6588 | struct net_device *dev = info->user_ptr[1]; |
| 6589 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6590 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6591 | int err; |
| 6592 | |
| 6593 | /* start with default */ |
| 6594 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6595 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6596 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6597 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6598 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6599 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6600 | if (err) |
| 6601 | return err; |
| 6602 | } |
| 6603 | |
| 6604 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6605 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 6606 | return -EINVAL; |
| 6607 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6608 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6609 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6610 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 6611 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6612 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 6613 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6614 | return -EINVAL; |
| 6615 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6616 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 6617 | /* parse additional setup parameters if given */ |
| 6618 | err = nl80211_parse_mesh_setup(info, &setup); |
| 6619 | if (err) |
| 6620 | return err; |
| 6621 | } |
| 6622 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6623 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6624 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 6625 | if (err) |
| 6626 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6627 | } else { |
| 6628 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6629 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6630 | } |
| 6631 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6632 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6633 | } |
| 6634 | |
| 6635 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6636 | { |
| 6637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6638 | struct net_device *dev = info->user_ptr[1]; |
| 6639 | |
| 6640 | return cfg80211_leave_mesh(rdev, dev); |
| 6641 | } |
| 6642 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6643 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6644 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6645 | { |
| 6646 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6647 | struct sk_buff *msg; |
| 6648 | void *hdr; |
| 6649 | |
| 6650 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6651 | return -EOPNOTSUPP; |
| 6652 | |
| 6653 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6654 | if (!msg) |
| 6655 | return -ENOMEM; |
| 6656 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6657 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6658 | NL80211_CMD_GET_WOWLAN); |
| 6659 | if (!hdr) |
| 6660 | goto nla_put_failure; |
| 6661 | |
| 6662 | if (rdev->wowlan) { |
| 6663 | struct nlattr *nl_wowlan; |
| 6664 | |
| 6665 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 6666 | if (!nl_wowlan) |
| 6667 | goto nla_put_failure; |
| 6668 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6669 | if ((rdev->wowlan->any && |
| 6670 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 6671 | (rdev->wowlan->disconnect && |
| 6672 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 6673 | (rdev->wowlan->magic_pkt && |
| 6674 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 6675 | (rdev->wowlan->gtk_rekey_failure && |
| 6676 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 6677 | (rdev->wowlan->eap_identity_req && |
| 6678 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 6679 | (rdev->wowlan->four_way_handshake && |
| 6680 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 6681 | (rdev->wowlan->rfkill_release && |
| 6682 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 6683 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6684 | if (rdev->wowlan->n_patterns) { |
| 6685 | struct nlattr *nl_pats, *nl_pat; |
| 6686 | int i, pat_len; |
| 6687 | |
| 6688 | nl_pats = nla_nest_start(msg, |
| 6689 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 6690 | if (!nl_pats) |
| 6691 | goto nla_put_failure; |
| 6692 | |
| 6693 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 6694 | nl_pat = nla_nest_start(msg, i + 1); |
| 6695 | if (!nl_pat) |
| 6696 | goto nla_put_failure; |
| 6697 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6698 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 6699 | DIV_ROUND_UP(pat_len, 8), |
| 6700 | rdev->wowlan->patterns[i].mask) || |
| 6701 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 6702 | pat_len, |
| 6703 | rdev->wowlan->patterns[i].pattern)) |
| 6704 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6705 | nla_nest_end(msg, nl_pat); |
| 6706 | } |
| 6707 | nla_nest_end(msg, nl_pats); |
| 6708 | } |
| 6709 | |
| 6710 | nla_nest_end(msg, nl_wowlan); |
| 6711 | } |
| 6712 | |
| 6713 | genlmsg_end(msg, hdr); |
| 6714 | return genlmsg_reply(msg, info); |
| 6715 | |
| 6716 | nla_put_failure: |
| 6717 | nlmsg_free(msg); |
| 6718 | return -ENOBUFS; |
| 6719 | } |
| 6720 | |
| 6721 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6722 | { |
| 6723 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6724 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6725 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6726 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6727 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 6728 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6729 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6730 | |
| 6731 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6732 | return -EOPNOTSUPP; |
| 6733 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6734 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 6735 | cfg80211_rdev_free_wowlan(rdev); |
| 6736 | rdev->wowlan = NULL; |
| 6737 | goto set_wakeup; |
| 6738 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6739 | |
| 6740 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 6741 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6742 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6743 | nl80211_wowlan_policy); |
| 6744 | if (err) |
| 6745 | return err; |
| 6746 | |
| 6747 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 6748 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 6749 | return -EINVAL; |
| 6750 | new_triggers.any = true; |
| 6751 | } |
| 6752 | |
| 6753 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 6754 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 6755 | return -EINVAL; |
| 6756 | new_triggers.disconnect = true; |
| 6757 | } |
| 6758 | |
| 6759 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 6760 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 6761 | return -EINVAL; |
| 6762 | new_triggers.magic_pkt = true; |
| 6763 | } |
| 6764 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 6765 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 6766 | return -EINVAL; |
| 6767 | |
| 6768 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 6769 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 6770 | return -EINVAL; |
| 6771 | new_triggers.gtk_rekey_failure = true; |
| 6772 | } |
| 6773 | |
| 6774 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 6775 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 6776 | return -EINVAL; |
| 6777 | new_triggers.eap_identity_req = true; |
| 6778 | } |
| 6779 | |
| 6780 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 6781 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 6782 | return -EINVAL; |
| 6783 | new_triggers.four_way_handshake = true; |
| 6784 | } |
| 6785 | |
| 6786 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 6787 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 6788 | return -EINVAL; |
| 6789 | new_triggers.rfkill_release = true; |
| 6790 | } |
| 6791 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6792 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 6793 | struct nlattr *pat; |
| 6794 | int n_patterns = 0; |
| 6795 | int rem, pat_len, mask_len; |
| 6796 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6797 | |
| 6798 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6799 | rem) |
| 6800 | n_patterns++; |
| 6801 | if (n_patterns > wowlan->n_patterns) |
| 6802 | return -EINVAL; |
| 6803 | |
| 6804 | new_triggers.patterns = kcalloc(n_patterns, |
| 6805 | sizeof(new_triggers.patterns[0]), |
| 6806 | GFP_KERNEL); |
| 6807 | if (!new_triggers.patterns) |
| 6808 | return -ENOMEM; |
| 6809 | |
| 6810 | new_triggers.n_patterns = n_patterns; |
| 6811 | i = 0; |
| 6812 | |
| 6813 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6814 | rem) { |
| 6815 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6816 | nla_data(pat), nla_len(pat), NULL); |
| 6817 | err = -EINVAL; |
| 6818 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6819 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6820 | goto error; |
| 6821 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6822 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6823 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6824 | mask_len) |
| 6825 | goto error; |
| 6826 | if (pat_len > wowlan->pattern_max_len || |
| 6827 | pat_len < wowlan->pattern_min_len) |
| 6828 | goto error; |
| 6829 | |
| 6830 | new_triggers.patterns[i].mask = |
| 6831 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6832 | if (!new_triggers.patterns[i].mask) { |
| 6833 | err = -ENOMEM; |
| 6834 | goto error; |
| 6835 | } |
| 6836 | new_triggers.patterns[i].pattern = |
| 6837 | new_triggers.patterns[i].mask + mask_len; |
| 6838 | memcpy(new_triggers.patterns[i].mask, |
| 6839 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6840 | mask_len); |
| 6841 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6842 | memcpy(new_triggers.patterns[i].pattern, |
| 6843 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6844 | pat_len); |
| 6845 | i++; |
| 6846 | } |
| 6847 | } |
| 6848 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6849 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 6850 | if (!ntrig) { |
| 6851 | err = -ENOMEM; |
| 6852 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6853 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6854 | cfg80211_rdev_free_wowlan(rdev); |
| 6855 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6856 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6857 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6858 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6859 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6860 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6861 | return 0; |
| 6862 | error: |
| 6863 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6864 | kfree(new_triggers.patterns[i].mask); |
| 6865 | kfree(new_triggers.patterns); |
| 6866 | return err; |
| 6867 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6868 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6869 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6870 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6871 | { |
| 6872 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6873 | struct net_device *dev = info->user_ptr[1]; |
| 6874 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6875 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6876 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6877 | int err; |
| 6878 | |
| 6879 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6880 | return -EINVAL; |
| 6881 | |
| 6882 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6883 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6884 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6885 | nl80211_rekey_policy); |
| 6886 | if (err) |
| 6887 | return err; |
| 6888 | |
| 6889 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6890 | return -ERANGE; |
| 6891 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6892 | return -ERANGE; |
| 6893 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6894 | return -ERANGE; |
| 6895 | |
| 6896 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6897 | NL80211_KEK_LEN); |
| 6898 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6899 | NL80211_KCK_LEN); |
| 6900 | memcpy(rekey_data.replay_ctr, |
| 6901 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6902 | NL80211_REPLAY_CTR_LEN); |
| 6903 | |
| 6904 | wdev_lock(wdev); |
| 6905 | if (!wdev->current_bss) { |
| 6906 | err = -ENOTCONN; |
| 6907 | goto out; |
| 6908 | } |
| 6909 | |
| 6910 | if (!rdev->ops->set_rekey_data) { |
| 6911 | err = -EOPNOTSUPP; |
| 6912 | goto out; |
| 6913 | } |
| 6914 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6915 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6916 | out: |
| 6917 | wdev_unlock(wdev); |
| 6918 | return err; |
| 6919 | } |
| 6920 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6921 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6922 | struct genl_info *info) |
| 6923 | { |
| 6924 | struct net_device *dev = info->user_ptr[1]; |
| 6925 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6926 | |
| 6927 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6928 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6929 | return -EINVAL; |
| 6930 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6931 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6932 | return -EBUSY; |
| 6933 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6934 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6935 | return 0; |
| 6936 | } |
| 6937 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6938 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6939 | struct genl_info *info) |
| 6940 | { |
| 6941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6942 | struct net_device *dev = info->user_ptr[1]; |
| 6943 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6944 | struct sk_buff *msg; |
| 6945 | void *hdr; |
| 6946 | const u8 *addr; |
| 6947 | u64 cookie; |
| 6948 | int err; |
| 6949 | |
| 6950 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6951 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6952 | return -EOPNOTSUPP; |
| 6953 | |
| 6954 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6955 | return -EINVAL; |
| 6956 | |
| 6957 | if (!rdev->ops->probe_client) |
| 6958 | return -EOPNOTSUPP; |
| 6959 | |
| 6960 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6961 | if (!msg) |
| 6962 | return -ENOMEM; |
| 6963 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6964 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6965 | NL80211_CMD_PROBE_CLIENT); |
| 6966 | |
| 6967 | if (IS_ERR(hdr)) { |
| 6968 | err = PTR_ERR(hdr); |
| 6969 | goto free_msg; |
| 6970 | } |
| 6971 | |
| 6972 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6973 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6974 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6975 | if (err) |
| 6976 | goto free_msg; |
| 6977 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6978 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6979 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6980 | |
| 6981 | genlmsg_end(msg, hdr); |
| 6982 | |
| 6983 | return genlmsg_reply(msg, info); |
| 6984 | |
| 6985 | nla_put_failure: |
| 6986 | err = -ENOBUFS; |
| 6987 | free_msg: |
| 6988 | nlmsg_free(msg); |
| 6989 | return err; |
| 6990 | } |
| 6991 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6992 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 6993 | { |
| 6994 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 6995 | struct cfg80211_beacon_registration *reg, *nreg; |
| 6996 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6997 | |
| 6998 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 6999 | return -EOPNOTSUPP; |
| 7000 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7001 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 7002 | if (!nreg) |
| 7003 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7004 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7005 | /* First, check if already registered. */ |
| 7006 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 7007 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 7008 | if (reg->nlportid == info->snd_portid) { |
| 7009 | rv = -EALREADY; |
| 7010 | goto out_err; |
| 7011 | } |
| 7012 | } |
| 7013 | /* Add it to the list */ |
| 7014 | nreg->nlportid = info->snd_portid; |
| 7015 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 7016 | |
| 7017 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7018 | |
| 7019 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7020 | out_err: |
| 7021 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 7022 | kfree(nreg); |
| 7023 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7024 | } |
| 7025 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7026 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7027 | { |
| 7028 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7029 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7030 | int err; |
| 7031 | |
| 7032 | if (!rdev->ops->start_p2p_device) |
| 7033 | return -EOPNOTSUPP; |
| 7034 | |
| 7035 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7036 | return -EOPNOTSUPP; |
| 7037 | |
| 7038 | if (wdev->p2p_started) |
| 7039 | return 0; |
| 7040 | |
| 7041 | mutex_lock(&rdev->devlist_mtx); |
| 7042 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 7043 | mutex_unlock(&rdev->devlist_mtx); |
| 7044 | if (err) |
| 7045 | return err; |
| 7046 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7047 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7048 | if (err) |
| 7049 | return err; |
| 7050 | |
| 7051 | wdev->p2p_started = true; |
| 7052 | mutex_lock(&rdev->devlist_mtx); |
| 7053 | rdev->opencount++; |
| 7054 | mutex_unlock(&rdev->devlist_mtx); |
| 7055 | |
| 7056 | return 0; |
| 7057 | } |
| 7058 | |
| 7059 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7060 | { |
| 7061 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7062 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7063 | |
| 7064 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7065 | return -EOPNOTSUPP; |
| 7066 | |
| 7067 | if (!rdev->ops->stop_p2p_device) |
| 7068 | return -EOPNOTSUPP; |
| 7069 | |
| 7070 | if (!wdev->p2p_started) |
| 7071 | return 0; |
| 7072 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7073 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7074 | wdev->p2p_started = false; |
| 7075 | |
| 7076 | mutex_lock(&rdev->devlist_mtx); |
| 7077 | rdev->opencount--; |
| 7078 | mutex_unlock(&rdev->devlist_mtx); |
| 7079 | |
| 7080 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 7081 | rdev->scan_req->aborted = true; |
| 7082 | ___cfg80211_scan_done(rdev, true); |
| 7083 | } |
| 7084 | |
| 7085 | return 0; |
| 7086 | } |
| 7087 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7088 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 7089 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 7090 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7091 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 7092 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 7093 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7094 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7095 | /* 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] | 7096 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 7097 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7098 | |
| 7099 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7100 | struct genl_info *info) |
| 7101 | { |
| 7102 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7103 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7104 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7105 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 7106 | |
| 7107 | if (rtnl) |
| 7108 | rtnl_lock(); |
| 7109 | |
| 7110 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 7111 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7112 | if (IS_ERR(rdev)) { |
| 7113 | if (rtnl) |
| 7114 | rtnl_unlock(); |
| 7115 | return PTR_ERR(rdev); |
| 7116 | } |
| 7117 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7118 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7119 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7120 | mutex_lock(&cfg80211_mutex); |
| 7121 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7122 | info->attrs); |
| 7123 | if (IS_ERR(wdev)) { |
| 7124 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7125 | if (rtnl) |
| 7126 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7127 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7128 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7129 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7130 | dev = wdev->netdev; |
| 7131 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7132 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7133 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7134 | if (!dev) { |
| 7135 | mutex_unlock(&cfg80211_mutex); |
| 7136 | if (rtnl) |
| 7137 | rtnl_unlock(); |
| 7138 | return -EINVAL; |
| 7139 | } |
| 7140 | |
| 7141 | info->user_ptr[1] = dev; |
| 7142 | } else { |
| 7143 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7144 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7145 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7146 | if (dev) { |
| 7147 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7148 | !netif_running(dev)) { |
| 7149 | mutex_unlock(&cfg80211_mutex); |
| 7150 | if (rtnl) |
| 7151 | rtnl_unlock(); |
| 7152 | return -ENETDOWN; |
| 7153 | } |
| 7154 | |
| 7155 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7156 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7157 | if (!wdev->p2p_started) { |
| 7158 | mutex_unlock(&cfg80211_mutex); |
| 7159 | if (rtnl) |
| 7160 | rtnl_unlock(); |
| 7161 | return -ENETDOWN; |
| 7162 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7163 | } |
| 7164 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7165 | cfg80211_lock_rdev(rdev); |
| 7166 | |
| 7167 | mutex_unlock(&cfg80211_mutex); |
| 7168 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7169 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7170 | } |
| 7171 | |
| 7172 | return 0; |
| 7173 | } |
| 7174 | |
| 7175 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7176 | struct genl_info *info) |
| 7177 | { |
| 7178 | if (info->user_ptr[0]) |
| 7179 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7180 | if (info->user_ptr[1]) { |
| 7181 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7182 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7183 | |
| 7184 | if (wdev->netdev) |
| 7185 | dev_put(wdev->netdev); |
| 7186 | } else { |
| 7187 | dev_put(info->user_ptr[1]); |
| 7188 | } |
| 7189 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7190 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7191 | rtnl_unlock(); |
| 7192 | } |
| 7193 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7194 | static struct genl_ops nl80211_ops[] = { |
| 7195 | { |
| 7196 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7197 | .doit = nl80211_get_wiphy, |
| 7198 | .dumpit = nl80211_dump_wiphy, |
| 7199 | .policy = nl80211_policy, |
| 7200 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7201 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7202 | }, |
| 7203 | { |
| 7204 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7205 | .doit = nl80211_set_wiphy, |
| 7206 | .policy = nl80211_policy, |
| 7207 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7208 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7209 | }, |
| 7210 | { |
| 7211 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7212 | .doit = nl80211_get_interface, |
| 7213 | .dumpit = nl80211_dump_interface, |
| 7214 | .policy = nl80211_policy, |
| 7215 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7216 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7217 | }, |
| 7218 | { |
| 7219 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7220 | .doit = nl80211_set_interface, |
| 7221 | .policy = nl80211_policy, |
| 7222 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7223 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7224 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7225 | }, |
| 7226 | { |
| 7227 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7228 | .doit = nl80211_new_interface, |
| 7229 | .policy = nl80211_policy, |
| 7230 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7231 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7232 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7233 | }, |
| 7234 | { |
| 7235 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7236 | .doit = nl80211_del_interface, |
| 7237 | .policy = nl80211_policy, |
| 7238 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7239 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7240 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7241 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7242 | { |
| 7243 | .cmd = NL80211_CMD_GET_KEY, |
| 7244 | .doit = nl80211_get_key, |
| 7245 | .policy = nl80211_policy, |
| 7246 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7247 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7248 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7249 | }, |
| 7250 | { |
| 7251 | .cmd = NL80211_CMD_SET_KEY, |
| 7252 | .doit = nl80211_set_key, |
| 7253 | .policy = nl80211_policy, |
| 7254 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7255 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7256 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7257 | }, |
| 7258 | { |
| 7259 | .cmd = NL80211_CMD_NEW_KEY, |
| 7260 | .doit = nl80211_new_key, |
| 7261 | .policy = nl80211_policy, |
| 7262 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7263 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7264 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7265 | }, |
| 7266 | { |
| 7267 | .cmd = NL80211_CMD_DEL_KEY, |
| 7268 | .doit = nl80211_del_key, |
| 7269 | .policy = nl80211_policy, |
| 7270 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7271 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7272 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7273 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7274 | { |
| 7275 | .cmd = NL80211_CMD_SET_BEACON, |
| 7276 | .policy = nl80211_policy, |
| 7277 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7278 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7279 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7280 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7281 | }, |
| 7282 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7283 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7284 | .policy = nl80211_policy, |
| 7285 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7286 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7287 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7288 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7289 | }, |
| 7290 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7291 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7292 | .policy = nl80211_policy, |
| 7293 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7294 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7295 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7296 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7297 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7298 | { |
| 7299 | .cmd = NL80211_CMD_GET_STATION, |
| 7300 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7301 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7302 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7303 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7304 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7305 | }, |
| 7306 | { |
| 7307 | .cmd = NL80211_CMD_SET_STATION, |
| 7308 | .doit = nl80211_set_station, |
| 7309 | .policy = nl80211_policy, |
| 7310 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7311 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7312 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7313 | }, |
| 7314 | { |
| 7315 | .cmd = NL80211_CMD_NEW_STATION, |
| 7316 | .doit = nl80211_new_station, |
| 7317 | .policy = nl80211_policy, |
| 7318 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7319 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7320 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7321 | }, |
| 7322 | { |
| 7323 | .cmd = NL80211_CMD_DEL_STATION, |
| 7324 | .doit = nl80211_del_station, |
| 7325 | .policy = nl80211_policy, |
| 7326 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7327 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7328 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7329 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7330 | { |
| 7331 | .cmd = NL80211_CMD_GET_MPATH, |
| 7332 | .doit = nl80211_get_mpath, |
| 7333 | .dumpit = nl80211_dump_mpath, |
| 7334 | .policy = nl80211_policy, |
| 7335 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7336 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7337 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7338 | }, |
| 7339 | { |
| 7340 | .cmd = NL80211_CMD_SET_MPATH, |
| 7341 | .doit = nl80211_set_mpath, |
| 7342 | .policy = nl80211_policy, |
| 7343 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7344 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7345 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7346 | }, |
| 7347 | { |
| 7348 | .cmd = NL80211_CMD_NEW_MPATH, |
| 7349 | .doit = nl80211_new_mpath, |
| 7350 | .policy = nl80211_policy, |
| 7351 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7352 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7353 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7354 | }, |
| 7355 | { |
| 7356 | .cmd = NL80211_CMD_DEL_MPATH, |
| 7357 | .doit = nl80211_del_mpath, |
| 7358 | .policy = nl80211_policy, |
| 7359 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7360 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7361 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7362 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7363 | { |
| 7364 | .cmd = NL80211_CMD_SET_BSS, |
| 7365 | .doit = nl80211_set_bss, |
| 7366 | .policy = nl80211_policy, |
| 7367 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7368 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7369 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7370 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7371 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7372 | .cmd = NL80211_CMD_GET_REG, |
| 7373 | .doit = nl80211_get_reg, |
| 7374 | .policy = nl80211_policy, |
| 7375 | /* can be retrieved by unprivileged users */ |
| 7376 | }, |
| 7377 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7378 | .cmd = NL80211_CMD_SET_REG, |
| 7379 | .doit = nl80211_set_reg, |
| 7380 | .policy = nl80211_policy, |
| 7381 | .flags = GENL_ADMIN_PERM, |
| 7382 | }, |
| 7383 | { |
| 7384 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 7385 | .doit = nl80211_req_set_reg, |
| 7386 | .policy = nl80211_policy, |
| 7387 | .flags = GENL_ADMIN_PERM, |
| 7388 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7389 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7390 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 7391 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7392 | .policy = nl80211_policy, |
| 7393 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7394 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7395 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7396 | }, |
| 7397 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7398 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 7399 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7400 | .policy = nl80211_policy, |
| 7401 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7402 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7403 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7404 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 7405 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7406 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 7407 | .doit = nl80211_trigger_scan, |
| 7408 | .policy = nl80211_policy, |
| 7409 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7410 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7411 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7412 | }, |
| 7413 | { |
| 7414 | .cmd = NL80211_CMD_GET_SCAN, |
| 7415 | .policy = nl80211_policy, |
| 7416 | .dumpit = nl80211_dump_scan, |
| 7417 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7418 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7419 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 7420 | .doit = nl80211_start_sched_scan, |
| 7421 | .policy = nl80211_policy, |
| 7422 | .flags = GENL_ADMIN_PERM, |
| 7423 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7424 | NL80211_FLAG_NEED_RTNL, |
| 7425 | }, |
| 7426 | { |
| 7427 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 7428 | .doit = nl80211_stop_sched_scan, |
| 7429 | .policy = nl80211_policy, |
| 7430 | .flags = GENL_ADMIN_PERM, |
| 7431 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7432 | NL80211_FLAG_NEED_RTNL, |
| 7433 | }, |
| 7434 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7435 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 7436 | .doit = nl80211_authenticate, |
| 7437 | .policy = nl80211_policy, |
| 7438 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7439 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7440 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7441 | }, |
| 7442 | { |
| 7443 | .cmd = NL80211_CMD_ASSOCIATE, |
| 7444 | .doit = nl80211_associate, |
| 7445 | .policy = nl80211_policy, |
| 7446 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7447 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7448 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7449 | }, |
| 7450 | { |
| 7451 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 7452 | .doit = nl80211_deauthenticate, |
| 7453 | .policy = nl80211_policy, |
| 7454 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7455 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7456 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7457 | }, |
| 7458 | { |
| 7459 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 7460 | .doit = nl80211_disassociate, |
| 7461 | .policy = nl80211_policy, |
| 7462 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7463 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7464 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7465 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7466 | { |
| 7467 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 7468 | .doit = nl80211_join_ibss, |
| 7469 | .policy = nl80211_policy, |
| 7470 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7471 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7472 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7473 | }, |
| 7474 | { |
| 7475 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 7476 | .doit = nl80211_leave_ibss, |
| 7477 | .policy = nl80211_policy, |
| 7478 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7479 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7480 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7481 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7482 | #ifdef CONFIG_NL80211_TESTMODE |
| 7483 | { |
| 7484 | .cmd = NL80211_CMD_TESTMODE, |
| 7485 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7486 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7487 | .policy = nl80211_policy, |
| 7488 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7489 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7490 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7491 | }, |
| 7492 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7493 | { |
| 7494 | .cmd = NL80211_CMD_CONNECT, |
| 7495 | .doit = nl80211_connect, |
| 7496 | .policy = nl80211_policy, |
| 7497 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7498 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7499 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7500 | }, |
| 7501 | { |
| 7502 | .cmd = NL80211_CMD_DISCONNECT, |
| 7503 | .doit = nl80211_disconnect, |
| 7504 | .policy = nl80211_policy, |
| 7505 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7506 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7507 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7508 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7509 | { |
| 7510 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 7511 | .doit = nl80211_wiphy_netns, |
| 7512 | .policy = nl80211_policy, |
| 7513 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7514 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7515 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7516 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7517 | { |
| 7518 | .cmd = NL80211_CMD_GET_SURVEY, |
| 7519 | .policy = nl80211_policy, |
| 7520 | .dumpit = nl80211_dump_survey, |
| 7521 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7522 | { |
| 7523 | .cmd = NL80211_CMD_SET_PMKSA, |
| 7524 | .doit = nl80211_setdel_pmksa, |
| 7525 | .policy = nl80211_policy, |
| 7526 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7527 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7528 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7529 | }, |
| 7530 | { |
| 7531 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 7532 | .doit = nl80211_setdel_pmksa, |
| 7533 | .policy = nl80211_policy, |
| 7534 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7535 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7536 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7537 | }, |
| 7538 | { |
| 7539 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 7540 | .doit = nl80211_flush_pmksa, |
| 7541 | .policy = nl80211_policy, |
| 7542 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7543 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7544 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7545 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7546 | { |
| 7547 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7548 | .doit = nl80211_remain_on_channel, |
| 7549 | .policy = nl80211_policy, |
| 7550 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7551 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7552 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7553 | }, |
| 7554 | { |
| 7555 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7556 | .doit = nl80211_cancel_remain_on_channel, |
| 7557 | .policy = nl80211_policy, |
| 7558 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7559 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7560 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7561 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7562 | { |
| 7563 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 7564 | .doit = nl80211_set_tx_bitrate_mask, |
| 7565 | .policy = nl80211_policy, |
| 7566 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7567 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7568 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7569 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7570 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7571 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 7572 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7573 | .policy = nl80211_policy, |
| 7574 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7575 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7576 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7577 | }, |
| 7578 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7579 | .cmd = NL80211_CMD_FRAME, |
| 7580 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7581 | .policy = nl80211_policy, |
| 7582 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7583 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7584 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7585 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7586 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7587 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 7588 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 7589 | .policy = nl80211_policy, |
| 7590 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7591 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7592 | NL80211_FLAG_NEED_RTNL, |
| 7593 | }, |
| 7594 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7595 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 7596 | .doit = nl80211_set_power_save, |
| 7597 | .policy = nl80211_policy, |
| 7598 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7599 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7600 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7601 | }, |
| 7602 | { |
| 7603 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 7604 | .doit = nl80211_get_power_save, |
| 7605 | .policy = nl80211_policy, |
| 7606 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7607 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7608 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7609 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7610 | { |
| 7611 | .cmd = NL80211_CMD_SET_CQM, |
| 7612 | .doit = nl80211_set_cqm, |
| 7613 | .policy = nl80211_policy, |
| 7614 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7615 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7616 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7617 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7618 | { |
| 7619 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 7620 | .doit = nl80211_set_channel, |
| 7621 | .policy = nl80211_policy, |
| 7622 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7623 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7624 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7625 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7626 | { |
| 7627 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 7628 | .doit = nl80211_set_wds_peer, |
| 7629 | .policy = nl80211_policy, |
| 7630 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 7631 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7632 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7633 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7634 | { |
| 7635 | .cmd = NL80211_CMD_JOIN_MESH, |
| 7636 | .doit = nl80211_join_mesh, |
| 7637 | .policy = nl80211_policy, |
| 7638 | .flags = GENL_ADMIN_PERM, |
| 7639 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7640 | NL80211_FLAG_NEED_RTNL, |
| 7641 | }, |
| 7642 | { |
| 7643 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 7644 | .doit = nl80211_leave_mesh, |
| 7645 | .policy = nl80211_policy, |
| 7646 | .flags = GENL_ADMIN_PERM, |
| 7647 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7648 | NL80211_FLAG_NEED_RTNL, |
| 7649 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7650 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7651 | { |
| 7652 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 7653 | .doit = nl80211_get_wowlan, |
| 7654 | .policy = nl80211_policy, |
| 7655 | /* can be retrieved by unprivileged users */ |
| 7656 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7657 | NL80211_FLAG_NEED_RTNL, |
| 7658 | }, |
| 7659 | { |
| 7660 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 7661 | .doit = nl80211_set_wowlan, |
| 7662 | .policy = nl80211_policy, |
| 7663 | .flags = GENL_ADMIN_PERM, |
| 7664 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7665 | NL80211_FLAG_NEED_RTNL, |
| 7666 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7667 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7668 | { |
| 7669 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 7670 | .doit = nl80211_set_rekey_data, |
| 7671 | .policy = nl80211_policy, |
| 7672 | .flags = GENL_ADMIN_PERM, |
| 7673 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7674 | NL80211_FLAG_NEED_RTNL, |
| 7675 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7676 | { |
| 7677 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 7678 | .doit = nl80211_tdls_mgmt, |
| 7679 | .policy = nl80211_policy, |
| 7680 | .flags = GENL_ADMIN_PERM, |
| 7681 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7682 | NL80211_FLAG_NEED_RTNL, |
| 7683 | }, |
| 7684 | { |
| 7685 | .cmd = NL80211_CMD_TDLS_OPER, |
| 7686 | .doit = nl80211_tdls_oper, |
| 7687 | .policy = nl80211_policy, |
| 7688 | .flags = GENL_ADMIN_PERM, |
| 7689 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7690 | NL80211_FLAG_NEED_RTNL, |
| 7691 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7692 | { |
| 7693 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 7694 | .doit = nl80211_register_unexpected_frame, |
| 7695 | .policy = nl80211_policy, |
| 7696 | .flags = GENL_ADMIN_PERM, |
| 7697 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7698 | NL80211_FLAG_NEED_RTNL, |
| 7699 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7700 | { |
| 7701 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 7702 | .doit = nl80211_probe_client, |
| 7703 | .policy = nl80211_policy, |
| 7704 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7705 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7706 | NL80211_FLAG_NEED_RTNL, |
| 7707 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7708 | { |
| 7709 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 7710 | .doit = nl80211_register_beacons, |
| 7711 | .policy = nl80211_policy, |
| 7712 | .flags = GENL_ADMIN_PERM, |
| 7713 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7714 | NL80211_FLAG_NEED_RTNL, |
| 7715 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 7716 | { |
| 7717 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 7718 | .doit = nl80211_set_noack_map, |
| 7719 | .policy = nl80211_policy, |
| 7720 | .flags = GENL_ADMIN_PERM, |
| 7721 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7722 | NL80211_FLAG_NEED_RTNL, |
| 7723 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7724 | { |
| 7725 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 7726 | .doit = nl80211_start_p2p_device, |
| 7727 | .policy = nl80211_policy, |
| 7728 | .flags = GENL_ADMIN_PERM, |
| 7729 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 7730 | NL80211_FLAG_NEED_RTNL, |
| 7731 | }, |
| 7732 | { |
| 7733 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 7734 | .doit = nl80211_stop_p2p_device, |
| 7735 | .policy = nl80211_policy, |
| 7736 | .flags = GENL_ADMIN_PERM, |
| 7737 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 7738 | NL80211_FLAG_NEED_RTNL, |
| 7739 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7740 | { |
| 7741 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 7742 | .doit = nl80211_set_mcast_rate, |
| 7743 | .policy = nl80211_policy, |
| 7744 | .flags = GENL_ADMIN_PERM, |
| 7745 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7746 | NL80211_FLAG_NEED_RTNL, |
| 7747 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7748 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7749 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7750 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 7751 | .name = "mlme", |
| 7752 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7753 | |
| 7754 | /* multicast groups */ |
| 7755 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 7756 | .name = "config", |
| 7757 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7758 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 7759 | .name = "scan", |
| 7760 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7761 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 7762 | .name = "regulatory", |
| 7763 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7764 | |
| 7765 | /* notification functions */ |
| 7766 | |
| 7767 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 7768 | { |
| 7769 | struct sk_buff *msg; |
| 7770 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7771 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7772 | if (!msg) |
| 7773 | return; |
| 7774 | |
| 7775 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 7776 | nlmsg_free(msg); |
| 7777 | return; |
| 7778 | } |
| 7779 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7780 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7781 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7782 | } |
| 7783 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7784 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 7785 | struct cfg80211_registered_device *rdev) |
| 7786 | { |
| 7787 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 7788 | struct nlattr *nest; |
| 7789 | int i; |
| 7790 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7791 | ASSERT_RDEV_LOCK(rdev); |
| 7792 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7793 | if (WARN_ON(!req)) |
| 7794 | return 0; |
| 7795 | |
| 7796 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 7797 | if (!nest) |
| 7798 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7799 | for (i = 0; i < req->n_ssids; i++) { |
| 7800 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 7801 | goto nla_put_failure; |
| 7802 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7803 | nla_nest_end(msg, nest); |
| 7804 | |
| 7805 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 7806 | if (!nest) |
| 7807 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7808 | for (i = 0; i < req->n_channels; i++) { |
| 7809 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 7810 | goto nla_put_failure; |
| 7811 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7812 | nla_nest_end(msg, nest); |
| 7813 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7814 | if (req->ie && |
| 7815 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 7816 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7817 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7818 | if (req->flags) |
| 7819 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 7820 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7821 | return 0; |
| 7822 | nla_put_failure: |
| 7823 | return -ENOBUFS; |
| 7824 | } |
| 7825 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7826 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 7827 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7828 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7829 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7830 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7831 | { |
| 7832 | void *hdr; |
| 7833 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7834 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7835 | if (!hdr) |
| 7836 | return -1; |
| 7837 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7838 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7839 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 7840 | wdev->netdev->ifindex)) || |
| 7841 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7842 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7843 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7844 | /* ignore errors and send incomplete event anyway */ |
| 7845 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7846 | |
| 7847 | return genlmsg_end(msg, hdr); |
| 7848 | |
| 7849 | nla_put_failure: |
| 7850 | genlmsg_cancel(msg, hdr); |
| 7851 | return -EMSGSIZE; |
| 7852 | } |
| 7853 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7854 | static int |
| 7855 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 7856 | struct cfg80211_registered_device *rdev, |
| 7857 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7858 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7859 | { |
| 7860 | void *hdr; |
| 7861 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7862 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7863 | if (!hdr) |
| 7864 | return -1; |
| 7865 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7866 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7867 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7868 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7869 | |
| 7870 | return genlmsg_end(msg, hdr); |
| 7871 | |
| 7872 | nla_put_failure: |
| 7873 | genlmsg_cancel(msg, hdr); |
| 7874 | return -EMSGSIZE; |
| 7875 | } |
| 7876 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7877 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7878 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7879 | { |
| 7880 | struct sk_buff *msg; |
| 7881 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 7882 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7883 | if (!msg) |
| 7884 | return; |
| 7885 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7886 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7887 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 7888 | nlmsg_free(msg); |
| 7889 | return; |
| 7890 | } |
| 7891 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7892 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7893 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7894 | } |
| 7895 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7896 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7897 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7898 | { |
| 7899 | struct sk_buff *msg; |
| 7900 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7901 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7902 | if (!msg) |
| 7903 | return; |
| 7904 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7905 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7906 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7907 | nlmsg_free(msg); |
| 7908 | return; |
| 7909 | } |
| 7910 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7911 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7912 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7913 | } |
| 7914 | |
| 7915 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7916 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7917 | { |
| 7918 | struct sk_buff *msg; |
| 7919 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7920 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7921 | if (!msg) |
| 7922 | return; |
| 7923 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7924 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7925 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7926 | nlmsg_free(msg); |
| 7927 | return; |
| 7928 | } |
| 7929 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7930 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7931 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7932 | } |
| 7933 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7934 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 7935 | struct net_device *netdev) |
| 7936 | { |
| 7937 | struct sk_buff *msg; |
| 7938 | |
| 7939 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7940 | if (!msg) |
| 7941 | return; |
| 7942 | |
| 7943 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7944 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 7945 | nlmsg_free(msg); |
| 7946 | return; |
| 7947 | } |
| 7948 | |
| 7949 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7950 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7951 | } |
| 7952 | |
| 7953 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 7954 | struct net_device *netdev, u32 cmd) |
| 7955 | { |
| 7956 | struct sk_buff *msg; |
| 7957 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 7958 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7959 | if (!msg) |
| 7960 | return; |
| 7961 | |
| 7962 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 7963 | nlmsg_free(msg); |
| 7964 | return; |
| 7965 | } |
| 7966 | |
| 7967 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7968 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7969 | } |
| 7970 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7971 | /* |
| 7972 | * This can happen on global regulatory changes or device specific settings |
| 7973 | * based on custom world regulatory domains. |
| 7974 | */ |
| 7975 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 7976 | { |
| 7977 | struct sk_buff *msg; |
| 7978 | void *hdr; |
| 7979 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7980 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7981 | if (!msg) |
| 7982 | return; |
| 7983 | |
| 7984 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 7985 | if (!hdr) { |
| 7986 | nlmsg_free(msg); |
| 7987 | return; |
| 7988 | } |
| 7989 | |
| 7990 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7991 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 7992 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7993 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7994 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 7995 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7996 | NL80211_REGDOM_TYPE_WORLD)) |
| 7997 | goto nla_put_failure; |
| 7998 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 7999 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8000 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 8001 | goto nla_put_failure; |
| 8002 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 8003 | request->intersect) { |
| 8004 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8005 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 8006 | goto nla_put_failure; |
| 8007 | } else { |
| 8008 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8009 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 8010 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 8011 | request->alpha2)) |
| 8012 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8013 | } |
| 8014 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8015 | if (wiphy_idx_valid(request->wiphy_idx) && |
| 8016 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 8017 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8018 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8019 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8020 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8021 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8022 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8023 | GFP_ATOMIC); |
| 8024 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8025 | |
| 8026 | return; |
| 8027 | |
| 8028 | nla_put_failure: |
| 8029 | genlmsg_cancel(msg, hdr); |
| 8030 | nlmsg_free(msg); |
| 8031 | } |
| 8032 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8033 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 8034 | struct net_device *netdev, |
| 8035 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8036 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8037 | { |
| 8038 | struct sk_buff *msg; |
| 8039 | void *hdr; |
| 8040 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8041 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8042 | if (!msg) |
| 8043 | return; |
| 8044 | |
| 8045 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8046 | if (!hdr) { |
| 8047 | nlmsg_free(msg); |
| 8048 | return; |
| 8049 | } |
| 8050 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8051 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8052 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8053 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8054 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8055 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8056 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8057 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8058 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8059 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8060 | return; |
| 8061 | |
| 8062 | nla_put_failure: |
| 8063 | genlmsg_cancel(msg, hdr); |
| 8064 | nlmsg_free(msg); |
| 8065 | } |
| 8066 | |
| 8067 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8068 | struct net_device *netdev, const u8 *buf, |
| 8069 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8070 | { |
| 8071 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8072 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8073 | } |
| 8074 | |
| 8075 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 8076 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8077 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8078 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8079 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8080 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8081 | } |
| 8082 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8083 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8084 | struct net_device *netdev, const u8 *buf, |
| 8085 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8086 | { |
| 8087 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8088 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8089 | } |
| 8090 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8091 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 8092 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8093 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8094 | { |
| 8095 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8096 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8097 | } |
| 8098 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 8099 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 8100 | struct net_device *netdev, const u8 *buf, |
| 8101 | size_t len, gfp_t gfp) |
| 8102 | { |
| 8103 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8104 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 8105 | } |
| 8106 | |
| 8107 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 8108 | struct net_device *netdev, const u8 *buf, |
| 8109 | size_t len, gfp_t gfp) |
| 8110 | { |
| 8111 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8112 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 8113 | } |
| 8114 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 8115 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 8116 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8117 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8118 | { |
| 8119 | struct sk_buff *msg; |
| 8120 | void *hdr; |
| 8121 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8122 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8123 | if (!msg) |
| 8124 | return; |
| 8125 | |
| 8126 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8127 | if (!hdr) { |
| 8128 | nlmsg_free(msg); |
| 8129 | return; |
| 8130 | } |
| 8131 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8132 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8133 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8134 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8135 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8136 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8137 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8138 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8139 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8140 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8141 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8142 | return; |
| 8143 | |
| 8144 | nla_put_failure: |
| 8145 | genlmsg_cancel(msg, hdr); |
| 8146 | nlmsg_free(msg); |
| 8147 | } |
| 8148 | |
| 8149 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8150 | struct net_device *netdev, const u8 *addr, |
| 8151 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8152 | { |
| 8153 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8154 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8155 | } |
| 8156 | |
| 8157 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8158 | struct net_device *netdev, const u8 *addr, |
| 8159 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8160 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8161 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8162 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8163 | } |
| 8164 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8165 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8166 | struct net_device *netdev, const u8 *bssid, |
| 8167 | const u8 *req_ie, size_t req_ie_len, |
| 8168 | const u8 *resp_ie, size_t resp_ie_len, |
| 8169 | u16 status, gfp_t gfp) |
| 8170 | { |
| 8171 | struct sk_buff *msg; |
| 8172 | void *hdr; |
| 8173 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8174 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8175 | if (!msg) |
| 8176 | return; |
| 8177 | |
| 8178 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8179 | if (!hdr) { |
| 8180 | nlmsg_free(msg); |
| 8181 | return; |
| 8182 | } |
| 8183 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8184 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8185 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8186 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8187 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8188 | (req_ie && |
| 8189 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8190 | (resp_ie && |
| 8191 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8192 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8193 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8194 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8195 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8196 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8197 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8198 | return; |
| 8199 | |
| 8200 | nla_put_failure: |
| 8201 | genlmsg_cancel(msg, hdr); |
| 8202 | nlmsg_free(msg); |
| 8203 | |
| 8204 | } |
| 8205 | |
| 8206 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8207 | struct net_device *netdev, const u8 *bssid, |
| 8208 | const u8 *req_ie, size_t req_ie_len, |
| 8209 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8210 | { |
| 8211 | struct sk_buff *msg; |
| 8212 | void *hdr; |
| 8213 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8214 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8215 | if (!msg) |
| 8216 | return; |
| 8217 | |
| 8218 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8219 | if (!hdr) { |
| 8220 | nlmsg_free(msg); |
| 8221 | return; |
| 8222 | } |
| 8223 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8224 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8225 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8226 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8227 | (req_ie && |
| 8228 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8229 | (resp_ie && |
| 8230 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8231 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8232 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8233 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8234 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8235 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8236 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8237 | return; |
| 8238 | |
| 8239 | nla_put_failure: |
| 8240 | genlmsg_cancel(msg, hdr); |
| 8241 | nlmsg_free(msg); |
| 8242 | |
| 8243 | } |
| 8244 | |
| 8245 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 8246 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8247 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8248 | { |
| 8249 | struct sk_buff *msg; |
| 8250 | void *hdr; |
| 8251 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8252 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8253 | if (!msg) |
| 8254 | return; |
| 8255 | |
| 8256 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 8257 | if (!hdr) { |
| 8258 | nlmsg_free(msg); |
| 8259 | return; |
| 8260 | } |
| 8261 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8262 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8263 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8264 | (from_ap && reason && |
| 8265 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 8266 | (from_ap && |
| 8267 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 8268 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 8269 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8270 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8271 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8272 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8273 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8274 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8275 | return; |
| 8276 | |
| 8277 | nla_put_failure: |
| 8278 | genlmsg_cancel(msg, hdr); |
| 8279 | nlmsg_free(msg); |
| 8280 | |
| 8281 | } |
| 8282 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8283 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 8284 | struct net_device *netdev, const u8 *bssid, |
| 8285 | gfp_t gfp) |
| 8286 | { |
| 8287 | struct sk_buff *msg; |
| 8288 | void *hdr; |
| 8289 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8290 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8291 | if (!msg) |
| 8292 | return; |
| 8293 | |
| 8294 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 8295 | if (!hdr) { |
| 8296 | nlmsg_free(msg); |
| 8297 | return; |
| 8298 | } |
| 8299 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8300 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8301 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8302 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8303 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8304 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8305 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8306 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8307 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8308 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8309 | return; |
| 8310 | |
| 8311 | nla_put_failure: |
| 8312 | genlmsg_cancel(msg, hdr); |
| 8313 | nlmsg_free(msg); |
| 8314 | } |
| 8315 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8316 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 8317 | struct net_device *netdev, |
| 8318 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 8319 | gfp_t gfp) |
| 8320 | { |
| 8321 | struct sk_buff *msg; |
| 8322 | void *hdr; |
| 8323 | |
| 8324 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8325 | if (!msg) |
| 8326 | return; |
| 8327 | |
| 8328 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 8329 | if (!hdr) { |
| 8330 | nlmsg_free(msg); |
| 8331 | return; |
| 8332 | } |
| 8333 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8334 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8335 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8336 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 8337 | (ie_len && ie && |
| 8338 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 8339 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8340 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8341 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8342 | |
| 8343 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8344 | nl80211_mlme_mcgrp.id, gfp); |
| 8345 | return; |
| 8346 | |
| 8347 | nla_put_failure: |
| 8348 | genlmsg_cancel(msg, hdr); |
| 8349 | nlmsg_free(msg); |
| 8350 | } |
| 8351 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8352 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 8353 | struct net_device *netdev, const u8 *addr, |
| 8354 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8355 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8356 | { |
| 8357 | struct sk_buff *msg; |
| 8358 | void *hdr; |
| 8359 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8360 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8361 | if (!msg) |
| 8362 | return; |
| 8363 | |
| 8364 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 8365 | if (!hdr) { |
| 8366 | nlmsg_free(msg); |
| 8367 | return; |
| 8368 | } |
| 8369 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8370 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8371 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8372 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 8373 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 8374 | (key_id != -1 && |
| 8375 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 8376 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 8377 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8378 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8379 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8380 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8381 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8382 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8383 | return; |
| 8384 | |
| 8385 | nla_put_failure: |
| 8386 | genlmsg_cancel(msg, hdr); |
| 8387 | nlmsg_free(msg); |
| 8388 | } |
| 8389 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8390 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 8391 | struct ieee80211_channel *channel_before, |
| 8392 | struct ieee80211_channel *channel_after) |
| 8393 | { |
| 8394 | struct sk_buff *msg; |
| 8395 | void *hdr; |
| 8396 | struct nlattr *nl_freq; |
| 8397 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8398 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8399 | if (!msg) |
| 8400 | return; |
| 8401 | |
| 8402 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 8403 | if (!hdr) { |
| 8404 | nlmsg_free(msg); |
| 8405 | return; |
| 8406 | } |
| 8407 | |
| 8408 | /* |
| 8409 | * Since we are applying the beacon hint to a wiphy we know its |
| 8410 | * wiphy_idx is valid |
| 8411 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8412 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 8413 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8414 | |
| 8415 | /* Before */ |
| 8416 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 8417 | if (!nl_freq) |
| 8418 | goto nla_put_failure; |
| 8419 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 8420 | goto nla_put_failure; |
| 8421 | nla_nest_end(msg, nl_freq); |
| 8422 | |
| 8423 | /* After */ |
| 8424 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 8425 | if (!nl_freq) |
| 8426 | goto nla_put_failure; |
| 8427 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 8428 | goto nla_put_failure; |
| 8429 | nla_nest_end(msg, nl_freq); |
| 8430 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8431 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8432 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8433 | rcu_read_lock(); |
| 8434 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 8435 | GFP_ATOMIC); |
| 8436 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8437 | |
| 8438 | return; |
| 8439 | |
| 8440 | nla_put_failure: |
| 8441 | genlmsg_cancel(msg, hdr); |
| 8442 | nlmsg_free(msg); |
| 8443 | } |
| 8444 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8445 | static void nl80211_send_remain_on_chan_event( |
| 8446 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8447 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8448 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8449 | unsigned int duration, gfp_t gfp) |
| 8450 | { |
| 8451 | struct sk_buff *msg; |
| 8452 | void *hdr; |
| 8453 | |
| 8454 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8455 | if (!msg) |
| 8456 | return; |
| 8457 | |
| 8458 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8459 | if (!hdr) { |
| 8460 | nlmsg_free(msg); |
| 8461 | return; |
| 8462 | } |
| 8463 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8464 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8465 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8466 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 8467 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8468 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8469 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 8470 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8471 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8472 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8473 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8474 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 8475 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 8476 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8477 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8478 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8479 | |
| 8480 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8481 | nl80211_mlme_mcgrp.id, gfp); |
| 8482 | return; |
| 8483 | |
| 8484 | nla_put_failure: |
| 8485 | genlmsg_cancel(msg, hdr); |
| 8486 | nlmsg_free(msg); |
| 8487 | } |
| 8488 | |
| 8489 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8490 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8491 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8492 | unsigned int duration, gfp_t gfp) |
| 8493 | { |
| 8494 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8495 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8496 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8497 | } |
| 8498 | |
| 8499 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8500 | struct cfg80211_registered_device *rdev, |
| 8501 | struct wireless_dev *wdev, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8502 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8503 | { |
| 8504 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8505 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8506 | } |
| 8507 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8508 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 8509 | struct net_device *dev, const u8 *mac_addr, |
| 8510 | struct station_info *sinfo, gfp_t gfp) |
| 8511 | { |
| 8512 | struct sk_buff *msg; |
| 8513 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8514 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8515 | if (!msg) |
| 8516 | return; |
| 8517 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 8518 | if (nl80211_send_station(msg, 0, 0, 0, |
| 8519 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8520 | nlmsg_free(msg); |
| 8521 | return; |
| 8522 | } |
| 8523 | |
| 8524 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8525 | nl80211_mlme_mcgrp.id, gfp); |
| 8526 | } |
| 8527 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8528 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 8529 | struct net_device *dev, const u8 *mac_addr, |
| 8530 | gfp_t gfp) |
| 8531 | { |
| 8532 | struct sk_buff *msg; |
| 8533 | void *hdr; |
| 8534 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8535 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8536 | if (!msg) |
| 8537 | return; |
| 8538 | |
| 8539 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 8540 | if (!hdr) { |
| 8541 | nlmsg_free(msg); |
| 8542 | return; |
| 8543 | } |
| 8544 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8545 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8546 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 8547 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8548 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8549 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8550 | |
| 8551 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8552 | nl80211_mlme_mcgrp.id, gfp); |
| 8553 | return; |
| 8554 | |
| 8555 | nla_put_failure: |
| 8556 | genlmsg_cancel(msg, hdr); |
| 8557 | nlmsg_free(msg); |
| 8558 | } |
| 8559 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 8560 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 8561 | struct net_device *dev, const u8 *mac_addr, |
| 8562 | enum nl80211_connect_failed_reason reason, |
| 8563 | gfp_t gfp) |
| 8564 | { |
| 8565 | struct sk_buff *msg; |
| 8566 | void *hdr; |
| 8567 | |
| 8568 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8569 | if (!msg) |
| 8570 | return; |
| 8571 | |
| 8572 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 8573 | if (!hdr) { |
| 8574 | nlmsg_free(msg); |
| 8575 | return; |
| 8576 | } |
| 8577 | |
| 8578 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8579 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 8580 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 8581 | goto nla_put_failure; |
| 8582 | |
| 8583 | genlmsg_end(msg, hdr); |
| 8584 | |
| 8585 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8586 | nl80211_mlme_mcgrp.id, gfp); |
| 8587 | return; |
| 8588 | |
| 8589 | nla_put_failure: |
| 8590 | genlmsg_cancel(msg, hdr); |
| 8591 | nlmsg_free(msg); |
| 8592 | } |
| 8593 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8594 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 8595 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8596 | { |
| 8597 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8598 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8599 | struct sk_buff *msg; |
| 8600 | void *hdr; |
| 8601 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8602 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8603 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8604 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8605 | return false; |
| 8606 | |
| 8607 | msg = nlmsg_new(100, gfp); |
| 8608 | if (!msg) |
| 8609 | return true; |
| 8610 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8611 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8612 | if (!hdr) { |
| 8613 | nlmsg_free(msg); |
| 8614 | return true; |
| 8615 | } |
| 8616 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8617 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8618 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8619 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8620 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8621 | |
| 8622 | err = genlmsg_end(msg, hdr); |
| 8623 | if (err < 0) { |
| 8624 | nlmsg_free(msg); |
| 8625 | return true; |
| 8626 | } |
| 8627 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8628 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8629 | return true; |
| 8630 | |
| 8631 | nla_put_failure: |
| 8632 | genlmsg_cancel(msg, hdr); |
| 8633 | nlmsg_free(msg); |
| 8634 | return true; |
| 8635 | } |
| 8636 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8637 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 8638 | { |
| 8639 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 8640 | addr, gfp); |
| 8641 | } |
| 8642 | |
| 8643 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 8644 | const u8 *addr, gfp_t gfp) |
| 8645 | { |
| 8646 | return __nl80211_unexpected_frame(dev, |
| 8647 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 8648 | addr, gfp); |
| 8649 | } |
| 8650 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8651 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8652 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8653 | int freq, int sig_dbm, |
| 8654 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8655 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8656 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8657 | struct sk_buff *msg; |
| 8658 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8659 | |
| 8660 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8661 | if (!msg) |
| 8662 | return -ENOMEM; |
| 8663 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8664 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8665 | if (!hdr) { |
| 8666 | nlmsg_free(msg); |
| 8667 | return -ENOMEM; |
| 8668 | } |
| 8669 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8670 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8671 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8672 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8673 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8674 | (sig_dbm && |
| 8675 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8676 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8677 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8678 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8679 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8680 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8681 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8682 | |
| 8683 | nla_put_failure: |
| 8684 | genlmsg_cancel(msg, hdr); |
| 8685 | nlmsg_free(msg); |
| 8686 | return -ENOBUFS; |
| 8687 | } |
| 8688 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8689 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8690 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8691 | const u8 *buf, size_t len, bool ack, |
| 8692 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8693 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8694 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8695 | struct sk_buff *msg; |
| 8696 | void *hdr; |
| 8697 | |
| 8698 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8699 | if (!msg) |
| 8700 | return; |
| 8701 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8702 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8703 | if (!hdr) { |
| 8704 | nlmsg_free(msg); |
| 8705 | return; |
| 8706 | } |
| 8707 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8708 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8709 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8710 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8711 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 8712 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8713 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8714 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8715 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8716 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8717 | |
| 8718 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 8719 | return; |
| 8720 | |
| 8721 | nla_put_failure: |
| 8722 | genlmsg_cancel(msg, hdr); |
| 8723 | nlmsg_free(msg); |
| 8724 | } |
| 8725 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8726 | void |
| 8727 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 8728 | struct net_device *netdev, |
| 8729 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 8730 | gfp_t gfp) |
| 8731 | { |
| 8732 | struct sk_buff *msg; |
| 8733 | struct nlattr *pinfoattr; |
| 8734 | void *hdr; |
| 8735 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8736 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8737 | if (!msg) |
| 8738 | return; |
| 8739 | |
| 8740 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8741 | if (!hdr) { |
| 8742 | nlmsg_free(msg); |
| 8743 | return; |
| 8744 | } |
| 8745 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8746 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8747 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8748 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8749 | |
| 8750 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8751 | if (!pinfoattr) |
| 8752 | goto nla_put_failure; |
| 8753 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8754 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 8755 | rssi_event)) |
| 8756 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8757 | |
| 8758 | nla_nest_end(msg, pinfoattr); |
| 8759 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8760 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8761 | |
| 8762 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8763 | nl80211_mlme_mcgrp.id, gfp); |
| 8764 | return; |
| 8765 | |
| 8766 | nla_put_failure: |
| 8767 | genlmsg_cancel(msg, hdr); |
| 8768 | nlmsg_free(msg); |
| 8769 | } |
| 8770 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8771 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 8772 | struct net_device *netdev, const u8 *bssid, |
| 8773 | const u8 *replay_ctr, gfp_t gfp) |
| 8774 | { |
| 8775 | struct sk_buff *msg; |
| 8776 | struct nlattr *rekey_attr; |
| 8777 | void *hdr; |
| 8778 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8779 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8780 | if (!msg) |
| 8781 | return; |
| 8782 | |
| 8783 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 8784 | if (!hdr) { |
| 8785 | nlmsg_free(msg); |
| 8786 | return; |
| 8787 | } |
| 8788 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8789 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8790 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8791 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8792 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8793 | |
| 8794 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 8795 | if (!rekey_attr) |
| 8796 | goto nla_put_failure; |
| 8797 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8798 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 8799 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 8800 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8801 | |
| 8802 | nla_nest_end(msg, rekey_attr); |
| 8803 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8804 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8805 | |
| 8806 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8807 | nl80211_mlme_mcgrp.id, gfp); |
| 8808 | return; |
| 8809 | |
| 8810 | nla_put_failure: |
| 8811 | genlmsg_cancel(msg, hdr); |
| 8812 | nlmsg_free(msg); |
| 8813 | } |
| 8814 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8815 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 8816 | struct net_device *netdev, int index, |
| 8817 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 8818 | { |
| 8819 | struct sk_buff *msg; |
| 8820 | struct nlattr *attr; |
| 8821 | void *hdr; |
| 8822 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8823 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8824 | if (!msg) |
| 8825 | return; |
| 8826 | |
| 8827 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 8828 | if (!hdr) { |
| 8829 | nlmsg_free(msg); |
| 8830 | return; |
| 8831 | } |
| 8832 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8833 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8834 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8835 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8836 | |
| 8837 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 8838 | if (!attr) |
| 8839 | goto nla_put_failure; |
| 8840 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8841 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 8842 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 8843 | (preauth && |
| 8844 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 8845 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8846 | |
| 8847 | nla_nest_end(msg, attr); |
| 8848 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8849 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8850 | |
| 8851 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8852 | nl80211_mlme_mcgrp.id, gfp); |
| 8853 | return; |
| 8854 | |
| 8855 | nla_put_failure: |
| 8856 | genlmsg_cancel(msg, hdr); |
| 8857 | nlmsg_free(msg); |
| 8858 | } |
| 8859 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8860 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8861 | struct net_device *netdev, |
| 8862 | struct cfg80211_chan_def *chandef, gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8863 | { |
| 8864 | struct sk_buff *msg; |
| 8865 | void *hdr; |
| 8866 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8867 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8868 | if (!msg) |
| 8869 | return; |
| 8870 | |
| 8871 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 8872 | if (!hdr) { |
| 8873 | nlmsg_free(msg); |
| 8874 | return; |
| 8875 | } |
| 8876 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8877 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8878 | goto nla_put_failure; |
| 8879 | |
| 8880 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 8881 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8882 | |
| 8883 | genlmsg_end(msg, hdr); |
| 8884 | |
| 8885 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8886 | nl80211_mlme_mcgrp.id, gfp); |
| 8887 | return; |
| 8888 | |
| 8889 | nla_put_failure: |
| 8890 | genlmsg_cancel(msg, hdr); |
| 8891 | nlmsg_free(msg); |
| 8892 | } |
| 8893 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8894 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8895 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 8896 | struct net_device *netdev, const u8 *peer, |
| 8897 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 8898 | { |
| 8899 | struct sk_buff *msg; |
| 8900 | struct nlattr *pinfoattr; |
| 8901 | void *hdr; |
| 8902 | |
| 8903 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8904 | if (!msg) |
| 8905 | return; |
| 8906 | |
| 8907 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8908 | if (!hdr) { |
| 8909 | nlmsg_free(msg); |
| 8910 | return; |
| 8911 | } |
| 8912 | |
| 8913 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8914 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8915 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8916 | goto nla_put_failure; |
| 8917 | |
| 8918 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8919 | if (!pinfoattr) |
| 8920 | goto nla_put_failure; |
| 8921 | |
| 8922 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 8923 | goto nla_put_failure; |
| 8924 | |
| 8925 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 8926 | goto nla_put_failure; |
| 8927 | |
| 8928 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 8929 | goto nla_put_failure; |
| 8930 | |
| 8931 | nla_nest_end(msg, pinfoattr); |
| 8932 | |
| 8933 | genlmsg_end(msg, hdr); |
| 8934 | |
| 8935 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8936 | nl80211_mlme_mcgrp.id, gfp); |
| 8937 | return; |
| 8938 | |
| 8939 | nla_put_failure: |
| 8940 | genlmsg_cancel(msg, hdr); |
| 8941 | nlmsg_free(msg); |
| 8942 | } |
| 8943 | |
| 8944 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8945 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 8946 | struct net_device *netdev, const u8 *peer, |
| 8947 | u32 num_packets, gfp_t gfp) |
| 8948 | { |
| 8949 | struct sk_buff *msg; |
| 8950 | struct nlattr *pinfoattr; |
| 8951 | void *hdr; |
| 8952 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8953 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8954 | if (!msg) |
| 8955 | return; |
| 8956 | |
| 8957 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8958 | if (!hdr) { |
| 8959 | nlmsg_free(msg); |
| 8960 | return; |
| 8961 | } |
| 8962 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8963 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8964 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8965 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8966 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8967 | |
| 8968 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8969 | if (!pinfoattr) |
| 8970 | goto nla_put_failure; |
| 8971 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8972 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 8973 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8974 | |
| 8975 | nla_nest_end(msg, pinfoattr); |
| 8976 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8977 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8978 | |
| 8979 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8980 | nl80211_mlme_mcgrp.id, gfp); |
| 8981 | return; |
| 8982 | |
| 8983 | nla_put_failure: |
| 8984 | genlmsg_cancel(msg, hdr); |
| 8985 | nlmsg_free(msg); |
| 8986 | } |
| 8987 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8988 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 8989 | u64 cookie, bool acked, gfp_t gfp) |
| 8990 | { |
| 8991 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8992 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8993 | struct sk_buff *msg; |
| 8994 | void *hdr; |
| 8995 | int err; |
| 8996 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 8997 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 8998 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8999 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9000 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9001 | if (!msg) |
| 9002 | return; |
| 9003 | |
| 9004 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 9005 | if (!hdr) { |
| 9006 | nlmsg_free(msg); |
| 9007 | return; |
| 9008 | } |
| 9009 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9010 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9011 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9012 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9013 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9014 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9015 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9016 | |
| 9017 | err = genlmsg_end(msg, hdr); |
| 9018 | if (err < 0) { |
| 9019 | nlmsg_free(msg); |
| 9020 | return; |
| 9021 | } |
| 9022 | |
| 9023 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9024 | nl80211_mlme_mcgrp.id, gfp); |
| 9025 | return; |
| 9026 | |
| 9027 | nla_put_failure: |
| 9028 | genlmsg_cancel(msg, hdr); |
| 9029 | nlmsg_free(msg); |
| 9030 | } |
| 9031 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 9032 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9033 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 9034 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9035 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9036 | { |
| 9037 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9038 | struct sk_buff *msg; |
| 9039 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9040 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9041 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9042 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 9043 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9044 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9045 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9046 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 9047 | if (!msg) { |
| 9048 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9049 | return; |
| 9050 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9051 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9052 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 9053 | if (!hdr) |
| 9054 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9055 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9056 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9057 | (freq && |
| 9058 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9059 | (sig_dbm && |
| 9060 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9061 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 9062 | goto nla_put_failure; |
| 9063 | |
| 9064 | genlmsg_end(msg, hdr); |
| 9065 | |
| 9066 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9067 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9068 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9069 | return; |
| 9070 | |
| 9071 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9072 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9073 | if (hdr) |
| 9074 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9075 | nlmsg_free(msg); |
| 9076 | } |
| 9077 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 9078 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 9079 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 9080 | enum nl80211_tdls_operation oper, |
| 9081 | u16 reason_code, gfp_t gfp) |
| 9082 | { |
| 9083 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9084 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9085 | struct sk_buff *msg; |
| 9086 | void *hdr; |
| 9087 | int err; |
| 9088 | |
| 9089 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 9090 | reason_code); |
| 9091 | |
| 9092 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9093 | if (!msg) |
| 9094 | return; |
| 9095 | |
| 9096 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 9097 | if (!hdr) { |
| 9098 | nlmsg_free(msg); |
| 9099 | return; |
| 9100 | } |
| 9101 | |
| 9102 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9103 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9104 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 9105 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 9106 | (reason_code > 0 && |
| 9107 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 9108 | goto nla_put_failure; |
| 9109 | |
| 9110 | err = genlmsg_end(msg, hdr); |
| 9111 | if (err < 0) { |
| 9112 | nlmsg_free(msg); |
| 9113 | return; |
| 9114 | } |
| 9115 | |
| 9116 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9117 | nl80211_mlme_mcgrp.id, gfp); |
| 9118 | return; |
| 9119 | |
| 9120 | nla_put_failure: |
| 9121 | genlmsg_cancel(msg, hdr); |
| 9122 | nlmsg_free(msg); |
| 9123 | } |
| 9124 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 9125 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9126 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 9127 | unsigned long state, |
| 9128 | void *_notify) |
| 9129 | { |
| 9130 | struct netlink_notify *notify = _notify; |
| 9131 | struct cfg80211_registered_device *rdev; |
| 9132 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9133 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9134 | |
| 9135 | if (state != NETLINK_URELEASE) |
| 9136 | return NOTIFY_DONE; |
| 9137 | |
| 9138 | rcu_read_lock(); |
| 9139 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9140 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9141 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9142 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9143 | |
| 9144 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9145 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 9146 | list) { |
| 9147 | if (reg->nlportid == notify->portid) { |
| 9148 | list_del(®->list); |
| 9149 | kfree(reg); |
| 9150 | break; |
| 9151 | } |
| 9152 | } |
| 9153 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9154 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9155 | |
| 9156 | rcu_read_unlock(); |
| 9157 | |
| 9158 | return NOTIFY_DONE; |
| 9159 | } |
| 9160 | |
| 9161 | static struct notifier_block nl80211_netlink_notifier = { |
| 9162 | .notifier_call = nl80211_netlink_notify, |
| 9163 | }; |
| 9164 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9165 | /* initialisation/exit functions */ |
| 9166 | |
| 9167 | int nl80211_init(void) |
| 9168 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9169 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9170 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9171 | err = genl_register_family_with_ops(&nl80211_fam, |
| 9172 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9173 | if (err) |
| 9174 | return err; |
| 9175 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9176 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 9177 | if (err) |
| 9178 | goto err_out; |
| 9179 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9180 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 9181 | if (err) |
| 9182 | goto err_out; |
| 9183 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9184 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 9185 | if (err) |
| 9186 | goto err_out; |
| 9187 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9188 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 9189 | if (err) |
| 9190 | goto err_out; |
| 9191 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9192 | #ifdef CONFIG_NL80211_TESTMODE |
| 9193 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 9194 | if (err) |
| 9195 | goto err_out; |
| 9196 | #endif |
| 9197 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9198 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 9199 | if (err) |
| 9200 | goto err_out; |
| 9201 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9202 | return 0; |
| 9203 | err_out: |
| 9204 | genl_unregister_family(&nl80211_fam); |
| 9205 | return err; |
| 9206 | } |
| 9207 | |
| 9208 | void nl80211_exit(void) |
| 9209 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9210 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9211 | genl_unregister_family(&nl80211_fam); |
| 9212 | } |