Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
| 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = "nl80211", /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
| 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 50 | /* returns ERR_PTR values */ |
| 51 | static struct wireless_dev * |
| 52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 54 | struct cfg80211_registered_device *rdev; |
| 55 | struct wireless_dev *result = NULL; |
| 56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 58 | u64 wdev_id; |
| 59 | int wiphy_idx = -1; |
| 60 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 62 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | if (!have_ifidx && !have_wdev_id) |
| 65 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | if (have_ifidx) |
| 68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 69 | if (have_wdev_id) { |
| 70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 71 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 75 | struct wireless_dev *wdev; |
| 76 | |
| 77 | if (wiphy_net(&rdev->wiphy) != netns) |
| 78 | continue; |
| 79 | |
| 80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 81 | continue; |
| 82 | |
| 83 | mutex_lock(&rdev->devlist_mtx); |
| 84 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 85 | if (have_ifidx && wdev->netdev && |
| 86 | wdev->netdev->ifindex == ifidx) { |
| 87 | result = wdev; |
| 88 | break; |
| 89 | } |
| 90 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 91 | result = wdev; |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | mutex_unlock(&rdev->devlist_mtx); |
| 96 | |
| 97 | if (result) |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | if (result) |
| 102 | return result; |
| 103 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 107 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 108 | { |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 109 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 110 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | |
| 112 | assert_cfg80211_lock(); |
| 113 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 114 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 115 | !attrs[NL80211_ATTR_IFINDEX] && |
| 116 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 117 | return ERR_PTR(-EINVAL); |
| 118 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 120 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 121 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 122 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 123 | if (attrs[NL80211_ATTR_WDEV]) { |
| 124 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 125 | struct wireless_dev *wdev; |
| 126 | bool found = false; |
| 127 | |
| 128 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 129 | if (tmp) { |
| 130 | /* make sure wdev exists */ |
| 131 | mutex_lock(&tmp->devlist_mtx); |
| 132 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 133 | if (wdev->identifier != (u32)wdev_id) |
| 134 | continue; |
| 135 | found = true; |
| 136 | break; |
| 137 | } |
| 138 | mutex_unlock(&tmp->devlist_mtx); |
| 139 | |
| 140 | if (!found) |
| 141 | tmp = NULL; |
| 142 | |
| 143 | if (rdev && tmp != rdev) |
| 144 | return ERR_PTR(-EINVAL); |
| 145 | rdev = tmp; |
| 146 | } |
| 147 | } |
| 148 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 149 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 150 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 151 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 152 | if (netdev) { |
| 153 | if (netdev->ieee80211_ptr) |
| 154 | tmp = wiphy_to_dev( |
| 155 | netdev->ieee80211_ptr->wiphy); |
| 156 | else |
| 157 | tmp = NULL; |
| 158 | |
| 159 | dev_put(netdev); |
| 160 | |
| 161 | /* not wireless device -- return error */ |
| 162 | if (!tmp) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | |
| 165 | /* mismatch -- return error */ |
| 166 | if (rdev && tmp != rdev) |
| 167 | return ERR_PTR(-EINVAL); |
| 168 | |
| 169 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 170 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 173 | if (!rdev) |
| 174 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 175 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 176 | if (netns != wiphy_net(&rdev->wiphy)) |
| 177 | return ERR_PTR(-ENODEV); |
| 178 | |
| 179 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This function returns a pointer to the driver |
| 184 | * that the genl_info item that is passed refers to. |
| 185 | * If successful, it returns non-NULL and also locks |
| 186 | * the driver's mutex! |
| 187 | * |
| 188 | * This means that you need to call cfg80211_unlock_rdev() |
| 189 | * before being allowed to acquire &cfg80211_mutex! |
| 190 | * |
| 191 | * This is necessary because we need to lock the global |
| 192 | * mutex to get an item off the list safely, and then |
| 193 | * we lock the rdev mutex so it doesn't go away under us. |
| 194 | * |
| 195 | * We don't want to keep cfg80211_mutex locked |
| 196 | * for all the time in order to allow requests on |
| 197 | * other interfaces to go through at the same time. |
| 198 | * |
| 199 | * The result of this can be a PTR_ERR and hence must |
| 200 | * be checked with IS_ERR() for errors. |
| 201 | */ |
| 202 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 203 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 204 | { |
| 205 | struct cfg80211_registered_device *rdev; |
| 206 | |
| 207 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 208 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 209 | |
| 210 | /* if it is not an error we grab the lock on |
| 211 | * it to assure it won't be going away while |
| 212 | * we operate on it */ |
| 213 | if (!IS_ERR(rdev)) |
| 214 | mutex_lock(&rdev->mtx); |
| 215 | |
| 216 | mutex_unlock(&cfg80211_mutex); |
| 217 | |
| 218 | return rdev; |
| 219 | } |
| 220 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 221 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 222 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 224 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 225 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 226 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 227 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 230 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 232 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 233 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 234 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 235 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 236 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 237 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 238 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 239 | |
| 240 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 242 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 243 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 244 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 245 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 246 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 247 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 248 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 249 | .len = WLAN_MAX_KEY_LEN }, |
| 250 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 251 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 252 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 253 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 254 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 255 | |
| 256 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 257 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 258 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 259 | .len = IEEE80211_MAX_DATA_LEN }, |
| 260 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 263 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 264 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 265 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 266 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 268 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 270 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 271 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 272 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 273 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 275 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 276 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 277 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 278 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 280 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 281 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 283 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 284 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 285 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 286 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 287 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 288 | |
| 289 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 290 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 291 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 292 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 293 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 294 | |
| 295 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 296 | .len = IEEE80211_MAX_SSID_LEN }, |
| 297 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 298 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 302 | [NL80211_ATTR_STA_FLAGS2] = { |
| 303 | .len = sizeof(struct nl80211_sta_flag_update), |
| 304 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 306 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 307 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 309 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 310 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 313 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 314 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 315 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 316 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 319 | .len = IEEE80211_MAX_DATA_LEN }, |
| 320 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 323 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 324 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 325 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 326 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 328 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 329 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 330 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 331 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 332 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 333 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 334 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 336 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 337 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 339 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 340 | .len = IEEE80211_MAX_DATA_LEN }, |
| 341 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 343 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 344 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 345 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 346 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 347 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 348 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 349 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 350 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 351 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 352 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 353 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 354 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 355 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 356 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 357 | .len = NL80211_HT_CAPABILITY_LEN |
| 358 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 359 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 360 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 361 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 362 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 363 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 364 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 365 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 366 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 367 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 368 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 369 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 370 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 372 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 373 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 374 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 375 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 376 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 377 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 378 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 379 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 380 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 381 | }; |
| 382 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 383 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 384 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 385 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 386 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 387 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 388 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 389 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 390 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 391 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 392 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 393 | }; |
| 394 | |
| 395 | /* policy for the key default flags */ |
| 396 | static const struct nla_policy |
| 397 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 398 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 399 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 400 | }; |
| 401 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 402 | /* policy for WoWLAN attributes */ |
| 403 | static const struct nla_policy |
| 404 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 405 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 406 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 407 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 408 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 409 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 410 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 411 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 412 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 413 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 414 | }; |
| 415 | |
| 416 | static const struct nla_policy |
| 417 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 418 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 419 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 420 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 421 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 422 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 423 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 424 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 425 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 426 | }, |
| 427 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 428 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 429 | }, |
| 430 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 431 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 432 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 433 | }; |
| 434 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 435 | /* policy for GTK rekey offload attributes */ |
| 436 | static const struct nla_policy |
| 437 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 438 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 439 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 440 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 441 | }; |
| 442 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 443 | static const struct nla_policy |
| 444 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 445 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 446 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 447 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 448 | }; |
| 449 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 450 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 451 | struct netlink_callback *cb, |
| 452 | struct cfg80211_registered_device **rdev, |
| 453 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 454 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 455 | int err; |
| 456 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 457 | rtnl_lock(); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 458 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 459 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 460 | if (!cb->args[0]) { |
| 461 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 462 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 463 | nl80211_policy); |
| 464 | if (err) |
| 465 | goto out_unlock; |
| 466 | |
| 467 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 468 | nl80211_fam.attrbuf); |
| 469 | if (IS_ERR(*wdev)) { |
| 470 | err = PTR_ERR(*wdev); |
| 471 | goto out_unlock; |
| 472 | } |
| 473 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
| 474 | cb->args[0] = (*rdev)->wiphy_idx; |
| 475 | cb->args[1] = (*wdev)->identifier; |
| 476 | } else { |
| 477 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]); |
| 478 | struct wireless_dev *tmp; |
| 479 | |
| 480 | if (!wiphy) { |
| 481 | err = -ENODEV; |
| 482 | goto out_unlock; |
| 483 | } |
| 484 | *rdev = wiphy_to_dev(wiphy); |
| 485 | *wdev = NULL; |
| 486 | |
| 487 | mutex_lock(&(*rdev)->devlist_mtx); |
| 488 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 489 | if (tmp->identifier == cb->args[1]) { |
| 490 | *wdev = tmp; |
| 491 | break; |
| 492 | } |
| 493 | } |
| 494 | mutex_unlock(&(*rdev)->devlist_mtx); |
| 495 | |
| 496 | if (!*wdev) { |
| 497 | err = -ENODEV; |
| 498 | goto out_unlock; |
| 499 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 500 | } |
| 501 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 502 | cfg80211_lock_rdev(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 503 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 504 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 505 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 506 | out_unlock: |
| 507 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 508 | rtnl_unlock(); |
| 509 | return err; |
| 510 | } |
| 511 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 512 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 513 | { |
| 514 | cfg80211_unlock_rdev(rdev); |
| 515 | rtnl_unlock(); |
| 516 | } |
| 517 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 518 | /* IE validation */ |
| 519 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 520 | { |
| 521 | const u8 *pos; |
| 522 | int len; |
| 523 | |
| 524 | if (!attr) |
| 525 | return true; |
| 526 | |
| 527 | pos = nla_data(attr); |
| 528 | len = nla_len(attr); |
| 529 | |
| 530 | while (len) { |
| 531 | u8 elemlen; |
| 532 | |
| 533 | if (len < 2) |
| 534 | return false; |
| 535 | len -= 2; |
| 536 | |
| 537 | elemlen = pos[1]; |
| 538 | if (elemlen > len) |
| 539 | return false; |
| 540 | |
| 541 | len -= elemlen; |
| 542 | pos += 2 + elemlen; |
| 543 | } |
| 544 | |
| 545 | return true; |
| 546 | } |
| 547 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 548 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 549 | 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] | 550 | int flags, u8 cmd) |
| 551 | { |
| 552 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 553 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 554 | } |
| 555 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 556 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 557 | struct ieee80211_channel *chan, |
| 558 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 559 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 560 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 561 | chan->center_freq)) |
| 562 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 563 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 564 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 565 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 566 | goto nla_put_failure; |
| 567 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 568 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 569 | goto nla_put_failure; |
| 570 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 571 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 572 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 573 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 574 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 575 | goto nla_put_failure; |
| 576 | if (large) { |
| 577 | u32 time; |
| 578 | |
| 579 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 580 | |
| 581 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 582 | chan->dfs_state)) |
| 583 | goto nla_put_failure; |
| 584 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 585 | time)) |
| 586 | goto nla_put_failure; |
| 587 | } |
| 588 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 589 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 590 | if (large) { |
| 591 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 592 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 593 | goto nla_put_failure; |
| 594 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 595 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 596 | goto nla_put_failure; |
| 597 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 598 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 599 | goto nla_put_failure; |
| 600 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 601 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 602 | goto nla_put_failure; |
| 603 | } |
| 604 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 605 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 606 | DBM_TO_MBM(chan->max_power))) |
| 607 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 608 | |
| 609 | return 0; |
| 610 | |
| 611 | nla_put_failure: |
| 612 | return -ENOBUFS; |
| 613 | } |
| 614 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 615 | /* netlink command implementations */ |
| 616 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 617 | struct key_parse { |
| 618 | struct key_params p; |
| 619 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 620 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 621 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 622 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 623 | }; |
| 624 | |
| 625 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 626 | { |
| 627 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 628 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 629 | nl80211_key_policy); |
| 630 | if (err) |
| 631 | return err; |
| 632 | |
| 633 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 634 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 635 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 636 | if (k->def) { |
| 637 | k->def_uni = true; |
| 638 | k->def_multi = true; |
| 639 | } |
| 640 | if (k->defmgmt) |
| 641 | k->def_multi = true; |
| 642 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 643 | if (tb[NL80211_KEY_IDX]) |
| 644 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 645 | |
| 646 | if (tb[NL80211_KEY_DATA]) { |
| 647 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 648 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 649 | } |
| 650 | |
| 651 | if (tb[NL80211_KEY_SEQ]) { |
| 652 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 653 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 654 | } |
| 655 | |
| 656 | if (tb[NL80211_KEY_CIPHER]) |
| 657 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 658 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 659 | if (tb[NL80211_KEY_TYPE]) { |
| 660 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 661 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 662 | return -EINVAL; |
| 663 | } |
| 664 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 665 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 666 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 667 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 668 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 669 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 670 | if (err) |
| 671 | return err; |
| 672 | |
| 673 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 674 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 675 | } |
| 676 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 681 | { |
| 682 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 683 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 684 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 685 | } |
| 686 | |
| 687 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 688 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 689 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 690 | } |
| 691 | |
| 692 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 693 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 694 | |
| 695 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 696 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 697 | |
| 698 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 699 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 700 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 701 | if (k->def) { |
| 702 | k->def_uni = true; |
| 703 | k->def_multi = true; |
| 704 | } |
| 705 | if (k->defmgmt) |
| 706 | k->def_multi = true; |
| 707 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 708 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 709 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 710 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 711 | return -EINVAL; |
| 712 | } |
| 713 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 714 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 715 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 716 | int err = nla_parse_nested( |
| 717 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 718 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 719 | nl80211_key_default_policy); |
| 720 | if (err) |
| 721 | return err; |
| 722 | |
| 723 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 724 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 725 | } |
| 726 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 731 | { |
| 732 | int err; |
| 733 | |
| 734 | memset(k, 0, sizeof(*k)); |
| 735 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 736 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 737 | |
| 738 | if (info->attrs[NL80211_ATTR_KEY]) |
| 739 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 740 | else |
| 741 | err = nl80211_parse_key_old(info, k); |
| 742 | |
| 743 | if (err) |
| 744 | return err; |
| 745 | |
| 746 | if (k->def && k->defmgmt) |
| 747 | return -EINVAL; |
| 748 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 749 | if (k->defmgmt) { |
| 750 | if (k->def_uni || !k->def_multi) |
| 751 | return -EINVAL; |
| 752 | } |
| 753 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 754 | if (k->idx != -1) { |
| 755 | if (k->defmgmt) { |
| 756 | if (k->idx < 4 || k->idx > 5) |
| 757 | return -EINVAL; |
| 758 | } else if (k->def) { |
| 759 | if (k->idx < 0 || k->idx > 3) |
| 760 | return -EINVAL; |
| 761 | } else { |
| 762 | if (k->idx < 0 || k->idx > 5) |
| 763 | return -EINVAL; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | return 0; |
| 768 | } |
| 769 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 770 | static struct cfg80211_cached_keys * |
| 771 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 772 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 773 | { |
| 774 | struct key_parse parse; |
| 775 | struct nlattr *key; |
| 776 | struct cfg80211_cached_keys *result; |
| 777 | int rem, err, def = 0; |
| 778 | |
| 779 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 780 | if (!result) |
| 781 | return ERR_PTR(-ENOMEM); |
| 782 | |
| 783 | result->def = -1; |
| 784 | result->defmgmt = -1; |
| 785 | |
| 786 | nla_for_each_nested(key, keys, rem) { |
| 787 | memset(&parse, 0, sizeof(parse)); |
| 788 | parse.idx = -1; |
| 789 | |
| 790 | err = nl80211_parse_key_new(key, &parse); |
| 791 | if (err) |
| 792 | goto error; |
| 793 | err = -EINVAL; |
| 794 | if (!parse.p.key) |
| 795 | goto error; |
| 796 | if (parse.idx < 0 || parse.idx > 4) |
| 797 | goto error; |
| 798 | if (parse.def) { |
| 799 | if (def) |
| 800 | goto error; |
| 801 | def = 1; |
| 802 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 803 | if (!parse.def_uni || !parse.def_multi) |
| 804 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 805 | } else if (parse.defmgmt) |
| 806 | goto error; |
| 807 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 808 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 809 | if (err) |
| 810 | goto error; |
| 811 | result->params[parse.idx].cipher = parse.p.cipher; |
| 812 | result->params[parse.idx].key_len = parse.p.key_len; |
| 813 | result->params[parse.idx].key = result->data[parse.idx]; |
| 814 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 815 | |
| 816 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 817 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 818 | if (no_ht) |
| 819 | *no_ht = true; |
| 820 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | return result; |
| 824 | error: |
| 825 | kfree(result); |
| 826 | return ERR_PTR(err); |
| 827 | } |
| 828 | |
| 829 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 830 | { |
| 831 | ASSERT_WDEV_LOCK(wdev); |
| 832 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 833 | switch (wdev->iftype) { |
| 834 | case NL80211_IFTYPE_AP: |
| 835 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 836 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 837 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 838 | break; |
| 839 | case NL80211_IFTYPE_ADHOC: |
| 840 | if (!wdev->current_bss) |
| 841 | return -ENOLINK; |
| 842 | break; |
| 843 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 844 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 845 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 846 | return -ENOLINK; |
| 847 | break; |
| 848 | default: |
| 849 | return -EINVAL; |
| 850 | } |
| 851 | |
| 852 | return 0; |
| 853 | } |
| 854 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 855 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 856 | { |
| 857 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 858 | int i; |
| 859 | |
| 860 | if (!nl_modes) |
| 861 | goto nla_put_failure; |
| 862 | |
| 863 | i = 0; |
| 864 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 865 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 866 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 867 | ifmodes >>= 1; |
| 868 | i++; |
| 869 | } |
| 870 | |
| 871 | nla_nest_end(msg, nl_modes); |
| 872 | return 0; |
| 873 | |
| 874 | nla_put_failure: |
| 875 | return -ENOBUFS; |
| 876 | } |
| 877 | |
| 878 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 879 | struct sk_buff *msg, |
| 880 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 881 | { |
| 882 | struct nlattr *nl_combis; |
| 883 | int i, j; |
| 884 | |
| 885 | nl_combis = nla_nest_start(msg, |
| 886 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 887 | if (!nl_combis) |
| 888 | goto nla_put_failure; |
| 889 | |
| 890 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 891 | const struct ieee80211_iface_combination *c; |
| 892 | struct nlattr *nl_combi, *nl_limits; |
| 893 | |
| 894 | c = &wiphy->iface_combinations[i]; |
| 895 | |
| 896 | nl_combi = nla_nest_start(msg, i + 1); |
| 897 | if (!nl_combi) |
| 898 | goto nla_put_failure; |
| 899 | |
| 900 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 901 | if (!nl_limits) |
| 902 | goto nla_put_failure; |
| 903 | |
| 904 | for (j = 0; j < c->n_limits; j++) { |
| 905 | struct nlattr *nl_limit; |
| 906 | |
| 907 | nl_limit = nla_nest_start(msg, j + 1); |
| 908 | if (!nl_limit) |
| 909 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 910 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 911 | c->limits[j].max)) |
| 912 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 913 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 914 | c->limits[j].types)) |
| 915 | goto nla_put_failure; |
| 916 | nla_nest_end(msg, nl_limit); |
| 917 | } |
| 918 | |
| 919 | nla_nest_end(msg, nl_limits); |
| 920 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 921 | if (c->beacon_int_infra_match && |
| 922 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 923 | goto nla_put_failure; |
| 924 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 925 | c->num_different_channels) || |
| 926 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 927 | c->max_interfaces)) |
| 928 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 929 | if (large && |
| 930 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 931 | c->radar_detect_widths)) |
| 932 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 933 | |
| 934 | nla_nest_end(msg, nl_combi); |
| 935 | } |
| 936 | |
| 937 | nla_nest_end(msg, nl_combis); |
| 938 | |
| 939 | return 0; |
| 940 | nla_put_failure: |
| 941 | return -ENOBUFS; |
| 942 | } |
| 943 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 944 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 945 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 946 | struct sk_buff *msg) |
| 947 | { |
| 948 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; |
| 949 | struct nlattr *nl_tcp; |
| 950 | |
| 951 | if (!tcp) |
| 952 | return 0; |
| 953 | |
| 954 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 955 | if (!nl_tcp) |
| 956 | return -ENOBUFS; |
| 957 | |
| 958 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 959 | tcp->data_payload_max)) |
| 960 | return -ENOBUFS; |
| 961 | |
| 962 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 963 | tcp->data_payload_max)) |
| 964 | return -ENOBUFS; |
| 965 | |
| 966 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 967 | return -ENOBUFS; |
| 968 | |
| 969 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 970 | sizeof(*tcp->tok), tcp->tok)) |
| 971 | return -ENOBUFS; |
| 972 | |
| 973 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 974 | tcp->data_interval_max)) |
| 975 | return -ENOBUFS; |
| 976 | |
| 977 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 978 | tcp->wake_payload_max)) |
| 979 | return -ENOBUFS; |
| 980 | |
| 981 | nla_nest_end(msg, nl_tcp); |
| 982 | return 0; |
| 983 | } |
| 984 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 985 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 986 | struct cfg80211_registered_device *dev, |
| 987 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 988 | { |
| 989 | struct nlattr *nl_wowlan; |
| 990 | |
| 991 | if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns) |
| 992 | return 0; |
| 993 | |
| 994 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 995 | if (!nl_wowlan) |
| 996 | return -ENOBUFS; |
| 997 | |
| 998 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 999 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1000 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1001 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1002 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1003 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1004 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1005 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1006 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1007 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1008 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1009 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1010 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1011 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1012 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1013 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1014 | return -ENOBUFS; |
| 1015 | |
| 1016 | if (dev->wiphy.wowlan.n_patterns) { |
| 1017 | struct nl80211_wowlan_pattern_support pat = { |
| 1018 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1019 | .min_pattern_len = dev->wiphy.wowlan.pattern_min_len, |
| 1020 | .max_pattern_len = dev->wiphy.wowlan.pattern_max_len, |
| 1021 | .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset, |
| 1022 | }; |
| 1023 | |
| 1024 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1025 | sizeof(pat), &pat)) |
| 1026 | return -ENOBUFS; |
| 1027 | } |
| 1028 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1029 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1030 | return -ENOBUFS; |
| 1031 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1032 | nla_nest_end(msg, nl_wowlan); |
| 1033 | |
| 1034 | return 0; |
| 1035 | } |
| 1036 | #endif |
| 1037 | |
| 1038 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1039 | struct ieee80211_supported_band *sband) |
| 1040 | { |
| 1041 | struct nlattr *nl_rates, *nl_rate; |
| 1042 | struct ieee80211_rate *rate; |
| 1043 | int i; |
| 1044 | |
| 1045 | /* add HT info */ |
| 1046 | if (sband->ht_cap.ht_supported && |
| 1047 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1048 | sizeof(sband->ht_cap.mcs), |
| 1049 | &sband->ht_cap.mcs) || |
| 1050 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1051 | sband->ht_cap.cap) || |
| 1052 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1053 | sband->ht_cap.ampdu_factor) || |
| 1054 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1055 | sband->ht_cap.ampdu_density))) |
| 1056 | return -ENOBUFS; |
| 1057 | |
| 1058 | /* add VHT info */ |
| 1059 | if (sband->vht_cap.vht_supported && |
| 1060 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1061 | sizeof(sband->vht_cap.vht_mcs), |
| 1062 | &sband->vht_cap.vht_mcs) || |
| 1063 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1064 | sband->vht_cap.cap))) |
| 1065 | return -ENOBUFS; |
| 1066 | |
| 1067 | /* add bitrates */ |
| 1068 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1069 | if (!nl_rates) |
| 1070 | return -ENOBUFS; |
| 1071 | |
| 1072 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1073 | nl_rate = nla_nest_start(msg, i); |
| 1074 | if (!nl_rate) |
| 1075 | return -ENOBUFS; |
| 1076 | |
| 1077 | rate = &sband->bitrates[i]; |
| 1078 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1079 | rate->bitrate)) |
| 1080 | return -ENOBUFS; |
| 1081 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1082 | nla_put_flag(msg, |
| 1083 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1084 | return -ENOBUFS; |
| 1085 | |
| 1086 | nla_nest_end(msg, nl_rate); |
| 1087 | } |
| 1088 | |
| 1089 | nla_nest_end(msg, nl_rates); |
| 1090 | |
| 1091 | return 0; |
| 1092 | } |
| 1093 | |
| 1094 | static int |
| 1095 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1096 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1097 | { |
| 1098 | u16 stypes; |
| 1099 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1100 | enum nl80211_iftype ift; |
| 1101 | int i; |
| 1102 | |
| 1103 | if (!mgmt_stypes) |
| 1104 | return 0; |
| 1105 | |
| 1106 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1107 | if (!nl_ifs) |
| 1108 | return -ENOBUFS; |
| 1109 | |
| 1110 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1111 | nl_ftypes = nla_nest_start(msg, ift); |
| 1112 | if (!nl_ftypes) |
| 1113 | return -ENOBUFS; |
| 1114 | i = 0; |
| 1115 | stypes = mgmt_stypes[ift].tx; |
| 1116 | while (stypes) { |
| 1117 | if ((stypes & 1) && |
| 1118 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1119 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1120 | return -ENOBUFS; |
| 1121 | stypes >>= 1; |
| 1122 | i++; |
| 1123 | } |
| 1124 | nla_nest_end(msg, nl_ftypes); |
| 1125 | } |
| 1126 | |
| 1127 | nla_nest_end(msg, nl_ifs); |
| 1128 | |
| 1129 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1130 | if (!nl_ifs) |
| 1131 | return -ENOBUFS; |
| 1132 | |
| 1133 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1134 | nl_ftypes = nla_nest_start(msg, ift); |
| 1135 | if (!nl_ftypes) |
| 1136 | return -ENOBUFS; |
| 1137 | i = 0; |
| 1138 | stypes = mgmt_stypes[ift].rx; |
| 1139 | while (stypes) { |
| 1140 | if ((stypes & 1) && |
| 1141 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1142 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1143 | return -ENOBUFS; |
| 1144 | stypes >>= 1; |
| 1145 | i++; |
| 1146 | } |
| 1147 | nla_nest_end(msg, nl_ftypes); |
| 1148 | } |
| 1149 | nla_nest_end(msg, nl_ifs); |
| 1150 | |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
| 1154 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1155 | struct sk_buff *msg, u32 portid, u32 seq, |
| 1156 | int flags, bool split, long *split_start, |
| 1157 | long *band_start, long *chan_start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1158 | { |
| 1159 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1160 | struct nlattr *nl_bands, *nl_band; |
| 1161 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1162 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1163 | enum ieee80211_band band; |
| 1164 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1165 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1166 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1167 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1168 | long start = 0, start_chan = 0, start_band = 0; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1169 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1170 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1171 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1172 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1173 | return -ENOBUFS; |
| 1174 | |
| 1175 | /* allow always using the variables */ |
| 1176 | if (!split) { |
| 1177 | split_start = &start; |
| 1178 | band_start = &start_band; |
| 1179 | chan_start = &start_chan; |
| 1180 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1181 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1182 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1183 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1184 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1185 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1186 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1187 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1188 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1189 | switch (*split_start) { |
| 1190 | case 0: |
| 1191 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1192 | dev->wiphy.retry_short) || |
| 1193 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1194 | dev->wiphy.retry_long) || |
| 1195 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1196 | dev->wiphy.frag_threshold) || |
| 1197 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1198 | dev->wiphy.rts_threshold) || |
| 1199 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1200 | dev->wiphy.coverage_class) || |
| 1201 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1202 | dev->wiphy.max_scan_ssids) || |
| 1203 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1204 | dev->wiphy.max_sched_scan_ssids) || |
| 1205 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1206 | dev->wiphy.max_scan_ie_len) || |
| 1207 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1208 | dev->wiphy.max_sched_scan_ie_len) || |
| 1209 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1210 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1211 | goto nla_put_failure; |
| 1212 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1213 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1214 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1215 | goto nla_put_failure; |
| 1216 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1217 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1218 | goto nla_put_failure; |
| 1219 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1220 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1221 | goto nla_put_failure; |
| 1222 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1223 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1224 | goto nla_put_failure; |
| 1225 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1226 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1227 | goto nla_put_failure; |
| 1228 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1229 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1230 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1231 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1232 | (*split_start)++; |
| 1233 | if (split) |
| 1234 | break; |
| 1235 | case 1: |
| 1236 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1237 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1238 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1239 | goto nla_put_failure; |
| 1240 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1241 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1242 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1243 | goto nla_put_failure; |
| 1244 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1245 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1246 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1247 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1248 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1249 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1250 | dev->wiphy.available_antennas_tx) || |
| 1251 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1252 | dev->wiphy.available_antennas_rx)) |
| 1253 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1254 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1255 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1256 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1257 | dev->wiphy.probe_resp_offload)) |
| 1258 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1259 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1260 | if ((dev->wiphy.available_antennas_tx || |
| 1261 | dev->wiphy.available_antennas_rx) && |
| 1262 | dev->ops->get_antenna) { |
| 1263 | u32 tx_ant = 0, rx_ant = 0; |
| 1264 | int res; |
| 1265 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1266 | if (!res) { |
| 1267 | if (nla_put_u32(msg, |
| 1268 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1269 | tx_ant) || |
| 1270 | nla_put_u32(msg, |
| 1271 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1272 | rx_ant)) |
| 1273 | goto nla_put_failure; |
| 1274 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1275 | } |
| 1276 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1277 | (*split_start)++; |
| 1278 | if (split) |
| 1279 | break; |
| 1280 | case 2: |
| 1281 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1282 | dev->wiphy.interface_modes)) |
| 1283 | goto nla_put_failure; |
| 1284 | (*split_start)++; |
| 1285 | if (split) |
| 1286 | break; |
| 1287 | case 3: |
| 1288 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1289 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1290 | goto nla_put_failure; |
| 1291 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1292 | for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) { |
| 1293 | struct ieee80211_supported_band *sband; |
| 1294 | |
| 1295 | sband = dev->wiphy.bands[band]; |
| 1296 | |
| 1297 | if (!sband) |
| 1298 | continue; |
| 1299 | |
| 1300 | nl_band = nla_nest_start(msg, band); |
| 1301 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1302 | goto nla_put_failure; |
| 1303 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1304 | switch (*chan_start) { |
| 1305 | case 0: |
| 1306 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1307 | goto nla_put_failure; |
| 1308 | (*chan_start)++; |
| 1309 | if (split) |
| 1310 | break; |
| 1311 | default: |
| 1312 | /* add frequencies */ |
| 1313 | nl_freqs = nla_nest_start( |
| 1314 | msg, NL80211_BAND_ATTR_FREQS); |
| 1315 | if (!nl_freqs) |
| 1316 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1317 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1318 | for (i = *chan_start - 1; |
| 1319 | i < sband->n_channels; |
| 1320 | i++) { |
| 1321 | nl_freq = nla_nest_start(msg, i); |
| 1322 | if (!nl_freq) |
| 1323 | goto nla_put_failure; |
| 1324 | |
| 1325 | chan = &sband->channels[i]; |
| 1326 | |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1327 | if (nl80211_msg_put_channel(msg, chan, |
| 1328 | split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1329 | goto nla_put_failure; |
| 1330 | |
| 1331 | nla_nest_end(msg, nl_freq); |
| 1332 | if (split) |
| 1333 | break; |
| 1334 | } |
| 1335 | if (i < sband->n_channels) |
| 1336 | *chan_start = i + 2; |
| 1337 | else |
| 1338 | *chan_start = 0; |
| 1339 | nla_nest_end(msg, nl_freqs); |
| 1340 | } |
| 1341 | |
| 1342 | nla_nest_end(msg, nl_band); |
| 1343 | |
| 1344 | if (split) { |
| 1345 | /* start again here */ |
| 1346 | if (*chan_start) |
| 1347 | band--; |
| 1348 | break; |
| 1349 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1350 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1351 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1352 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1353 | if (band < IEEE80211_NUM_BANDS) |
| 1354 | *band_start = band + 1; |
| 1355 | else |
| 1356 | *band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1357 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1358 | /* if bands & channels are done, continue outside */ |
| 1359 | if (*band_start == 0 && *chan_start == 0) |
| 1360 | (*split_start)++; |
| 1361 | if (split) |
| 1362 | break; |
| 1363 | case 4: |
| 1364 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1365 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1366 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1367 | |
| 1368 | i = 0; |
| 1369 | #define CMD(op, n) \ |
| 1370 | do { \ |
| 1371 | if (dev->ops->op) { \ |
| 1372 | i++; \ |
| 1373 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1374 | goto nla_put_failure; \ |
| 1375 | } \ |
| 1376 | } while (0) |
| 1377 | |
| 1378 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1379 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1380 | CMD(add_key, NEW_KEY); |
| 1381 | CMD(start_ap, START_AP); |
| 1382 | CMD(add_station, NEW_STATION); |
| 1383 | CMD(add_mpath, NEW_MPATH); |
| 1384 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1385 | CMD(change_bss, SET_BSS); |
| 1386 | CMD(auth, AUTHENTICATE); |
| 1387 | CMD(assoc, ASSOCIATE); |
| 1388 | CMD(deauth, DEAUTHENTICATE); |
| 1389 | CMD(disassoc, DISASSOCIATE); |
| 1390 | CMD(join_ibss, JOIN_IBSS); |
| 1391 | CMD(join_mesh, JOIN_MESH); |
| 1392 | CMD(set_pmksa, SET_PMKSA); |
| 1393 | CMD(del_pmksa, DEL_PMKSA); |
| 1394 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1395 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1396 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1397 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1398 | CMD(mgmt_tx, FRAME); |
| 1399 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1400 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1401 | i++; |
| 1402 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1403 | goto nla_put_failure; |
| 1404 | } |
| 1405 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1406 | dev->ops->join_mesh) { |
| 1407 | i++; |
| 1408 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1409 | goto nla_put_failure; |
| 1410 | } |
| 1411 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1412 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1413 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1414 | CMD(tdls_oper, TDLS_OPER); |
| 1415 | } |
| 1416 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1417 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1418 | CMD(probe_client, PROBE_CLIENT); |
| 1419 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1420 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1421 | i++; |
| 1422 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1423 | goto nla_put_failure; |
| 1424 | } |
| 1425 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1426 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1427 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1428 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1429 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1430 | #endif |
| 1431 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1432 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1433 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1434 | if (dev->ops->connect || dev->ops->auth) { |
| 1435 | i++; |
| 1436 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1437 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1438 | } |
| 1439 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1440 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1441 | i++; |
| 1442 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1443 | goto nla_put_failure; |
| 1444 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1445 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1446 | nla_nest_end(msg, nl_cmds); |
| 1447 | (*split_start)++; |
| 1448 | if (split) |
| 1449 | break; |
| 1450 | case 5: |
| 1451 | if (dev->ops->remain_on_channel && |
| 1452 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1453 | nla_put_u32(msg, |
| 1454 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1455 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1456 | goto nla_put_failure; |
| 1457 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1458 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1459 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1460 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1461 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1462 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1463 | goto nla_put_failure; |
| 1464 | (*split_start)++; |
| 1465 | if (split) |
| 1466 | break; |
| 1467 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1468 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1469 | if (nl80211_send_wowlan(msg, dev, split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1470 | goto nla_put_failure; |
| 1471 | (*split_start)++; |
| 1472 | if (split) |
| 1473 | break; |
| 1474 | #else |
| 1475 | (*split_start)++; |
| 1476 | #endif |
| 1477 | case 7: |
| 1478 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1479 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1480 | goto nla_put_failure; |
| 1481 | |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1482 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1483 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1484 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1485 | (*split_start)++; |
| 1486 | if (split) |
| 1487 | break; |
| 1488 | case 8: |
| 1489 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1490 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1491 | dev->wiphy.ap_sme_capa)) |
| 1492 | goto nla_put_failure; |
| 1493 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1494 | features = dev->wiphy.features; |
| 1495 | /* |
| 1496 | * We can only add the per-channel limit information if the |
| 1497 | * dump is split, otherwise it makes it too big. Therefore |
| 1498 | * only advertise it in that case. |
| 1499 | */ |
| 1500 | if (split) |
| 1501 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1502 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1503 | goto nla_put_failure; |
| 1504 | |
| 1505 | if (dev->wiphy.ht_capa_mod_mask && |
| 1506 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1507 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1508 | dev->wiphy.ht_capa_mod_mask)) |
| 1509 | goto nla_put_failure; |
| 1510 | |
| 1511 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1512 | dev->wiphy.max_acl_mac_addrs && |
| 1513 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1514 | dev->wiphy.max_acl_mac_addrs)) |
| 1515 | goto nla_put_failure; |
| 1516 | |
| 1517 | /* |
| 1518 | * Any information below this point is only available to |
| 1519 | * applications that can deal with it being split. This |
| 1520 | * helps ensure that newly added capabilities don't break |
| 1521 | * older tools by overrunning their buffers. |
| 1522 | * |
| 1523 | * We still increment split_start so that in the split |
| 1524 | * case we'll continue with more data in the next round, |
| 1525 | * but break unconditionally so unsplit data stops here. |
| 1526 | */ |
| 1527 | (*split_start)++; |
| 1528 | break; |
| 1529 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1530 | if (dev->wiphy.extended_capabilities && |
| 1531 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1532 | dev->wiphy.extended_capabilities_len, |
| 1533 | dev->wiphy.extended_capabilities) || |
| 1534 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1535 | dev->wiphy.extended_capabilities_len, |
| 1536 | dev->wiphy.extended_capabilities_mask))) |
| 1537 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1538 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1539 | if (dev->wiphy.vht_capa_mod_mask && |
| 1540 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1541 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1542 | dev->wiphy.vht_capa_mod_mask)) |
| 1543 | goto nla_put_failure; |
| 1544 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1545 | /* done */ |
| 1546 | *split_start = 0; |
| 1547 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1548 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1549 | return genlmsg_end(msg, hdr); |
| 1550 | |
| 1551 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1552 | genlmsg_cancel(msg, hdr); |
| 1553 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1557 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1558 | int idx = 0, ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1559 | int start = cb->args[0]; |
| 1560 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1561 | s64 filter_wiphy = -1; |
| 1562 | bool split = false; |
| 1563 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1564 | int res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1565 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1566 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1567 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1568 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1569 | if (res == 0) { |
| 1570 | split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1571 | if (tb[NL80211_ATTR_WIPHY]) |
| 1572 | filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1573 | if (tb[NL80211_ATTR_WDEV]) |
| 1574 | filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1575 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1576 | struct net_device *netdev; |
| 1577 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1578 | |
| 1579 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1580 | if (!netdev) { |
| 1581 | mutex_unlock(&cfg80211_mutex); |
| 1582 | return -ENODEV; |
| 1583 | } |
| 1584 | if (netdev->ieee80211_ptr) { |
| 1585 | dev = wiphy_to_dev( |
| 1586 | netdev->ieee80211_ptr->wiphy); |
| 1587 | filter_wiphy = dev->wiphy_idx; |
| 1588 | } |
| 1589 | dev_put(netdev); |
| 1590 | } |
| 1591 | } |
| 1592 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1593 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1594 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1595 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1596 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1597 | continue; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1598 | if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy) |
| 1599 | continue; |
| 1600 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1601 | do { |
| 1602 | ret = nl80211_send_wiphy(dev, skb, |
| 1603 | NETLINK_CB(cb->skb).portid, |
| 1604 | cb->nlh->nlmsg_seq, |
| 1605 | NLM_F_MULTI, |
| 1606 | split, &cb->args[1], |
| 1607 | &cb->args[2], |
| 1608 | &cb->args[3]); |
| 1609 | if (ret < 0) { |
| 1610 | /* |
| 1611 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1612 | * or EMSGSIZE returned), this SKB is still |
| 1613 | * empty (so it's not too big because another |
| 1614 | * wiphy dataset is already in the skb) and |
| 1615 | * we've not tried to adjust the dump allocation |
| 1616 | * yet ... then adjust the alloc size to be |
| 1617 | * bigger, and return 1 but with the empty skb. |
| 1618 | * This results in an empty message being RX'ed |
| 1619 | * in userspace, but that is ignored. |
| 1620 | * |
| 1621 | * We can then retry with the larger buffer. |
| 1622 | */ |
| 1623 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1624 | !skb->len && |
| 1625 | cb->min_dump_alloc < 4096) { |
| 1626 | cb->min_dump_alloc = 4096; |
| 1627 | mutex_unlock(&cfg80211_mutex); |
| 1628 | return 1; |
| 1629 | } |
| 1630 | idx--; |
| 1631 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1632 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1633 | } while (cb->args[1] > 0); |
| 1634 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1635 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1636 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1637 | |
| 1638 | cb->args[0] = idx; |
| 1639 | |
| 1640 | return skb->len; |
| 1641 | } |
| 1642 | |
| 1643 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1644 | { |
| 1645 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1646 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1647 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1648 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1649 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1650 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1651 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1652 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
| 1653 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1654 | nlmsg_free(msg); |
| 1655 | return -ENOBUFS; |
| 1656 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1657 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1658 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1659 | } |
| 1660 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1661 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1662 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1663 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1664 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1665 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1666 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1667 | }; |
| 1668 | |
| 1669 | static int parse_txq_params(struct nlattr *tb[], |
| 1670 | struct ieee80211_txq_params *txq_params) |
| 1671 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1672 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1673 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1674 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1675 | return -EINVAL; |
| 1676 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1677 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1678 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1679 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1680 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1681 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1682 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1683 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1684 | return -EINVAL; |
| 1685 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1686 | return 0; |
| 1687 | } |
| 1688 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1689 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1690 | { |
| 1691 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1692 | * You can only set the channel explicitly for WDS interfaces, |
| 1693 | * all others have their channel managed via their respective |
| 1694 | * "establish a connection" command (connect, join, ...) |
| 1695 | * |
| 1696 | * For AP/GO and mesh mode, the channel can be set with the |
| 1697 | * channel userspace API, but is only stored and passed to the |
| 1698 | * low-level driver when the AP starts or the mesh is joined. |
| 1699 | * This is for backward compatibility, userspace can also give |
| 1700 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1701 | * |
| 1702 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1703 | * whatever else is going on, so they have their own special |
| 1704 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1705 | */ |
| 1706 | return !wdev || |
| 1707 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1708 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1709 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1710 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1711 | } |
| 1712 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1713 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1714 | struct genl_info *info, |
| 1715 | struct cfg80211_chan_def *chandef) |
| 1716 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1717 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1718 | |
| 1719 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1720 | return -EINVAL; |
| 1721 | |
| 1722 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1723 | |
| 1724 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1725 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1726 | chandef->center_freq1 = control_freq; |
| 1727 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1728 | |
| 1729 | /* Primary channel not allowed */ |
| 1730 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1731 | return -EINVAL; |
| 1732 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1733 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1734 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1735 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1736 | chantype = nla_get_u32( |
| 1737 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1738 | |
| 1739 | switch (chantype) { |
| 1740 | case NL80211_CHAN_NO_HT: |
| 1741 | case NL80211_CHAN_HT20: |
| 1742 | case NL80211_CHAN_HT40PLUS: |
| 1743 | case NL80211_CHAN_HT40MINUS: |
| 1744 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1745 | chantype); |
| 1746 | break; |
| 1747 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1748 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1749 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1750 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1751 | chandef->width = |
| 1752 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1753 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1754 | chandef->center_freq1 = |
| 1755 | nla_get_u32( |
| 1756 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1757 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1758 | chandef->center_freq2 = |
| 1759 | nla_get_u32( |
| 1760 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1761 | } |
| 1762 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1763 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1764 | return -EINVAL; |
| 1765 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1766 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1767 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1768 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1769 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1770 | return 0; |
| 1771 | } |
| 1772 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1773 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1774 | struct wireless_dev *wdev, |
| 1775 | struct genl_info *info) |
| 1776 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1777 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1778 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1779 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1780 | |
| 1781 | if (wdev) |
| 1782 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1783 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1784 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1785 | return -EOPNOTSUPP; |
| 1786 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1787 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1788 | if (result) |
| 1789 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1790 | |
| 1791 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1792 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1793 | case NL80211_IFTYPE_AP: |
| 1794 | case NL80211_IFTYPE_P2P_GO: |
| 1795 | if (wdev->beacon_interval) { |
| 1796 | result = -EBUSY; |
| 1797 | break; |
| 1798 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1799 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1800 | result = -EINVAL; |
| 1801 | break; |
| 1802 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1803 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1804 | result = 0; |
| 1805 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1806 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1807 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1808 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1809 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1810 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1811 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1812 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1813 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1814 | } |
| 1815 | mutex_unlock(&rdev->devlist_mtx); |
| 1816 | |
| 1817 | return result; |
| 1818 | } |
| 1819 | |
| 1820 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1821 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1823 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1824 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1825 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1826 | } |
| 1827 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1828 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1829 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1830 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1831 | struct net_device *dev = info->user_ptr[1]; |
| 1832 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1833 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1834 | |
| 1835 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1836 | return -EINVAL; |
| 1837 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1838 | if (netif_running(dev)) |
| 1839 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1840 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1841 | if (!rdev->ops->set_wds_peer) |
| 1842 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1843 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1844 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1845 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1846 | |
| 1847 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1848 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1852 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1853 | { |
| 1854 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1855 | struct net_device *netdev = NULL; |
| 1856 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1857 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1858 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1859 | u32 changed; |
| 1860 | u8 retry_short = 0, retry_long = 0; |
| 1861 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1862 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1863 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1864 | /* |
| 1865 | * Try to find the wiphy and netdev. Normally this |
| 1866 | * function shouldn't need the netdev, but this is |
| 1867 | * done for backward compatibility -- previously |
| 1868 | * setting the channel was done per wiphy, but now |
| 1869 | * it is per netdev. Previous userland like hostapd |
| 1870 | * also passed a netdev to set_wiphy, so that it is |
| 1871 | * possible to let that go to the right netdev! |
| 1872 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1873 | mutex_lock(&cfg80211_mutex); |
| 1874 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1875 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1876 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1877 | |
| 1878 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1879 | if (netdev && netdev->ieee80211_ptr) { |
| 1880 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1881 | mutex_lock(&rdev->mtx); |
| 1882 | } else |
| 1883 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1884 | } |
| 1885 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1886 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1887 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1888 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1889 | if (IS_ERR(rdev)) { |
| 1890 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1891 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1892 | } |
| 1893 | wdev = NULL; |
| 1894 | netdev = NULL; |
| 1895 | result = 0; |
| 1896 | |
| 1897 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1898 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1899 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1900 | |
| 1901 | /* |
| 1902 | * end workaround code, by now the rdev is available |
| 1903 | * and locked, and wdev may or may not be NULL. |
| 1904 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1905 | |
| 1906 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1907 | result = cfg80211_dev_rename( |
| 1908 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1909 | |
| 1910 | mutex_unlock(&cfg80211_mutex); |
| 1911 | |
| 1912 | if (result) |
| 1913 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1914 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1915 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1916 | struct ieee80211_txq_params txq_params; |
| 1917 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1918 | |
| 1919 | if (!rdev->ops->set_txq_params) { |
| 1920 | result = -EOPNOTSUPP; |
| 1921 | goto bad_res; |
| 1922 | } |
| 1923 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1924 | if (!netdev) { |
| 1925 | result = -EINVAL; |
| 1926 | goto bad_res; |
| 1927 | } |
| 1928 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1929 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1930 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1931 | result = -EINVAL; |
| 1932 | goto bad_res; |
| 1933 | } |
| 1934 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1935 | if (!netif_running(netdev)) { |
| 1936 | result = -ENETDOWN; |
| 1937 | goto bad_res; |
| 1938 | } |
| 1939 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1940 | nla_for_each_nested(nl_txq_params, |
| 1941 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1942 | rem_txq_params) { |
| 1943 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1944 | nla_data(nl_txq_params), |
| 1945 | nla_len(nl_txq_params), |
| 1946 | txq_params_policy); |
| 1947 | result = parse_txq_params(tb, &txq_params); |
| 1948 | if (result) |
| 1949 | goto bad_res; |
| 1950 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1951 | result = rdev_set_txq_params(rdev, netdev, |
| 1952 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1953 | if (result) |
| 1954 | goto bad_res; |
| 1955 | } |
| 1956 | } |
| 1957 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1958 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1959 | result = __nl80211_set_channel(rdev, |
| 1960 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1961 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1962 | if (result) |
| 1963 | goto bad_res; |
| 1964 | } |
| 1965 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1966 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1967 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1968 | enum nl80211_tx_power_setting type; |
| 1969 | int idx, mbm = 0; |
| 1970 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1971 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1972 | txp_wdev = NULL; |
| 1973 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1974 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1975 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1976 | goto bad_res; |
| 1977 | } |
| 1978 | |
| 1979 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1980 | type = nla_get_u32(info->attrs[idx]); |
| 1981 | |
| 1982 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1983 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1984 | result = -EINVAL; |
| 1985 | goto bad_res; |
| 1986 | } |
| 1987 | |
| 1988 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1989 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1990 | mbm = nla_get_u32(info->attrs[idx]); |
| 1991 | } |
| 1992 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1993 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1994 | if (result) |
| 1995 | goto bad_res; |
| 1996 | } |
| 1997 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1998 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1999 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2000 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2001 | if ((!rdev->wiphy.available_antennas_tx && |
| 2002 | !rdev->wiphy.available_antennas_rx) || |
| 2003 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2004 | result = -EOPNOTSUPP; |
| 2005 | goto bad_res; |
| 2006 | } |
| 2007 | |
| 2008 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2009 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2010 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2011 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2012 | * available antenna masks, except for the "all" mask */ |
| 2013 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2014 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2015 | result = -EINVAL; |
| 2016 | goto bad_res; |
| 2017 | } |
| 2018 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2019 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2020 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2021 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2022 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2023 | if (result) |
| 2024 | goto bad_res; |
| 2025 | } |
| 2026 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2027 | changed = 0; |
| 2028 | |
| 2029 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2030 | retry_short = nla_get_u8( |
| 2031 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2032 | if (retry_short == 0) { |
| 2033 | result = -EINVAL; |
| 2034 | goto bad_res; |
| 2035 | } |
| 2036 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2037 | } |
| 2038 | |
| 2039 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2040 | retry_long = nla_get_u8( |
| 2041 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2042 | if (retry_long == 0) { |
| 2043 | result = -EINVAL; |
| 2044 | goto bad_res; |
| 2045 | } |
| 2046 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2047 | } |
| 2048 | |
| 2049 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2050 | frag_threshold = nla_get_u32( |
| 2051 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2052 | if (frag_threshold < 256) { |
| 2053 | result = -EINVAL; |
| 2054 | goto bad_res; |
| 2055 | } |
| 2056 | if (frag_threshold != (u32) -1) { |
| 2057 | /* |
| 2058 | * Fragments (apart from the last one) are required to |
| 2059 | * have even length. Make the fragmentation code |
| 2060 | * simpler by stripping LSB should someone try to use |
| 2061 | * odd threshold value. |
| 2062 | */ |
| 2063 | frag_threshold &= ~0x1; |
| 2064 | } |
| 2065 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2066 | } |
| 2067 | |
| 2068 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2069 | rts_threshold = nla_get_u32( |
| 2070 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2071 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2072 | } |
| 2073 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2074 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2075 | coverage_class = nla_get_u8( |
| 2076 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2077 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2078 | } |
| 2079 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2080 | if (changed) { |
| 2081 | u8 old_retry_short, old_retry_long; |
| 2082 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2083 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2084 | |
| 2085 | if (!rdev->ops->set_wiphy_params) { |
| 2086 | result = -EOPNOTSUPP; |
| 2087 | goto bad_res; |
| 2088 | } |
| 2089 | |
| 2090 | old_retry_short = rdev->wiphy.retry_short; |
| 2091 | old_retry_long = rdev->wiphy.retry_long; |
| 2092 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2093 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2094 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2095 | |
| 2096 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2097 | rdev->wiphy.retry_short = retry_short; |
| 2098 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2099 | rdev->wiphy.retry_long = retry_long; |
| 2100 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2101 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2102 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2103 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2104 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2105 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2106 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2107 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2108 | if (result) { |
| 2109 | rdev->wiphy.retry_short = old_retry_short; |
| 2110 | rdev->wiphy.retry_long = old_retry_long; |
| 2111 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2112 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2113 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2114 | } |
| 2115 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2116 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2117 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2118 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2119 | if (netdev) |
| 2120 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2121 | return result; |
| 2122 | } |
| 2123 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2124 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2125 | { |
| 2126 | return (u64)wdev->identifier | |
| 2127 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2128 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2129 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2130 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 2131 | struct cfg80211_chan_def *chandef) |
| 2132 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2133 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2134 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2135 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2136 | chandef->chan->center_freq)) |
| 2137 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2138 | switch (chandef->width) { |
| 2139 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2140 | case NL80211_CHAN_WIDTH_20: |
| 2141 | case NL80211_CHAN_WIDTH_40: |
| 2142 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2143 | cfg80211_get_chandef_type(chandef))) |
| 2144 | return -ENOBUFS; |
| 2145 | break; |
| 2146 | default: |
| 2147 | break; |
| 2148 | } |
| 2149 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2150 | return -ENOBUFS; |
| 2151 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2152 | return -ENOBUFS; |
| 2153 | if (chandef->center_freq2 && |
| 2154 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2155 | return -ENOBUFS; |
| 2156 | return 0; |
| 2157 | } |
| 2158 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2159 | 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] | 2160 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2161 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2162 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2163 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2164 | void *hdr; |
| 2165 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2166 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2167 | if (!hdr) |
| 2168 | return -1; |
| 2169 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2170 | if (dev && |
| 2171 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2172 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2173 | goto nla_put_failure; |
| 2174 | |
| 2175 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2176 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2177 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2178 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2179 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2180 | rdev->devlist_generation ^ |
| 2181 | (cfg80211_rdev_list_generation << 2))) |
| 2182 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2183 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2184 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2185 | int ret; |
| 2186 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2187 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2188 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2189 | if (ret == 0) { |
| 2190 | if (nl80211_send_chandef(msg, &chandef)) |
| 2191 | goto nla_put_failure; |
| 2192 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2193 | } |
| 2194 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2195 | if (wdev->ssid_len) { |
| 2196 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2197 | goto nla_put_failure; |
| 2198 | } |
| 2199 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2200 | return genlmsg_end(msg, hdr); |
| 2201 | |
| 2202 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2203 | genlmsg_cancel(msg, hdr); |
| 2204 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2208 | { |
| 2209 | int wp_idx = 0; |
| 2210 | int if_idx = 0; |
| 2211 | int wp_start = cb->args[0]; |
| 2212 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2213 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2214 | struct wireless_dev *wdev; |
| 2215 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2216 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2217 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2218 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2219 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2220 | if (wp_idx < wp_start) { |
| 2221 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2222 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2223 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2224 | if_idx = 0; |
| 2225 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2226 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2227 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2228 | if (if_idx < if_start) { |
| 2229 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2230 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2231 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2232 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2233 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2234 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2235 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2236 | goto out; |
| 2237 | } |
| 2238 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2239 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2240 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2241 | |
| 2242 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2243 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2244 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2245 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2246 | |
| 2247 | cb->args[0] = wp_idx; |
| 2248 | cb->args[1] = if_idx; |
| 2249 | |
| 2250 | return skb->len; |
| 2251 | } |
| 2252 | |
| 2253 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2254 | { |
| 2255 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2256 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2257 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2258 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2259 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2260 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2261 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2262 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2263 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2264 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2265 | nlmsg_free(msg); |
| 2266 | return -ENOBUFS; |
| 2267 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2268 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2269 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2270 | } |
| 2271 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2272 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2273 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2274 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2275 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2276 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2277 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 2278 | }; |
| 2279 | |
| 2280 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2281 | { |
| 2282 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2283 | int flag; |
| 2284 | |
| 2285 | *mntrflags = 0; |
| 2286 | |
| 2287 | if (!nla) |
| 2288 | return -EINVAL; |
| 2289 | |
| 2290 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2291 | nla, mntr_flags_policy)) |
| 2292 | return -EINVAL; |
| 2293 | |
| 2294 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2295 | if (flags[flag]) |
| 2296 | *mntrflags |= (1<<flag); |
| 2297 | |
| 2298 | return 0; |
| 2299 | } |
| 2300 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2301 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2302 | struct net_device *netdev, u8 use_4addr, |
| 2303 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2304 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2305 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2306 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2307 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2308 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2309 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2310 | |
| 2311 | switch (iftype) { |
| 2312 | case NL80211_IFTYPE_AP_VLAN: |
| 2313 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2314 | return 0; |
| 2315 | break; |
| 2316 | case NL80211_IFTYPE_STATION: |
| 2317 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2318 | return 0; |
| 2319 | break; |
| 2320 | default: |
| 2321 | break; |
| 2322 | } |
| 2323 | |
| 2324 | return -EOPNOTSUPP; |
| 2325 | } |
| 2326 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2327 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2328 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2330 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2331 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2332 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2333 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2334 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2335 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2336 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2337 | memset(¶ms, 0, sizeof(params)); |
| 2338 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2339 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2340 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2341 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2342 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2343 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2344 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2345 | if (ntype > NL80211_IFTYPE_MAX) |
| 2346 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2347 | } |
| 2348 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2349 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2350 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2351 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2352 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2353 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2354 | if (netif_running(dev)) |
| 2355 | return -EBUSY; |
| 2356 | |
| 2357 | wdev_lock(wdev); |
| 2358 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2359 | IEEE80211_MAX_MESH_ID_LEN); |
| 2360 | wdev->mesh_id_up_len = |
| 2361 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2362 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2363 | wdev->mesh_id_up_len); |
| 2364 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2365 | } |
| 2366 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2367 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2368 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2369 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2370 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2371 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2372 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2373 | } else { |
| 2374 | params.use_4addr = -1; |
| 2375 | } |
| 2376 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2377 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2378 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2379 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2380 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2381 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2382 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2383 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2384 | |
| 2385 | flags = &_flags; |
| 2386 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2387 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2388 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2389 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2390 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2391 | else |
| 2392 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2393 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2394 | if (!err && params.use_4addr != -1) |
| 2395 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2396 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2397 | return err; |
| 2398 | } |
| 2399 | |
| 2400 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2401 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2402 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2403 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2404 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2405 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2406 | int err; |
| 2407 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2408 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2409 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2410 | memset(¶ms, 0, sizeof(params)); |
| 2411 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2412 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2413 | return -EINVAL; |
| 2414 | |
| 2415 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2416 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2417 | if (type > NL80211_IFTYPE_MAX) |
| 2418 | return -EINVAL; |
| 2419 | } |
| 2420 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2421 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2422 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2423 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2424 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2425 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2426 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2427 | ETH_ALEN); |
| 2428 | if (!is_valid_ether_addr(params.macaddr)) |
| 2429 | return -EADDRNOTAVAIL; |
| 2430 | } |
| 2431 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2432 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2433 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2434 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2435 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2436 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2437 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2438 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2439 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2440 | if (!msg) |
| 2441 | return -ENOMEM; |
| 2442 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2443 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2444 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2445 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2446 | wdev = rdev_add_virtual_intf(rdev, |
| 2447 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2448 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2449 | if (IS_ERR(wdev)) { |
| 2450 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2451 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2452 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2453 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2454 | switch (type) { |
| 2455 | case NL80211_IFTYPE_MESH_POINT: |
| 2456 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2457 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2458 | wdev_lock(wdev); |
| 2459 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2460 | IEEE80211_MAX_MESH_ID_LEN); |
| 2461 | wdev->mesh_id_up_len = |
| 2462 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2463 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2464 | wdev->mesh_id_up_len); |
| 2465 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2466 | break; |
| 2467 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2468 | /* |
| 2469 | * P2P Device doesn't have a netdev, so doesn't go |
| 2470 | * through the netdev notifier and must be added here |
| 2471 | */ |
| 2472 | mutex_init(&wdev->mtx); |
| 2473 | INIT_LIST_HEAD(&wdev->event_list); |
| 2474 | spin_lock_init(&wdev->event_lock); |
| 2475 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2476 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2477 | |
| 2478 | mutex_lock(&rdev->devlist_mtx); |
| 2479 | wdev->identifier = ++rdev->wdev_id; |
| 2480 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2481 | rdev->devlist_generation++; |
| 2482 | mutex_unlock(&rdev->devlist_mtx); |
| 2483 | break; |
| 2484 | default: |
| 2485 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2486 | } |
| 2487 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2488 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2489 | rdev, wdev) < 0) { |
| 2490 | nlmsg_free(msg); |
| 2491 | return -ENOBUFS; |
| 2492 | } |
| 2493 | |
| 2494 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2498 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2499 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2500 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2501 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2502 | if (!rdev->ops->del_virtual_intf) |
| 2503 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2504 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2505 | /* |
| 2506 | * If we remove a wireless device without a netdev then clear |
| 2507 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2508 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2509 | * since the wdev has been freed, unlike with a netdev where |
| 2510 | * we need the dev_put() for the netdev to really be freed. |
| 2511 | */ |
| 2512 | if (!wdev->netdev) |
| 2513 | info->user_ptr[1] = NULL; |
| 2514 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2515 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2516 | } |
| 2517 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2518 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2519 | { |
| 2520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2521 | struct net_device *dev = info->user_ptr[1]; |
| 2522 | u16 noack_map; |
| 2523 | |
| 2524 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2525 | return -EINVAL; |
| 2526 | |
| 2527 | if (!rdev->ops->set_noack_map) |
| 2528 | return -EOPNOTSUPP; |
| 2529 | |
| 2530 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2531 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2532 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2533 | } |
| 2534 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2535 | struct get_key_cookie { |
| 2536 | struct sk_buff *msg; |
| 2537 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2538 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2539 | }; |
| 2540 | |
| 2541 | static void get_key_callback(void *c, struct key_params *params) |
| 2542 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2543 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2544 | struct get_key_cookie *cookie = c; |
| 2545 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2546 | if ((params->key && |
| 2547 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2548 | params->key_len, params->key)) || |
| 2549 | (params->seq && |
| 2550 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2551 | params->seq_len, params->seq)) || |
| 2552 | (params->cipher && |
| 2553 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2554 | params->cipher))) |
| 2555 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2556 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2557 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2558 | if (!key) |
| 2559 | goto nla_put_failure; |
| 2560 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2561 | if ((params->key && |
| 2562 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2563 | params->key_len, params->key)) || |
| 2564 | (params->seq && |
| 2565 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2566 | params->seq_len, params->seq)) || |
| 2567 | (params->cipher && |
| 2568 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2569 | params->cipher))) |
| 2570 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2571 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2572 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2573 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2574 | |
| 2575 | nla_nest_end(cookie->msg, key); |
| 2576 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2577 | return; |
| 2578 | nla_put_failure: |
| 2579 | cookie->error = 1; |
| 2580 | } |
| 2581 | |
| 2582 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2583 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2584 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2585 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2586 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2587 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2588 | const u8 *mac_addr = NULL; |
| 2589 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2590 | struct get_key_cookie cookie = { |
| 2591 | .error = 0, |
| 2592 | }; |
| 2593 | void *hdr; |
| 2594 | struct sk_buff *msg; |
| 2595 | |
| 2596 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2597 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2598 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2599 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2600 | return -EINVAL; |
| 2601 | |
| 2602 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2603 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2604 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2605 | pairwise = !!mac_addr; |
| 2606 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2607 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2608 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2609 | return -EINVAL; |
| 2610 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2611 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2612 | return -EINVAL; |
| 2613 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2614 | } |
| 2615 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2616 | if (!rdev->ops->get_key) |
| 2617 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2618 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2619 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2620 | if (!msg) |
| 2621 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2622 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2623 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2624 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2625 | if (IS_ERR(hdr)) |
| 2626 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2627 | |
| 2628 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2629 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2630 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2631 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2632 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2633 | goto nla_put_failure; |
| 2634 | if (mac_addr && |
| 2635 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2636 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2637 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2638 | if (pairwise && mac_addr && |
| 2639 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2640 | return -ENOENT; |
| 2641 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2642 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2643 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2644 | |
| 2645 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2646 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2647 | |
| 2648 | if (cookie.error) |
| 2649 | goto nla_put_failure; |
| 2650 | |
| 2651 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2652 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2653 | |
| 2654 | nla_put_failure: |
| 2655 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2656 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2657 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2658 | return err; |
| 2659 | } |
| 2660 | |
| 2661 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2662 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2663 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2664 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2665 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2666 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2667 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2668 | err = nl80211_parse_key(info, &key); |
| 2669 | if (err) |
| 2670 | return err; |
| 2671 | |
| 2672 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2673 | return -EINVAL; |
| 2674 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2675 | /* only support setting default key */ |
| 2676 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2677 | return -EINVAL; |
| 2678 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2679 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2680 | |
| 2681 | if (key.def) { |
| 2682 | if (!rdev->ops->set_default_key) { |
| 2683 | err = -EOPNOTSUPP; |
| 2684 | goto out; |
| 2685 | } |
| 2686 | |
| 2687 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2688 | if (err) |
| 2689 | goto out; |
| 2690 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2691 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2692 | key.def_uni, key.def_multi); |
| 2693 | |
| 2694 | if (err) |
| 2695 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2696 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2697 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2698 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2699 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2700 | } else { |
| 2701 | if (key.def_uni || !key.def_multi) { |
| 2702 | err = -EINVAL; |
| 2703 | goto out; |
| 2704 | } |
| 2705 | |
| 2706 | if (!rdev->ops->set_default_mgmt_key) { |
| 2707 | err = -EOPNOTSUPP; |
| 2708 | goto out; |
| 2709 | } |
| 2710 | |
| 2711 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2712 | if (err) |
| 2713 | goto out; |
| 2714 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2715 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2716 | if (err) |
| 2717 | goto out; |
| 2718 | |
| 2719 | #ifdef CONFIG_CFG80211_WEXT |
| 2720 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2721 | #endif |
| 2722 | } |
| 2723 | |
| 2724 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2725 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2726 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2727 | return err; |
| 2728 | } |
| 2729 | |
| 2730 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2731 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2732 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2733 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2734 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2735 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2736 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2737 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2738 | err = nl80211_parse_key(info, &key); |
| 2739 | if (err) |
| 2740 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2741 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2742 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2743 | return -EINVAL; |
| 2744 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2745 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2746 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2747 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2748 | if (key.type == -1) { |
| 2749 | if (mac_addr) |
| 2750 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2751 | else |
| 2752 | key.type = NL80211_KEYTYPE_GROUP; |
| 2753 | } |
| 2754 | |
| 2755 | /* for now */ |
| 2756 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2757 | key.type != NL80211_KEYTYPE_GROUP) |
| 2758 | return -EINVAL; |
| 2759 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2760 | if (!rdev->ops->add_key) |
| 2761 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2762 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2763 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2764 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2765 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2766 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2767 | |
| 2768 | wdev_lock(dev->ieee80211_ptr); |
| 2769 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2770 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2771 | err = rdev_add_key(rdev, dev, key.idx, |
| 2772 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2773 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2774 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2775 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2776 | return err; |
| 2777 | } |
| 2778 | |
| 2779 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2780 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2781 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2782 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2783 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2784 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2785 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2786 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2787 | err = nl80211_parse_key(info, &key); |
| 2788 | if (err) |
| 2789 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2790 | |
| 2791 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2792 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2793 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2794 | if (key.type == -1) { |
| 2795 | if (mac_addr) |
| 2796 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2797 | else |
| 2798 | key.type = NL80211_KEYTYPE_GROUP; |
| 2799 | } |
| 2800 | |
| 2801 | /* for now */ |
| 2802 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2803 | key.type != NL80211_KEYTYPE_GROUP) |
| 2804 | return -EINVAL; |
| 2805 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2806 | if (!rdev->ops->del_key) |
| 2807 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2808 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2809 | wdev_lock(dev->ieee80211_ptr); |
| 2810 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2811 | |
| 2812 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2813 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2814 | err = -ENOENT; |
| 2815 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2816 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2817 | err = rdev_del_key(rdev, dev, key.idx, |
| 2818 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2819 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2820 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2821 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2822 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2823 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2824 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2825 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2826 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2827 | } |
| 2828 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2829 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2830 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2831 | return err; |
| 2832 | } |
| 2833 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2834 | /* This function returns an error or the number of nested attributes */ |
| 2835 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2836 | { |
| 2837 | struct nlattr *attr; |
| 2838 | int n_entries = 0, tmp; |
| 2839 | |
| 2840 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2841 | if (nla_len(attr) != ETH_ALEN) |
| 2842 | return -EINVAL; |
| 2843 | |
| 2844 | n_entries++; |
| 2845 | } |
| 2846 | |
| 2847 | return n_entries; |
| 2848 | } |
| 2849 | |
| 2850 | /* |
| 2851 | * This function parses ACL information and allocates memory for ACL data. |
| 2852 | * On successful return, the calling function is responsible to free the |
| 2853 | * ACL buffer returned by this function. |
| 2854 | */ |
| 2855 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2856 | struct genl_info *info) |
| 2857 | { |
| 2858 | enum nl80211_acl_policy acl_policy; |
| 2859 | struct nlattr *attr; |
| 2860 | struct cfg80211_acl_data *acl; |
| 2861 | int i = 0, n_entries, tmp; |
| 2862 | |
| 2863 | if (!wiphy->max_acl_mac_addrs) |
| 2864 | return ERR_PTR(-EOPNOTSUPP); |
| 2865 | |
| 2866 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2867 | return ERR_PTR(-EINVAL); |
| 2868 | |
| 2869 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2870 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2871 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2872 | return ERR_PTR(-EINVAL); |
| 2873 | |
| 2874 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2875 | return ERR_PTR(-EINVAL); |
| 2876 | |
| 2877 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2878 | if (n_entries < 0) |
| 2879 | return ERR_PTR(n_entries); |
| 2880 | |
| 2881 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2882 | return ERR_PTR(-ENOTSUPP); |
| 2883 | |
| 2884 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2885 | GFP_KERNEL); |
| 2886 | if (!acl) |
| 2887 | return ERR_PTR(-ENOMEM); |
| 2888 | |
| 2889 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2890 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2891 | i++; |
| 2892 | } |
| 2893 | |
| 2894 | acl->n_acl_entries = n_entries; |
| 2895 | acl->acl_policy = acl_policy; |
| 2896 | |
| 2897 | return acl; |
| 2898 | } |
| 2899 | |
| 2900 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2901 | { |
| 2902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2903 | struct net_device *dev = info->user_ptr[1]; |
| 2904 | struct cfg80211_acl_data *acl; |
| 2905 | int err; |
| 2906 | |
| 2907 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2908 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2909 | return -EOPNOTSUPP; |
| 2910 | |
| 2911 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2912 | return -EINVAL; |
| 2913 | |
| 2914 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2915 | if (IS_ERR(acl)) |
| 2916 | return PTR_ERR(acl); |
| 2917 | |
| 2918 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2919 | |
| 2920 | kfree(acl); |
| 2921 | |
| 2922 | return err; |
| 2923 | } |
| 2924 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2925 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2926 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2927 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2928 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2929 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2930 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2931 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2932 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2933 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2934 | return -EINVAL; |
| 2935 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2936 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2937 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2938 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2939 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2940 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2941 | if (!bcn->head_len) |
| 2942 | return -EINVAL; |
| 2943 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2947 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2948 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2949 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2950 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2951 | } |
| 2952 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2953 | if (!haveinfo) |
| 2954 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2955 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2956 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2957 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2958 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2962 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2963 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2964 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2965 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2966 | } |
| 2967 | |
| 2968 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2969 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2970 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2971 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2972 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2973 | } |
| 2974 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2975 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2976 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2977 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2978 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2979 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2980 | } |
| 2981 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2982 | return 0; |
| 2983 | } |
| 2984 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2985 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2986 | struct cfg80211_ap_settings *params) |
| 2987 | { |
| 2988 | struct wireless_dev *wdev; |
| 2989 | bool ret = false; |
| 2990 | |
| 2991 | mutex_lock(&rdev->devlist_mtx); |
| 2992 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2993 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2994 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2995 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2996 | continue; |
| 2997 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2998 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2999 | continue; |
| 3000 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3001 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3002 | ret = true; |
| 3003 | break; |
| 3004 | } |
| 3005 | |
| 3006 | mutex_unlock(&rdev->devlist_mtx); |
| 3007 | |
| 3008 | return ret; |
| 3009 | } |
| 3010 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3011 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3012 | enum nl80211_auth_type auth_type, |
| 3013 | enum nl80211_commands cmd) |
| 3014 | { |
| 3015 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3016 | return false; |
| 3017 | |
| 3018 | switch (cmd) { |
| 3019 | case NL80211_CMD_AUTHENTICATE: |
| 3020 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3021 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3022 | return false; |
| 3023 | return true; |
| 3024 | case NL80211_CMD_CONNECT: |
| 3025 | case NL80211_CMD_START_AP: |
| 3026 | /* SAE not supported yet */ |
| 3027 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3028 | return false; |
| 3029 | return true; |
| 3030 | default: |
| 3031 | return false; |
| 3032 | } |
| 3033 | } |
| 3034 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3035 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3036 | { |
| 3037 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3038 | struct net_device *dev = info->user_ptr[1]; |
| 3039 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3040 | struct cfg80211_ap_settings params; |
| 3041 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3042 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3043 | |
| 3044 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3045 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3046 | return -EOPNOTSUPP; |
| 3047 | |
| 3048 | if (!rdev->ops->start_ap) |
| 3049 | return -EOPNOTSUPP; |
| 3050 | |
| 3051 | if (wdev->beacon_interval) |
| 3052 | return -EALREADY; |
| 3053 | |
| 3054 | memset(¶ms, 0, sizeof(params)); |
| 3055 | |
| 3056 | /* these are required for START_AP */ |
| 3057 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3058 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3059 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3060 | return -EINVAL; |
| 3061 | |
| 3062 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 3063 | if (err) |
| 3064 | return err; |
| 3065 | |
| 3066 | params.beacon_interval = |
| 3067 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3068 | params.dtim_period = |
| 3069 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3070 | |
| 3071 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3072 | if (err) |
| 3073 | return err; |
| 3074 | |
| 3075 | /* |
| 3076 | * In theory, some of these attributes should be required here |
| 3077 | * but since they were not used when the command was originally |
| 3078 | * added, keep them optional for old user space programs to let |
| 3079 | * them continue to work with drivers that do not need the |
| 3080 | * additional information -- drivers must check! |
| 3081 | */ |
| 3082 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3083 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3084 | params.ssid_len = |
| 3085 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3086 | if (params.ssid_len == 0 || |
| 3087 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3088 | return -EINVAL; |
| 3089 | } |
| 3090 | |
| 3091 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3092 | params.hidden_ssid = nla_get_u32( |
| 3093 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3094 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3095 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3096 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3097 | return -EINVAL; |
| 3098 | } |
| 3099 | |
| 3100 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3101 | |
| 3102 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3103 | params.auth_type = nla_get_u32( |
| 3104 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3105 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3106 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3107 | return -EINVAL; |
| 3108 | } else |
| 3109 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3110 | |
| 3111 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3112 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3113 | if (err) |
| 3114 | return err; |
| 3115 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3116 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3117 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3118 | return -EOPNOTSUPP; |
| 3119 | params.inactivity_timeout = nla_get_u16( |
| 3120 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3121 | } |
| 3122 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3123 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3124 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3125 | return -EINVAL; |
| 3126 | params.p2p_ctwindow = |
| 3127 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3128 | if (params.p2p_ctwindow > 127) |
| 3129 | return -EINVAL; |
| 3130 | if (params.p2p_ctwindow != 0 && |
| 3131 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3132 | return -EINVAL; |
| 3133 | } |
| 3134 | |
| 3135 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3136 | u8 tmp; |
| 3137 | |
| 3138 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3139 | return -EINVAL; |
| 3140 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3141 | if (tmp > 1) |
| 3142 | return -EINVAL; |
| 3143 | params.p2p_opp_ps = tmp; |
| 3144 | if (params.p2p_opp_ps != 0 && |
| 3145 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3146 | return -EINVAL; |
| 3147 | } |
| 3148 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3149 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3150 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3151 | if (err) |
| 3152 | return err; |
| 3153 | } else if (wdev->preset_chandef.chan) { |
| 3154 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3155 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3156 | return -EINVAL; |
| 3157 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3158 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3159 | return -EINVAL; |
| 3160 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3161 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3162 | if (err < 0) |
| 3163 | return err; |
| 3164 | if (err) { |
| 3165 | radar_detect_width = BIT(params.chandef.width); |
| 3166 | params.radar_required = true; |
| 3167 | } |
| 3168 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3169 | mutex_lock(&rdev->devlist_mtx); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3170 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3171 | params.chandef.chan, |
| 3172 | CHAN_MODE_SHARED, |
| 3173 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3174 | mutex_unlock(&rdev->devlist_mtx); |
| 3175 | |
| 3176 | if (err) |
| 3177 | return err; |
| 3178 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3179 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3180 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3181 | if (IS_ERR(params.acl)) |
| 3182 | return PTR_ERR(params.acl); |
| 3183 | } |
| 3184 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3185 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3186 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3187 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3188 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3189 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3190 | wdev->ssid_len = params.ssid_len; |
| 3191 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3192 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3193 | |
| 3194 | kfree(params.acl); |
| 3195 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3196 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3197 | } |
| 3198 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3199 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3200 | { |
| 3201 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3202 | struct net_device *dev = info->user_ptr[1]; |
| 3203 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3204 | struct cfg80211_beacon_data params; |
| 3205 | int err; |
| 3206 | |
| 3207 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3208 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3209 | return -EOPNOTSUPP; |
| 3210 | |
| 3211 | if (!rdev->ops->change_beacon) |
| 3212 | return -EOPNOTSUPP; |
| 3213 | |
| 3214 | if (!wdev->beacon_interval) |
| 3215 | return -EINVAL; |
| 3216 | |
| 3217 | err = nl80211_parse_beacon(info, ¶ms); |
| 3218 | if (err) |
| 3219 | return err; |
| 3220 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3221 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | 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] | 3225 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3227 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3228 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3229 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3230 | } |
| 3231 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3232 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3233 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3234 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3235 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3236 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3237 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3238 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3239 | }; |
| 3240 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3241 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3242 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3243 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3244 | { |
| 3245 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3246 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3247 | int flag; |
| 3248 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3249 | /* |
| 3250 | * Try parsing the new attribute first so userspace |
| 3251 | * can specify both for older kernels. |
| 3252 | */ |
| 3253 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3254 | if (nla) { |
| 3255 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3256 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3257 | sta_flags = nla_data(nla); |
| 3258 | params->sta_flags_mask = sta_flags->mask; |
| 3259 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3260 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3261 | if ((params->sta_flags_mask | |
| 3262 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3263 | return -EINVAL; |
| 3264 | return 0; |
| 3265 | } |
| 3266 | |
| 3267 | /* if present, parse the old attribute */ |
| 3268 | |
| 3269 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3270 | if (!nla) |
| 3271 | return 0; |
| 3272 | |
| 3273 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3274 | nla, sta_flags_policy)) |
| 3275 | return -EINVAL; |
| 3276 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3277 | /* |
| 3278 | * Only allow certain flags for interface types so that |
| 3279 | * other attributes are silently ignored. Remember that |
| 3280 | * this is backward compatibility code with old userspace |
| 3281 | * and shouldn't be hit in other cases anyway. |
| 3282 | */ |
| 3283 | switch (iftype) { |
| 3284 | case NL80211_IFTYPE_AP: |
| 3285 | case NL80211_IFTYPE_AP_VLAN: |
| 3286 | case NL80211_IFTYPE_P2P_GO: |
| 3287 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3288 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3289 | BIT(NL80211_STA_FLAG_WME) | |
| 3290 | BIT(NL80211_STA_FLAG_MFP); |
| 3291 | break; |
| 3292 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3293 | case NL80211_IFTYPE_STATION: |
| 3294 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3295 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3296 | break; |
| 3297 | case NL80211_IFTYPE_MESH_POINT: |
| 3298 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3299 | BIT(NL80211_STA_FLAG_MFP) | |
| 3300 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3301 | default: |
| 3302 | return -EINVAL; |
| 3303 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3304 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3305 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3306 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3307 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3308 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3309 | /* no longer support new API additions in old API */ |
| 3310 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3311 | return -EINVAL; |
| 3312 | } |
| 3313 | } |
| 3314 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3315 | return 0; |
| 3316 | } |
| 3317 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3318 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3319 | int attr) |
| 3320 | { |
| 3321 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3322 | u32 bitrate; |
| 3323 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3324 | |
| 3325 | rate = nla_nest_start(msg, attr); |
| 3326 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3327 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3328 | |
| 3329 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3330 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3331 | /* report 16-bit bitrate only if we can */ |
| 3332 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3333 | if (bitrate > 0 && |
| 3334 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3335 | return false; |
| 3336 | if (bitrate_compat > 0 && |
| 3337 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3338 | return false; |
| 3339 | |
| 3340 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3341 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3342 | return false; |
| 3343 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3344 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3345 | return false; |
| 3346 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3347 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3348 | return false; |
| 3349 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3350 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3351 | return false; |
| 3352 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3353 | return false; |
| 3354 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3355 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3356 | return false; |
| 3357 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3358 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3359 | return false; |
| 3360 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3361 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3362 | return false; |
| 3363 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3364 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3365 | return false; |
| 3366 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3367 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3368 | return false; |
| 3369 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3370 | |
| 3371 | nla_nest_end(msg, rate); |
| 3372 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3373 | } |
| 3374 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3375 | 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] | 3376 | int flags, |
| 3377 | struct cfg80211_registered_device *rdev, |
| 3378 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3379 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3380 | { |
| 3381 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3382 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3383 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3384 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3385 | if (!hdr) |
| 3386 | return -1; |
| 3387 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3388 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3389 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3390 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3391 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3392 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3393 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3394 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3395 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3396 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3397 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3398 | sinfo->connected_time)) |
| 3399 | goto nla_put_failure; |
| 3400 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3401 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3402 | sinfo->inactive_time)) |
| 3403 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3404 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3405 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3406 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3407 | (u32)sinfo->rx_bytes)) |
| 3408 | goto nla_put_failure; |
| 3409 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
| 3410 | NL80211_STA_INFO_TX_BYTES64)) && |
| 3411 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3412 | (u32)sinfo->tx_bytes)) |
| 3413 | goto nla_put_failure; |
| 3414 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3415 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3416 | sinfo->rx_bytes)) |
| 3417 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3418 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3419 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3420 | sinfo->tx_bytes)) |
| 3421 | goto nla_put_failure; |
| 3422 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3423 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3424 | goto nla_put_failure; |
| 3425 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3426 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3427 | goto nla_put_failure; |
| 3428 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3429 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3430 | sinfo->plink_state)) |
| 3431 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3432 | switch (rdev->wiphy.signal_type) { |
| 3433 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3434 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3435 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3436 | sinfo->signal)) |
| 3437 | goto nla_put_failure; |
| 3438 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3439 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3440 | sinfo->signal_avg)) |
| 3441 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3442 | break; |
| 3443 | default: |
| 3444 | break; |
| 3445 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3446 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3447 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3448 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3449 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3450 | } |
| 3451 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3452 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3453 | NL80211_STA_INFO_RX_BITRATE)) |
| 3454 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3455 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3456 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3457 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3458 | sinfo->rx_packets)) |
| 3459 | goto nla_put_failure; |
| 3460 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3461 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3462 | sinfo->tx_packets)) |
| 3463 | goto nla_put_failure; |
| 3464 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3465 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3466 | sinfo->tx_retries)) |
| 3467 | goto nla_put_failure; |
| 3468 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3469 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3470 | sinfo->tx_failed)) |
| 3471 | goto nla_put_failure; |
| 3472 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3473 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3474 | sinfo->beacon_loss_count)) |
| 3475 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3476 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3477 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3478 | sinfo->local_pm)) |
| 3479 | goto nla_put_failure; |
| 3480 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3481 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3482 | sinfo->peer_pm)) |
| 3483 | goto nla_put_failure; |
| 3484 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3485 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3486 | sinfo->nonpeer_pm)) |
| 3487 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3488 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3489 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3490 | if (!bss_param) |
| 3491 | goto nla_put_failure; |
| 3492 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3493 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3494 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3495 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3496 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3497 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3498 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3499 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3500 | sinfo->bss_param.dtim_period) || |
| 3501 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3502 | sinfo->bss_param.beacon_interval)) |
| 3503 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3504 | |
| 3505 | nla_nest_end(msg, bss_param); |
| 3506 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3507 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3508 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3509 | sizeof(struct nl80211_sta_flag_update), |
| 3510 | &sinfo->sta_flags)) |
| 3511 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3512 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3513 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3514 | sinfo->t_offset)) |
| 3515 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3516 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3517 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3518 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3519 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3520 | sinfo->assoc_req_ies)) |
| 3521 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3522 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3523 | return genlmsg_end(msg, hdr); |
| 3524 | |
| 3525 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3526 | genlmsg_cancel(msg, hdr); |
| 3527 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3528 | } |
| 3529 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3530 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3531 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3532 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3533 | struct station_info sinfo; |
| 3534 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 3535 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3536 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 3537 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3538 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3539 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 3540 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3541 | if (err) |
| 3542 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3543 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 3544 | if (!wdev->netdev) { |
| 3545 | err = -EINVAL; |
| 3546 | goto out_err; |
| 3547 | } |
| 3548 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3549 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3550 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3551 | goto out_err; |
| 3552 | } |
| 3553 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3554 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3555 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 3556 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3557 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3558 | if (err == -ENOENT) |
| 3559 | break; |
| 3560 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3561 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3562 | |
| 3563 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3564 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3565 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 3566 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3567 | &sinfo) < 0) |
| 3568 | goto out; |
| 3569 | |
| 3570 | sta_idx++; |
| 3571 | } |
| 3572 | |
| 3573 | |
| 3574 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 3575 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3576 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3577 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 3578 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3579 | |
| 3580 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3581 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3582 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3583 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3584 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3585 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3586 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3587 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3588 | struct sk_buff *msg; |
| 3589 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3590 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3591 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3592 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3593 | |
| 3594 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3595 | return -EINVAL; |
| 3596 | |
| 3597 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3598 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3599 | if (!rdev->ops->get_station) |
| 3600 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3601 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3602 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3603 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3604 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3605 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3606 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3607 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3608 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3609 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3610 | 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] | 3611 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3612 | nlmsg_free(msg); |
| 3613 | return -ENOBUFS; |
| 3614 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3615 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3616 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3617 | } |
| 3618 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3619 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3620 | struct station_parameters *params, |
| 3621 | enum cfg80211_station_type statype) |
| 3622 | { |
| 3623 | if (params->listen_interval != -1) |
| 3624 | return -EINVAL; |
| 3625 | if (params->aid) |
| 3626 | return -EINVAL; |
| 3627 | |
| 3628 | /* When you run into this, adjust the code below for the new flag */ |
| 3629 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3630 | |
| 3631 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3632 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3633 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3634 | /* |
| 3635 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3636 | * code doesn't have the bug of including TDLS in the |
| 3637 | * mask everywhere. |
| 3638 | */ |
| 3639 | if (params->sta_flags_mask & |
| 3640 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3641 | BIT(NL80211_STA_FLAG_MFP) | |
| 3642 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3643 | return -EINVAL; |
| 3644 | break; |
| 3645 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3646 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3647 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3648 | return -EINVAL; |
| 3649 | /* ignore since it can't change */ |
| 3650 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3651 | break; |
| 3652 | default: |
| 3653 | /* disallow mesh-specific things */ |
| 3654 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3655 | return -EINVAL; |
| 3656 | if (params->local_pm) |
| 3657 | return -EINVAL; |
| 3658 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3659 | return -EINVAL; |
| 3660 | } |
| 3661 | |
| 3662 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3663 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3664 | /* TDLS can't be set, ... */ |
| 3665 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3666 | return -EINVAL; |
| 3667 | /* |
| 3668 | * ... but don't bother the driver with it. This works around |
| 3669 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3670 | * TLDS_PEER flag in the mask even for AP mode. |
| 3671 | */ |
| 3672 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3673 | } |
| 3674 | |
| 3675 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3676 | /* reject other things that can't change */ |
| 3677 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3678 | return -EINVAL; |
| 3679 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3680 | return -EINVAL; |
| 3681 | if (params->supported_rates) |
| 3682 | return -EINVAL; |
| 3683 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3684 | return -EINVAL; |
| 3685 | } |
| 3686 | |
| 3687 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3688 | if (params->vlan) |
| 3689 | return -EINVAL; |
| 3690 | } |
| 3691 | |
| 3692 | switch (statype) { |
| 3693 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3694 | /* Use this only for authorizing/unauthorizing a station */ |
| 3695 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3696 | return -EOPNOTSUPP; |
| 3697 | break; |
| 3698 | case CFG80211_STA_AP_CLIENT: |
| 3699 | /* accept only the listed bits */ |
| 3700 | if (params->sta_flags_mask & |
| 3701 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3702 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3703 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3704 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3705 | BIT(NL80211_STA_FLAG_WME) | |
| 3706 | BIT(NL80211_STA_FLAG_MFP))) |
| 3707 | return -EINVAL; |
| 3708 | |
| 3709 | /* but authenticated/associated only if driver handles it */ |
| 3710 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3711 | params->sta_flags_mask & |
| 3712 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3713 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3714 | return -EINVAL; |
| 3715 | break; |
| 3716 | case CFG80211_STA_IBSS: |
| 3717 | case CFG80211_STA_AP_STA: |
| 3718 | /* reject any changes other than AUTHORIZED */ |
| 3719 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3720 | return -EINVAL; |
| 3721 | break; |
| 3722 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3723 | /* reject any changes other than AUTHORIZED or WME */ |
| 3724 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3725 | BIT(NL80211_STA_FLAG_WME))) |
| 3726 | return -EINVAL; |
| 3727 | /* force (at least) rates when authorizing */ |
| 3728 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3729 | !params->supported_rates) |
| 3730 | return -EINVAL; |
| 3731 | break; |
| 3732 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3733 | /* reject any changes */ |
| 3734 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3735 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3736 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3737 | return -EINVAL; |
| 3738 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3739 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3740 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3741 | return -EINVAL; |
| 3742 | break; |
| 3743 | } |
| 3744 | |
| 3745 | return 0; |
| 3746 | } |
| 3747 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3748 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3749 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3750 | * 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] | 3751 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3752 | static struct net_device *get_vlan(struct genl_info *info, |
| 3753 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3754 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3755 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3756 | struct net_device *v; |
| 3757 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3758 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3759 | if (!vlanattr) |
| 3760 | return NULL; |
| 3761 | |
| 3762 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3763 | if (!v) |
| 3764 | return ERR_PTR(-ENODEV); |
| 3765 | |
| 3766 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3767 | ret = -EINVAL; |
| 3768 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3769 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3770 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3771 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3772 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3773 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3774 | ret = -EINVAL; |
| 3775 | goto error; |
| 3776 | } |
| 3777 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3778 | if (!netif_running(v)) { |
| 3779 | ret = -ENETDOWN; |
| 3780 | goto error; |
| 3781 | } |
| 3782 | |
| 3783 | return v; |
| 3784 | error: |
| 3785 | dev_put(v); |
| 3786 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3787 | } |
| 3788 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3789 | static struct nla_policy |
| 3790 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3791 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3792 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3793 | }; |
| 3794 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3795 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3796 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3797 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3798 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3799 | struct nlattr *nla; |
| 3800 | int err; |
| 3801 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3802 | /* parse WME attributes if present */ |
| 3803 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3804 | return 0; |
| 3805 | |
| 3806 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3807 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3808 | nl80211_sta_wme_policy); |
| 3809 | if (err) |
| 3810 | return err; |
| 3811 | |
| 3812 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3813 | params->uapsd_queues = nla_get_u8( |
| 3814 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3815 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3816 | return -EINVAL; |
| 3817 | |
| 3818 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3819 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3820 | |
| 3821 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3822 | return -EINVAL; |
| 3823 | |
| 3824 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3825 | |
| 3826 | return 0; |
| 3827 | } |
| 3828 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3829 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3830 | struct station_parameters *params) |
| 3831 | { |
| 3832 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
| 3833 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3834 | params->ht_capa = |
| 3835 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3836 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3837 | params->vht_capa = |
| 3838 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3839 | |
| 3840 | return nl80211_parse_sta_wme(info, params); |
| 3841 | } |
| 3842 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3843 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3844 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3846 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3847 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3848 | u8 *mac_addr; |
| 3849 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3850 | |
| 3851 | memset(¶ms, 0, sizeof(params)); |
| 3852 | |
| 3853 | params.listen_interval = -1; |
| 3854 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3855 | if (!rdev->ops->change_station) |
| 3856 | return -EOPNOTSUPP; |
| 3857 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3858 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3859 | return -EINVAL; |
| 3860 | |
| 3861 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3862 | return -EINVAL; |
| 3863 | |
| 3864 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3865 | |
| 3866 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3867 | params.supported_rates = |
| 3868 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3869 | params.supported_rates_len = |
| 3870 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3871 | } |
| 3872 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3873 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3874 | params.capability = |
| 3875 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3876 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3877 | } |
| 3878 | |
| 3879 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3880 | params.ext_capab = |
| 3881 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3882 | params.ext_capab_len = |
| 3883 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3884 | } |
| 3885 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3886 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3887 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3888 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3889 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3890 | return -EINVAL; |
| 3891 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3892 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3893 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3894 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3895 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3896 | return -EINVAL; |
| 3897 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3898 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3899 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3900 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3901 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3902 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 3903 | return -EINVAL; |
| 3904 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 3905 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3906 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3907 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3908 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3909 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3910 | |
| 3911 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3912 | pm > NL80211_MESH_POWER_MAX) |
| 3913 | return -EINVAL; |
| 3914 | |
| 3915 | params.local_pm = pm; |
| 3916 | } |
| 3917 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3918 | /* Include parameters for TDLS peer (will check later) */ |
| 3919 | err = nl80211_set_station_tdls(info, ¶ms); |
| 3920 | if (err) |
| 3921 | return err; |
| 3922 | |
| 3923 | params.vlan = get_vlan(info, rdev); |
| 3924 | if (IS_ERR(params.vlan)) |
| 3925 | return PTR_ERR(params.vlan); |
| 3926 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3927 | switch (dev->ieee80211_ptr->iftype) { |
| 3928 | case NL80211_IFTYPE_AP: |
| 3929 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3930 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3931 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3932 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3933 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3934 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3935 | break; |
| 3936 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3937 | err = -EOPNOTSUPP; |
| 3938 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3939 | } |
| 3940 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3941 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3942 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3943 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3944 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3945 | if (params.vlan) |
| 3946 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3947 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3948 | return err; |
| 3949 | } |
| 3950 | |
| 3951 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3952 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3953 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3954 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3955 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3956 | struct station_parameters params; |
| 3957 | u8 *mac_addr = NULL; |
| 3958 | |
| 3959 | memset(¶ms, 0, sizeof(params)); |
| 3960 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 3961 | if (!rdev->ops->add_station) |
| 3962 | return -EOPNOTSUPP; |
| 3963 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3964 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3965 | return -EINVAL; |
| 3966 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3967 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3968 | return -EINVAL; |
| 3969 | |
| 3970 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3971 | return -EINVAL; |
| 3972 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3973 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3974 | return -EINVAL; |
| 3975 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3976 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3977 | params.supported_rates = |
| 3978 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3979 | params.supported_rates_len = |
| 3980 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3981 | params.listen_interval = |
| 3982 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3983 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3984 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3985 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3986 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3987 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3988 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3989 | params.capability = |
| 3990 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3991 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3992 | } |
| 3993 | |
| 3994 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3995 | params.ext_capab = |
| 3996 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3997 | params.ext_capab_len = |
| 3998 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3999 | } |
| 4000 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4001 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4002 | params.ht_capa = |
| 4003 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4004 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4005 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4006 | params.vht_capa = |
| 4007 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4008 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4009 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4010 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4011 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4012 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4013 | return -EINVAL; |
| 4014 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4015 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4016 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4017 | if (err) |
| 4018 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4019 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4020 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4021 | return -EINVAL; |
| 4022 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4023 | /* When you run into this, adjust the code below for the new flag */ |
| 4024 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4025 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4026 | switch (dev->ieee80211_ptr->iftype) { |
| 4027 | case NL80211_IFTYPE_AP: |
| 4028 | case NL80211_IFTYPE_AP_VLAN: |
| 4029 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4030 | /* ignore WME attributes if iface/sta is not capable */ |
| 4031 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4032 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4033 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4034 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4035 | /* TDLS peers cannot be added */ |
| 4036 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4037 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4038 | /* but don't bother the driver with it */ |
| 4039 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4040 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4041 | /* allow authenticated/associated only if driver handles it */ |
| 4042 | if (!(rdev->wiphy.features & |
| 4043 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4044 | params.sta_flags_mask & |
| 4045 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4046 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4047 | return -EINVAL; |
| 4048 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4049 | /* must be last in here for error handling */ |
| 4050 | params.vlan = get_vlan(info, rdev); |
| 4051 | if (IS_ERR(params.vlan)) |
| 4052 | return PTR_ERR(params.vlan); |
| 4053 | break; |
| 4054 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4055 | /* ignore uAPSD data */ |
| 4056 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4057 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4058 | /* associated is disallowed */ |
| 4059 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4060 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4061 | /* TDLS peers cannot be added */ |
| 4062 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4063 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4064 | break; |
| 4065 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4066 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4067 | /* ignore uAPSD data */ |
| 4068 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4069 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4070 | /* these are disallowed */ |
| 4071 | if (params.sta_flags_mask & |
| 4072 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4073 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4074 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4075 | /* Only TDLS peers can be added */ |
| 4076 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4077 | return -EINVAL; |
| 4078 | /* Can only add if TDLS ... */ |
| 4079 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4080 | return -EOPNOTSUPP; |
| 4081 | /* ... with external setup is supported */ |
| 4082 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4083 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4084 | /* |
| 4085 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4086 | * as authorized, but it shouldn't yet be. |
| 4087 | */ |
| 4088 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4089 | break; |
| 4090 | default: |
| 4091 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4092 | } |
| 4093 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4094 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4095 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4096 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4097 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4098 | if (params.vlan) |
| 4099 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4100 | return err; |
| 4101 | } |
| 4102 | |
| 4103 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4104 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4105 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4106 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4107 | u8 *mac_addr = NULL; |
| 4108 | |
| 4109 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4110 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4111 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4112 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4113 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4114 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4115 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4116 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4117 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4118 | if (!rdev->ops->del_station) |
| 4119 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4120 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4121 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4122 | } |
| 4123 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4124 | 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] | 4125 | int flags, struct net_device *dev, |
| 4126 | u8 *dst, u8 *next_hop, |
| 4127 | struct mpath_info *pinfo) |
| 4128 | { |
| 4129 | void *hdr; |
| 4130 | struct nlattr *pinfoattr; |
| 4131 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4132 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4133 | if (!hdr) |
| 4134 | return -1; |
| 4135 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4136 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4137 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4138 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4139 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4140 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4141 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4142 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4143 | if (!pinfoattr) |
| 4144 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4145 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4146 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4147 | pinfo->frame_qlen)) |
| 4148 | goto nla_put_failure; |
| 4149 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4150 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4151 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4152 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4153 | pinfo->metric)) || |
| 4154 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4155 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4156 | pinfo->exptime)) || |
| 4157 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4158 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4159 | pinfo->flags)) || |
| 4160 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4161 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4162 | pinfo->discovery_timeout)) || |
| 4163 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4164 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4165 | pinfo->discovery_retries))) |
| 4166 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4167 | |
| 4168 | nla_nest_end(msg, pinfoattr); |
| 4169 | |
| 4170 | return genlmsg_end(msg, hdr); |
| 4171 | |
| 4172 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4173 | genlmsg_cancel(msg, hdr); |
| 4174 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4178 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4179 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4180 | struct mpath_info pinfo; |
| 4181 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 4182 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4183 | u8 dst[ETH_ALEN]; |
| 4184 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 4185 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4186 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4187 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 4188 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4189 | if (err) |
| 4190 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4191 | |
| 4192 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4193 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4194 | goto out_err; |
| 4195 | } |
| 4196 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 4197 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4198 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4199 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4200 | } |
| 4201 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4202 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 4203 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4204 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4205 | if (err == -ENOENT) |
| 4206 | break; |
| 4207 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4208 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4209 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4210 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4211 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 4212 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4213 | &pinfo) < 0) |
| 4214 | goto out; |
| 4215 | |
| 4216 | path_idx++; |
| 4217 | } |
| 4218 | |
| 4219 | |
| 4220 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 4221 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4222 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4223 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 4224 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4225 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4229 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4231 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4232 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4233 | struct mpath_info pinfo; |
| 4234 | struct sk_buff *msg; |
| 4235 | u8 *dst = NULL; |
| 4236 | u8 next_hop[ETH_ALEN]; |
| 4237 | |
| 4238 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4239 | |
| 4240 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4241 | return -EINVAL; |
| 4242 | |
| 4243 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4244 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4245 | if (!rdev->ops->get_mpath) |
| 4246 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4247 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4248 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4249 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4250 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4251 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4252 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4253 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4254 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4255 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4256 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4257 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4258 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4259 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4260 | dev, dst, next_hop, &pinfo) < 0) { |
| 4261 | nlmsg_free(msg); |
| 4262 | return -ENOBUFS; |
| 4263 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4264 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4265 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4266 | } |
| 4267 | |
| 4268 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4269 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4271 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4272 | u8 *dst = NULL; |
| 4273 | u8 *next_hop = NULL; |
| 4274 | |
| 4275 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4276 | return -EINVAL; |
| 4277 | |
| 4278 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4279 | return -EINVAL; |
| 4280 | |
| 4281 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4282 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4283 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4284 | if (!rdev->ops->change_mpath) |
| 4285 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4286 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4287 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4288 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4289 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4290 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4291 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4292 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4293 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4294 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4295 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4296 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4297 | u8 *dst = NULL; |
| 4298 | u8 *next_hop = NULL; |
| 4299 | |
| 4300 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4301 | return -EINVAL; |
| 4302 | |
| 4303 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4304 | return -EINVAL; |
| 4305 | |
| 4306 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4307 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4308 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4309 | if (!rdev->ops->add_mpath) |
| 4310 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4311 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4312 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4313 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4314 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4315 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4319 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4321 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4322 | u8 *dst = NULL; |
| 4323 | |
| 4324 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4325 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4326 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4327 | if (!rdev->ops->del_mpath) |
| 4328 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4329 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4330 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4331 | } |
| 4332 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4333 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4334 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4335 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4336 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4337 | struct bss_parameters params; |
| 4338 | |
| 4339 | memset(¶ms, 0, sizeof(params)); |
| 4340 | /* default to not changing parameters */ |
| 4341 | params.use_cts_prot = -1; |
| 4342 | params.use_short_preamble = -1; |
| 4343 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4344 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4345 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4346 | params.p2p_ctwindow = -1; |
| 4347 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4348 | |
| 4349 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4350 | params.use_cts_prot = |
| 4351 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4352 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4353 | params.use_short_preamble = |
| 4354 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4355 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4356 | params.use_short_slot_time = |
| 4357 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4358 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4359 | params.basic_rates = |
| 4360 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4361 | params.basic_rates_len = |
| 4362 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4363 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4364 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4365 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4366 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4367 | params.ht_opmode = |
| 4368 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4369 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4370 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4371 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4372 | return -EINVAL; |
| 4373 | params.p2p_ctwindow = |
| 4374 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4375 | if (params.p2p_ctwindow < 0) |
| 4376 | return -EINVAL; |
| 4377 | if (params.p2p_ctwindow != 0 && |
| 4378 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4379 | return -EINVAL; |
| 4380 | } |
| 4381 | |
| 4382 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4383 | u8 tmp; |
| 4384 | |
| 4385 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4386 | return -EINVAL; |
| 4387 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4388 | if (tmp > 1) |
| 4389 | return -EINVAL; |
| 4390 | params.p2p_opp_ps = tmp; |
| 4391 | if (params.p2p_opp_ps && |
| 4392 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4393 | return -EINVAL; |
| 4394 | } |
| 4395 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4396 | if (!rdev->ops->change_bss) |
| 4397 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4398 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4399 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4400 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4401 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4402 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4403 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4404 | } |
| 4405 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4406 | 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] | 4407 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4408 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4409 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4410 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4411 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4412 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4413 | }; |
| 4414 | |
| 4415 | static int parse_reg_rule(struct nlattr *tb[], |
| 4416 | struct ieee80211_reg_rule *reg_rule) |
| 4417 | { |
| 4418 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4419 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4420 | |
| 4421 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4422 | return -EINVAL; |
| 4423 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4424 | return -EINVAL; |
| 4425 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4426 | return -EINVAL; |
| 4427 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4428 | return -EINVAL; |
| 4429 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4430 | return -EINVAL; |
| 4431 | |
| 4432 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4433 | |
| 4434 | freq_range->start_freq_khz = |
| 4435 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4436 | freq_range->end_freq_khz = |
| 4437 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4438 | freq_range->max_bandwidth_khz = |
| 4439 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4440 | |
| 4441 | power_rule->max_eirp = |
| 4442 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4443 | |
| 4444 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4445 | power_rule->max_antenna_gain = |
| 4446 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4447 | |
| 4448 | return 0; |
| 4449 | } |
| 4450 | |
| 4451 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4452 | { |
| 4453 | int r; |
| 4454 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4455 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4456 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4457 | /* |
| 4458 | * You should only get this when cfg80211 hasn't yet initialized |
| 4459 | * completely when built-in to the kernel right between the time |
| 4460 | * window between nl80211_init() and regulatory_init(), if that is |
| 4461 | * even possible. |
| 4462 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4463 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4464 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4465 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4466 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4467 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4468 | |
| 4469 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4470 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4471 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4472 | user_reg_hint_type = |
| 4473 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4474 | else |
| 4475 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4476 | |
| 4477 | switch (user_reg_hint_type) { |
| 4478 | case NL80211_USER_REG_HINT_USER: |
| 4479 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4480 | break; |
| 4481 | default: |
| 4482 | return -EINVAL; |
| 4483 | } |
| 4484 | |
| 4485 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4486 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4487 | return r; |
| 4488 | } |
| 4489 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4490 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4491 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4492 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4494 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4495 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4496 | struct mesh_config cur_params; |
| 4497 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4498 | void *hdr; |
| 4499 | struct nlattr *pinfoattr; |
| 4500 | struct sk_buff *msg; |
| 4501 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4502 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4503 | return -EOPNOTSUPP; |
| 4504 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4505 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4506 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4507 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4508 | wdev_lock(wdev); |
| 4509 | /* If not connected, get default parameters */ |
| 4510 | if (!wdev->mesh_id_len) |
| 4511 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4512 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4513 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4514 | wdev_unlock(wdev); |
| 4515 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4516 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4517 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4518 | |
| 4519 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4520 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4521 | if (!msg) |
| 4522 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4523 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4524 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4525 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4526 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4527 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4528 | if (!pinfoattr) |
| 4529 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4530 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4531 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4532 | cur_params.dot11MeshRetryTimeout) || |
| 4533 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4534 | cur_params.dot11MeshConfirmTimeout) || |
| 4535 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4536 | cur_params.dot11MeshHoldingTimeout) || |
| 4537 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4538 | cur_params.dot11MeshMaxPeerLinks) || |
| 4539 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4540 | cur_params.dot11MeshMaxRetries) || |
| 4541 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4542 | cur_params.dot11MeshTTL) || |
| 4543 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4544 | cur_params.element_ttl) || |
| 4545 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4546 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4547 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4548 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4549 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4550 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4551 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4552 | cur_params.path_refresh_time) || |
| 4553 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4554 | cur_params.min_discovery_timeout) || |
| 4555 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4556 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4557 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4558 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4559 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4560 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4561 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4562 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4563 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4564 | cur_params.dot11MeshHWMPRootMode) || |
| 4565 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4566 | cur_params.dot11MeshHWMPRannInterval) || |
| 4567 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4568 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4569 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4570 | cur_params.dot11MeshForwarding) || |
| 4571 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4572 | cur_params.rssi_threshold) || |
| 4573 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4574 | cur_params.ht_opmode) || |
| 4575 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4576 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4577 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4578 | cur_params.dot11MeshHWMProotInterval) || |
| 4579 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4580 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4581 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4582 | cur_params.power_mode) || |
| 4583 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
| 4584 | cur_params.dot11MeshAwakeWindowDuration)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4585 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4586 | nla_nest_end(msg, pinfoattr); |
| 4587 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4588 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4589 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4590 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4591 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4592 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4593 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4594 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4595 | } |
| 4596 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4597 | 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] | 4598 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4599 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4600 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4601 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4602 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4603 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4604 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4605 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4606 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4607 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4608 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4609 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4610 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4611 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4612 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4613 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4614 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4615 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4616 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4617 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4618 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4619 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4620 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4621 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4622 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4623 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4624 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4625 | }; |
| 4626 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4627 | static const struct nla_policy |
| 4628 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4629 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4630 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4631 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4632 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4633 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4634 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4635 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4636 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4637 | }; |
| 4638 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4639 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4640 | struct mesh_config *cfg, |
| 4641 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4642 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4643 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4644 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4645 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4646 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4647 | do { \ |
| 4648 | if (tb[attr]) { \ |
| 4649 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4650 | return -EINVAL; \ |
| 4651 | cfg->param = fn(tb[attr]); \ |
| 4652 | mask |= (1 << (attr - 1)); \ |
| 4653 | } \ |
| 4654 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4655 | |
| 4656 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4657 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4658 | return -EINVAL; |
| 4659 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4660 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4661 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4662 | return -EINVAL; |
| 4663 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4664 | /* This makes sure that there aren't more than 32 mesh config |
| 4665 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4666 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4667 | |
| 4668 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4669 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4670 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4671 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4672 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4673 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4674 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4675 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4676 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4677 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4678 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4679 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4680 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4681 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4682 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4683 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4684 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4685 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4686 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4687 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4688 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4689 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4690 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4691 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4692 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4693 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4694 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4695 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4696 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4697 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4698 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4699 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4700 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4701 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4702 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4703 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4704 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4705 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4706 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4707 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4708 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4709 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4710 | 1, 65535, mask, |
| 4711 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4712 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4713 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4714 | 1, 65535, mask, |
| 4715 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4716 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4717 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4718 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4719 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4720 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4721 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4722 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4723 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4724 | nla_get_u8); |
| 4725 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4726 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4727 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4728 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4729 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4730 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4731 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4732 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4733 | mask, NL80211_MESHCONF_FORWARDING, |
| 4734 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4735 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4736 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4737 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4738 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4739 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4740 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4741 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4742 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4743 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4744 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4745 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4746 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4747 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4748 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4749 | dot11MeshHWMPconfirmationInterval, |
| 4750 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4751 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4752 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4753 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4754 | NL80211_MESH_POWER_ACTIVE, |
| 4755 | NL80211_MESH_POWER_MAX, |
| 4756 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4757 | nla_get_u32); |
| 4758 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4759 | 0, 65535, mask, |
| 4760 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4761 | if (mask_out) |
| 4762 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4763 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4764 | return 0; |
| 4765 | |
| 4766 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4767 | } |
| 4768 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4769 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4770 | struct mesh_setup *setup) |
| 4771 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4773 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4774 | |
| 4775 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4776 | return -EINVAL; |
| 4777 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4778 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4779 | nl80211_mesh_setup_params_policy)) |
| 4780 | return -EINVAL; |
| 4781 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4782 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4783 | setup->sync_method = |
| 4784 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4785 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4786 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4787 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4788 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4789 | setup->path_sel_proto = |
| 4790 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4791 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4792 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4793 | |
| 4794 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4795 | setup->path_metric = |
| 4796 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4797 | IEEE80211_PATH_METRIC_VENDOR : |
| 4798 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4799 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4800 | |
| 4801 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4802 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4803 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4804 | if (!is_valid_ie_attr(ieattr)) |
| 4805 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4806 | setup->ie = nla_data(ieattr); |
| 4807 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4808 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4809 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4810 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4811 | return -EINVAL; |
| 4812 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4813 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4814 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4815 | if (setup->is_secure) |
| 4816 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4817 | |
| 4818 | return 0; |
| 4819 | } |
| 4820 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4821 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4822 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4823 | { |
| 4824 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4825 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4826 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4827 | struct mesh_config cfg; |
| 4828 | u32 mask; |
| 4829 | int err; |
| 4830 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4831 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4832 | return -EOPNOTSUPP; |
| 4833 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4834 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4835 | return -EOPNOTSUPP; |
| 4836 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4837 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4838 | if (err) |
| 4839 | return err; |
| 4840 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4841 | wdev_lock(wdev); |
| 4842 | if (!wdev->mesh_id_len) |
| 4843 | err = -ENOLINK; |
| 4844 | |
| 4845 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4846 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4847 | |
| 4848 | wdev_unlock(wdev); |
| 4849 | |
| 4850 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4851 | } |
| 4852 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4853 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4854 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4855 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4856 | struct sk_buff *msg; |
| 4857 | void *hdr = NULL; |
| 4858 | struct nlattr *nl_reg_rules; |
| 4859 | unsigned int i; |
| 4860 | int err = -EINVAL; |
| 4861 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4862 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4863 | |
| 4864 | if (!cfg80211_regdomain) |
| 4865 | goto out; |
| 4866 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4867 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4868 | if (!msg) { |
| 4869 | err = -ENOBUFS; |
| 4870 | goto out; |
| 4871 | } |
| 4872 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4873 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4874 | NL80211_CMD_GET_REG); |
| 4875 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4876 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4877 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4878 | if (reg_last_request_cell_base() && |
| 4879 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4880 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4881 | goto nla_put_failure; |
| 4882 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4883 | rcu_read_lock(); |
| 4884 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4885 | |
| 4886 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4887 | (regdom->dfs_region && |
| 4888 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4889 | goto nla_put_failure_rcu; |
| 4890 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4891 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4892 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4893 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4894 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4895 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4896 | struct nlattr *nl_reg_rule; |
| 4897 | const struct ieee80211_reg_rule *reg_rule; |
| 4898 | const struct ieee80211_freq_range *freq_range; |
| 4899 | const struct ieee80211_power_rule *power_rule; |
| 4900 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4901 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4902 | freq_range = ®_rule->freq_range; |
| 4903 | power_rule = ®_rule->power_rule; |
| 4904 | |
| 4905 | nl_reg_rule = nla_nest_start(msg, i); |
| 4906 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4907 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4908 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4909 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4910 | reg_rule->flags) || |
| 4911 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4912 | freq_range->start_freq_khz) || |
| 4913 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4914 | freq_range->end_freq_khz) || |
| 4915 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4916 | freq_range->max_bandwidth_khz) || |
| 4917 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4918 | power_rule->max_antenna_gain) || |
| 4919 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4920 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4921 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4922 | |
| 4923 | nla_nest_end(msg, nl_reg_rule); |
| 4924 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4925 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4926 | |
| 4927 | nla_nest_end(msg, nl_reg_rules); |
| 4928 | |
| 4929 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4930 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4931 | goto out; |
| 4932 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4933 | nla_put_failure_rcu: |
| 4934 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4935 | nla_put_failure: |
| 4936 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4937 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4938 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4939 | err = -EMSGSIZE; |
| 4940 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4941 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4942 | return err; |
| 4943 | } |
| 4944 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4945 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4946 | { |
| 4947 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4948 | struct nlattr *nl_reg_rule; |
| 4949 | char *alpha2 = NULL; |
| 4950 | int rem_reg_rules = 0, r = 0; |
| 4951 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4952 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4953 | struct ieee80211_regdomain *rd = NULL; |
| 4954 | |
| 4955 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4956 | return -EINVAL; |
| 4957 | |
| 4958 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4959 | return -EINVAL; |
| 4960 | |
| 4961 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4962 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4963 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4964 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4965 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4966 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4967 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4968 | num_rules++; |
| 4969 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4970 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4971 | } |
| 4972 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4973 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4974 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4975 | |
| 4976 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4977 | if (!rd) |
| 4978 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4979 | |
| 4980 | rd->n_reg_rules = num_rules; |
| 4981 | rd->alpha2[0] = alpha2[0]; |
| 4982 | rd->alpha2[1] = alpha2[1]; |
| 4983 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4984 | /* |
| 4985 | * Disable DFS master mode if the DFS region was |
| 4986 | * not supported or known on this kernel. |
| 4987 | */ |
| 4988 | if (reg_supported_dfs_region(dfs_region)) |
| 4989 | rd->dfs_region = dfs_region; |
| 4990 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4991 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4992 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4993 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4994 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4995 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4996 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4997 | if (r) |
| 4998 | goto bad_reg; |
| 4999 | |
| 5000 | rule_idx++; |
| 5001 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5002 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5003 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5004 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5005 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5006 | } |
| 5007 | |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5008 | mutex_lock(&cfg80211_mutex); |
| 5009 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5010 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5011 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5012 | rd = NULL; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5013 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5014 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5015 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5016 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5017 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5018 | } |
| 5019 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5020 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5021 | { |
| 5022 | struct nlattr *attr1, *attr2; |
| 5023 | int n_channels = 0, tmp1, tmp2; |
| 5024 | |
| 5025 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5026 | n_channels++; |
| 5027 | /* |
| 5028 | * Some hardware has a limited channel list for |
| 5029 | * scanning, and it is pretty much nonsensical |
| 5030 | * to scan for a channel twice, so disallow that |
| 5031 | * and don't require drivers to check that the |
| 5032 | * channel list they get isn't longer than what |
| 5033 | * they can scan, as long as they can scan all |
| 5034 | * the channels they registered at once. |
| 5035 | */ |
| 5036 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5037 | if (attr1 != attr2 && |
| 5038 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5039 | return 0; |
| 5040 | } |
| 5041 | |
| 5042 | return n_channels; |
| 5043 | } |
| 5044 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5045 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5046 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5048 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5049 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5050 | struct nlattr *attr; |
| 5051 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5052 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5053 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5054 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5055 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5056 | return -EINVAL; |
| 5057 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5058 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5059 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5060 | if (!rdev->ops->scan) |
| 5061 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5062 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5063 | if (rdev->scan_req) |
| 5064 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5065 | |
| 5066 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5067 | n_channels = validate_scan_freqs( |
| 5068 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5069 | if (!n_channels) |
| 5070 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5071 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5072 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5073 | n_channels = 0; |
| 5074 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5075 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5076 | if (wiphy->bands[band]) |
| 5077 | n_channels += wiphy->bands[band]->n_channels; |
| 5078 | } |
| 5079 | |
| 5080 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5081 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5082 | n_ssids++; |
| 5083 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5084 | if (n_ssids > wiphy->max_scan_ssids) |
| 5085 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5086 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5087 | if (info->attrs[NL80211_ATTR_IE]) |
| 5088 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5089 | else |
| 5090 | ie_len = 0; |
| 5091 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5092 | if (ie_len > wiphy->max_scan_ie_len) |
| 5093 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5094 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5095 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5096 | + sizeof(*request->ssids) * n_ssids |
| 5097 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5098 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5099 | if (!request) |
| 5100 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5101 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5102 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5103 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5104 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5105 | if (ie_len) { |
| 5106 | if (request->ssids) |
| 5107 | request->ie = (void *)(request->ssids + n_ssids); |
| 5108 | else |
| 5109 | request->ie = (void *)(request->channels + n_channels); |
| 5110 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5111 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5112 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5113 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5114 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5115 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5116 | struct ieee80211_channel *chan; |
| 5117 | |
| 5118 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5119 | |
| 5120 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5121 | err = -EINVAL; |
| 5122 | goto out_free; |
| 5123 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5124 | |
| 5125 | /* ignore disabled channels */ |
| 5126 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5127 | continue; |
| 5128 | |
| 5129 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5130 | i++; |
| 5131 | } |
| 5132 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5133 | enum ieee80211_band band; |
| 5134 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5135 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5136 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5137 | int j; |
| 5138 | if (!wiphy->bands[band]) |
| 5139 | continue; |
| 5140 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5141 | struct ieee80211_channel *chan; |
| 5142 | |
| 5143 | chan = &wiphy->bands[band]->channels[j]; |
| 5144 | |
| 5145 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5146 | continue; |
| 5147 | |
| 5148 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5149 | i++; |
| 5150 | } |
| 5151 | } |
| 5152 | } |
| 5153 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5154 | if (!i) { |
| 5155 | err = -EINVAL; |
| 5156 | goto out_free; |
| 5157 | } |
| 5158 | |
| 5159 | request->n_channels = i; |
| 5160 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5161 | i = 0; |
| 5162 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5163 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5164 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5165 | err = -EINVAL; |
| 5166 | goto out_free; |
| 5167 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5168 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5169 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5170 | i++; |
| 5171 | } |
| 5172 | } |
| 5173 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5174 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5175 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5176 | memcpy((void *)request->ie, |
| 5177 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5178 | request->ie_len); |
| 5179 | } |
| 5180 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5181 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5182 | if (wiphy->bands[i]) |
| 5183 | request->rates[i] = |
| 5184 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5185 | |
| 5186 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5187 | nla_for_each_nested(attr, |
| 5188 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5189 | tmp) { |
| 5190 | enum ieee80211_band band = nla_type(attr); |
| 5191 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5192 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5193 | err = -EINVAL; |
| 5194 | goto out_free; |
| 5195 | } |
| 5196 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5197 | nla_data(attr), |
| 5198 | nla_len(attr), |
| 5199 | &request->rates[band]); |
| 5200 | if (err) |
| 5201 | goto out_free; |
| 5202 | } |
| 5203 | } |
| 5204 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5205 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5206 | request->flags = nla_get_u32( |
| 5207 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5208 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5209 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5210 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5211 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5212 | err = -EOPNOTSUPP; |
| 5213 | goto out_free; |
| 5214 | } |
| 5215 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5216 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5217 | request->no_cck = |
| 5218 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5219 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5220 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5221 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5222 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5223 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5224 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5225 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5226 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5227 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5228 | nl80211_send_scan_start(rdev, wdev); |
| 5229 | if (wdev->netdev) |
| 5230 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5231 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5232 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5233 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5234 | kfree(request); |
| 5235 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5236 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5237 | return err; |
| 5238 | } |
| 5239 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5240 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5241 | struct genl_info *info) |
| 5242 | { |
| 5243 | struct cfg80211_sched_scan_request *request; |
| 5244 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5245 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5246 | struct nlattr *attr; |
| 5247 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5248 | 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] | 5249 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5250 | enum ieee80211_band band; |
| 5251 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5252 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5253 | |
| 5254 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5255 | !rdev->ops->sched_scan_start) |
| 5256 | return -EOPNOTSUPP; |
| 5257 | |
| 5258 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5259 | return -EINVAL; |
| 5260 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5261 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5262 | return -EINVAL; |
| 5263 | |
| 5264 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5265 | if (interval == 0) |
| 5266 | return -EINVAL; |
| 5267 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5268 | wiphy = &rdev->wiphy; |
| 5269 | |
| 5270 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5271 | n_channels = validate_scan_freqs( |
| 5272 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5273 | if (!n_channels) |
| 5274 | return -EINVAL; |
| 5275 | } else { |
| 5276 | n_channels = 0; |
| 5277 | |
| 5278 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5279 | if (wiphy->bands[band]) |
| 5280 | n_channels += wiphy->bands[band]->n_channels; |
| 5281 | } |
| 5282 | |
| 5283 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5284 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5285 | tmp) |
| 5286 | n_ssids++; |
| 5287 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5288 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5289 | return -EINVAL; |
| 5290 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5291 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5292 | nla_for_each_nested(attr, |
| 5293 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5294 | tmp) |
| 5295 | n_match_sets++; |
| 5296 | |
| 5297 | if (n_match_sets > wiphy->max_match_sets) |
| 5298 | return -EINVAL; |
| 5299 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5300 | if (info->attrs[NL80211_ATTR_IE]) |
| 5301 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5302 | else |
| 5303 | ie_len = 0; |
| 5304 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5305 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5306 | return -EINVAL; |
| 5307 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5308 | mutex_lock(&rdev->sched_scan_mtx); |
| 5309 | |
| 5310 | if (rdev->sched_scan_req) { |
| 5311 | err = -EINPROGRESS; |
| 5312 | goto out; |
| 5313 | } |
| 5314 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5315 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5316 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5317 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5318 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5319 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5320 | if (!request) { |
| 5321 | err = -ENOMEM; |
| 5322 | goto out; |
| 5323 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5324 | |
| 5325 | if (n_ssids) |
| 5326 | request->ssids = (void *)&request->channels[n_channels]; |
| 5327 | request->n_ssids = n_ssids; |
| 5328 | if (ie_len) { |
| 5329 | if (request->ssids) |
| 5330 | request->ie = (void *)(request->ssids + n_ssids); |
| 5331 | else |
| 5332 | request->ie = (void *)(request->channels + n_channels); |
| 5333 | } |
| 5334 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5335 | if (n_match_sets) { |
| 5336 | if (request->ie) |
| 5337 | request->match_sets = (void *)(request->ie + ie_len); |
| 5338 | else if (request->ssids) |
| 5339 | request->match_sets = |
| 5340 | (void *)(request->ssids + n_ssids); |
| 5341 | else |
| 5342 | request->match_sets = |
| 5343 | (void *)(request->channels + n_channels); |
| 5344 | } |
| 5345 | request->n_match_sets = n_match_sets; |
| 5346 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5347 | i = 0; |
| 5348 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5349 | /* user specified, bail out if channel not found */ |
| 5350 | nla_for_each_nested(attr, |
| 5351 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5352 | tmp) { |
| 5353 | struct ieee80211_channel *chan; |
| 5354 | |
| 5355 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5356 | |
| 5357 | if (!chan) { |
| 5358 | err = -EINVAL; |
| 5359 | goto out_free; |
| 5360 | } |
| 5361 | |
| 5362 | /* ignore disabled channels */ |
| 5363 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5364 | continue; |
| 5365 | |
| 5366 | request->channels[i] = chan; |
| 5367 | i++; |
| 5368 | } |
| 5369 | } else { |
| 5370 | /* all channels */ |
| 5371 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5372 | int j; |
| 5373 | if (!wiphy->bands[band]) |
| 5374 | continue; |
| 5375 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5376 | struct ieee80211_channel *chan; |
| 5377 | |
| 5378 | chan = &wiphy->bands[band]->channels[j]; |
| 5379 | |
| 5380 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5381 | continue; |
| 5382 | |
| 5383 | request->channels[i] = chan; |
| 5384 | i++; |
| 5385 | } |
| 5386 | } |
| 5387 | } |
| 5388 | |
| 5389 | if (!i) { |
| 5390 | err = -EINVAL; |
| 5391 | goto out_free; |
| 5392 | } |
| 5393 | |
| 5394 | request->n_channels = i; |
| 5395 | |
| 5396 | i = 0; |
| 5397 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5398 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5399 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5400 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5401 | err = -EINVAL; |
| 5402 | goto out_free; |
| 5403 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5404 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5405 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5406 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5407 | i++; |
| 5408 | } |
| 5409 | } |
| 5410 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5411 | i = 0; |
| 5412 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5413 | nla_for_each_nested(attr, |
| 5414 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5415 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5416 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5417 | |
| 5418 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5419 | nla_data(attr), nla_len(attr), |
| 5420 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5421 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5422 | if (ssid) { |
| 5423 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5424 | err = -EINVAL; |
| 5425 | goto out_free; |
| 5426 | } |
| 5427 | memcpy(request->match_sets[i].ssid.ssid, |
| 5428 | nla_data(ssid), nla_len(ssid)); |
| 5429 | request->match_sets[i].ssid.ssid_len = |
| 5430 | nla_len(ssid); |
| 5431 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5432 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5433 | if (rssi) |
| 5434 | request->rssi_thold = nla_get_u32(rssi); |
| 5435 | else |
| 5436 | request->rssi_thold = |
| 5437 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5438 | i++; |
| 5439 | } |
| 5440 | } |
| 5441 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5442 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5443 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5444 | memcpy((void *)request->ie, |
| 5445 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5446 | request->ie_len); |
| 5447 | } |
| 5448 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5449 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5450 | request->flags = nla_get_u32( |
| 5451 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5452 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5453 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5454 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5455 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5456 | err = -EOPNOTSUPP; |
| 5457 | goto out_free; |
| 5458 | } |
| 5459 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5460 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5461 | request->dev = dev; |
| 5462 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5463 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5464 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5465 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5466 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5467 | if (!err) { |
| 5468 | rdev->sched_scan_req = request; |
| 5469 | nl80211_send_sched_scan(rdev, dev, |
| 5470 | NL80211_CMD_START_SCHED_SCAN); |
| 5471 | goto out; |
| 5472 | } |
| 5473 | |
| 5474 | out_free: |
| 5475 | kfree(request); |
| 5476 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5477 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5478 | return err; |
| 5479 | } |
| 5480 | |
| 5481 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5482 | struct genl_info *info) |
| 5483 | { |
| 5484 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5485 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5486 | |
| 5487 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5488 | !rdev->ops->sched_scan_stop) |
| 5489 | return -EOPNOTSUPP; |
| 5490 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5491 | mutex_lock(&rdev->sched_scan_mtx); |
| 5492 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 5493 | mutex_unlock(&rdev->sched_scan_mtx); |
| 5494 | |
| 5495 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5496 | } |
| 5497 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5498 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5499 | struct genl_info *info) |
| 5500 | { |
| 5501 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5502 | struct net_device *dev = info->user_ptr[1]; |
| 5503 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5504 | struct cfg80211_chan_def chandef; |
| 5505 | int err; |
| 5506 | |
| 5507 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5508 | if (err) |
| 5509 | return err; |
| 5510 | |
| 5511 | if (wdev->cac_started) |
| 5512 | return -EBUSY; |
| 5513 | |
| 5514 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5515 | if (err < 0) |
| 5516 | return err; |
| 5517 | |
| 5518 | if (err == 0) |
| 5519 | return -EINVAL; |
| 5520 | |
| 5521 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5522 | return -EINVAL; |
| 5523 | |
| 5524 | if (!rdev->ops->start_radar_detection) |
| 5525 | return -EOPNOTSUPP; |
| 5526 | |
| 5527 | mutex_lock(&rdev->devlist_mtx); |
| 5528 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5529 | chandef.chan, CHAN_MODE_SHARED, |
| 5530 | BIT(chandef.width)); |
| 5531 | if (err) |
| 5532 | goto err_locked; |
| 5533 | |
| 5534 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5535 | if (!err) { |
| 5536 | wdev->channel = chandef.chan; |
| 5537 | wdev->cac_started = true; |
| 5538 | wdev->cac_start_time = jiffies; |
| 5539 | } |
| 5540 | err_locked: |
| 5541 | mutex_unlock(&rdev->devlist_mtx); |
| 5542 | |
| 5543 | return err; |
| 5544 | } |
| 5545 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5546 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5547 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5548 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5549 | struct wireless_dev *wdev, |
| 5550 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5551 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5552 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5553 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5554 | void *hdr; |
| 5555 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5556 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5557 | |
| 5558 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5559 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5560 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5561 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5562 | if (!hdr) |
| 5563 | return -1; |
| 5564 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5565 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5566 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 5567 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5568 | goto nla_put_failure; |
| 5569 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5570 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5571 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 5572 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5573 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5574 | |
| 5575 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5576 | if (!bss) |
| 5577 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5578 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5579 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5580 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5581 | |
| 5582 | rcu_read_lock(); |
| 5583 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5584 | if (ies) { |
| 5585 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5586 | goto fail_unlock_rcu; |
| 5587 | tsf = true; |
| 5588 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5589 | ies->len, ies->data)) |
| 5590 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5591 | } |
| 5592 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5593 | if (ies) { |
| 5594 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5595 | goto fail_unlock_rcu; |
| 5596 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5597 | ies->len, ies->data)) |
| 5598 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5599 | } |
| 5600 | rcu_read_unlock(); |
| 5601 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5602 | if (res->beacon_interval && |
| 5603 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5604 | goto nla_put_failure; |
| 5605 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5606 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5607 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5608 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5609 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5610 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5611 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5612 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5613 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5614 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5615 | break; |
| 5616 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5617 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5618 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5619 | break; |
| 5620 | default: |
| 5621 | break; |
| 5622 | } |
| 5623 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5624 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5625 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5626 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5627 | if (intbss == wdev->current_bss && |
| 5628 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5629 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5630 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5631 | break; |
| 5632 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5633 | if (intbss == wdev->current_bss && |
| 5634 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5635 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5636 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5637 | break; |
| 5638 | default: |
| 5639 | break; |
| 5640 | } |
| 5641 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5642 | nla_nest_end(msg, bss); |
| 5643 | |
| 5644 | return genlmsg_end(msg, hdr); |
| 5645 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5646 | fail_unlock_rcu: |
| 5647 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5648 | nla_put_failure: |
| 5649 | genlmsg_cancel(msg, hdr); |
| 5650 | return -EMSGSIZE; |
| 5651 | } |
| 5652 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 5653 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5654 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5655 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5656 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5657 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 5658 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5659 | int err; |
| 5660 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 5661 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5662 | if (err) |
| 5663 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5664 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5665 | wdev_lock(wdev); |
| 5666 | spin_lock_bh(&rdev->bss_lock); |
| 5667 | cfg80211_bss_expire(rdev); |
| 5668 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5669 | cb->seq = rdev->bss_generation; |
| 5670 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5671 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5672 | if (++idx <= start) |
| 5673 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5674 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5675 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5676 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5677 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5678 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5679 | } |
| 5680 | } |
| 5681 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5682 | spin_unlock_bh(&rdev->bss_lock); |
| 5683 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5684 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 5685 | cb->args[2] = idx; |
| 5686 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5687 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5688 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5689 | } |
| 5690 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5691 | 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] | 5692 | int flags, struct net_device *dev, |
| 5693 | struct survey_info *survey) |
| 5694 | { |
| 5695 | void *hdr; |
| 5696 | struct nlattr *infoattr; |
| 5697 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5698 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5699 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5700 | if (!hdr) |
| 5701 | return -ENOMEM; |
| 5702 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5703 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5704 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5705 | |
| 5706 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5707 | if (!infoattr) |
| 5708 | goto nla_put_failure; |
| 5709 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5710 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5711 | survey->channel->center_freq)) |
| 5712 | goto nla_put_failure; |
| 5713 | |
| 5714 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5715 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5716 | goto nla_put_failure; |
| 5717 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5718 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5719 | goto nla_put_failure; |
| 5720 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5721 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5722 | survey->channel_time)) |
| 5723 | goto nla_put_failure; |
| 5724 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5725 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5726 | survey->channel_time_busy)) |
| 5727 | goto nla_put_failure; |
| 5728 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5729 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5730 | survey->channel_time_ext_busy)) |
| 5731 | goto nla_put_failure; |
| 5732 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5733 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5734 | survey->channel_time_rx)) |
| 5735 | goto nla_put_failure; |
| 5736 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5737 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5738 | survey->channel_time_tx)) |
| 5739 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5740 | |
| 5741 | nla_nest_end(msg, infoattr); |
| 5742 | |
| 5743 | return genlmsg_end(msg, hdr); |
| 5744 | |
| 5745 | nla_put_failure: |
| 5746 | genlmsg_cancel(msg, hdr); |
| 5747 | return -EMSGSIZE; |
| 5748 | } |
| 5749 | |
| 5750 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5751 | struct netlink_callback *cb) |
| 5752 | { |
| 5753 | struct survey_info survey; |
| 5754 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 5755 | struct wireless_dev *wdev; |
| 5756 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5757 | int res; |
| 5758 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 5759 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5760 | if (res) |
| 5761 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5762 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 5763 | if (!wdev->netdev) { |
| 5764 | res = -EINVAL; |
| 5765 | goto out_err; |
| 5766 | } |
| 5767 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5768 | if (!dev->ops->dump_survey) { |
| 5769 | res = -EOPNOTSUPP; |
| 5770 | goto out_err; |
| 5771 | } |
| 5772 | |
| 5773 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5774 | struct ieee80211_channel *chan; |
| 5775 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 5776 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5777 | if (res == -ENOENT) |
| 5778 | break; |
| 5779 | if (res) |
| 5780 | goto out_err; |
| 5781 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5782 | /* Survey without a channel doesn't make sense */ |
| 5783 | if (!survey.channel) { |
| 5784 | res = -EINVAL; |
| 5785 | goto out; |
| 5786 | } |
| 5787 | |
| 5788 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5789 | survey.channel->center_freq); |
| 5790 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5791 | survey_idx++; |
| 5792 | continue; |
| 5793 | } |
| 5794 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5795 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5796 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5797 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 5798 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5799 | goto out; |
| 5800 | survey_idx++; |
| 5801 | } |
| 5802 | |
| 5803 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 5804 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5805 | res = skb->len; |
| 5806 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame^] | 5807 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5808 | return res; |
| 5809 | } |
| 5810 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5811 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5812 | { |
| 5813 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5814 | NL80211_WPA_VERSION_2)); |
| 5815 | } |
| 5816 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5817 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5818 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5819 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5820 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5821 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5822 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5823 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5824 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5825 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5826 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5827 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5828 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5829 | return -EINVAL; |
| 5830 | |
| 5831 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5832 | return -EINVAL; |
| 5833 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5834 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5835 | return -EINVAL; |
| 5836 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5837 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5838 | return -EINVAL; |
| 5839 | |
| 5840 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5841 | return -EINVAL; |
| 5842 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5843 | err = nl80211_parse_key(info, &key); |
| 5844 | if (err) |
| 5845 | return err; |
| 5846 | |
| 5847 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5848 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5849 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5850 | if (!key.p.key || !key.p.key_len) |
| 5851 | return -EINVAL; |
| 5852 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5853 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5854 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5855 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5856 | return -EINVAL; |
| 5857 | if (key.idx > 4) |
| 5858 | return -EINVAL; |
| 5859 | } else { |
| 5860 | key.p.key_len = 0; |
| 5861 | key.p.key = NULL; |
| 5862 | } |
| 5863 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5864 | if (key.idx >= 0) { |
| 5865 | int i; |
| 5866 | bool ok = false; |
| 5867 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5868 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5869 | ok = true; |
| 5870 | break; |
| 5871 | } |
| 5872 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5873 | if (!ok) |
| 5874 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5875 | } |
| 5876 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5877 | if (!rdev->ops->auth) |
| 5878 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5879 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5880 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5881 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5882 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5883 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5884 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5885 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5886 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5887 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5888 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5889 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5890 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5891 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5892 | |
| 5893 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5894 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5895 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5896 | } |
| 5897 | |
| 5898 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5899 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5900 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5901 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5902 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5903 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5904 | return -EINVAL; |
| 5905 | |
| 5906 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5907 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5908 | return -EINVAL; |
| 5909 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5910 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5911 | /* need to include at least Auth Transaction and Status Code */ |
| 5912 | if (sae_data_len < 4) |
| 5913 | return -EINVAL; |
| 5914 | } |
| 5915 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5916 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5917 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5918 | /* |
| 5919 | * Since we no longer track auth state, ignore |
| 5920 | * requests to only change local state. |
| 5921 | */ |
| 5922 | if (local_state_change) |
| 5923 | return 0; |
| 5924 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5925 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5926 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5927 | key.p.key, key.p.key_len, key.idx, |
| 5928 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5929 | } |
| 5930 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5931 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5932 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5933 | struct cfg80211_crypto_settings *settings, |
| 5934 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5935 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5936 | memset(settings, 0, sizeof(*settings)); |
| 5937 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5938 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5939 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5940 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5941 | u16 proto; |
| 5942 | proto = nla_get_u16( |
| 5943 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5944 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5945 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5946 | proto != ETH_P_PAE) |
| 5947 | return -EINVAL; |
| 5948 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5949 | settings->control_port_no_encrypt = true; |
| 5950 | } else |
| 5951 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5952 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5953 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5954 | void *data; |
| 5955 | int len, i; |
| 5956 | |
| 5957 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5958 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5959 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5960 | |
| 5961 | if (len % sizeof(u32)) |
| 5962 | return -EINVAL; |
| 5963 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5964 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5965 | return -EINVAL; |
| 5966 | |
| 5967 | memcpy(settings->ciphers_pairwise, data, len); |
| 5968 | |
| 5969 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5970 | if (!cfg80211_supported_cipher_suite( |
| 5971 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5972 | settings->ciphers_pairwise[i])) |
| 5973 | return -EINVAL; |
| 5974 | } |
| 5975 | |
| 5976 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5977 | settings->cipher_group = |
| 5978 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5979 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5980 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5981 | return -EINVAL; |
| 5982 | } |
| 5983 | |
| 5984 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5985 | settings->wpa_versions = |
| 5986 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5987 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5988 | return -EINVAL; |
| 5989 | } |
| 5990 | |
| 5991 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5992 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5993 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5994 | |
| 5995 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5996 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5997 | settings->n_akm_suites = len / sizeof(u32); |
| 5998 | |
| 5999 | if (len % sizeof(u32)) |
| 6000 | return -EINVAL; |
| 6001 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6002 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6003 | return -EINVAL; |
| 6004 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6005 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6006 | } |
| 6007 | |
| 6008 | return 0; |
| 6009 | } |
| 6010 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6011 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6012 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6013 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6014 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6015 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6016 | struct cfg80211_assoc_request req = {}; |
| 6017 | const u8 *bssid, *ssid; |
| 6018 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6019 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6020 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6021 | return -EINVAL; |
| 6022 | |
| 6023 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6024 | !info->attrs[NL80211_ATTR_SSID] || |
| 6025 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6026 | return -EINVAL; |
| 6027 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6028 | if (!rdev->ops->assoc) |
| 6029 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6030 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6031 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6032 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6033 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6034 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6035 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6036 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6037 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6038 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6039 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6040 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6041 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6042 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6043 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6044 | |
| 6045 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6046 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6047 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6048 | } |
| 6049 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6050 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6051 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6052 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6053 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6054 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6055 | else if (mfp != NL80211_MFP_NO) |
| 6056 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6057 | } |
| 6058 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6059 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6060 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6061 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6062 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6063 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6064 | |
| 6065 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6066 | memcpy(&req.ht_capa_mask, |
| 6067 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6068 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6069 | |
| 6070 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6071 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6072 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6073 | memcpy(&req.ht_capa, |
| 6074 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6075 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6076 | } |
| 6077 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6078 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6079 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6080 | |
| 6081 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6082 | memcpy(&req.vht_capa_mask, |
| 6083 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6084 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6085 | |
| 6086 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6087 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6088 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6089 | memcpy(&req.vht_capa, |
| 6090 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6091 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6092 | } |
| 6093 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6094 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6095 | if (!err) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6096 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6097 | ssid, ssid_len, &req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6098 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6099 | return err; |
| 6100 | } |
| 6101 | |
| 6102 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6103 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6104 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6105 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6106 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6107 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6108 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6109 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6110 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6111 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6112 | return -EINVAL; |
| 6113 | |
| 6114 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6115 | return -EINVAL; |
| 6116 | |
| 6117 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6118 | return -EINVAL; |
| 6119 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6120 | if (!rdev->ops->deauth) |
| 6121 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6122 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6123 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6124 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6125 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6126 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6127 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6128 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6129 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6130 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6131 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6132 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6133 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6134 | |
| 6135 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6136 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6137 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6138 | } |
| 6139 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6140 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6141 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6142 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6143 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6144 | } |
| 6145 | |
| 6146 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6147 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6148 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6149 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6150 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6151 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6152 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6153 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6154 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6155 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6156 | return -EINVAL; |
| 6157 | |
| 6158 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6159 | return -EINVAL; |
| 6160 | |
| 6161 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6162 | return -EINVAL; |
| 6163 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6164 | if (!rdev->ops->disassoc) |
| 6165 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6166 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6167 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6168 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6169 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6170 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6171 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6172 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6173 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6174 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6175 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6176 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6177 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6178 | |
| 6179 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6180 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6181 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6182 | } |
| 6183 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6184 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6185 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6186 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6187 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6188 | } |
| 6189 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6190 | static bool |
| 6191 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6192 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6193 | int rateval) |
| 6194 | { |
| 6195 | struct wiphy *wiphy = &rdev->wiphy; |
| 6196 | bool found = false; |
| 6197 | int band, i; |
| 6198 | |
| 6199 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6200 | struct ieee80211_supported_band *sband; |
| 6201 | |
| 6202 | sband = wiphy->bands[band]; |
| 6203 | if (!sband) |
| 6204 | continue; |
| 6205 | |
| 6206 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6207 | if (sband->bitrates[i].bitrate == rateval) { |
| 6208 | mcast_rate[band] = i + 1; |
| 6209 | found = true; |
| 6210 | break; |
| 6211 | } |
| 6212 | } |
| 6213 | } |
| 6214 | |
| 6215 | return found; |
| 6216 | } |
| 6217 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6218 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6219 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6220 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6221 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6222 | struct cfg80211_ibss_params ibss; |
| 6223 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6224 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6225 | int err; |
| 6226 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6227 | memset(&ibss, 0, sizeof(ibss)); |
| 6228 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6229 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6230 | return -EINVAL; |
| 6231 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6232 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6233 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6234 | return -EINVAL; |
| 6235 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6236 | ibss.beacon_interval = 100; |
| 6237 | |
| 6238 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6239 | ibss.beacon_interval = |
| 6240 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6241 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6242 | return -EINVAL; |
| 6243 | } |
| 6244 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6245 | if (!rdev->ops->join_ibss) |
| 6246 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6247 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6248 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6249 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6250 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6251 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6252 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6253 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6254 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6255 | |
| 6256 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6257 | return -EINVAL; |
| 6258 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6259 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6260 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6261 | |
| 6262 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6263 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6264 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6265 | } |
| 6266 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6267 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6268 | if (err) |
| 6269 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6270 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6271 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6272 | return -EINVAL; |
| 6273 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6274 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 6275 | return -EINVAL; |
| 6276 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 6277 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 6278 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6279 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6280 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6281 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6282 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6283 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6284 | u8 *rates = |
| 6285 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6286 | int n_rates = |
| 6287 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6288 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6289 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6290 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6291 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6292 | &ibss.basic_rates); |
| 6293 | if (err) |
| 6294 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6295 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6296 | |
| 6297 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6298 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6299 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6300 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6301 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6302 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6303 | bool no_ht = false; |
| 6304 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6305 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6306 | info->attrs[NL80211_ATTR_KEYS], |
| 6307 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6308 | if (IS_ERR(connkeys)) |
| 6309 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6310 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6311 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6312 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6313 | kfree(connkeys); |
| 6314 | return -EINVAL; |
| 6315 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6316 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6317 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6318 | ibss.control_port = |
| 6319 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6320 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6321 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6322 | if (err) |
| 6323 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6324 | return err; |
| 6325 | } |
| 6326 | |
| 6327 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6328 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6330 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6331 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6332 | if (!rdev->ops->leave_ibss) |
| 6333 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6334 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6335 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6336 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6337 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6338 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6339 | } |
| 6340 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6341 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6342 | { |
| 6343 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6344 | struct net_device *dev = info->user_ptr[1]; |
| 6345 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6346 | u32 nla_rate; |
| 6347 | int err; |
| 6348 | |
| 6349 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6350 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6351 | return -EOPNOTSUPP; |
| 6352 | |
| 6353 | if (!rdev->ops->set_mcast_rate) |
| 6354 | return -EOPNOTSUPP; |
| 6355 | |
| 6356 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6357 | |
| 6358 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6359 | return -EINVAL; |
| 6360 | |
| 6361 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6362 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6363 | return -EINVAL; |
| 6364 | |
| 6365 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6366 | |
| 6367 | return err; |
| 6368 | } |
| 6369 | |
| 6370 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6371 | #ifdef CONFIG_NL80211_TESTMODE |
| 6372 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6373 | .name = "testmode", |
| 6374 | }; |
| 6375 | |
| 6376 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6377 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6378 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6379 | int err; |
| 6380 | |
| 6381 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6382 | return -EINVAL; |
| 6383 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6384 | err = -EOPNOTSUPP; |
| 6385 | if (rdev->ops->testmode_cmd) { |
| 6386 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6387 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6388 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6389 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 6390 | rdev->testmode_info = NULL; |
| 6391 | } |
| 6392 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6393 | return err; |
| 6394 | } |
| 6395 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6396 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6397 | struct netlink_callback *cb) |
| 6398 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6399 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6400 | int err; |
| 6401 | long phy_idx; |
| 6402 | void *data = NULL; |
| 6403 | int data_len = 0; |
| 6404 | |
| 6405 | if (cb->args[0]) { |
| 6406 | /* |
| 6407 | * 0 is a valid index, but not valid for args[0], |
| 6408 | * so we need to offset by 1. |
| 6409 | */ |
| 6410 | phy_idx = cb->args[0] - 1; |
| 6411 | } else { |
| 6412 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6413 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6414 | nl80211_policy); |
| 6415 | if (err) |
| 6416 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6417 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6418 | mutex_lock(&cfg80211_mutex); |
| 6419 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6420 | nl80211_fam.attrbuf); |
| 6421 | if (IS_ERR(rdev)) { |
| 6422 | mutex_unlock(&cfg80211_mutex); |
| 6423 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6424 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6425 | phy_idx = rdev->wiphy_idx; |
| 6426 | rdev = NULL; |
| 6427 | mutex_unlock(&cfg80211_mutex); |
| 6428 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6429 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6430 | cb->args[1] = |
| 6431 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6432 | } |
| 6433 | |
| 6434 | if (cb->args[1]) { |
| 6435 | data = nla_data((void *)cb->args[1]); |
| 6436 | data_len = nla_len((void *)cb->args[1]); |
| 6437 | } |
| 6438 | |
| 6439 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6440 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6441 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6442 | mutex_unlock(&cfg80211_mutex); |
| 6443 | return -ENOENT; |
| 6444 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6445 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6446 | mutex_unlock(&cfg80211_mutex); |
| 6447 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6448 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6449 | err = -EOPNOTSUPP; |
| 6450 | goto out_err; |
| 6451 | } |
| 6452 | |
| 6453 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6454 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6455 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6456 | NL80211_CMD_TESTMODE); |
| 6457 | struct nlattr *tmdata; |
| 6458 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6459 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6460 | genlmsg_cancel(skb, hdr); |
| 6461 | break; |
| 6462 | } |
| 6463 | |
| 6464 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6465 | if (!tmdata) { |
| 6466 | genlmsg_cancel(skb, hdr); |
| 6467 | break; |
| 6468 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6469 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6470 | nla_nest_end(skb, tmdata); |
| 6471 | |
| 6472 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6473 | genlmsg_cancel(skb, hdr); |
| 6474 | break; |
| 6475 | } else if (err) { |
| 6476 | genlmsg_cancel(skb, hdr); |
| 6477 | goto out_err; |
| 6478 | } |
| 6479 | |
| 6480 | genlmsg_end(skb, hdr); |
| 6481 | } |
| 6482 | |
| 6483 | err = skb->len; |
| 6484 | /* see above */ |
| 6485 | cb->args[0] = phy_idx + 1; |
| 6486 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6487 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6488 | return err; |
| 6489 | } |
| 6490 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6491 | static struct sk_buff * |
| 6492 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6493 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6494 | { |
| 6495 | struct sk_buff *skb; |
| 6496 | void *hdr; |
| 6497 | struct nlattr *data; |
| 6498 | |
| 6499 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6500 | if (!skb) |
| 6501 | return NULL; |
| 6502 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6503 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6504 | if (!hdr) { |
| 6505 | kfree_skb(skb); |
| 6506 | return NULL; |
| 6507 | } |
| 6508 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6509 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6510 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6511 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6512 | |
| 6513 | ((void **)skb->cb)[0] = rdev; |
| 6514 | ((void **)skb->cb)[1] = hdr; |
| 6515 | ((void **)skb->cb)[2] = data; |
| 6516 | |
| 6517 | return skb; |
| 6518 | |
| 6519 | nla_put_failure: |
| 6520 | kfree_skb(skb); |
| 6521 | return NULL; |
| 6522 | } |
| 6523 | |
| 6524 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6525 | int approxlen) |
| 6526 | { |
| 6527 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6528 | |
| 6529 | if (WARN_ON(!rdev->testmode_info)) |
| 6530 | return NULL; |
| 6531 | |
| 6532 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6533 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6534 | rdev->testmode_info->snd_seq, |
| 6535 | GFP_KERNEL); |
| 6536 | } |
| 6537 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6538 | |
| 6539 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6540 | { |
| 6541 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6542 | void *hdr = ((void **)skb->cb)[1]; |
| 6543 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6544 | |
| 6545 | if (WARN_ON(!rdev->testmode_info)) { |
| 6546 | kfree_skb(skb); |
| 6547 | return -EINVAL; |
| 6548 | } |
| 6549 | |
| 6550 | nla_nest_end(skb, data); |
| 6551 | genlmsg_end(skb, hdr); |
| 6552 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6553 | } |
| 6554 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6555 | |
| 6556 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6557 | int approxlen, gfp_t gfp) |
| 6558 | { |
| 6559 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6560 | |
| 6561 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6562 | } |
| 6563 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6564 | |
| 6565 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6566 | { |
| 6567 | void *hdr = ((void **)skb->cb)[1]; |
| 6568 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6569 | |
| 6570 | nla_nest_end(skb, data); |
| 6571 | genlmsg_end(skb, hdr); |
| 6572 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6573 | } |
| 6574 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6575 | #endif |
| 6576 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6577 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6578 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6579 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6580 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6581 | struct cfg80211_connect_params connect; |
| 6582 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6583 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6584 | int err; |
| 6585 | |
| 6586 | memset(&connect, 0, sizeof(connect)); |
| 6587 | |
| 6588 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6589 | return -EINVAL; |
| 6590 | |
| 6591 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6592 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6593 | return -EINVAL; |
| 6594 | |
| 6595 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6596 | connect.auth_type = |
| 6597 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6598 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6599 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6600 | return -EINVAL; |
| 6601 | } else |
| 6602 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6603 | |
| 6604 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6605 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6606 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6607 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6608 | if (err) |
| 6609 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6610 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6611 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6612 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6613 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6614 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6615 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6616 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6617 | connect.bg_scan_period = -1; |
| 6618 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6619 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6620 | connect.bg_scan_period = |
| 6621 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6622 | } |
| 6623 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6624 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6625 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6626 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6627 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6628 | |
| 6629 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6630 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6631 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6632 | } |
| 6633 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6634 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6635 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6636 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6637 | connect.mfp != NL80211_MFP_NO) |
| 6638 | return -EINVAL; |
| 6639 | } else { |
| 6640 | connect.mfp = NL80211_MFP_NO; |
| 6641 | } |
| 6642 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6643 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6644 | connect.channel = |
| 6645 | ieee80211_get_channel(wiphy, |
| 6646 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6647 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6648 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6649 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6650 | } |
| 6651 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6652 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6653 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6654 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6655 | if (IS_ERR(connkeys)) |
| 6656 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6657 | } |
| 6658 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6659 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6660 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6661 | |
| 6662 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6663 | memcpy(&connect.ht_capa_mask, |
| 6664 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6665 | sizeof(connect.ht_capa_mask)); |
| 6666 | |
| 6667 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6668 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6669 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6670 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6671 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6672 | memcpy(&connect.ht_capa, |
| 6673 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6674 | sizeof(connect.ht_capa)); |
| 6675 | } |
| 6676 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6677 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6678 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6679 | |
| 6680 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6681 | memcpy(&connect.vht_capa_mask, |
| 6682 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6683 | sizeof(connect.vht_capa_mask)); |
| 6684 | |
| 6685 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 6686 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 6687 | kfree(connkeys); |
| 6688 | return -EINVAL; |
| 6689 | } |
| 6690 | memcpy(&connect.vht_capa, |
| 6691 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6692 | sizeof(connect.vht_capa)); |
| 6693 | } |
| 6694 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6695 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6696 | if (err) |
| 6697 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6698 | return err; |
| 6699 | } |
| 6700 | |
| 6701 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6702 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6703 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6704 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6705 | u16 reason; |
| 6706 | |
| 6707 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6708 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6709 | else |
| 6710 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6711 | |
| 6712 | if (reason == 0) |
| 6713 | return -EINVAL; |
| 6714 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6715 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6716 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6717 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6718 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6719 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6720 | } |
| 6721 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6722 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6723 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6724 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6725 | struct net *net; |
| 6726 | int err; |
| 6727 | u32 pid; |
| 6728 | |
| 6729 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6730 | return -EINVAL; |
| 6731 | |
| 6732 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6733 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6734 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6735 | if (IS_ERR(net)) |
| 6736 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6737 | |
| 6738 | err = 0; |
| 6739 | |
| 6740 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6741 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6742 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6743 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6744 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6745 | return err; |
| 6746 | } |
| 6747 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6748 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6749 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6750 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6751 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6752 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6753 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6754 | struct cfg80211_pmksa pmksa; |
| 6755 | |
| 6756 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6757 | |
| 6758 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6759 | return -EINVAL; |
| 6760 | |
| 6761 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6762 | return -EINVAL; |
| 6763 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6764 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6765 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6766 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6767 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6768 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6769 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6770 | |
| 6771 | switch (info->genlhdr->cmd) { |
| 6772 | case NL80211_CMD_SET_PMKSA: |
| 6773 | rdev_ops = rdev->ops->set_pmksa; |
| 6774 | break; |
| 6775 | case NL80211_CMD_DEL_PMKSA: |
| 6776 | rdev_ops = rdev->ops->del_pmksa; |
| 6777 | break; |
| 6778 | default: |
| 6779 | WARN_ON(1); |
| 6780 | break; |
| 6781 | } |
| 6782 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6783 | if (!rdev_ops) |
| 6784 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6785 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6786 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6787 | } |
| 6788 | |
| 6789 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6790 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6791 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6792 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6793 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6794 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6795 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6796 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6797 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6798 | if (!rdev->ops->flush_pmksa) |
| 6799 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6800 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6801 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6802 | } |
| 6803 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6804 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6805 | { |
| 6806 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6807 | struct net_device *dev = info->user_ptr[1]; |
| 6808 | u8 action_code, dialog_token; |
| 6809 | u16 status_code; |
| 6810 | u8 *peer; |
| 6811 | |
| 6812 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6813 | !rdev->ops->tdls_mgmt) |
| 6814 | return -EOPNOTSUPP; |
| 6815 | |
| 6816 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6817 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6818 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6819 | !info->attrs[NL80211_ATTR_IE] || |
| 6820 | !info->attrs[NL80211_ATTR_MAC]) |
| 6821 | return -EINVAL; |
| 6822 | |
| 6823 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6824 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6825 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6826 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6827 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6828 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6829 | dialog_token, status_code, |
| 6830 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6831 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6832 | } |
| 6833 | |
| 6834 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6835 | { |
| 6836 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6837 | struct net_device *dev = info->user_ptr[1]; |
| 6838 | enum nl80211_tdls_operation operation; |
| 6839 | u8 *peer; |
| 6840 | |
| 6841 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6842 | !rdev->ops->tdls_oper) |
| 6843 | return -EOPNOTSUPP; |
| 6844 | |
| 6845 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6846 | !info->attrs[NL80211_ATTR_MAC]) |
| 6847 | return -EINVAL; |
| 6848 | |
| 6849 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6850 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6851 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6852 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6853 | } |
| 6854 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6855 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6856 | struct genl_info *info) |
| 6857 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6858 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6859 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6860 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6861 | struct sk_buff *msg; |
| 6862 | void *hdr; |
| 6863 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6864 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6865 | int err; |
| 6866 | |
| 6867 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6868 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6869 | return -EINVAL; |
| 6870 | |
| 6871 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6872 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6873 | if (!rdev->ops->remain_on_channel || |
| 6874 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6875 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6876 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6877 | /* |
| 6878 | * We should be on that channel for at least a minimum amount of |
| 6879 | * time (10ms) but no longer than the driver supports. |
| 6880 | */ |
| 6881 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6882 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6883 | return -EINVAL; |
| 6884 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6885 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6886 | if (err) |
| 6887 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6888 | |
| 6889 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6890 | if (!msg) |
| 6891 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6892 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6893 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6894 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6895 | |
| 6896 | if (IS_ERR(hdr)) { |
| 6897 | err = PTR_ERR(hdr); |
| 6898 | goto free_msg; |
| 6899 | } |
| 6900 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6901 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6902 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6903 | |
| 6904 | if (err) |
| 6905 | goto free_msg; |
| 6906 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6907 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6908 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6909 | |
| 6910 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6911 | |
| 6912 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6913 | |
| 6914 | nla_put_failure: |
| 6915 | err = -ENOBUFS; |
| 6916 | free_msg: |
| 6917 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6918 | return err; |
| 6919 | } |
| 6920 | |
| 6921 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6922 | struct genl_info *info) |
| 6923 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6924 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6925 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6926 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6927 | |
| 6928 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6929 | return -EINVAL; |
| 6930 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6931 | if (!rdev->ops->cancel_remain_on_channel) |
| 6932 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6933 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6934 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6935 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6936 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6937 | } |
| 6938 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6939 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6940 | u8 *rates, u8 rates_len) |
| 6941 | { |
| 6942 | u8 i; |
| 6943 | u32 mask = 0; |
| 6944 | |
| 6945 | for (i = 0; i < rates_len; i++) { |
| 6946 | int rate = (rates[i] & 0x7f) * 5; |
| 6947 | int ridx; |
| 6948 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6949 | struct ieee80211_rate *srate = |
| 6950 | &sband->bitrates[ridx]; |
| 6951 | if (rate == srate->bitrate) { |
| 6952 | mask |= 1 << ridx; |
| 6953 | break; |
| 6954 | } |
| 6955 | } |
| 6956 | if (ridx == sband->n_bitrates) |
| 6957 | return 0; /* rate not found */ |
| 6958 | } |
| 6959 | |
| 6960 | return mask; |
| 6961 | } |
| 6962 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6963 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6964 | u8 *rates, u8 rates_len, |
| 6965 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6966 | { |
| 6967 | u8 i; |
| 6968 | |
| 6969 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6970 | |
| 6971 | for (i = 0; i < rates_len; i++) { |
| 6972 | int ridx, rbit; |
| 6973 | |
| 6974 | ridx = rates[i] / 8; |
| 6975 | rbit = BIT(rates[i] % 8); |
| 6976 | |
| 6977 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6978 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6979 | return false; |
| 6980 | |
| 6981 | /* check availability */ |
| 6982 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6983 | mcs[ridx] |= rbit; |
| 6984 | else |
| 6985 | return false; |
| 6986 | } |
| 6987 | |
| 6988 | return true; |
| 6989 | } |
| 6990 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6991 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6992 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6993 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6994 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6995 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6996 | }; |
| 6997 | |
| 6998 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6999 | struct genl_info *info) |
| 7000 | { |
| 7001 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7003 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7004 | int rem, i; |
| 7005 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7006 | struct nlattr *tx_rates; |
| 7007 | struct ieee80211_supported_band *sband; |
| 7008 | |
| 7009 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7010 | return -EINVAL; |
| 7011 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7012 | if (!rdev->ops->set_bitrate_mask) |
| 7013 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7014 | |
| 7015 | memset(&mask, 0, sizeof(mask)); |
| 7016 | /* Default to all rates enabled */ |
| 7017 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7018 | sband = rdev->wiphy.bands[i]; |
| 7019 | mask.control[i].legacy = |
| 7020 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7021 | if (sband) |
| 7022 | memcpy(mask.control[i].mcs, |
| 7023 | sband->ht_cap.mcs.rx_mask, |
| 7024 | sizeof(mask.control[i].mcs)); |
| 7025 | else |
| 7026 | memset(mask.control[i].mcs, 0, |
| 7027 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7028 | } |
| 7029 | |
| 7030 | /* |
| 7031 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7032 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7033 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7034 | 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] | 7035 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7036 | { |
| 7037 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7038 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7039 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7040 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7041 | if (sband == NULL) |
| 7042 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7043 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7044 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7045 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7046 | mask.control[band].legacy = rateset_to_mask( |
| 7047 | sband, |
| 7048 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7049 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7050 | if ((mask.control[band].legacy == 0) && |
| 7051 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7052 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7053 | } |
| 7054 | if (tb[NL80211_TXRATE_MCS]) { |
| 7055 | if (!ht_rateset_to_mask( |
| 7056 | sband, |
| 7057 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7058 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7059 | mask.control[band].mcs)) |
| 7060 | return -EINVAL; |
| 7061 | } |
| 7062 | |
| 7063 | if (mask.control[band].legacy == 0) { |
| 7064 | /* don't allow empty legacy rates if HT |
| 7065 | * is not even supported. */ |
| 7066 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7067 | return -EINVAL; |
| 7068 | |
| 7069 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7070 | if (mask.control[band].mcs[i]) |
| 7071 | break; |
| 7072 | |
| 7073 | /* legacy and mcs rates may not be both empty */ |
| 7074 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7075 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7076 | } |
| 7077 | } |
| 7078 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7079 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7080 | } |
| 7081 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7082 | 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] | 7083 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7084 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7085 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7086 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7087 | |
| 7088 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7089 | return -EINVAL; |
| 7090 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7091 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7092 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7093 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7094 | switch (wdev->iftype) { |
| 7095 | case NL80211_IFTYPE_STATION: |
| 7096 | case NL80211_IFTYPE_ADHOC: |
| 7097 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7098 | case NL80211_IFTYPE_AP: |
| 7099 | case NL80211_IFTYPE_AP_VLAN: |
| 7100 | case NL80211_IFTYPE_MESH_POINT: |
| 7101 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7102 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7103 | break; |
| 7104 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7105 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7106 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7107 | |
| 7108 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7109 | if (!rdev->ops->mgmt_tx) |
| 7110 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7111 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7112 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7113 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7114 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7115 | } |
| 7116 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7117 | 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] | 7118 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7119 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7120 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7121 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7122 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7123 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7124 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7125 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7126 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7127 | bool offchan, no_cck, dont_wait_for_ack; |
| 7128 | |
| 7129 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7130 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7131 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7132 | return -EINVAL; |
| 7133 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7134 | if (!rdev->ops->mgmt_tx) |
| 7135 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7136 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7137 | switch (wdev->iftype) { |
| 7138 | case NL80211_IFTYPE_STATION: |
| 7139 | case NL80211_IFTYPE_ADHOC: |
| 7140 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7141 | case NL80211_IFTYPE_AP: |
| 7142 | case NL80211_IFTYPE_AP_VLAN: |
| 7143 | case NL80211_IFTYPE_MESH_POINT: |
| 7144 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7145 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7146 | break; |
| 7147 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7148 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7149 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7150 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7151 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7152 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7153 | return -EINVAL; |
| 7154 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7155 | |
| 7156 | /* |
| 7157 | * We should wait on the channel for at least a minimum amount |
| 7158 | * of time (10ms) but no longer than the driver supports. |
| 7159 | */ |
| 7160 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7161 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7162 | return -EINVAL; |
| 7163 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7164 | } |
| 7165 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7166 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7167 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7168 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7169 | return -EINVAL; |
| 7170 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7171 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7172 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7173 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7174 | if (err) |
| 7175 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7176 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7177 | if (!dont_wait_for_ack) { |
| 7178 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7179 | if (!msg) |
| 7180 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7181 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7182 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7183 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7184 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7185 | if (IS_ERR(hdr)) { |
| 7186 | err = PTR_ERR(hdr); |
| 7187 | goto free_msg; |
| 7188 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7189 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7190 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7191 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7192 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7193 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7194 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7195 | if (err) |
| 7196 | goto free_msg; |
| 7197 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7198 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7199 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7200 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7201 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7202 | genlmsg_end(msg, hdr); |
| 7203 | return genlmsg_reply(msg, info); |
| 7204 | } |
| 7205 | |
| 7206 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7207 | |
| 7208 | nla_put_failure: |
| 7209 | err = -ENOBUFS; |
| 7210 | free_msg: |
| 7211 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7212 | return err; |
| 7213 | } |
| 7214 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7215 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7216 | { |
| 7217 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7218 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7219 | u64 cookie; |
| 7220 | |
| 7221 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7222 | return -EINVAL; |
| 7223 | |
| 7224 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7225 | return -EOPNOTSUPP; |
| 7226 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7227 | switch (wdev->iftype) { |
| 7228 | case NL80211_IFTYPE_STATION: |
| 7229 | case NL80211_IFTYPE_ADHOC: |
| 7230 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7231 | case NL80211_IFTYPE_AP: |
| 7232 | case NL80211_IFTYPE_AP_VLAN: |
| 7233 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7234 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7235 | break; |
| 7236 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7237 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7238 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7239 | |
| 7240 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7241 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7242 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7243 | } |
| 7244 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7245 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7246 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7247 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7248 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7249 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7250 | u8 ps_state; |
| 7251 | bool state; |
| 7252 | int err; |
| 7253 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7254 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7255 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7256 | |
| 7257 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7258 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7259 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7260 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7261 | |
| 7262 | wdev = dev->ieee80211_ptr; |
| 7263 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7264 | if (!rdev->ops->set_power_mgmt) |
| 7265 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7266 | |
| 7267 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7268 | |
| 7269 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7270 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7271 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7272 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7273 | if (!err) |
| 7274 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7275 | return err; |
| 7276 | } |
| 7277 | |
| 7278 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7279 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7280 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7281 | enum nl80211_ps_state ps_state; |
| 7282 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7283 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7284 | struct sk_buff *msg; |
| 7285 | void *hdr; |
| 7286 | int err; |
| 7287 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7288 | wdev = dev->ieee80211_ptr; |
| 7289 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7290 | if (!rdev->ops->set_power_mgmt) |
| 7291 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7292 | |
| 7293 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7294 | if (!msg) |
| 7295 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7296 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7297 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7298 | NL80211_CMD_GET_POWER_SAVE); |
| 7299 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7300 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7301 | goto free_msg; |
| 7302 | } |
| 7303 | |
| 7304 | if (wdev->ps) |
| 7305 | ps_state = NL80211_PS_ENABLED; |
| 7306 | else |
| 7307 | ps_state = NL80211_PS_DISABLED; |
| 7308 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7309 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7310 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7311 | |
| 7312 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7313 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7314 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7315 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7316 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7317 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7318 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7319 | return err; |
| 7320 | } |
| 7321 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7322 | static struct nla_policy |
| 7323 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7324 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7325 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7326 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7327 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7328 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7329 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7330 | }; |
| 7331 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7332 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7333 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7334 | { |
| 7335 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7336 | struct wireless_dev *wdev; |
| 7337 | struct net_device *dev = info->user_ptr[1]; |
| 7338 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7339 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7340 | return -EINVAL; |
| 7341 | |
| 7342 | wdev = dev->ieee80211_ptr; |
| 7343 | |
| 7344 | if (!rdev->ops->set_cqm_txe_config) |
| 7345 | return -EOPNOTSUPP; |
| 7346 | |
| 7347 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7348 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7349 | return -EOPNOTSUPP; |
| 7350 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7351 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7352 | } |
| 7353 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7354 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7355 | s32 threshold, u32 hysteresis) |
| 7356 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7357 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7358 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7359 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7360 | |
| 7361 | if (threshold > 0) |
| 7362 | return -EINVAL; |
| 7363 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7364 | wdev = dev->ieee80211_ptr; |
| 7365 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7366 | if (!rdev->ops->set_cqm_rssi_config) |
| 7367 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7368 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7369 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7370 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7371 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7372 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7373 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7374 | } |
| 7375 | |
| 7376 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7377 | { |
| 7378 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7379 | struct nlattr *cqm; |
| 7380 | int err; |
| 7381 | |
| 7382 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 7383 | if (!cqm) { |
| 7384 | err = -EINVAL; |
| 7385 | goto out; |
| 7386 | } |
| 7387 | |
| 7388 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7389 | nl80211_attr_cqm_policy); |
| 7390 | if (err) |
| 7391 | goto out; |
| 7392 | |
| 7393 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7394 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 7395 | s32 threshold; |
| 7396 | u32 hysteresis; |
| 7397 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7398 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 7399 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7400 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7401 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7402 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7403 | u32 rate, pkts, intvl; |
| 7404 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7405 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7406 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7407 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7408 | } else |
| 7409 | err = -EINVAL; |
| 7410 | |
| 7411 | out: |
| 7412 | return err; |
| 7413 | } |
| 7414 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7415 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7416 | { |
| 7417 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7418 | struct net_device *dev = info->user_ptr[1]; |
| 7419 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7420 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7421 | int err; |
| 7422 | |
| 7423 | /* start with default */ |
| 7424 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7425 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7426 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7427 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7428 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7429 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7430 | if (err) |
| 7431 | return err; |
| 7432 | } |
| 7433 | |
| 7434 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7435 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7436 | return -EINVAL; |
| 7437 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7438 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7439 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7440 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7441 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7442 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7443 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7444 | return -EINVAL; |
| 7445 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7446 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7447 | setup.beacon_interval = |
| 7448 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7449 | if (setup.beacon_interval < 10 || |
| 7450 | setup.beacon_interval > 10000) |
| 7451 | return -EINVAL; |
| 7452 | } |
| 7453 | |
| 7454 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7455 | setup.dtim_period = |
| 7456 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7457 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7458 | return -EINVAL; |
| 7459 | } |
| 7460 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7461 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7462 | /* parse additional setup parameters if given */ |
| 7463 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7464 | if (err) |
| 7465 | return err; |
| 7466 | } |
| 7467 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7468 | if (setup.user_mpm) |
| 7469 | cfg.auto_open_plinks = false; |
| 7470 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7471 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7472 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7473 | if (err) |
| 7474 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7475 | } else { |
| 7476 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7477 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7478 | } |
| 7479 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7480 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7481 | } |
| 7482 | |
| 7483 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7484 | { |
| 7485 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7486 | struct net_device *dev = info->user_ptr[1]; |
| 7487 | |
| 7488 | return cfg80211_leave_mesh(rdev, dev); |
| 7489 | } |
| 7490 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7491 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7492 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7493 | struct cfg80211_registered_device *rdev) |
| 7494 | { |
| 7495 | struct nlattr *nl_pats, *nl_pat; |
| 7496 | int i, pat_len; |
| 7497 | |
| 7498 | if (!rdev->wowlan->n_patterns) |
| 7499 | return 0; |
| 7500 | |
| 7501 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7502 | if (!nl_pats) |
| 7503 | return -ENOBUFS; |
| 7504 | |
| 7505 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 7506 | nl_pat = nla_nest_start(msg, i + 1); |
| 7507 | if (!nl_pat) |
| 7508 | return -ENOBUFS; |
| 7509 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 7510 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 7511 | DIV_ROUND_UP(pat_len, 8), |
| 7512 | rdev->wowlan->patterns[i].mask) || |
| 7513 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 7514 | pat_len, rdev->wowlan->patterns[i].pattern) || |
| 7515 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
| 7516 | rdev->wowlan->patterns[i].pkt_offset)) |
| 7517 | return -ENOBUFS; |
| 7518 | nla_nest_end(msg, nl_pat); |
| 7519 | } |
| 7520 | nla_nest_end(msg, nl_pats); |
| 7521 | |
| 7522 | return 0; |
| 7523 | } |
| 7524 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7525 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7526 | struct cfg80211_wowlan_tcp *tcp) |
| 7527 | { |
| 7528 | struct nlattr *nl_tcp; |
| 7529 | |
| 7530 | if (!tcp) |
| 7531 | return 0; |
| 7532 | |
| 7533 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7534 | if (!nl_tcp) |
| 7535 | return -ENOBUFS; |
| 7536 | |
| 7537 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7538 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7539 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7540 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7541 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7542 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7543 | tcp->payload_len, tcp->payload) || |
| 7544 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7545 | tcp->data_interval) || |
| 7546 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7547 | tcp->wake_len, tcp->wake_data) || |
| 7548 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7549 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7550 | return -ENOBUFS; |
| 7551 | |
| 7552 | if (tcp->payload_seq.len && |
| 7553 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7554 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7555 | return -ENOBUFS; |
| 7556 | |
| 7557 | if (tcp->payload_tok.len && |
| 7558 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7559 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7560 | &tcp->payload_tok)) |
| 7561 | return -ENOBUFS; |
| 7562 | |
| 7563 | return 0; |
| 7564 | } |
| 7565 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7566 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7567 | { |
| 7568 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7569 | struct sk_buff *msg; |
| 7570 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7571 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7572 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7573 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7574 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7575 | return -EOPNOTSUPP; |
| 7576 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7577 | if (rdev->wowlan && rdev->wowlan->tcp) { |
| 7578 | /* adjust size to have room for all the data */ |
| 7579 | size += rdev->wowlan->tcp->tokens_size + |
| 7580 | rdev->wowlan->tcp->payload_len + |
| 7581 | rdev->wowlan->tcp->wake_len + |
| 7582 | rdev->wowlan->tcp->wake_len / 8; |
| 7583 | } |
| 7584 | |
| 7585 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7586 | if (!msg) |
| 7587 | return -ENOMEM; |
| 7588 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7589 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7590 | NL80211_CMD_GET_WOWLAN); |
| 7591 | if (!hdr) |
| 7592 | goto nla_put_failure; |
| 7593 | |
| 7594 | if (rdev->wowlan) { |
| 7595 | struct nlattr *nl_wowlan; |
| 7596 | |
| 7597 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7598 | if (!nl_wowlan) |
| 7599 | goto nla_put_failure; |
| 7600 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7601 | if ((rdev->wowlan->any && |
| 7602 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7603 | (rdev->wowlan->disconnect && |
| 7604 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7605 | (rdev->wowlan->magic_pkt && |
| 7606 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7607 | (rdev->wowlan->gtk_rekey_failure && |
| 7608 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7609 | (rdev->wowlan->eap_identity_req && |
| 7610 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7611 | (rdev->wowlan->four_way_handshake && |
| 7612 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7613 | (rdev->wowlan->rfkill_release && |
| 7614 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7615 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7616 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7617 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7618 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7619 | |
| 7620 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) |
| 7621 | goto nla_put_failure; |
| 7622 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7623 | nla_nest_end(msg, nl_wowlan); |
| 7624 | } |
| 7625 | |
| 7626 | genlmsg_end(msg, hdr); |
| 7627 | return genlmsg_reply(msg, info); |
| 7628 | |
| 7629 | nla_put_failure: |
| 7630 | nlmsg_free(msg); |
| 7631 | return -ENOBUFS; |
| 7632 | } |
| 7633 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7634 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7635 | struct nlattr *attr, |
| 7636 | struct cfg80211_wowlan *trig) |
| 7637 | { |
| 7638 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7639 | struct cfg80211_wowlan_tcp *cfg; |
| 7640 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7641 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7642 | u32 size; |
| 7643 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7644 | int err, port; |
| 7645 | |
| 7646 | if (!rdev->wiphy.wowlan.tcp) |
| 7647 | return -EINVAL; |
| 7648 | |
| 7649 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7650 | nla_data(attr), nla_len(attr), |
| 7651 | nl80211_wowlan_tcp_policy); |
| 7652 | if (err) |
| 7653 | return err; |
| 7654 | |
| 7655 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7656 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7657 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7658 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7659 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7660 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7661 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7662 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7663 | return -EINVAL; |
| 7664 | |
| 7665 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
| 7666 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) |
| 7667 | return -EINVAL; |
| 7668 | |
| 7669 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 7670 | rdev->wiphy.wowlan.tcp->data_interval_max || |
| 7671 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7672 | return -EINVAL; |
| 7673 | |
| 7674 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
| 7675 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) |
| 7676 | return -EINVAL; |
| 7677 | |
| 7678 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7679 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7680 | return -EINVAL; |
| 7681 | |
| 7682 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7683 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7684 | |
| 7685 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7686 | tokens_size = tokln - sizeof(*tok); |
| 7687 | |
| 7688 | if (!tok->len || tokens_size % tok->len) |
| 7689 | return -EINVAL; |
| 7690 | if (!rdev->wiphy.wowlan.tcp->tok) |
| 7691 | return -EINVAL; |
| 7692 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) |
| 7693 | return -EINVAL; |
| 7694 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) |
| 7695 | return -EINVAL; |
| 7696 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) |
| 7697 | return -EINVAL; |
| 7698 | if (tok->offset + tok->len > data_size) |
| 7699 | return -EINVAL; |
| 7700 | } |
| 7701 | |
| 7702 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7703 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
| 7704 | if (!rdev->wiphy.wowlan.tcp->seq) |
| 7705 | return -EINVAL; |
| 7706 | if (seq->len == 0 || seq->len > 4) |
| 7707 | return -EINVAL; |
| 7708 | if (seq->len + seq->offset > data_size) |
| 7709 | return -EINVAL; |
| 7710 | } |
| 7711 | |
| 7712 | size = sizeof(*cfg); |
| 7713 | size += data_size; |
| 7714 | size += wake_size + wake_mask_size; |
| 7715 | size += tokens_size; |
| 7716 | |
| 7717 | cfg = kzalloc(size, GFP_KERNEL); |
| 7718 | if (!cfg) |
| 7719 | return -ENOMEM; |
| 7720 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7721 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7722 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7723 | ETH_ALEN); |
| 7724 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7725 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7726 | else |
| 7727 | port = 0; |
| 7728 | #ifdef CONFIG_INET |
| 7729 | /* allocate a socket and port for it and use it */ |
| 7730 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7731 | IPPROTO_TCP, &cfg->sock, 1); |
| 7732 | if (err) { |
| 7733 | kfree(cfg); |
| 7734 | return err; |
| 7735 | } |
| 7736 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7737 | sock_release(cfg->sock); |
| 7738 | kfree(cfg); |
| 7739 | return -EADDRINUSE; |
| 7740 | } |
| 7741 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7742 | #else |
| 7743 | if (!port) { |
| 7744 | kfree(cfg); |
| 7745 | return -EINVAL; |
| 7746 | } |
| 7747 | cfg->src_port = port; |
| 7748 | #endif |
| 7749 | |
| 7750 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7751 | cfg->payload_len = data_size; |
| 7752 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7753 | memcpy((void *)cfg->payload, |
| 7754 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7755 | data_size); |
| 7756 | if (seq) |
| 7757 | cfg->payload_seq = *seq; |
| 7758 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7759 | cfg->wake_len = wake_size; |
| 7760 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7761 | memcpy((void *)cfg->wake_data, |
| 7762 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7763 | wake_size); |
| 7764 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7765 | data_size + wake_size; |
| 7766 | memcpy((void *)cfg->wake_mask, |
| 7767 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7768 | wake_mask_size); |
| 7769 | if (tok) { |
| 7770 | cfg->tokens_size = tokens_size; |
| 7771 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7772 | } |
| 7773 | |
| 7774 | trig->tcp = cfg; |
| 7775 | |
| 7776 | return 0; |
| 7777 | } |
| 7778 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7779 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7780 | { |
| 7781 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7782 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7783 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7784 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7785 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 7786 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7787 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7788 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7789 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7790 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7791 | return -EOPNOTSUPP; |
| 7792 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7793 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7794 | cfg80211_rdev_free_wowlan(rdev); |
| 7795 | rdev->wowlan = NULL; |
| 7796 | goto set_wakeup; |
| 7797 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7798 | |
| 7799 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7800 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7801 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7802 | nl80211_wowlan_policy); |
| 7803 | if (err) |
| 7804 | return err; |
| 7805 | |
| 7806 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7807 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7808 | return -EINVAL; |
| 7809 | new_triggers.any = true; |
| 7810 | } |
| 7811 | |
| 7812 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7813 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7814 | return -EINVAL; |
| 7815 | new_triggers.disconnect = true; |
| 7816 | } |
| 7817 | |
| 7818 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7819 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7820 | return -EINVAL; |
| 7821 | new_triggers.magic_pkt = true; |
| 7822 | } |
| 7823 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7824 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7825 | return -EINVAL; |
| 7826 | |
| 7827 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7828 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7829 | return -EINVAL; |
| 7830 | new_triggers.gtk_rekey_failure = true; |
| 7831 | } |
| 7832 | |
| 7833 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7834 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7835 | return -EINVAL; |
| 7836 | new_triggers.eap_identity_req = true; |
| 7837 | } |
| 7838 | |
| 7839 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7840 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7841 | return -EINVAL; |
| 7842 | new_triggers.four_way_handshake = true; |
| 7843 | } |
| 7844 | |
| 7845 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7846 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7847 | return -EINVAL; |
| 7848 | new_triggers.rfkill_release = true; |
| 7849 | } |
| 7850 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7851 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7852 | struct nlattr *pat; |
| 7853 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7854 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7855 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7856 | |
| 7857 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7858 | rem) |
| 7859 | n_patterns++; |
| 7860 | if (n_patterns > wowlan->n_patterns) |
| 7861 | return -EINVAL; |
| 7862 | |
| 7863 | new_triggers.patterns = kcalloc(n_patterns, |
| 7864 | sizeof(new_triggers.patterns[0]), |
| 7865 | GFP_KERNEL); |
| 7866 | if (!new_triggers.patterns) |
| 7867 | return -ENOMEM; |
| 7868 | |
| 7869 | new_triggers.n_patterns = n_patterns; |
| 7870 | i = 0; |
| 7871 | |
| 7872 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7873 | rem) { |
| 7874 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7875 | nla_data(pat), nla_len(pat), NULL); |
| 7876 | err = -EINVAL; |
| 7877 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7878 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7879 | goto error; |
| 7880 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7881 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7882 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7883 | mask_len) |
| 7884 | goto error; |
| 7885 | if (pat_len > wowlan->pattern_max_len || |
| 7886 | pat_len < wowlan->pattern_min_len) |
| 7887 | goto error; |
| 7888 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7889 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7890 | pkt_offset = 0; |
| 7891 | else |
| 7892 | pkt_offset = nla_get_u32( |
| 7893 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7894 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7895 | goto error; |
| 7896 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7897 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7898 | new_triggers.patterns[i].mask = |
| 7899 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7900 | if (!new_triggers.patterns[i].mask) { |
| 7901 | err = -ENOMEM; |
| 7902 | goto error; |
| 7903 | } |
| 7904 | new_triggers.patterns[i].pattern = |
| 7905 | new_triggers.patterns[i].mask + mask_len; |
| 7906 | memcpy(new_triggers.patterns[i].mask, |
| 7907 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7908 | mask_len); |
| 7909 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7910 | memcpy(new_triggers.patterns[i].pattern, |
| 7911 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7912 | pat_len); |
| 7913 | i++; |
| 7914 | } |
| 7915 | } |
| 7916 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7917 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 7918 | err = nl80211_parse_wowlan_tcp( |
| 7919 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 7920 | &new_triggers); |
| 7921 | if (err) |
| 7922 | goto error; |
| 7923 | } |
| 7924 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7925 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7926 | if (!ntrig) { |
| 7927 | err = -ENOMEM; |
| 7928 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7929 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7930 | cfg80211_rdev_free_wowlan(rdev); |
| 7931 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7932 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7933 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7934 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7935 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7936 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7937 | return 0; |
| 7938 | error: |
| 7939 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7940 | kfree(new_triggers.patterns[i].mask); |
| 7941 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7942 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 7943 | sock_release(new_triggers.tcp->sock); |
| 7944 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7945 | return err; |
| 7946 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7947 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7948 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7949 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 7950 | { |
| 7951 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7952 | struct net_device *dev = info->user_ptr[1]; |
| 7953 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7954 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 7955 | struct cfg80211_gtk_rekey_data rekey_data; |
| 7956 | int err; |
| 7957 | |
| 7958 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 7959 | return -EINVAL; |
| 7960 | |
| 7961 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 7962 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7963 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7964 | nl80211_rekey_policy); |
| 7965 | if (err) |
| 7966 | return err; |
| 7967 | |
| 7968 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 7969 | return -ERANGE; |
| 7970 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 7971 | return -ERANGE; |
| 7972 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 7973 | return -ERANGE; |
| 7974 | |
| 7975 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 7976 | NL80211_KEK_LEN); |
| 7977 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 7978 | NL80211_KCK_LEN); |
| 7979 | memcpy(rekey_data.replay_ctr, |
| 7980 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 7981 | NL80211_REPLAY_CTR_LEN); |
| 7982 | |
| 7983 | wdev_lock(wdev); |
| 7984 | if (!wdev->current_bss) { |
| 7985 | err = -ENOTCONN; |
| 7986 | goto out; |
| 7987 | } |
| 7988 | |
| 7989 | if (!rdev->ops->set_rekey_data) { |
| 7990 | err = -EOPNOTSUPP; |
| 7991 | goto out; |
| 7992 | } |
| 7993 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7994 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7995 | out: |
| 7996 | wdev_unlock(wdev); |
| 7997 | return err; |
| 7998 | } |
| 7999 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8000 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8001 | struct genl_info *info) |
| 8002 | { |
| 8003 | struct net_device *dev = info->user_ptr[1]; |
| 8004 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8005 | |
| 8006 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8007 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8008 | return -EINVAL; |
| 8009 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8010 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8011 | return -EBUSY; |
| 8012 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8013 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8014 | return 0; |
| 8015 | } |
| 8016 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8017 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8018 | struct genl_info *info) |
| 8019 | { |
| 8020 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8021 | struct net_device *dev = info->user_ptr[1]; |
| 8022 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8023 | struct sk_buff *msg; |
| 8024 | void *hdr; |
| 8025 | const u8 *addr; |
| 8026 | u64 cookie; |
| 8027 | int err; |
| 8028 | |
| 8029 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8030 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8031 | return -EOPNOTSUPP; |
| 8032 | |
| 8033 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8034 | return -EINVAL; |
| 8035 | |
| 8036 | if (!rdev->ops->probe_client) |
| 8037 | return -EOPNOTSUPP; |
| 8038 | |
| 8039 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8040 | if (!msg) |
| 8041 | return -ENOMEM; |
| 8042 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8043 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8044 | NL80211_CMD_PROBE_CLIENT); |
| 8045 | |
| 8046 | if (IS_ERR(hdr)) { |
| 8047 | err = PTR_ERR(hdr); |
| 8048 | goto free_msg; |
| 8049 | } |
| 8050 | |
| 8051 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8052 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8053 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8054 | if (err) |
| 8055 | goto free_msg; |
| 8056 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8057 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8058 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8059 | |
| 8060 | genlmsg_end(msg, hdr); |
| 8061 | |
| 8062 | return genlmsg_reply(msg, info); |
| 8063 | |
| 8064 | nla_put_failure: |
| 8065 | err = -ENOBUFS; |
| 8066 | free_msg: |
| 8067 | nlmsg_free(msg); |
| 8068 | return err; |
| 8069 | } |
| 8070 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8071 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8072 | { |
| 8073 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8074 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8075 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8076 | |
| 8077 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8078 | return -EOPNOTSUPP; |
| 8079 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8080 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8081 | if (!nreg) |
| 8082 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8083 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8084 | /* First, check if already registered. */ |
| 8085 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8086 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8087 | if (reg->nlportid == info->snd_portid) { |
| 8088 | rv = -EALREADY; |
| 8089 | goto out_err; |
| 8090 | } |
| 8091 | } |
| 8092 | /* Add it to the list */ |
| 8093 | nreg->nlportid = info->snd_portid; |
| 8094 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8095 | |
| 8096 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8097 | |
| 8098 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8099 | out_err: |
| 8100 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8101 | kfree(nreg); |
| 8102 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8103 | } |
| 8104 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8105 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8106 | { |
| 8107 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8108 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8109 | int err; |
| 8110 | |
| 8111 | if (!rdev->ops->start_p2p_device) |
| 8112 | return -EOPNOTSUPP; |
| 8113 | |
| 8114 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8115 | return -EOPNOTSUPP; |
| 8116 | |
| 8117 | if (wdev->p2p_started) |
| 8118 | return 0; |
| 8119 | |
| 8120 | mutex_lock(&rdev->devlist_mtx); |
| 8121 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 8122 | mutex_unlock(&rdev->devlist_mtx); |
| 8123 | if (err) |
| 8124 | return err; |
| 8125 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8126 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8127 | if (err) |
| 8128 | return err; |
| 8129 | |
| 8130 | wdev->p2p_started = true; |
| 8131 | mutex_lock(&rdev->devlist_mtx); |
| 8132 | rdev->opencount++; |
| 8133 | mutex_unlock(&rdev->devlist_mtx); |
| 8134 | |
| 8135 | return 0; |
| 8136 | } |
| 8137 | |
| 8138 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8139 | { |
| 8140 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8141 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8142 | |
| 8143 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8144 | return -EOPNOTSUPP; |
| 8145 | |
| 8146 | if (!rdev->ops->stop_p2p_device) |
| 8147 | return -EOPNOTSUPP; |
| 8148 | |
| 8149 | if (!wdev->p2p_started) |
| 8150 | return 0; |
| 8151 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8152 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8153 | wdev->p2p_started = false; |
| 8154 | |
| 8155 | mutex_lock(&rdev->devlist_mtx); |
| 8156 | rdev->opencount--; |
| 8157 | mutex_unlock(&rdev->devlist_mtx); |
| 8158 | |
| 8159 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 8160 | rdev->scan_req->aborted = true; |
| 8161 | ___cfg80211_scan_done(rdev, true); |
| 8162 | } |
| 8163 | |
| 8164 | return 0; |
| 8165 | } |
| 8166 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8167 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8168 | struct genl_info *info) |
| 8169 | { |
| 8170 | void *hdr; |
| 8171 | struct sk_buff *msg; |
| 8172 | |
| 8173 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8174 | if (!msg) |
| 8175 | return -ENOMEM; |
| 8176 | |
| 8177 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8178 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8179 | if (!hdr) |
| 8180 | goto nla_put_failure; |
| 8181 | |
| 8182 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8183 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8184 | goto nla_put_failure; |
| 8185 | |
| 8186 | genlmsg_end(msg, hdr); |
| 8187 | return genlmsg_reply(msg, info); |
| 8188 | |
| 8189 | nla_put_failure: |
| 8190 | kfree_skb(msg); |
| 8191 | return -ENOBUFS; |
| 8192 | } |
| 8193 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8194 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8195 | { |
| 8196 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8197 | struct cfg80211_update_ft_ies_params ft_params; |
| 8198 | struct net_device *dev = info->user_ptr[1]; |
| 8199 | |
| 8200 | if (!rdev->ops->update_ft_ies) |
| 8201 | return -EOPNOTSUPP; |
| 8202 | |
| 8203 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8204 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8205 | return -EINVAL; |
| 8206 | |
| 8207 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8208 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8209 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8210 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8211 | |
| 8212 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8213 | } |
| 8214 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8215 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8216 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8217 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8218 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8219 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8220 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8221 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8222 | /* 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] | 8223 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8224 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8225 | |
| 8226 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8227 | struct genl_info *info) |
| 8228 | { |
| 8229 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8230 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8231 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8232 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8233 | |
| 8234 | if (rtnl) |
| 8235 | rtnl_lock(); |
| 8236 | |
| 8237 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8238 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8239 | if (IS_ERR(rdev)) { |
| 8240 | if (rtnl) |
| 8241 | rtnl_unlock(); |
| 8242 | return PTR_ERR(rdev); |
| 8243 | } |
| 8244 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8245 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8246 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8247 | mutex_lock(&cfg80211_mutex); |
| 8248 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8249 | info->attrs); |
| 8250 | if (IS_ERR(wdev)) { |
| 8251 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8252 | if (rtnl) |
| 8253 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8254 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8255 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8256 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8257 | dev = wdev->netdev; |
| 8258 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8259 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8260 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8261 | if (!dev) { |
| 8262 | mutex_unlock(&cfg80211_mutex); |
| 8263 | if (rtnl) |
| 8264 | rtnl_unlock(); |
| 8265 | return -EINVAL; |
| 8266 | } |
| 8267 | |
| 8268 | info->user_ptr[1] = dev; |
| 8269 | } else { |
| 8270 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8271 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8272 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8273 | if (dev) { |
| 8274 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8275 | !netif_running(dev)) { |
| 8276 | mutex_unlock(&cfg80211_mutex); |
| 8277 | if (rtnl) |
| 8278 | rtnl_unlock(); |
| 8279 | return -ENETDOWN; |
| 8280 | } |
| 8281 | |
| 8282 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8283 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8284 | if (!wdev->p2p_started) { |
| 8285 | mutex_unlock(&cfg80211_mutex); |
| 8286 | if (rtnl) |
| 8287 | rtnl_unlock(); |
| 8288 | return -ENETDOWN; |
| 8289 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8290 | } |
| 8291 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8292 | cfg80211_lock_rdev(rdev); |
| 8293 | |
| 8294 | mutex_unlock(&cfg80211_mutex); |
| 8295 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8296 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8297 | } |
| 8298 | |
| 8299 | return 0; |
| 8300 | } |
| 8301 | |
| 8302 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8303 | struct genl_info *info) |
| 8304 | { |
| 8305 | if (info->user_ptr[0]) |
| 8306 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8307 | if (info->user_ptr[1]) { |
| 8308 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8309 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8310 | |
| 8311 | if (wdev->netdev) |
| 8312 | dev_put(wdev->netdev); |
| 8313 | } else { |
| 8314 | dev_put(info->user_ptr[1]); |
| 8315 | } |
| 8316 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8317 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8318 | rtnl_unlock(); |
| 8319 | } |
| 8320 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8321 | static struct genl_ops nl80211_ops[] = { |
| 8322 | { |
| 8323 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8324 | .doit = nl80211_get_wiphy, |
| 8325 | .dumpit = nl80211_dump_wiphy, |
| 8326 | .policy = nl80211_policy, |
| 8327 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8328 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8329 | }, |
| 8330 | { |
| 8331 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8332 | .doit = nl80211_set_wiphy, |
| 8333 | .policy = nl80211_policy, |
| 8334 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8335 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8336 | }, |
| 8337 | { |
| 8338 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8339 | .doit = nl80211_get_interface, |
| 8340 | .dumpit = nl80211_dump_interface, |
| 8341 | .policy = nl80211_policy, |
| 8342 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 8343 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8344 | }, |
| 8345 | { |
| 8346 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8347 | .doit = nl80211_set_interface, |
| 8348 | .policy = nl80211_policy, |
| 8349 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8350 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8351 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8352 | }, |
| 8353 | { |
| 8354 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8355 | .doit = nl80211_new_interface, |
| 8356 | .policy = nl80211_policy, |
| 8357 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8358 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8359 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8360 | }, |
| 8361 | { |
| 8362 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 8363 | .doit = nl80211_del_interface, |
| 8364 | .policy = nl80211_policy, |
| 8365 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 8366 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8367 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8368 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8369 | { |
| 8370 | .cmd = NL80211_CMD_GET_KEY, |
| 8371 | .doit = nl80211_get_key, |
| 8372 | .policy = nl80211_policy, |
| 8373 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8374 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8375 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8376 | }, |
| 8377 | { |
| 8378 | .cmd = NL80211_CMD_SET_KEY, |
| 8379 | .doit = nl80211_set_key, |
| 8380 | .policy = nl80211_policy, |
| 8381 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8382 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8383 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8384 | }, |
| 8385 | { |
| 8386 | .cmd = NL80211_CMD_NEW_KEY, |
| 8387 | .doit = nl80211_new_key, |
| 8388 | .policy = nl80211_policy, |
| 8389 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8390 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8391 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8392 | }, |
| 8393 | { |
| 8394 | .cmd = NL80211_CMD_DEL_KEY, |
| 8395 | .doit = nl80211_del_key, |
| 8396 | .policy = nl80211_policy, |
| 8397 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8398 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8399 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8400 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8401 | { |
| 8402 | .cmd = NL80211_CMD_SET_BEACON, |
| 8403 | .policy = nl80211_policy, |
| 8404 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8405 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8406 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8407 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8408 | }, |
| 8409 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8410 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8411 | .policy = nl80211_policy, |
| 8412 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8413 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8414 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8415 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8416 | }, |
| 8417 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8418 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8419 | .policy = nl80211_policy, |
| 8420 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8421 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8422 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8423 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8424 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8425 | { |
| 8426 | .cmd = NL80211_CMD_GET_STATION, |
| 8427 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8428 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8429 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8430 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8431 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8432 | }, |
| 8433 | { |
| 8434 | .cmd = NL80211_CMD_SET_STATION, |
| 8435 | .doit = nl80211_set_station, |
| 8436 | .policy = nl80211_policy, |
| 8437 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8438 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8439 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8440 | }, |
| 8441 | { |
| 8442 | .cmd = NL80211_CMD_NEW_STATION, |
| 8443 | .doit = nl80211_new_station, |
| 8444 | .policy = nl80211_policy, |
| 8445 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8446 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8447 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8448 | }, |
| 8449 | { |
| 8450 | .cmd = NL80211_CMD_DEL_STATION, |
| 8451 | .doit = nl80211_del_station, |
| 8452 | .policy = nl80211_policy, |
| 8453 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8454 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8455 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8456 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8457 | { |
| 8458 | .cmd = NL80211_CMD_GET_MPATH, |
| 8459 | .doit = nl80211_get_mpath, |
| 8460 | .dumpit = nl80211_dump_mpath, |
| 8461 | .policy = nl80211_policy, |
| 8462 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8463 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8464 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8465 | }, |
| 8466 | { |
| 8467 | .cmd = NL80211_CMD_SET_MPATH, |
| 8468 | .doit = nl80211_set_mpath, |
| 8469 | .policy = nl80211_policy, |
| 8470 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8471 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8472 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8473 | }, |
| 8474 | { |
| 8475 | .cmd = NL80211_CMD_NEW_MPATH, |
| 8476 | .doit = nl80211_new_mpath, |
| 8477 | .policy = nl80211_policy, |
| 8478 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8479 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8480 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8481 | }, |
| 8482 | { |
| 8483 | .cmd = NL80211_CMD_DEL_MPATH, |
| 8484 | .doit = nl80211_del_mpath, |
| 8485 | .policy = nl80211_policy, |
| 8486 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8487 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8488 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8489 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8490 | { |
| 8491 | .cmd = NL80211_CMD_SET_BSS, |
| 8492 | .doit = nl80211_set_bss, |
| 8493 | .policy = nl80211_policy, |
| 8494 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8495 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8496 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8497 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8498 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8499 | .cmd = NL80211_CMD_GET_REG, |
| 8500 | .doit = nl80211_get_reg, |
| 8501 | .policy = nl80211_policy, |
| 8502 | /* can be retrieved by unprivileged users */ |
| 8503 | }, |
| 8504 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8505 | .cmd = NL80211_CMD_SET_REG, |
| 8506 | .doit = nl80211_set_reg, |
| 8507 | .policy = nl80211_policy, |
| 8508 | .flags = GENL_ADMIN_PERM, |
| 8509 | }, |
| 8510 | { |
| 8511 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8512 | .doit = nl80211_req_set_reg, |
| 8513 | .policy = nl80211_policy, |
| 8514 | .flags = GENL_ADMIN_PERM, |
| 8515 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8516 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8517 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8518 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8519 | .policy = nl80211_policy, |
| 8520 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8521 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8522 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8523 | }, |
| 8524 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8525 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8526 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8527 | .policy = nl80211_policy, |
| 8528 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8529 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8530 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8531 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8532 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8533 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8534 | .doit = nl80211_trigger_scan, |
| 8535 | .policy = nl80211_policy, |
| 8536 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8537 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8538 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8539 | }, |
| 8540 | { |
| 8541 | .cmd = NL80211_CMD_GET_SCAN, |
| 8542 | .policy = nl80211_policy, |
| 8543 | .dumpit = nl80211_dump_scan, |
| 8544 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8545 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8546 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8547 | .doit = nl80211_start_sched_scan, |
| 8548 | .policy = nl80211_policy, |
| 8549 | .flags = GENL_ADMIN_PERM, |
| 8550 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8551 | NL80211_FLAG_NEED_RTNL, |
| 8552 | }, |
| 8553 | { |
| 8554 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8555 | .doit = nl80211_stop_sched_scan, |
| 8556 | .policy = nl80211_policy, |
| 8557 | .flags = GENL_ADMIN_PERM, |
| 8558 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8559 | NL80211_FLAG_NEED_RTNL, |
| 8560 | }, |
| 8561 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8562 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8563 | .doit = nl80211_authenticate, |
| 8564 | .policy = nl80211_policy, |
| 8565 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8566 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8567 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8568 | }, |
| 8569 | { |
| 8570 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8571 | .doit = nl80211_associate, |
| 8572 | .policy = nl80211_policy, |
| 8573 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8574 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8575 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8576 | }, |
| 8577 | { |
| 8578 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8579 | .doit = nl80211_deauthenticate, |
| 8580 | .policy = nl80211_policy, |
| 8581 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8582 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8583 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8584 | }, |
| 8585 | { |
| 8586 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8587 | .doit = nl80211_disassociate, |
| 8588 | .policy = nl80211_policy, |
| 8589 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8590 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8591 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8592 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8593 | { |
| 8594 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8595 | .doit = nl80211_join_ibss, |
| 8596 | .policy = nl80211_policy, |
| 8597 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8598 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8599 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8600 | }, |
| 8601 | { |
| 8602 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8603 | .doit = nl80211_leave_ibss, |
| 8604 | .policy = nl80211_policy, |
| 8605 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8606 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8607 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8608 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8609 | #ifdef CONFIG_NL80211_TESTMODE |
| 8610 | { |
| 8611 | .cmd = NL80211_CMD_TESTMODE, |
| 8612 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8613 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8614 | .policy = nl80211_policy, |
| 8615 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8616 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8617 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8618 | }, |
| 8619 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8620 | { |
| 8621 | .cmd = NL80211_CMD_CONNECT, |
| 8622 | .doit = nl80211_connect, |
| 8623 | .policy = nl80211_policy, |
| 8624 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8625 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8626 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8627 | }, |
| 8628 | { |
| 8629 | .cmd = NL80211_CMD_DISCONNECT, |
| 8630 | .doit = nl80211_disconnect, |
| 8631 | .policy = nl80211_policy, |
| 8632 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8633 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8634 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8635 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8636 | { |
| 8637 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8638 | .doit = nl80211_wiphy_netns, |
| 8639 | .policy = nl80211_policy, |
| 8640 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8641 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8642 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8643 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8644 | { |
| 8645 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8646 | .policy = nl80211_policy, |
| 8647 | .dumpit = nl80211_dump_survey, |
| 8648 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8649 | { |
| 8650 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8651 | .doit = nl80211_setdel_pmksa, |
| 8652 | .policy = nl80211_policy, |
| 8653 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8654 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8655 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8656 | }, |
| 8657 | { |
| 8658 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8659 | .doit = nl80211_setdel_pmksa, |
| 8660 | .policy = nl80211_policy, |
| 8661 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8662 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8663 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8664 | }, |
| 8665 | { |
| 8666 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8667 | .doit = nl80211_flush_pmksa, |
| 8668 | .policy = nl80211_policy, |
| 8669 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8670 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8671 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8672 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8673 | { |
| 8674 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8675 | .doit = nl80211_remain_on_channel, |
| 8676 | .policy = nl80211_policy, |
| 8677 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8678 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8679 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8680 | }, |
| 8681 | { |
| 8682 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8683 | .doit = nl80211_cancel_remain_on_channel, |
| 8684 | .policy = nl80211_policy, |
| 8685 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8686 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8687 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8688 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8689 | { |
| 8690 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8691 | .doit = nl80211_set_tx_bitrate_mask, |
| 8692 | .policy = nl80211_policy, |
| 8693 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8694 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8695 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8696 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8697 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8698 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8699 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8700 | .policy = nl80211_policy, |
| 8701 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8702 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8703 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8704 | }, |
| 8705 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8706 | .cmd = NL80211_CMD_FRAME, |
| 8707 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8708 | .policy = nl80211_policy, |
| 8709 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8710 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8711 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8712 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8713 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8714 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8715 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8716 | .policy = nl80211_policy, |
| 8717 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8718 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8719 | NL80211_FLAG_NEED_RTNL, |
| 8720 | }, |
| 8721 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8722 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8723 | .doit = nl80211_set_power_save, |
| 8724 | .policy = nl80211_policy, |
| 8725 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8726 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8727 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8728 | }, |
| 8729 | { |
| 8730 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8731 | .doit = nl80211_get_power_save, |
| 8732 | .policy = nl80211_policy, |
| 8733 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8734 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8735 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8736 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8737 | { |
| 8738 | .cmd = NL80211_CMD_SET_CQM, |
| 8739 | .doit = nl80211_set_cqm, |
| 8740 | .policy = nl80211_policy, |
| 8741 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8742 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8743 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8744 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8745 | { |
| 8746 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8747 | .doit = nl80211_set_channel, |
| 8748 | .policy = nl80211_policy, |
| 8749 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8750 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8751 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8752 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8753 | { |
| 8754 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8755 | .doit = nl80211_set_wds_peer, |
| 8756 | .policy = nl80211_policy, |
| 8757 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8758 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8759 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8760 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8761 | { |
| 8762 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8763 | .doit = nl80211_join_mesh, |
| 8764 | .policy = nl80211_policy, |
| 8765 | .flags = GENL_ADMIN_PERM, |
| 8766 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8767 | NL80211_FLAG_NEED_RTNL, |
| 8768 | }, |
| 8769 | { |
| 8770 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8771 | .doit = nl80211_leave_mesh, |
| 8772 | .policy = nl80211_policy, |
| 8773 | .flags = GENL_ADMIN_PERM, |
| 8774 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8775 | NL80211_FLAG_NEED_RTNL, |
| 8776 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8777 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8778 | { |
| 8779 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8780 | .doit = nl80211_get_wowlan, |
| 8781 | .policy = nl80211_policy, |
| 8782 | /* can be retrieved by unprivileged users */ |
| 8783 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8784 | NL80211_FLAG_NEED_RTNL, |
| 8785 | }, |
| 8786 | { |
| 8787 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8788 | .doit = nl80211_set_wowlan, |
| 8789 | .policy = nl80211_policy, |
| 8790 | .flags = GENL_ADMIN_PERM, |
| 8791 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8792 | NL80211_FLAG_NEED_RTNL, |
| 8793 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8794 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8795 | { |
| 8796 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8797 | .doit = nl80211_set_rekey_data, |
| 8798 | .policy = nl80211_policy, |
| 8799 | .flags = GENL_ADMIN_PERM, |
| 8800 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8801 | NL80211_FLAG_NEED_RTNL, |
| 8802 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8803 | { |
| 8804 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8805 | .doit = nl80211_tdls_mgmt, |
| 8806 | .policy = nl80211_policy, |
| 8807 | .flags = GENL_ADMIN_PERM, |
| 8808 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8809 | NL80211_FLAG_NEED_RTNL, |
| 8810 | }, |
| 8811 | { |
| 8812 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8813 | .doit = nl80211_tdls_oper, |
| 8814 | .policy = nl80211_policy, |
| 8815 | .flags = GENL_ADMIN_PERM, |
| 8816 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8817 | NL80211_FLAG_NEED_RTNL, |
| 8818 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8819 | { |
| 8820 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8821 | .doit = nl80211_register_unexpected_frame, |
| 8822 | .policy = nl80211_policy, |
| 8823 | .flags = GENL_ADMIN_PERM, |
| 8824 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8825 | NL80211_FLAG_NEED_RTNL, |
| 8826 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8827 | { |
| 8828 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8829 | .doit = nl80211_probe_client, |
| 8830 | .policy = nl80211_policy, |
| 8831 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8832 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8833 | NL80211_FLAG_NEED_RTNL, |
| 8834 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8835 | { |
| 8836 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8837 | .doit = nl80211_register_beacons, |
| 8838 | .policy = nl80211_policy, |
| 8839 | .flags = GENL_ADMIN_PERM, |
| 8840 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8841 | NL80211_FLAG_NEED_RTNL, |
| 8842 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8843 | { |
| 8844 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8845 | .doit = nl80211_set_noack_map, |
| 8846 | .policy = nl80211_policy, |
| 8847 | .flags = GENL_ADMIN_PERM, |
| 8848 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8849 | NL80211_FLAG_NEED_RTNL, |
| 8850 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8851 | { |
| 8852 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8853 | .doit = nl80211_start_p2p_device, |
| 8854 | .policy = nl80211_policy, |
| 8855 | .flags = GENL_ADMIN_PERM, |
| 8856 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8857 | NL80211_FLAG_NEED_RTNL, |
| 8858 | }, |
| 8859 | { |
| 8860 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8861 | .doit = nl80211_stop_p2p_device, |
| 8862 | .policy = nl80211_policy, |
| 8863 | .flags = GENL_ADMIN_PERM, |
| 8864 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8865 | NL80211_FLAG_NEED_RTNL, |
| 8866 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8867 | { |
| 8868 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8869 | .doit = nl80211_set_mcast_rate, |
| 8870 | .policy = nl80211_policy, |
| 8871 | .flags = GENL_ADMIN_PERM, |
| 8872 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8873 | NL80211_FLAG_NEED_RTNL, |
| 8874 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8875 | { |
| 8876 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8877 | .doit = nl80211_set_mac_acl, |
| 8878 | .policy = nl80211_policy, |
| 8879 | .flags = GENL_ADMIN_PERM, |
| 8880 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8881 | NL80211_FLAG_NEED_RTNL, |
| 8882 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8883 | { |
| 8884 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 8885 | .doit = nl80211_start_radar_detection, |
| 8886 | .policy = nl80211_policy, |
| 8887 | .flags = GENL_ADMIN_PERM, |
| 8888 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8889 | NL80211_FLAG_NEED_RTNL, |
| 8890 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8891 | { |
| 8892 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 8893 | .doit = nl80211_get_protocol_features, |
| 8894 | .policy = nl80211_policy, |
| 8895 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8896 | { |
| 8897 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 8898 | .doit = nl80211_update_ft_ies, |
| 8899 | .policy = nl80211_policy, |
| 8900 | .flags = GENL_ADMIN_PERM, |
| 8901 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8902 | NL80211_FLAG_NEED_RTNL, |
| 8903 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8904 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8905 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8906 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 8907 | .name = "mlme", |
| 8908 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8909 | |
| 8910 | /* multicast groups */ |
| 8911 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 8912 | .name = "config", |
| 8913 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8914 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 8915 | .name = "scan", |
| 8916 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8917 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 8918 | .name = "regulatory", |
| 8919 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8920 | |
| 8921 | /* notification functions */ |
| 8922 | |
| 8923 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 8924 | { |
| 8925 | struct sk_buff *msg; |
| 8926 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8927 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8928 | if (!msg) |
| 8929 | return; |
| 8930 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8931 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, |
| 8932 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8933 | nlmsg_free(msg); |
| 8934 | return; |
| 8935 | } |
| 8936 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8937 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8938 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8939 | } |
| 8940 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8941 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 8942 | struct cfg80211_registered_device *rdev) |
| 8943 | { |
| 8944 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 8945 | struct nlattr *nest; |
| 8946 | int i; |
| 8947 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8948 | ASSERT_RDEV_LOCK(rdev); |
| 8949 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8950 | if (WARN_ON(!req)) |
| 8951 | return 0; |
| 8952 | |
| 8953 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 8954 | if (!nest) |
| 8955 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8956 | for (i = 0; i < req->n_ssids; i++) { |
| 8957 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 8958 | goto nla_put_failure; |
| 8959 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8960 | nla_nest_end(msg, nest); |
| 8961 | |
| 8962 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 8963 | if (!nest) |
| 8964 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8965 | for (i = 0; i < req->n_channels; i++) { |
| 8966 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 8967 | goto nla_put_failure; |
| 8968 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8969 | nla_nest_end(msg, nest); |
| 8970 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8971 | if (req->ie && |
| 8972 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 8973 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8974 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8975 | if (req->flags) |
| 8976 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 8977 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8978 | return 0; |
| 8979 | nla_put_failure: |
| 8980 | return -ENOBUFS; |
| 8981 | } |
| 8982 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8983 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 8984 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8985 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8986 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8987 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8988 | { |
| 8989 | void *hdr; |
| 8990 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8991 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8992 | if (!hdr) |
| 8993 | return -1; |
| 8994 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8995 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8996 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8997 | wdev->netdev->ifindex)) || |
| 8998 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8999 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9000 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9001 | /* ignore errors and send incomplete event anyway */ |
| 9002 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9003 | |
| 9004 | return genlmsg_end(msg, hdr); |
| 9005 | |
| 9006 | nla_put_failure: |
| 9007 | genlmsg_cancel(msg, hdr); |
| 9008 | return -EMSGSIZE; |
| 9009 | } |
| 9010 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9011 | static int |
| 9012 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9013 | struct cfg80211_registered_device *rdev, |
| 9014 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9015 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9016 | { |
| 9017 | void *hdr; |
| 9018 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9019 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9020 | if (!hdr) |
| 9021 | return -1; |
| 9022 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9023 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9024 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9025 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9026 | |
| 9027 | return genlmsg_end(msg, hdr); |
| 9028 | |
| 9029 | nla_put_failure: |
| 9030 | genlmsg_cancel(msg, hdr); |
| 9031 | return -EMSGSIZE; |
| 9032 | } |
| 9033 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9034 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9035 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9036 | { |
| 9037 | struct sk_buff *msg; |
| 9038 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9039 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9040 | if (!msg) |
| 9041 | return; |
| 9042 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9043 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9044 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9045 | nlmsg_free(msg); |
| 9046 | return; |
| 9047 | } |
| 9048 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9049 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9050 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9051 | } |
| 9052 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9053 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9054 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9055 | { |
| 9056 | struct sk_buff *msg; |
| 9057 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9058 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9059 | if (!msg) |
| 9060 | return; |
| 9061 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9062 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9063 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9064 | nlmsg_free(msg); |
| 9065 | return; |
| 9066 | } |
| 9067 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9068 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9069 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9070 | } |
| 9071 | |
| 9072 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9073 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9074 | { |
| 9075 | struct sk_buff *msg; |
| 9076 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9077 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9078 | if (!msg) |
| 9079 | return; |
| 9080 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9081 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9082 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9083 | nlmsg_free(msg); |
| 9084 | return; |
| 9085 | } |
| 9086 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9087 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9088 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9089 | } |
| 9090 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9091 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9092 | struct net_device *netdev) |
| 9093 | { |
| 9094 | struct sk_buff *msg; |
| 9095 | |
| 9096 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9097 | if (!msg) |
| 9098 | return; |
| 9099 | |
| 9100 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9101 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9102 | nlmsg_free(msg); |
| 9103 | return; |
| 9104 | } |
| 9105 | |
| 9106 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9107 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9108 | } |
| 9109 | |
| 9110 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9111 | struct net_device *netdev, u32 cmd) |
| 9112 | { |
| 9113 | struct sk_buff *msg; |
| 9114 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9115 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9116 | if (!msg) |
| 9117 | return; |
| 9118 | |
| 9119 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9120 | nlmsg_free(msg); |
| 9121 | return; |
| 9122 | } |
| 9123 | |
| 9124 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9125 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9126 | } |
| 9127 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9128 | /* |
| 9129 | * This can happen on global regulatory changes or device specific settings |
| 9130 | * based on custom world regulatory domains. |
| 9131 | */ |
| 9132 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9133 | { |
| 9134 | struct sk_buff *msg; |
| 9135 | void *hdr; |
| 9136 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9137 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9138 | if (!msg) |
| 9139 | return; |
| 9140 | |
| 9141 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9142 | if (!hdr) { |
| 9143 | nlmsg_free(msg); |
| 9144 | return; |
| 9145 | } |
| 9146 | |
| 9147 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9148 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9149 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9150 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9151 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9152 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9153 | NL80211_REGDOM_TYPE_WORLD)) |
| 9154 | goto nla_put_failure; |
| 9155 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9156 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9157 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9158 | goto nla_put_failure; |
| 9159 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9160 | request->intersect) { |
| 9161 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9162 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9163 | goto nla_put_failure; |
| 9164 | } else { |
| 9165 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9166 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9167 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9168 | request->alpha2)) |
| 9169 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9170 | } |
| 9171 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9172 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9173 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9174 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9175 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9176 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9177 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9178 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9179 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9180 | GFP_ATOMIC); |
| 9181 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9182 | |
| 9183 | return; |
| 9184 | |
| 9185 | nla_put_failure: |
| 9186 | genlmsg_cancel(msg, hdr); |
| 9187 | nlmsg_free(msg); |
| 9188 | } |
| 9189 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9190 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9191 | struct net_device *netdev, |
| 9192 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9193 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9194 | { |
| 9195 | struct sk_buff *msg; |
| 9196 | void *hdr; |
| 9197 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9198 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9199 | if (!msg) |
| 9200 | return; |
| 9201 | |
| 9202 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9203 | if (!hdr) { |
| 9204 | nlmsg_free(msg); |
| 9205 | return; |
| 9206 | } |
| 9207 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9208 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9209 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9210 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9211 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9212 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9213 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9214 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9215 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9216 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9217 | return; |
| 9218 | |
| 9219 | nla_put_failure: |
| 9220 | genlmsg_cancel(msg, hdr); |
| 9221 | nlmsg_free(msg); |
| 9222 | } |
| 9223 | |
| 9224 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9225 | struct net_device *netdev, const u8 *buf, |
| 9226 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9227 | { |
| 9228 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9229 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9230 | } |
| 9231 | |
| 9232 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9233 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9234 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9235 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9236 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9237 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9238 | } |
| 9239 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9240 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9241 | struct net_device *netdev, const u8 *buf, |
| 9242 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9243 | { |
| 9244 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9245 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9246 | } |
| 9247 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9248 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9249 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9250 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9251 | { |
| 9252 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9253 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9254 | } |
| 9255 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9256 | void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf, |
| 9257 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9258 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9259 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9260 | struct wiphy *wiphy = wdev->wiphy; |
| 9261 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9262 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9263 | trace_cfg80211_send_unprot_deauth(dev); |
| 9264 | nl80211_send_mlme_event(rdev, dev, buf, len, |
| 9265 | NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9266 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9267 | EXPORT_SYMBOL(cfg80211_send_unprot_deauth); |
| 9268 | |
| 9269 | void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf, |
| 9270 | size_t len) |
| 9271 | { |
| 9272 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9273 | struct wiphy *wiphy = wdev->wiphy; |
| 9274 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9275 | |
| 9276 | trace_cfg80211_send_unprot_disassoc(dev); |
| 9277 | nl80211_send_mlme_event(rdev, dev, buf, len, |
| 9278 | NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC); |
| 9279 | } |
| 9280 | EXPORT_SYMBOL(cfg80211_send_unprot_disassoc); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9281 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9282 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9283 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9284 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9285 | { |
| 9286 | struct sk_buff *msg; |
| 9287 | void *hdr; |
| 9288 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9289 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9290 | if (!msg) |
| 9291 | return; |
| 9292 | |
| 9293 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9294 | if (!hdr) { |
| 9295 | nlmsg_free(msg); |
| 9296 | return; |
| 9297 | } |
| 9298 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9299 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9300 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9301 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9302 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9303 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9304 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9305 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9306 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9307 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9308 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9309 | return; |
| 9310 | |
| 9311 | nla_put_failure: |
| 9312 | genlmsg_cancel(msg, hdr); |
| 9313 | nlmsg_free(msg); |
| 9314 | } |
| 9315 | |
| 9316 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9317 | struct net_device *netdev, const u8 *addr, |
| 9318 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9319 | { |
| 9320 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9321 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9322 | } |
| 9323 | |
| 9324 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9325 | struct net_device *netdev, const u8 *addr, |
| 9326 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9327 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9328 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9329 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9330 | } |
| 9331 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9332 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9333 | struct net_device *netdev, const u8 *bssid, |
| 9334 | const u8 *req_ie, size_t req_ie_len, |
| 9335 | const u8 *resp_ie, size_t resp_ie_len, |
| 9336 | u16 status, gfp_t gfp) |
| 9337 | { |
| 9338 | struct sk_buff *msg; |
| 9339 | void *hdr; |
| 9340 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9341 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9342 | if (!msg) |
| 9343 | return; |
| 9344 | |
| 9345 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 9346 | if (!hdr) { |
| 9347 | nlmsg_free(msg); |
| 9348 | return; |
| 9349 | } |
| 9350 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9351 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9352 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9353 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 9354 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 9355 | (req_ie && |
| 9356 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9357 | (resp_ie && |
| 9358 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9359 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9360 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9361 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9362 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9363 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9364 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9365 | return; |
| 9366 | |
| 9367 | nla_put_failure: |
| 9368 | genlmsg_cancel(msg, hdr); |
| 9369 | nlmsg_free(msg); |
| 9370 | |
| 9371 | } |
| 9372 | |
| 9373 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 9374 | struct net_device *netdev, const u8 *bssid, |
| 9375 | const u8 *req_ie, size_t req_ie_len, |
| 9376 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 9377 | { |
| 9378 | struct sk_buff *msg; |
| 9379 | void *hdr; |
| 9380 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9381 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9382 | if (!msg) |
| 9383 | return; |
| 9384 | |
| 9385 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 9386 | if (!hdr) { |
| 9387 | nlmsg_free(msg); |
| 9388 | return; |
| 9389 | } |
| 9390 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9391 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9392 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9393 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 9394 | (req_ie && |
| 9395 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9396 | (resp_ie && |
| 9397 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9398 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9399 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9400 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9401 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9402 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9403 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9404 | return; |
| 9405 | |
| 9406 | nla_put_failure: |
| 9407 | genlmsg_cancel(msg, hdr); |
| 9408 | nlmsg_free(msg); |
| 9409 | |
| 9410 | } |
| 9411 | |
| 9412 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 9413 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 9414 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9415 | { |
| 9416 | struct sk_buff *msg; |
| 9417 | void *hdr; |
| 9418 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9419 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9420 | if (!msg) |
| 9421 | return; |
| 9422 | |
| 9423 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 9424 | if (!hdr) { |
| 9425 | nlmsg_free(msg); |
| 9426 | return; |
| 9427 | } |
| 9428 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9429 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9430 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9431 | (from_ap && reason && |
| 9432 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 9433 | (from_ap && |
| 9434 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 9435 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 9436 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9437 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9438 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9439 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9440 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9441 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9442 | return; |
| 9443 | |
| 9444 | nla_put_failure: |
| 9445 | genlmsg_cancel(msg, hdr); |
| 9446 | nlmsg_free(msg); |
| 9447 | |
| 9448 | } |
| 9449 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9450 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 9451 | struct net_device *netdev, const u8 *bssid, |
| 9452 | gfp_t gfp) |
| 9453 | { |
| 9454 | struct sk_buff *msg; |
| 9455 | void *hdr; |
| 9456 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9457 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9458 | if (!msg) |
| 9459 | return; |
| 9460 | |
| 9461 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 9462 | if (!hdr) { |
| 9463 | nlmsg_free(msg); |
| 9464 | return; |
| 9465 | } |
| 9466 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9467 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9468 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9469 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9470 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9471 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9472 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9473 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9474 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9475 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9476 | return; |
| 9477 | |
| 9478 | nla_put_failure: |
| 9479 | genlmsg_cancel(msg, hdr); |
| 9480 | nlmsg_free(msg); |
| 9481 | } |
| 9482 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9483 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 9484 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9485 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9486 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9487 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9488 | struct sk_buff *msg; |
| 9489 | void *hdr; |
| 9490 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9491 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 9492 | return; |
| 9493 | |
| 9494 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 9495 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9496 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9497 | if (!msg) |
| 9498 | return; |
| 9499 | |
| 9500 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 9501 | if (!hdr) { |
| 9502 | nlmsg_free(msg); |
| 9503 | return; |
| 9504 | } |
| 9505 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9506 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9507 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9508 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9509 | (ie_len && ie && |
| 9510 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 9511 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9512 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9513 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9514 | |
| 9515 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9516 | nl80211_mlme_mcgrp.id, gfp); |
| 9517 | return; |
| 9518 | |
| 9519 | nla_put_failure: |
| 9520 | genlmsg_cancel(msg, hdr); |
| 9521 | nlmsg_free(msg); |
| 9522 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9523 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9524 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9525 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 9526 | struct net_device *netdev, const u8 *addr, |
| 9527 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9528 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9529 | { |
| 9530 | struct sk_buff *msg; |
| 9531 | void *hdr; |
| 9532 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9533 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9534 | if (!msg) |
| 9535 | return; |
| 9536 | |
| 9537 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9538 | if (!hdr) { |
| 9539 | nlmsg_free(msg); |
| 9540 | return; |
| 9541 | } |
| 9542 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9543 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9544 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9545 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9546 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9547 | (key_id != -1 && |
| 9548 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9549 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9550 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9551 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9552 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9553 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9554 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9555 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9556 | return; |
| 9557 | |
| 9558 | nla_put_failure: |
| 9559 | genlmsg_cancel(msg, hdr); |
| 9560 | nlmsg_free(msg); |
| 9561 | } |
| 9562 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9563 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9564 | struct ieee80211_channel *channel_before, |
| 9565 | struct ieee80211_channel *channel_after) |
| 9566 | { |
| 9567 | struct sk_buff *msg; |
| 9568 | void *hdr; |
| 9569 | struct nlattr *nl_freq; |
| 9570 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9571 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9572 | if (!msg) |
| 9573 | return; |
| 9574 | |
| 9575 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9576 | if (!hdr) { |
| 9577 | nlmsg_free(msg); |
| 9578 | return; |
| 9579 | } |
| 9580 | |
| 9581 | /* |
| 9582 | * Since we are applying the beacon hint to a wiphy we know its |
| 9583 | * wiphy_idx is valid |
| 9584 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9585 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9586 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9587 | |
| 9588 | /* Before */ |
| 9589 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9590 | if (!nl_freq) |
| 9591 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9592 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9593 | goto nla_put_failure; |
| 9594 | nla_nest_end(msg, nl_freq); |
| 9595 | |
| 9596 | /* After */ |
| 9597 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9598 | if (!nl_freq) |
| 9599 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9600 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9601 | goto nla_put_failure; |
| 9602 | nla_nest_end(msg, nl_freq); |
| 9603 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9604 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9605 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9606 | rcu_read_lock(); |
| 9607 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9608 | GFP_ATOMIC); |
| 9609 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9610 | |
| 9611 | return; |
| 9612 | |
| 9613 | nla_put_failure: |
| 9614 | genlmsg_cancel(msg, hdr); |
| 9615 | nlmsg_free(msg); |
| 9616 | } |
| 9617 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9618 | static void nl80211_send_remain_on_chan_event( |
| 9619 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9620 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9621 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9622 | unsigned int duration, gfp_t gfp) |
| 9623 | { |
| 9624 | struct sk_buff *msg; |
| 9625 | void *hdr; |
| 9626 | |
| 9627 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9628 | if (!msg) |
| 9629 | return; |
| 9630 | |
| 9631 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9632 | if (!hdr) { |
| 9633 | nlmsg_free(msg); |
| 9634 | return; |
| 9635 | } |
| 9636 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9637 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9638 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9639 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9640 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9641 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9642 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9643 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9644 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9645 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9646 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9647 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9648 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9649 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9650 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9651 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9652 | |
| 9653 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9654 | nl80211_mlme_mcgrp.id, gfp); |
| 9655 | return; |
| 9656 | |
| 9657 | nla_put_failure: |
| 9658 | genlmsg_cancel(msg, hdr); |
| 9659 | nlmsg_free(msg); |
| 9660 | } |
| 9661 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9662 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 9663 | struct ieee80211_channel *chan, |
| 9664 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9665 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9666 | struct wiphy *wiphy = wdev->wiphy; |
| 9667 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9668 | |
| 9669 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9670 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9671 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9672 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9673 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9674 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9675 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9676 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 9677 | struct ieee80211_channel *chan, |
| 9678 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9679 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9680 | struct wiphy *wiphy = wdev->wiphy; |
| 9681 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9682 | |
| 9683 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9684 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9685 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9686 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9687 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9688 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9689 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 9690 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9691 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9692 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9693 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9694 | struct sk_buff *msg; |
| 9695 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9696 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 9697 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9698 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9699 | if (!msg) |
| 9700 | return; |
| 9701 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9702 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9703 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9704 | nlmsg_free(msg); |
| 9705 | return; |
| 9706 | } |
| 9707 | |
| 9708 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9709 | nl80211_mlme_mcgrp.id, gfp); |
| 9710 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9711 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9712 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9713 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9714 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9715 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9716 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9717 | struct sk_buff *msg; |
| 9718 | void *hdr; |
| 9719 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9720 | trace_cfg80211_del_sta(dev, mac_addr); |
| 9721 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9722 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9723 | if (!msg) |
| 9724 | return; |
| 9725 | |
| 9726 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9727 | if (!hdr) { |
| 9728 | nlmsg_free(msg); |
| 9729 | return; |
| 9730 | } |
| 9731 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9732 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9733 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9734 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9735 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9736 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9737 | |
| 9738 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9739 | nl80211_mlme_mcgrp.id, gfp); |
| 9740 | return; |
| 9741 | |
| 9742 | nla_put_failure: |
| 9743 | genlmsg_cancel(msg, hdr); |
| 9744 | nlmsg_free(msg); |
| 9745 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9746 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9747 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9748 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 9749 | enum nl80211_connect_failed_reason reason, |
| 9750 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9751 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9752 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9753 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9754 | struct sk_buff *msg; |
| 9755 | void *hdr; |
| 9756 | |
| 9757 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9758 | if (!msg) |
| 9759 | return; |
| 9760 | |
| 9761 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9762 | if (!hdr) { |
| 9763 | nlmsg_free(msg); |
| 9764 | return; |
| 9765 | } |
| 9766 | |
| 9767 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9768 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9769 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9770 | goto nla_put_failure; |
| 9771 | |
| 9772 | genlmsg_end(msg, hdr); |
| 9773 | |
| 9774 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9775 | nl80211_mlme_mcgrp.id, gfp); |
| 9776 | return; |
| 9777 | |
| 9778 | nla_put_failure: |
| 9779 | genlmsg_cancel(msg, hdr); |
| 9780 | nlmsg_free(msg); |
| 9781 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9782 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9783 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9784 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9785 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9786 | { |
| 9787 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9788 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9789 | struct sk_buff *msg; |
| 9790 | void *hdr; |
| 9791 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9792 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9793 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9794 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9795 | return false; |
| 9796 | |
| 9797 | msg = nlmsg_new(100, gfp); |
| 9798 | if (!msg) |
| 9799 | return true; |
| 9800 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9801 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9802 | if (!hdr) { |
| 9803 | nlmsg_free(msg); |
| 9804 | return true; |
| 9805 | } |
| 9806 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9807 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9808 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9809 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9810 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9811 | |
| 9812 | err = genlmsg_end(msg, hdr); |
| 9813 | if (err < 0) { |
| 9814 | nlmsg_free(msg); |
| 9815 | return true; |
| 9816 | } |
| 9817 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9818 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9819 | return true; |
| 9820 | |
| 9821 | nla_put_failure: |
| 9822 | genlmsg_cancel(msg, hdr); |
| 9823 | nlmsg_free(msg); |
| 9824 | return true; |
| 9825 | } |
| 9826 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9827 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 9828 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9829 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9830 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9831 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9832 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9833 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 9834 | |
| 9835 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9836 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 9837 | trace_cfg80211_return_bool(false); |
| 9838 | return false; |
| 9839 | } |
| 9840 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9841 | addr, gfp); |
| 9842 | trace_cfg80211_return_bool(ret); |
| 9843 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9844 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9845 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 9846 | |
| 9847 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 9848 | const u8 *addr, gfp_t gfp) |
| 9849 | { |
| 9850 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9851 | bool ret; |
| 9852 | |
| 9853 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 9854 | |
| 9855 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9856 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 9857 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 9858 | trace_cfg80211_return_bool(false); |
| 9859 | return false; |
| 9860 | } |
| 9861 | ret = __nl80211_unexpected_frame(dev, |
| 9862 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9863 | addr, gfp); |
| 9864 | trace_cfg80211_return_bool(ret); |
| 9865 | return ret; |
| 9866 | } |
| 9867 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9868 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9869 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9870 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9871 | int freq, int sig_dbm, |
| 9872 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9873 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9874 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9875 | struct sk_buff *msg; |
| 9876 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9877 | |
| 9878 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9879 | if (!msg) |
| 9880 | return -ENOMEM; |
| 9881 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9882 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9883 | if (!hdr) { |
| 9884 | nlmsg_free(msg); |
| 9885 | return -ENOMEM; |
| 9886 | } |
| 9887 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9888 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9889 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9890 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9891 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 9892 | (sig_dbm && |
| 9893 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9894 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9895 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9896 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9897 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9898 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9899 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9900 | |
| 9901 | nla_put_failure: |
| 9902 | genlmsg_cancel(msg, hdr); |
| 9903 | nlmsg_free(msg); |
| 9904 | return -ENOBUFS; |
| 9905 | } |
| 9906 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9907 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 9908 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9909 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9910 | struct wiphy *wiphy = wdev->wiphy; |
| 9911 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9912 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9913 | struct sk_buff *msg; |
| 9914 | void *hdr; |
| 9915 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9916 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 9917 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9918 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9919 | if (!msg) |
| 9920 | return; |
| 9921 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9922 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9923 | if (!hdr) { |
| 9924 | nlmsg_free(msg); |
| 9925 | return; |
| 9926 | } |
| 9927 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9928 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9929 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9930 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9931 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 9932 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9933 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9934 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9935 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9936 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9937 | |
| 9938 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 9939 | return; |
| 9940 | |
| 9941 | nla_put_failure: |
| 9942 | genlmsg_cancel(msg, hdr); |
| 9943 | nlmsg_free(msg); |
| 9944 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9945 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9946 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9947 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 9948 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 9949 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9950 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9951 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9952 | struct wiphy *wiphy = wdev->wiphy; |
| 9953 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9954 | struct sk_buff *msg; |
| 9955 | struct nlattr *pinfoattr; |
| 9956 | void *hdr; |
| 9957 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9958 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 9959 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9960 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9961 | if (!msg) |
| 9962 | return; |
| 9963 | |
| 9964 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9965 | if (!hdr) { |
| 9966 | nlmsg_free(msg); |
| 9967 | return; |
| 9968 | } |
| 9969 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9970 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9971 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9972 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9973 | |
| 9974 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9975 | if (!pinfoattr) |
| 9976 | goto nla_put_failure; |
| 9977 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9978 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 9979 | rssi_event)) |
| 9980 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9981 | |
| 9982 | nla_nest_end(msg, pinfoattr); |
| 9983 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9984 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9985 | |
| 9986 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9987 | nl80211_mlme_mcgrp.id, gfp); |
| 9988 | return; |
| 9989 | |
| 9990 | nla_put_failure: |
| 9991 | genlmsg_cancel(msg, hdr); |
| 9992 | nlmsg_free(msg); |
| 9993 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9994 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9995 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9996 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 9997 | struct net_device *netdev, const u8 *bssid, |
| 9998 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9999 | { |
| 10000 | struct sk_buff *msg; |
| 10001 | struct nlattr *rekey_attr; |
| 10002 | void *hdr; |
| 10003 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10004 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10005 | if (!msg) |
| 10006 | return; |
| 10007 | |
| 10008 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10009 | if (!hdr) { |
| 10010 | nlmsg_free(msg); |
| 10011 | return; |
| 10012 | } |
| 10013 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10014 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10015 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10016 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10017 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10018 | |
| 10019 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10020 | if (!rekey_attr) |
| 10021 | goto nla_put_failure; |
| 10022 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10023 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10024 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10025 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10026 | |
| 10027 | nla_nest_end(msg, rekey_attr); |
| 10028 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10029 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10030 | |
| 10031 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10032 | nl80211_mlme_mcgrp.id, gfp); |
| 10033 | return; |
| 10034 | |
| 10035 | nla_put_failure: |
| 10036 | genlmsg_cancel(msg, hdr); |
| 10037 | nlmsg_free(msg); |
| 10038 | } |
| 10039 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10040 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10041 | const u8 *replay_ctr, gfp_t gfp) |
| 10042 | { |
| 10043 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10044 | struct wiphy *wiphy = wdev->wiphy; |
| 10045 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10046 | |
| 10047 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10048 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10049 | } |
| 10050 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10051 | |
| 10052 | static void |
| 10053 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10054 | struct net_device *netdev, int index, |
| 10055 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10056 | { |
| 10057 | struct sk_buff *msg; |
| 10058 | struct nlattr *attr; |
| 10059 | void *hdr; |
| 10060 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10061 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10062 | if (!msg) |
| 10063 | return; |
| 10064 | |
| 10065 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10066 | if (!hdr) { |
| 10067 | nlmsg_free(msg); |
| 10068 | return; |
| 10069 | } |
| 10070 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10071 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10072 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10073 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10074 | |
| 10075 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10076 | if (!attr) |
| 10077 | goto nla_put_failure; |
| 10078 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10079 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10080 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10081 | (preauth && |
| 10082 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10083 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10084 | |
| 10085 | nla_nest_end(msg, attr); |
| 10086 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10087 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10088 | |
| 10089 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10090 | nl80211_mlme_mcgrp.id, gfp); |
| 10091 | return; |
| 10092 | |
| 10093 | nla_put_failure: |
| 10094 | genlmsg_cancel(msg, hdr); |
| 10095 | nlmsg_free(msg); |
| 10096 | } |
| 10097 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10098 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10099 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10100 | { |
| 10101 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10102 | struct wiphy *wiphy = wdev->wiphy; |
| 10103 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10104 | |
| 10105 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10106 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10107 | } |
| 10108 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10109 | |
| 10110 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10111 | struct net_device *netdev, |
| 10112 | struct cfg80211_chan_def *chandef, |
| 10113 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10114 | { |
| 10115 | struct sk_buff *msg; |
| 10116 | void *hdr; |
| 10117 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10118 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10119 | if (!msg) |
| 10120 | return; |
| 10121 | |
| 10122 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10123 | if (!hdr) { |
| 10124 | nlmsg_free(msg); |
| 10125 | return; |
| 10126 | } |
| 10127 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10128 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10129 | goto nla_put_failure; |
| 10130 | |
| 10131 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10132 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10133 | |
| 10134 | genlmsg_end(msg, hdr); |
| 10135 | |
| 10136 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10137 | nl80211_mlme_mcgrp.id, gfp); |
| 10138 | return; |
| 10139 | |
| 10140 | nla_put_failure: |
| 10141 | genlmsg_cancel(msg, hdr); |
| 10142 | nlmsg_free(msg); |
| 10143 | } |
| 10144 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10145 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10146 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10147 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10148 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10149 | struct wiphy *wiphy = wdev->wiphy; |
| 10150 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10151 | |
| 10152 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10153 | |
| 10154 | wdev_lock(wdev); |
| 10155 | |
| 10156 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10157 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) |
| 10158 | goto out; |
| 10159 | |
| 10160 | wdev->channel = chandef->chan; |
| 10161 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10162 | out: |
| 10163 | wdev_unlock(wdev); |
| 10164 | return; |
| 10165 | } |
| 10166 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10167 | |
| 10168 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10169 | const u8 *peer, u32 num_packets, |
| 10170 | u32 rate, u32 intvl, gfp_t gfp) |
| 10171 | { |
| 10172 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10173 | struct wiphy *wiphy = wdev->wiphy; |
| 10174 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10175 | struct sk_buff *msg; |
| 10176 | struct nlattr *pinfoattr; |
| 10177 | void *hdr; |
| 10178 | |
| 10179 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10180 | if (!msg) |
| 10181 | return; |
| 10182 | |
| 10183 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10184 | if (!hdr) { |
| 10185 | nlmsg_free(msg); |
| 10186 | return; |
| 10187 | } |
| 10188 | |
| 10189 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10190 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10191 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10192 | goto nla_put_failure; |
| 10193 | |
| 10194 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10195 | if (!pinfoattr) |
| 10196 | goto nla_put_failure; |
| 10197 | |
| 10198 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10199 | goto nla_put_failure; |
| 10200 | |
| 10201 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10202 | goto nla_put_failure; |
| 10203 | |
| 10204 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10205 | goto nla_put_failure; |
| 10206 | |
| 10207 | nla_nest_end(msg, pinfoattr); |
| 10208 | |
| 10209 | genlmsg_end(msg, hdr); |
| 10210 | |
| 10211 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10212 | nl80211_mlme_mcgrp.id, gfp); |
| 10213 | return; |
| 10214 | |
| 10215 | nla_put_failure: |
| 10216 | genlmsg_cancel(msg, hdr); |
| 10217 | nlmsg_free(msg); |
| 10218 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10219 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10220 | |
| 10221 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10222 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 10223 | struct cfg80211_chan_def *chandef, |
| 10224 | enum nl80211_radar_event event, |
| 10225 | struct net_device *netdev, gfp_t gfp) |
| 10226 | { |
| 10227 | struct sk_buff *msg; |
| 10228 | void *hdr; |
| 10229 | |
| 10230 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10231 | if (!msg) |
| 10232 | return; |
| 10233 | |
| 10234 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10235 | if (!hdr) { |
| 10236 | nlmsg_free(msg); |
| 10237 | return; |
| 10238 | } |
| 10239 | |
| 10240 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10241 | goto nla_put_failure; |
| 10242 | |
| 10243 | /* NOP and radar events don't need a netdev parameter */ |
| 10244 | if (netdev) { |
| 10245 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10246 | |
| 10247 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10248 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10249 | goto nla_put_failure; |
| 10250 | } |
| 10251 | |
| 10252 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10253 | goto nla_put_failure; |
| 10254 | |
| 10255 | if (nl80211_send_chandef(msg, chandef)) |
| 10256 | goto nla_put_failure; |
| 10257 | |
| 10258 | if (genlmsg_end(msg, hdr) < 0) { |
| 10259 | nlmsg_free(msg); |
| 10260 | return; |
| 10261 | } |
| 10262 | |
| 10263 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10264 | nl80211_mlme_mcgrp.id, gfp); |
| 10265 | return; |
| 10266 | |
| 10267 | nla_put_failure: |
| 10268 | genlmsg_cancel(msg, hdr); |
| 10269 | nlmsg_free(msg); |
| 10270 | } |
| 10271 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10272 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10273 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10274 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10275 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10276 | struct wiphy *wiphy = wdev->wiphy; |
| 10277 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10278 | struct sk_buff *msg; |
| 10279 | struct nlattr *pinfoattr; |
| 10280 | void *hdr; |
| 10281 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10282 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10283 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10284 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10285 | if (!msg) |
| 10286 | return; |
| 10287 | |
| 10288 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10289 | if (!hdr) { |
| 10290 | nlmsg_free(msg); |
| 10291 | return; |
| 10292 | } |
| 10293 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10294 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10295 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10296 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10297 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10298 | |
| 10299 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10300 | if (!pinfoattr) |
| 10301 | goto nla_put_failure; |
| 10302 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10303 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10304 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10305 | |
| 10306 | nla_nest_end(msg, pinfoattr); |
| 10307 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10308 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10309 | |
| 10310 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10311 | nl80211_mlme_mcgrp.id, gfp); |
| 10312 | return; |
| 10313 | |
| 10314 | nla_put_failure: |
| 10315 | genlmsg_cancel(msg, hdr); |
| 10316 | nlmsg_free(msg); |
| 10317 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10318 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10319 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10320 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10321 | u64 cookie, bool acked, gfp_t gfp) |
| 10322 | { |
| 10323 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10324 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10325 | struct sk_buff *msg; |
| 10326 | void *hdr; |
| 10327 | int err; |
| 10328 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10329 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10330 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10331 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10332 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10333 | if (!msg) |
| 10334 | return; |
| 10335 | |
| 10336 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10337 | if (!hdr) { |
| 10338 | nlmsg_free(msg); |
| 10339 | return; |
| 10340 | } |
| 10341 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10342 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10343 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10344 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10345 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10346 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10347 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10348 | |
| 10349 | err = genlmsg_end(msg, hdr); |
| 10350 | if (err < 0) { |
| 10351 | nlmsg_free(msg); |
| 10352 | return; |
| 10353 | } |
| 10354 | |
| 10355 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10356 | nl80211_mlme_mcgrp.id, gfp); |
| 10357 | return; |
| 10358 | |
| 10359 | nla_put_failure: |
| 10360 | genlmsg_cancel(msg, hdr); |
| 10361 | nlmsg_free(msg); |
| 10362 | } |
| 10363 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 10364 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10365 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 10366 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10367 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10368 | { |
| 10369 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10370 | struct sk_buff *msg; |
| 10371 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10372 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10373 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10374 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 10375 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10376 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10377 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10378 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 10379 | if (!msg) { |
| 10380 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10381 | return; |
| 10382 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10383 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10384 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 10385 | if (!hdr) |
| 10386 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10387 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10388 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10389 | (freq && |
| 10390 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 10391 | (sig_dbm && |
| 10392 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 10393 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 10394 | goto nla_put_failure; |
| 10395 | |
| 10396 | genlmsg_end(msg, hdr); |
| 10397 | |
| 10398 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10399 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10400 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10401 | return; |
| 10402 | |
| 10403 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10404 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10405 | if (hdr) |
| 10406 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10407 | nlmsg_free(msg); |
| 10408 | } |
| 10409 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 10410 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10411 | #ifdef CONFIG_PM |
| 10412 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 10413 | struct cfg80211_wowlan_wakeup *wakeup, |
| 10414 | gfp_t gfp) |
| 10415 | { |
| 10416 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10417 | struct sk_buff *msg; |
| 10418 | void *hdr; |
| 10419 | int err, size = 200; |
| 10420 | |
| 10421 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 10422 | |
| 10423 | if (wakeup) |
| 10424 | size += wakeup->packet_present_len; |
| 10425 | |
| 10426 | msg = nlmsg_new(size, gfp); |
| 10427 | if (!msg) |
| 10428 | return; |
| 10429 | |
| 10430 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 10431 | if (!hdr) |
| 10432 | goto free_msg; |
| 10433 | |
| 10434 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10435 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10436 | goto free_msg; |
| 10437 | |
| 10438 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10439 | wdev->netdev->ifindex)) |
| 10440 | goto free_msg; |
| 10441 | |
| 10442 | if (wakeup) { |
| 10443 | struct nlattr *reasons; |
| 10444 | |
| 10445 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10446 | |
| 10447 | if (wakeup->disconnect && |
| 10448 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 10449 | goto free_msg; |
| 10450 | if (wakeup->magic_pkt && |
| 10451 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 10452 | goto free_msg; |
| 10453 | if (wakeup->gtk_rekey_failure && |
| 10454 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 10455 | goto free_msg; |
| 10456 | if (wakeup->eap_identity_req && |
| 10457 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 10458 | goto free_msg; |
| 10459 | if (wakeup->four_way_handshake && |
| 10460 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 10461 | goto free_msg; |
| 10462 | if (wakeup->rfkill_release && |
| 10463 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 10464 | goto free_msg; |
| 10465 | |
| 10466 | if (wakeup->pattern_idx >= 0 && |
| 10467 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 10468 | wakeup->pattern_idx)) |
| 10469 | goto free_msg; |
| 10470 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10471 | if (wakeup->tcp_match) |
| 10472 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 10473 | |
| 10474 | if (wakeup->tcp_connlost) |
| 10475 | nla_put_flag(msg, |
| 10476 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 10477 | |
| 10478 | if (wakeup->tcp_nomoretokens) |
| 10479 | nla_put_flag(msg, |
| 10480 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 10481 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10482 | if (wakeup->packet) { |
| 10483 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 10484 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 10485 | |
| 10486 | if (!wakeup->packet_80211) { |
| 10487 | pkt_attr = |
| 10488 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 10489 | len_attr = |
| 10490 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 10491 | } |
| 10492 | |
| 10493 | if (wakeup->packet_len && |
| 10494 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 10495 | goto free_msg; |
| 10496 | |
| 10497 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 10498 | wakeup->packet)) |
| 10499 | goto free_msg; |
| 10500 | } |
| 10501 | |
| 10502 | nla_nest_end(msg, reasons); |
| 10503 | } |
| 10504 | |
| 10505 | err = genlmsg_end(msg, hdr); |
| 10506 | if (err < 0) |
| 10507 | goto free_msg; |
| 10508 | |
| 10509 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10510 | nl80211_mlme_mcgrp.id, gfp); |
| 10511 | return; |
| 10512 | |
| 10513 | free_msg: |
| 10514 | nlmsg_free(msg); |
| 10515 | } |
| 10516 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 10517 | #endif |
| 10518 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10519 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 10520 | enum nl80211_tdls_operation oper, |
| 10521 | u16 reason_code, gfp_t gfp) |
| 10522 | { |
| 10523 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10524 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10525 | struct sk_buff *msg; |
| 10526 | void *hdr; |
| 10527 | int err; |
| 10528 | |
| 10529 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 10530 | reason_code); |
| 10531 | |
| 10532 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10533 | if (!msg) |
| 10534 | return; |
| 10535 | |
| 10536 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 10537 | if (!hdr) { |
| 10538 | nlmsg_free(msg); |
| 10539 | return; |
| 10540 | } |
| 10541 | |
| 10542 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10543 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10544 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 10545 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 10546 | (reason_code > 0 && |
| 10547 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 10548 | goto nla_put_failure; |
| 10549 | |
| 10550 | err = genlmsg_end(msg, hdr); |
| 10551 | if (err < 0) { |
| 10552 | nlmsg_free(msg); |
| 10553 | return; |
| 10554 | } |
| 10555 | |
| 10556 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10557 | nl80211_mlme_mcgrp.id, gfp); |
| 10558 | return; |
| 10559 | |
| 10560 | nla_put_failure: |
| 10561 | genlmsg_cancel(msg, hdr); |
| 10562 | nlmsg_free(msg); |
| 10563 | } |
| 10564 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 10565 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10566 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 10567 | unsigned long state, |
| 10568 | void *_notify) |
| 10569 | { |
| 10570 | struct netlink_notify *notify = _notify; |
| 10571 | struct cfg80211_registered_device *rdev; |
| 10572 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10573 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10574 | |
| 10575 | if (state != NETLINK_URELEASE) |
| 10576 | return NOTIFY_DONE; |
| 10577 | |
| 10578 | rcu_read_lock(); |
| 10579 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10580 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10581 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10582 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10583 | |
| 10584 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10585 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 10586 | list) { |
| 10587 | if (reg->nlportid == notify->portid) { |
| 10588 | list_del(®->list); |
| 10589 | kfree(reg); |
| 10590 | break; |
| 10591 | } |
| 10592 | } |
| 10593 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10594 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10595 | |
| 10596 | rcu_read_unlock(); |
| 10597 | |
| 10598 | return NOTIFY_DONE; |
| 10599 | } |
| 10600 | |
| 10601 | static struct notifier_block nl80211_netlink_notifier = { |
| 10602 | .notifier_call = nl80211_netlink_notify, |
| 10603 | }; |
| 10604 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10605 | void cfg80211_ft_event(struct net_device *netdev, |
| 10606 | struct cfg80211_ft_event_params *ft_event) |
| 10607 | { |
| 10608 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 10609 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10610 | struct sk_buff *msg; |
| 10611 | void *hdr; |
| 10612 | int err; |
| 10613 | |
| 10614 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 10615 | |
| 10616 | if (!ft_event->target_ap) |
| 10617 | return; |
| 10618 | |
| 10619 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10620 | if (!msg) |
| 10621 | return; |
| 10622 | |
| 10623 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 10624 | if (!hdr) { |
| 10625 | nlmsg_free(msg); |
| 10626 | return; |
| 10627 | } |
| 10628 | |
| 10629 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 10630 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 10631 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 10632 | if (ft_event->ies) |
| 10633 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 10634 | if (ft_event->ric_ies) |
| 10635 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 10636 | ft_event->ric_ies); |
| 10637 | |
| 10638 | err = genlmsg_end(msg, hdr); |
| 10639 | if (err < 0) { |
| 10640 | nlmsg_free(msg); |
| 10641 | return; |
| 10642 | } |
| 10643 | |
| 10644 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10645 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 10646 | } |
| 10647 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 10648 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10649 | /* initialisation/exit functions */ |
| 10650 | |
| 10651 | int nl80211_init(void) |
| 10652 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10653 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10654 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10655 | err = genl_register_family_with_ops(&nl80211_fam, |
| 10656 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10657 | if (err) |
| 10658 | return err; |
| 10659 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10660 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 10661 | if (err) |
| 10662 | goto err_out; |
| 10663 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10664 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 10665 | if (err) |
| 10666 | goto err_out; |
| 10667 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10668 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 10669 | if (err) |
| 10670 | goto err_out; |
| 10671 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10672 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 10673 | if (err) |
| 10674 | goto err_out; |
| 10675 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10676 | #ifdef CONFIG_NL80211_TESTMODE |
| 10677 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 10678 | if (err) |
| 10679 | goto err_out; |
| 10680 | #endif |
| 10681 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10682 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10683 | if (err) |
| 10684 | goto err_out; |
| 10685 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10686 | return 0; |
| 10687 | err_out: |
| 10688 | genl_unregister_family(&nl80211_fam); |
| 10689 | return err; |
| 10690 | } |
| 10691 | |
| 10692 | void nl80211_exit(void) |
| 10693 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10694 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10695 | genl_unregister_family(&nl80211_fam); |
| 10696 | } |