Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
| 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = "nl80211", /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
| 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 50 | /* returns ERR_PTR values */ |
| 51 | static struct wireless_dev * |
| 52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 54 | struct cfg80211_registered_device *rdev; |
| 55 | struct wireless_dev *result = NULL; |
| 56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 58 | u64 wdev_id; |
| 59 | int wiphy_idx = -1; |
| 60 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 62 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | if (!have_ifidx && !have_wdev_id) |
| 65 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | if (have_ifidx) |
| 68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 69 | if (have_wdev_id) { |
| 70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 71 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 75 | struct wireless_dev *wdev; |
| 76 | |
| 77 | if (wiphy_net(&rdev->wiphy) != netns) |
| 78 | continue; |
| 79 | |
| 80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 81 | continue; |
| 82 | |
| 83 | mutex_lock(&rdev->devlist_mtx); |
| 84 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 85 | if (have_ifidx && wdev->netdev && |
| 86 | wdev->netdev->ifindex == ifidx) { |
| 87 | result = wdev; |
| 88 | break; |
| 89 | } |
| 90 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 91 | result = wdev; |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | mutex_unlock(&rdev->devlist_mtx); |
| 96 | |
| 97 | if (result) |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | if (result) |
| 102 | return result; |
| 103 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 107 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 108 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 109 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 110 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | |
| 112 | assert_cfg80211_lock(); |
| 113 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 114 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 115 | !attrs[NL80211_ATTR_IFINDEX] && |
| 116 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 117 | return ERR_PTR(-EINVAL); |
| 118 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 120 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 121 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 122 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 123 | if (attrs[NL80211_ATTR_WDEV]) { |
| 124 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 125 | struct wireless_dev *wdev; |
| 126 | bool found = false; |
| 127 | |
| 128 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 129 | if (tmp) { |
| 130 | /* make sure wdev exists */ |
| 131 | mutex_lock(&tmp->devlist_mtx); |
| 132 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 133 | if (wdev->identifier != (u32)wdev_id) |
| 134 | continue; |
| 135 | found = true; |
| 136 | break; |
| 137 | } |
| 138 | mutex_unlock(&tmp->devlist_mtx); |
| 139 | |
| 140 | if (!found) |
| 141 | tmp = NULL; |
| 142 | |
| 143 | if (rdev && tmp != rdev) |
| 144 | return ERR_PTR(-EINVAL); |
| 145 | rdev = tmp; |
| 146 | } |
| 147 | } |
| 148 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 149 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 150 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 151 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 152 | if (netdev) { |
| 153 | if (netdev->ieee80211_ptr) |
| 154 | tmp = wiphy_to_dev( |
| 155 | netdev->ieee80211_ptr->wiphy); |
| 156 | else |
| 157 | tmp = NULL; |
| 158 | |
| 159 | dev_put(netdev); |
| 160 | |
| 161 | /* not wireless device -- return error */ |
| 162 | if (!tmp) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | |
| 165 | /* mismatch -- return error */ |
| 166 | if (rdev && tmp != rdev) |
| 167 | return ERR_PTR(-EINVAL); |
| 168 | |
| 169 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 170 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 173 | if (!rdev) |
| 174 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 175 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 176 | if (netns != wiphy_net(&rdev->wiphy)) |
| 177 | return ERR_PTR(-ENODEV); |
| 178 | |
| 179 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * This function returns a pointer to the driver |
| 184 | * that the genl_info item that is passed refers to. |
| 185 | * If successful, it returns non-NULL and also locks |
| 186 | * the driver's mutex! |
| 187 | * |
| 188 | * This means that you need to call cfg80211_unlock_rdev() |
| 189 | * before being allowed to acquire &cfg80211_mutex! |
| 190 | * |
| 191 | * This is necessary because we need to lock the global |
| 192 | * mutex to get an item off the list safely, and then |
| 193 | * we lock the rdev mutex so it doesn't go away under us. |
| 194 | * |
| 195 | * We don't want to keep cfg80211_mutex locked |
| 196 | * for all the time in order to allow requests on |
| 197 | * other interfaces to go through at the same time. |
| 198 | * |
| 199 | * The result of this can be a PTR_ERR and hence must |
| 200 | * be checked with IS_ERR() for errors. |
| 201 | */ |
| 202 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 203 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 204 | { |
| 205 | struct cfg80211_registered_device *rdev; |
| 206 | |
| 207 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 208 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 209 | |
| 210 | /* if it is not an error we grab the lock on |
| 211 | * it to assure it won't be going away while |
| 212 | * we operate on it */ |
| 213 | if (!IS_ERR(rdev)) |
| 214 | mutex_lock(&rdev->mtx); |
| 215 | |
| 216 | mutex_unlock(&cfg80211_mutex); |
| 217 | |
| 218 | return rdev; |
| 219 | } |
| 220 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 221 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 222 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 224 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 225 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 226 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 227 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 230 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 232 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 233 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 234 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 235 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 236 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 237 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 238 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 239 | |
| 240 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 242 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 243 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 244 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 245 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 246 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 247 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 248 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 249 | .len = WLAN_MAX_KEY_LEN }, |
| 250 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 251 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 252 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 253 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 254 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 255 | |
| 256 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 257 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 258 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 259 | .len = IEEE80211_MAX_DATA_LEN }, |
| 260 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 263 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 264 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 265 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 266 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 268 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 270 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 271 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 272 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 273 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 274 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 275 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 276 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 277 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 278 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 279 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 280 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 281 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 283 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 284 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 285 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 286 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 287 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 288 | |
| 289 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 290 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 291 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 292 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 293 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 294 | |
| 295 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 296 | .len = IEEE80211_MAX_SSID_LEN }, |
| 297 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 298 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 302 | [NL80211_ATTR_STA_FLAGS2] = { |
| 303 | .len = sizeof(struct nl80211_sta_flag_update), |
| 304 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 306 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 307 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 309 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 310 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 313 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 314 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 315 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 316 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 319 | .len = IEEE80211_MAX_DATA_LEN }, |
| 320 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 323 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 324 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 325 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 326 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 328 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 329 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 330 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 331 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 332 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 333 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 334 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 336 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 337 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 339 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 340 | .len = IEEE80211_MAX_DATA_LEN }, |
| 341 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 342 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 343 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 344 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 345 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 346 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 347 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 348 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 349 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 350 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 351 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 352 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 353 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 354 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 355 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 356 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 357 | .len = NL80211_HT_CAPABILITY_LEN |
| 358 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 359 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 360 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 361 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 362 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 363 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 364 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 365 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 366 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 367 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 368 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 369 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 370 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 371 | }; |
| 372 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 373 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 374 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 375 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 376 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 377 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 378 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 379 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 380 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 381 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 382 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 383 | }; |
| 384 | |
| 385 | /* policy for the key default flags */ |
| 386 | static const struct nla_policy |
| 387 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 388 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 389 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 390 | }; |
| 391 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 392 | /* policy for WoWLAN attributes */ |
| 393 | static const struct nla_policy |
| 394 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 395 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 396 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 397 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 398 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 399 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 400 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 401 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 402 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 403 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 404 | }; |
| 405 | |
| 406 | static const struct nla_policy |
| 407 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 408 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 409 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 410 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 411 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 412 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 413 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 414 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 415 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 416 | }, |
| 417 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 418 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 419 | }, |
| 420 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 421 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 422 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 423 | }; |
| 424 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 425 | /* policy for GTK rekey offload attributes */ |
| 426 | static const struct nla_policy |
| 427 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 428 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 429 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 430 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 431 | }; |
| 432 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 433 | static const struct nla_policy |
| 434 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 435 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 436 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 437 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 438 | }; |
| 439 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 440 | /* ifidx get helper */ |
| 441 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 442 | { |
| 443 | int res; |
| 444 | |
| 445 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 446 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 447 | nl80211_policy); |
| 448 | if (res) |
| 449 | return res; |
| 450 | |
| 451 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 452 | return -EINVAL; |
| 453 | |
| 454 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 455 | if (!res) |
| 456 | return -EINVAL; |
| 457 | return res; |
| 458 | } |
| 459 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 460 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 461 | struct netlink_callback *cb, |
| 462 | struct cfg80211_registered_device **rdev, |
| 463 | struct net_device **dev) |
| 464 | { |
| 465 | int ifidx = cb->args[0]; |
| 466 | int err; |
| 467 | |
| 468 | if (!ifidx) |
| 469 | ifidx = nl80211_get_ifidx(cb); |
| 470 | if (ifidx < 0) |
| 471 | return ifidx; |
| 472 | |
| 473 | cb->args[0] = ifidx; |
| 474 | |
| 475 | rtnl_lock(); |
| 476 | |
| 477 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 478 | if (!*dev) { |
| 479 | err = -ENODEV; |
| 480 | goto out_rtnl; |
| 481 | } |
| 482 | |
| 483 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 484 | if (IS_ERR(*rdev)) { |
| 485 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 486 | goto out_rtnl; |
| 487 | } |
| 488 | |
| 489 | return 0; |
| 490 | out_rtnl: |
| 491 | rtnl_unlock(); |
| 492 | return err; |
| 493 | } |
| 494 | |
| 495 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 496 | { |
| 497 | cfg80211_unlock_rdev(rdev); |
| 498 | rtnl_unlock(); |
| 499 | } |
| 500 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 501 | /* IE validation */ |
| 502 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 503 | { |
| 504 | const u8 *pos; |
| 505 | int len; |
| 506 | |
| 507 | if (!attr) |
| 508 | return true; |
| 509 | |
| 510 | pos = nla_data(attr); |
| 511 | len = nla_len(attr); |
| 512 | |
| 513 | while (len) { |
| 514 | u8 elemlen; |
| 515 | |
| 516 | if (len < 2) |
| 517 | return false; |
| 518 | len -= 2; |
| 519 | |
| 520 | elemlen = pos[1]; |
| 521 | if (elemlen > len) |
| 522 | return false; |
| 523 | |
| 524 | len -= elemlen; |
| 525 | pos += 2 + elemlen; |
| 526 | } |
| 527 | |
| 528 | return true; |
| 529 | } |
| 530 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 531 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 532 | 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] | 533 | int flags, u8 cmd) |
| 534 | { |
| 535 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 536 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 537 | } |
| 538 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 539 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 540 | struct ieee80211_channel *chan) |
| 541 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 542 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 543 | chan->center_freq)) |
| 544 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 545 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 546 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 547 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 548 | goto nla_put_failure; |
| 549 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 550 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 551 | goto nla_put_failure; |
| 552 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 553 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 554 | goto nla_put_failure; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 555 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 556 | u32 time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 557 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 558 | goto nla_put_failure; |
| 559 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 560 | chan->dfs_state)) |
| 561 | goto nla_put_failure; |
| 562 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, time)) |
| 563 | goto nla_put_failure; |
| 564 | } |
Johannes Berg | 50640f1 | 2012-12-12 17:59:39 +0100 | [diff] [blame^] | 565 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 566 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 567 | goto nla_put_failure; |
| 568 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 569 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 570 | goto nla_put_failure; |
| 571 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 572 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 573 | goto nla_put_failure; |
| 574 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 575 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 576 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 577 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 578 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 579 | DBM_TO_MBM(chan->max_power))) |
| 580 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 581 | |
| 582 | return 0; |
| 583 | |
| 584 | nla_put_failure: |
| 585 | return -ENOBUFS; |
| 586 | } |
| 587 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 588 | /* netlink command implementations */ |
| 589 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 590 | struct key_parse { |
| 591 | struct key_params p; |
| 592 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 593 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 594 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 595 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 596 | }; |
| 597 | |
| 598 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 599 | { |
| 600 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 601 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 602 | nl80211_key_policy); |
| 603 | if (err) |
| 604 | return err; |
| 605 | |
| 606 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 607 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 608 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 609 | if (k->def) { |
| 610 | k->def_uni = true; |
| 611 | k->def_multi = true; |
| 612 | } |
| 613 | if (k->defmgmt) |
| 614 | k->def_multi = true; |
| 615 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 616 | if (tb[NL80211_KEY_IDX]) |
| 617 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 618 | |
| 619 | if (tb[NL80211_KEY_DATA]) { |
| 620 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 621 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 622 | } |
| 623 | |
| 624 | if (tb[NL80211_KEY_SEQ]) { |
| 625 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 626 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 627 | } |
| 628 | |
| 629 | if (tb[NL80211_KEY_CIPHER]) |
| 630 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 631 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 632 | if (tb[NL80211_KEY_TYPE]) { |
| 633 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 634 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 635 | return -EINVAL; |
| 636 | } |
| 637 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 638 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 639 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 640 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 641 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 642 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 643 | if (err) |
| 644 | return err; |
| 645 | |
| 646 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 647 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 648 | } |
| 649 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 654 | { |
| 655 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 656 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 657 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 658 | } |
| 659 | |
| 660 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 661 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 662 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 663 | } |
| 664 | |
| 665 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 666 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 667 | |
| 668 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 669 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 670 | |
| 671 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 672 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 673 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 674 | if (k->def) { |
| 675 | k->def_uni = true; |
| 676 | k->def_multi = true; |
| 677 | } |
| 678 | if (k->defmgmt) |
| 679 | k->def_multi = true; |
| 680 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 681 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 682 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 683 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 684 | return -EINVAL; |
| 685 | } |
| 686 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 687 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 688 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 689 | int err = nla_parse_nested( |
| 690 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 691 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 692 | nl80211_key_default_policy); |
| 693 | if (err) |
| 694 | return err; |
| 695 | |
| 696 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 697 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 698 | } |
| 699 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 700 | return 0; |
| 701 | } |
| 702 | |
| 703 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 704 | { |
| 705 | int err; |
| 706 | |
| 707 | memset(k, 0, sizeof(*k)); |
| 708 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 709 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 710 | |
| 711 | if (info->attrs[NL80211_ATTR_KEY]) |
| 712 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 713 | else |
| 714 | err = nl80211_parse_key_old(info, k); |
| 715 | |
| 716 | if (err) |
| 717 | return err; |
| 718 | |
| 719 | if (k->def && k->defmgmt) |
| 720 | return -EINVAL; |
| 721 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 722 | if (k->defmgmt) { |
| 723 | if (k->def_uni || !k->def_multi) |
| 724 | return -EINVAL; |
| 725 | } |
| 726 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 727 | if (k->idx != -1) { |
| 728 | if (k->defmgmt) { |
| 729 | if (k->idx < 4 || k->idx > 5) |
| 730 | return -EINVAL; |
| 731 | } else if (k->def) { |
| 732 | if (k->idx < 0 || k->idx > 3) |
| 733 | return -EINVAL; |
| 734 | } else { |
| 735 | if (k->idx < 0 || k->idx > 5) |
| 736 | return -EINVAL; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | return 0; |
| 741 | } |
| 742 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 743 | static struct cfg80211_cached_keys * |
| 744 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 745 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 746 | { |
| 747 | struct key_parse parse; |
| 748 | struct nlattr *key; |
| 749 | struct cfg80211_cached_keys *result; |
| 750 | int rem, err, def = 0; |
| 751 | |
| 752 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 753 | if (!result) |
| 754 | return ERR_PTR(-ENOMEM); |
| 755 | |
| 756 | result->def = -1; |
| 757 | result->defmgmt = -1; |
| 758 | |
| 759 | nla_for_each_nested(key, keys, rem) { |
| 760 | memset(&parse, 0, sizeof(parse)); |
| 761 | parse.idx = -1; |
| 762 | |
| 763 | err = nl80211_parse_key_new(key, &parse); |
| 764 | if (err) |
| 765 | goto error; |
| 766 | err = -EINVAL; |
| 767 | if (!parse.p.key) |
| 768 | goto error; |
| 769 | if (parse.idx < 0 || parse.idx > 4) |
| 770 | goto error; |
| 771 | if (parse.def) { |
| 772 | if (def) |
| 773 | goto error; |
| 774 | def = 1; |
| 775 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 776 | if (!parse.def_uni || !parse.def_multi) |
| 777 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 778 | } else if (parse.defmgmt) |
| 779 | goto error; |
| 780 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 781 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 782 | if (err) |
| 783 | goto error; |
| 784 | result->params[parse.idx].cipher = parse.p.cipher; |
| 785 | result->params[parse.idx].key_len = parse.p.key_len; |
| 786 | result->params[parse.idx].key = result->data[parse.idx]; |
| 787 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 788 | |
| 789 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 790 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 791 | if (no_ht) |
| 792 | *no_ht = true; |
| 793 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | return result; |
| 797 | error: |
| 798 | kfree(result); |
| 799 | return ERR_PTR(err); |
| 800 | } |
| 801 | |
| 802 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 803 | { |
| 804 | ASSERT_WDEV_LOCK(wdev); |
| 805 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 806 | switch (wdev->iftype) { |
| 807 | case NL80211_IFTYPE_AP: |
| 808 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 809 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 810 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 811 | break; |
| 812 | case NL80211_IFTYPE_ADHOC: |
| 813 | if (!wdev->current_bss) |
| 814 | return -ENOLINK; |
| 815 | break; |
| 816 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 817 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 818 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 819 | return -ENOLINK; |
| 820 | break; |
| 821 | default: |
| 822 | return -EINVAL; |
| 823 | } |
| 824 | |
| 825 | return 0; |
| 826 | } |
| 827 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 828 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 829 | { |
| 830 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 831 | int i; |
| 832 | |
| 833 | if (!nl_modes) |
| 834 | goto nla_put_failure; |
| 835 | |
| 836 | i = 0; |
| 837 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 838 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 839 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 840 | ifmodes >>= 1; |
| 841 | i++; |
| 842 | } |
| 843 | |
| 844 | nla_nest_end(msg, nl_modes); |
| 845 | return 0; |
| 846 | |
| 847 | nla_put_failure: |
| 848 | return -ENOBUFS; |
| 849 | } |
| 850 | |
| 851 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 852 | struct sk_buff *msg) |
| 853 | { |
| 854 | struct nlattr *nl_combis; |
| 855 | int i, j; |
| 856 | |
| 857 | nl_combis = nla_nest_start(msg, |
| 858 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 859 | if (!nl_combis) |
| 860 | goto nla_put_failure; |
| 861 | |
| 862 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 863 | const struct ieee80211_iface_combination *c; |
| 864 | struct nlattr *nl_combi, *nl_limits; |
| 865 | |
| 866 | c = &wiphy->iface_combinations[i]; |
| 867 | |
| 868 | nl_combi = nla_nest_start(msg, i + 1); |
| 869 | if (!nl_combi) |
| 870 | goto nla_put_failure; |
| 871 | |
| 872 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 873 | if (!nl_limits) |
| 874 | goto nla_put_failure; |
| 875 | |
| 876 | for (j = 0; j < c->n_limits; j++) { |
| 877 | struct nlattr *nl_limit; |
| 878 | |
| 879 | nl_limit = nla_nest_start(msg, j + 1); |
| 880 | if (!nl_limit) |
| 881 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 882 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 883 | c->limits[j].max)) |
| 884 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 885 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 886 | c->limits[j].types)) |
| 887 | goto nla_put_failure; |
| 888 | nla_nest_end(msg, nl_limit); |
| 889 | } |
| 890 | |
| 891 | nla_nest_end(msg, nl_limits); |
| 892 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 893 | if (c->beacon_int_infra_match && |
| 894 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 895 | goto nla_put_failure; |
| 896 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 897 | c->num_different_channels) || |
| 898 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 899 | c->max_interfaces)) |
| 900 | goto nla_put_failure; |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 901 | if (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 902 | c->radar_detect_widths)) |
| 903 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 904 | |
| 905 | nla_nest_end(msg, nl_combi); |
| 906 | } |
| 907 | |
| 908 | nla_nest_end(msg, nl_combis); |
| 909 | |
| 910 | return 0; |
| 911 | nla_put_failure: |
| 912 | return -ENOBUFS; |
| 913 | } |
| 914 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 915 | #ifdef CONFIG_PM |
| 916 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 917 | struct sk_buff *msg) |
| 918 | { |
| 919 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; |
| 920 | struct nlattr *nl_tcp; |
| 921 | |
| 922 | if (!tcp) |
| 923 | return 0; |
| 924 | |
| 925 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 926 | if (!nl_tcp) |
| 927 | return -ENOBUFS; |
| 928 | |
| 929 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 930 | tcp->data_payload_max)) |
| 931 | return -ENOBUFS; |
| 932 | |
| 933 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 934 | tcp->data_payload_max)) |
| 935 | return -ENOBUFS; |
| 936 | |
| 937 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 938 | return -ENOBUFS; |
| 939 | |
| 940 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 941 | sizeof(*tcp->tok), tcp->tok)) |
| 942 | return -ENOBUFS; |
| 943 | |
| 944 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 945 | tcp->data_interval_max)) |
| 946 | return -ENOBUFS; |
| 947 | |
| 948 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 949 | tcp->wake_payload_max)) |
| 950 | return -ENOBUFS; |
| 951 | |
| 952 | nla_nest_end(msg, nl_tcp); |
| 953 | return 0; |
| 954 | } |
| 955 | #endif |
| 956 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 957 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 958 | struct cfg80211_registered_device *dev) |
| 959 | { |
| 960 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 961 | struct nlattr *nl_bands, *nl_band; |
| 962 | struct nlattr *nl_freqs, *nl_freq; |
| 963 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 964 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 965 | enum ieee80211_band band; |
| 966 | struct ieee80211_channel *chan; |
| 967 | struct ieee80211_rate *rate; |
| 968 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 969 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 970 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 971 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 972 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 973 | if (!hdr) |
| 974 | return -1; |
| 975 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 976 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
| 977 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || |
| 978 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 979 | cfg80211_rdev_list_generation) || |
| 980 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 981 | dev->wiphy.retry_short) || |
| 982 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 983 | dev->wiphy.retry_long) || |
| 984 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 985 | dev->wiphy.frag_threshold) || |
| 986 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 987 | dev->wiphy.rts_threshold) || |
| 988 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 989 | dev->wiphy.coverage_class) || |
| 990 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 991 | dev->wiphy.max_scan_ssids) || |
| 992 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 993 | dev->wiphy.max_sched_scan_ssids) || |
| 994 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 995 | dev->wiphy.max_scan_ie_len) || |
| 996 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 997 | dev->wiphy.max_sched_scan_ie_len) || |
| 998 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 999 | dev->wiphy.max_match_sets)) |
| 1000 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1001 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1002 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1003 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1004 | goto nla_put_failure; |
| 1005 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1006 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1007 | goto nla_put_failure; |
| 1008 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1009 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1010 | goto nla_put_failure; |
| 1011 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1012 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1013 | goto nla_put_failure; |
| 1014 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1015 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1016 | goto nla_put_failure; |
| 1017 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1018 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 1019 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1020 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1021 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1022 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1023 | dev->wiphy.cipher_suites)) |
| 1024 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1025 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1026 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1027 | dev->wiphy.max_num_pmkids)) |
| 1028 | goto nla_put_failure; |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 1029 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1030 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1031 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1032 | goto nla_put_failure; |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 1033 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1034 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1035 | dev->wiphy.available_antennas_tx) || |
| 1036 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1037 | dev->wiphy.available_antennas_rx)) |
| 1038 | goto nla_put_failure; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1039 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1040 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1041 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1042 | dev->wiphy.probe_resp_offload)) |
| 1043 | goto nla_put_failure; |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 1044 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1045 | if ((dev->wiphy.available_antennas_tx || |
| 1046 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1047 | u32 tx_ant = 0, rx_ant = 0; |
| 1048 | int res; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1049 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1050 | if (!res) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1051 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1052 | tx_ant) || |
| 1053 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1054 | rx_ant)) |
| 1055 | goto nla_put_failure; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1056 | } |
| 1057 | } |
| 1058 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1059 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1060 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 1061 | goto nla_put_failure; |
| 1062 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1063 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1064 | if (!nl_bands) |
| 1065 | goto nla_put_failure; |
| 1066 | |
| 1067 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 1068 | if (!dev->wiphy.bands[band]) |
| 1069 | continue; |
| 1070 | |
| 1071 | nl_band = nla_nest_start(msg, band); |
| 1072 | if (!nl_band) |
| 1073 | goto nla_put_failure; |
| 1074 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1075 | /* add HT info */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1076 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
| 1077 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1078 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 1079 | &dev->wiphy.bands[band]->ht_cap.mcs) || |
| 1080 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1081 | dev->wiphy.bands[band]->ht_cap.cap) || |
| 1082 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1083 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || |
| 1084 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1085 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) |
| 1086 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1087 | |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1088 | /* add VHT info */ |
| 1089 | if (dev->wiphy.bands[band]->vht_cap.vht_supported && |
| 1090 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1091 | sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs), |
| 1092 | &dev->wiphy.bands[band]->vht_cap.vht_mcs) || |
| 1093 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1094 | dev->wiphy.bands[band]->vht_cap.cap))) |
| 1095 | goto nla_put_failure; |
| 1096 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1097 | /* add frequencies */ |
| 1098 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 1099 | if (!nl_freqs) |
| 1100 | goto nla_put_failure; |
| 1101 | |
| 1102 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 1103 | nl_freq = nla_nest_start(msg, i); |
| 1104 | if (!nl_freq) |
| 1105 | goto nla_put_failure; |
| 1106 | |
| 1107 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1108 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1109 | if (nl80211_msg_put_channel(msg, chan)) |
| 1110 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1111 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1112 | nla_nest_end(msg, nl_freq); |
| 1113 | } |
| 1114 | |
| 1115 | nla_nest_end(msg, nl_freqs); |
| 1116 | |
| 1117 | /* add bitrates */ |
| 1118 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1119 | if (!nl_rates) |
| 1120 | goto nla_put_failure; |
| 1121 | |
| 1122 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 1123 | nl_rate = nla_nest_start(msg, i); |
| 1124 | if (!nl_rate) |
| 1125 | goto nla_put_failure; |
| 1126 | |
| 1127 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1128 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1129 | rate->bitrate)) |
| 1130 | goto nla_put_failure; |
| 1131 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1132 | nla_put_flag(msg, |
| 1133 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1134 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1135 | |
| 1136 | nla_nest_end(msg, nl_rate); |
| 1137 | } |
| 1138 | |
| 1139 | nla_nest_end(msg, nl_rates); |
| 1140 | |
| 1141 | nla_nest_end(msg, nl_band); |
| 1142 | } |
| 1143 | nla_nest_end(msg, nl_bands); |
| 1144 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1145 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1146 | if (!nl_cmds) |
| 1147 | goto nla_put_failure; |
| 1148 | |
| 1149 | i = 0; |
| 1150 | #define CMD(op, n) \ |
| 1151 | do { \ |
| 1152 | if (dev->ops->op) { \ |
| 1153 | i++; \ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1154 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1155 | goto nla_put_failure; \ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1156 | } \ |
| 1157 | } while (0) |
| 1158 | |
| 1159 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1160 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1161 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1162 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1163 | CMD(add_station, NEW_STATION); |
| 1164 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 1165 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1166 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1167 | CMD(auth, AUTHENTICATE); |
| 1168 | CMD(assoc, ASSOCIATE); |
| 1169 | CMD(deauth, DEAUTHENTICATE); |
| 1170 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1171 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1172 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1173 | CMD(set_pmksa, SET_PMKSA); |
| 1174 | CMD(del_pmksa, DEL_PMKSA); |
| 1175 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1176 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1177 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 1178 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1179 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1180 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 1181 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1182 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1183 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1184 | goto nla_put_failure; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1185 | } |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1186 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1187 | dev->ops->join_mesh) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1188 | i++; |
| 1189 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1190 | goto nla_put_failure; |
| 1191 | } |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1192 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 1193 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1194 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1195 | CMD(tdls_oper, TDLS_OPER); |
| 1196 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 1197 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1198 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 1199 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1200 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1201 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1202 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1203 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1204 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1205 | } |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1206 | CMD(start_p2p_device, START_P2P_DEVICE); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 1207 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1208 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1209 | #ifdef CONFIG_NL80211_TESTMODE |
| 1210 | CMD(testmode_cmd, TESTMODE); |
| 1211 | #endif |
| 1212 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1213 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1214 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1215 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1216 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1217 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1218 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1219 | } |
| 1220 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1221 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1222 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1223 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1224 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1225 | } |
| 1226 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1227 | nla_nest_end(msg, nl_cmds); |
| 1228 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1229 | if (dev->ops->remain_on_channel && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1230 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1231 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1232 | dev->wiphy.max_remain_on_channel_duration)) |
| 1233 | goto nla_put_failure; |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 1234 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1235 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1236 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1237 | goto nla_put_failure; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1238 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1239 | if (mgmt_stypes) { |
| 1240 | u16 stypes; |
| 1241 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1242 | enum nl80211_iftype ift; |
| 1243 | |
| 1244 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1245 | if (!nl_ifs) |
| 1246 | goto nla_put_failure; |
| 1247 | |
| 1248 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1249 | nl_ftypes = nla_nest_start(msg, ift); |
| 1250 | if (!nl_ftypes) |
| 1251 | goto nla_put_failure; |
| 1252 | i = 0; |
| 1253 | stypes = mgmt_stypes[ift].tx; |
| 1254 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1255 | if ((stypes & 1) && |
| 1256 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1257 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1258 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1259 | stypes >>= 1; |
| 1260 | i++; |
| 1261 | } |
| 1262 | nla_nest_end(msg, nl_ftypes); |
| 1263 | } |
| 1264 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1265 | nla_nest_end(msg, nl_ifs); |
| 1266 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1267 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1268 | if (!nl_ifs) |
| 1269 | goto nla_put_failure; |
| 1270 | |
| 1271 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1272 | nl_ftypes = nla_nest_start(msg, ift); |
| 1273 | if (!nl_ftypes) |
| 1274 | goto nla_put_failure; |
| 1275 | i = 0; |
| 1276 | stypes = mgmt_stypes[ift].rx; |
| 1277 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1278 | if ((stypes & 1) && |
| 1279 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1280 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1281 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1282 | stypes >>= 1; |
| 1283 | i++; |
| 1284 | } |
| 1285 | nla_nest_end(msg, nl_ftypes); |
| 1286 | } |
| 1287 | nla_nest_end(msg, nl_ifs); |
| 1288 | } |
| 1289 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1290 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1291 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 1292 | struct nlattr *nl_wowlan; |
| 1293 | |
| 1294 | nl_wowlan = nla_nest_start(msg, |
| 1295 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1296 | if (!nl_wowlan) |
| 1297 | goto nla_put_failure; |
| 1298 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1299 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 1300 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1301 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1302 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1303 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1304 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1305 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1306 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1307 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1308 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1309 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1310 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1311 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1312 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1313 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1314 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1315 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1316 | if (dev->wiphy.wowlan.n_patterns) { |
| 1317 | struct nl80211_wowlan_pattern_support pat = { |
| 1318 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1319 | .min_pattern_len = |
| 1320 | dev->wiphy.wowlan.pattern_min_len, |
| 1321 | .max_pattern_len = |
| 1322 | dev->wiphy.wowlan.pattern_max_len, |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 1323 | .max_pkt_offset = |
| 1324 | dev->wiphy.wowlan.max_pkt_offset, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1325 | }; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1326 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1327 | sizeof(pat), &pat)) |
| 1328 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1329 | } |
| 1330 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 1331 | if (nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1332 | goto nla_put_failure; |
| 1333 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1334 | nla_nest_end(msg, nl_wowlan); |
| 1335 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1336 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1337 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1338 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1339 | dev->wiphy.software_iftypes)) |
| 1340 | goto nla_put_failure; |
| 1341 | |
| 1342 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1343 | goto nla_put_failure; |
| 1344 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1345 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1346 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1347 | dev->wiphy.ap_sme_capa)) |
| 1348 | goto nla_put_failure; |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1349 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1350 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
| 1351 | dev->wiphy.features)) |
| 1352 | goto nla_put_failure; |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1353 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1354 | if (dev->wiphy.ht_capa_mod_mask && |
| 1355 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1356 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1357 | dev->wiphy.ht_capa_mod_mask)) |
| 1358 | goto nla_put_failure; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1359 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 1360 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1361 | dev->wiphy.max_acl_mac_addrs && |
| 1362 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1363 | dev->wiphy.max_acl_mac_addrs)) |
| 1364 | goto nla_put_failure; |
| 1365 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1366 | return genlmsg_end(msg, hdr); |
| 1367 | |
| 1368 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1369 | genlmsg_cancel(msg, hdr); |
| 1370 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1374 | { |
| 1375 | int idx = 0; |
| 1376 | int start = cb->args[0]; |
| 1377 | struct cfg80211_registered_device *dev; |
| 1378 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1379 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1380 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1381 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1382 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1383 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1384 | continue; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1385 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1386 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1387 | dev) < 0) { |
| 1388 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1389 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1390 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1391 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1392 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1393 | |
| 1394 | cb->args[0] = idx; |
| 1395 | |
| 1396 | return skb->len; |
| 1397 | } |
| 1398 | |
| 1399 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1400 | { |
| 1401 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1402 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1403 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1404 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1405 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1406 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1407 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1408 | if (nl80211_send_wiphy(msg, info->snd_portid, info->snd_seq, 0, dev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1409 | nlmsg_free(msg); |
| 1410 | return -ENOBUFS; |
| 1411 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1412 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1413 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1414 | } |
| 1415 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1416 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1417 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1418 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1419 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1420 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1421 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1422 | }; |
| 1423 | |
| 1424 | static int parse_txq_params(struct nlattr *tb[], |
| 1425 | struct ieee80211_txq_params *txq_params) |
| 1426 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1427 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1428 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1429 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1430 | return -EINVAL; |
| 1431 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1432 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1433 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1434 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1435 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1436 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1437 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1438 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1439 | return -EINVAL; |
| 1440 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1441 | return 0; |
| 1442 | } |
| 1443 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1444 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1445 | { |
| 1446 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1447 | * You can only set the channel explicitly for WDS interfaces, |
| 1448 | * all others have their channel managed via their respective |
| 1449 | * "establish a connection" command (connect, join, ...) |
| 1450 | * |
| 1451 | * For AP/GO and mesh mode, the channel can be set with the |
| 1452 | * channel userspace API, but is only stored and passed to the |
| 1453 | * low-level driver when the AP starts or the mesh is joined. |
| 1454 | * This is for backward compatibility, userspace can also give |
| 1455 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1456 | * |
| 1457 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1458 | * whatever else is going on, so they have their own special |
| 1459 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1460 | */ |
| 1461 | return !wdev || |
| 1462 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1463 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1464 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1465 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1466 | } |
| 1467 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1468 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1469 | struct genl_info *info, |
| 1470 | struct cfg80211_chan_def *chandef) |
| 1471 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1472 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1473 | |
| 1474 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1475 | return -EINVAL; |
| 1476 | |
| 1477 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1478 | |
| 1479 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1480 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1481 | chandef->center_freq1 = control_freq; |
| 1482 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1483 | |
| 1484 | /* Primary channel not allowed */ |
| 1485 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1486 | return -EINVAL; |
| 1487 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1488 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1489 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1490 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1491 | chantype = nla_get_u32( |
| 1492 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1493 | |
| 1494 | switch (chantype) { |
| 1495 | case NL80211_CHAN_NO_HT: |
| 1496 | case NL80211_CHAN_HT20: |
| 1497 | case NL80211_CHAN_HT40PLUS: |
| 1498 | case NL80211_CHAN_HT40MINUS: |
| 1499 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1500 | chantype); |
| 1501 | break; |
| 1502 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1503 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1504 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1505 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1506 | chandef->width = |
| 1507 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1508 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1509 | chandef->center_freq1 = |
| 1510 | nla_get_u32( |
| 1511 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1512 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1513 | chandef->center_freq2 = |
| 1514 | nla_get_u32( |
| 1515 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1516 | } |
| 1517 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1518 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1519 | return -EINVAL; |
| 1520 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1521 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1522 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1523 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1524 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1525 | return 0; |
| 1526 | } |
| 1527 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1528 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1529 | struct wireless_dev *wdev, |
| 1530 | struct genl_info *info) |
| 1531 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1532 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1533 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1534 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1535 | |
| 1536 | if (wdev) |
| 1537 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1538 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1539 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1540 | return -EOPNOTSUPP; |
| 1541 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1542 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1543 | if (result) |
| 1544 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1545 | |
| 1546 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1547 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1548 | case NL80211_IFTYPE_AP: |
| 1549 | case NL80211_IFTYPE_P2P_GO: |
| 1550 | if (wdev->beacon_interval) { |
| 1551 | result = -EBUSY; |
| 1552 | break; |
| 1553 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1554 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1555 | result = -EINVAL; |
| 1556 | break; |
| 1557 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1558 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1559 | result = 0; |
| 1560 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1561 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1562 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1563 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1564 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1565 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1566 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1567 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1568 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1569 | } |
| 1570 | mutex_unlock(&rdev->devlist_mtx); |
| 1571 | |
| 1572 | return result; |
| 1573 | } |
| 1574 | |
| 1575 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1576 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1577 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1578 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1579 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1580 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1581 | } |
| 1582 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1583 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1584 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1585 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1586 | struct net_device *dev = info->user_ptr[1]; |
| 1587 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1588 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1589 | |
| 1590 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1591 | return -EINVAL; |
| 1592 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1593 | if (netif_running(dev)) |
| 1594 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1595 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1596 | if (!rdev->ops->set_wds_peer) |
| 1597 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1598 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1599 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1600 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1601 | |
| 1602 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1603 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1607 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1608 | { |
| 1609 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1610 | struct net_device *netdev = NULL; |
| 1611 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1612 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1613 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1614 | u32 changed; |
| 1615 | u8 retry_short = 0, retry_long = 0; |
| 1616 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1617 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1618 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1619 | /* |
| 1620 | * Try to find the wiphy and netdev. Normally this |
| 1621 | * function shouldn't need the netdev, but this is |
| 1622 | * done for backward compatibility -- previously |
| 1623 | * setting the channel was done per wiphy, but now |
| 1624 | * it is per netdev. Previous userland like hostapd |
| 1625 | * also passed a netdev to set_wiphy, so that it is |
| 1626 | * possible to let that go to the right netdev! |
| 1627 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1628 | mutex_lock(&cfg80211_mutex); |
| 1629 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1630 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1631 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1632 | |
| 1633 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1634 | if (netdev && netdev->ieee80211_ptr) { |
| 1635 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1636 | mutex_lock(&rdev->mtx); |
| 1637 | } else |
| 1638 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1639 | } |
| 1640 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1641 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1642 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1643 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1644 | if (IS_ERR(rdev)) { |
| 1645 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1646 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1647 | } |
| 1648 | wdev = NULL; |
| 1649 | netdev = NULL; |
| 1650 | result = 0; |
| 1651 | |
| 1652 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1653 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1654 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1655 | |
| 1656 | /* |
| 1657 | * end workaround code, by now the rdev is available |
| 1658 | * and locked, and wdev may or may not be NULL. |
| 1659 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1660 | |
| 1661 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1662 | result = cfg80211_dev_rename( |
| 1663 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1664 | |
| 1665 | mutex_unlock(&cfg80211_mutex); |
| 1666 | |
| 1667 | if (result) |
| 1668 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1669 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1670 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1671 | struct ieee80211_txq_params txq_params; |
| 1672 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1673 | |
| 1674 | if (!rdev->ops->set_txq_params) { |
| 1675 | result = -EOPNOTSUPP; |
| 1676 | goto bad_res; |
| 1677 | } |
| 1678 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1679 | if (!netdev) { |
| 1680 | result = -EINVAL; |
| 1681 | goto bad_res; |
| 1682 | } |
| 1683 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1684 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1685 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1686 | result = -EINVAL; |
| 1687 | goto bad_res; |
| 1688 | } |
| 1689 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1690 | if (!netif_running(netdev)) { |
| 1691 | result = -ENETDOWN; |
| 1692 | goto bad_res; |
| 1693 | } |
| 1694 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1695 | nla_for_each_nested(nl_txq_params, |
| 1696 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1697 | rem_txq_params) { |
| 1698 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1699 | nla_data(nl_txq_params), |
| 1700 | nla_len(nl_txq_params), |
| 1701 | txq_params_policy); |
| 1702 | result = parse_txq_params(tb, &txq_params); |
| 1703 | if (result) |
| 1704 | goto bad_res; |
| 1705 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1706 | result = rdev_set_txq_params(rdev, netdev, |
| 1707 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1708 | if (result) |
| 1709 | goto bad_res; |
| 1710 | } |
| 1711 | } |
| 1712 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1713 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1714 | result = __nl80211_set_channel(rdev, |
| 1715 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1716 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1717 | if (result) |
| 1718 | goto bad_res; |
| 1719 | } |
| 1720 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1721 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1722 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1723 | enum nl80211_tx_power_setting type; |
| 1724 | int idx, mbm = 0; |
| 1725 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1726 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1727 | txp_wdev = NULL; |
| 1728 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1729 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1730 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1731 | goto bad_res; |
| 1732 | } |
| 1733 | |
| 1734 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1735 | type = nla_get_u32(info->attrs[idx]); |
| 1736 | |
| 1737 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1738 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1739 | result = -EINVAL; |
| 1740 | goto bad_res; |
| 1741 | } |
| 1742 | |
| 1743 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1744 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1745 | mbm = nla_get_u32(info->attrs[idx]); |
| 1746 | } |
| 1747 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1748 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1749 | if (result) |
| 1750 | goto bad_res; |
| 1751 | } |
| 1752 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1753 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1754 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1755 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1756 | if ((!rdev->wiphy.available_antennas_tx && |
| 1757 | !rdev->wiphy.available_antennas_rx) || |
| 1758 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1759 | result = -EOPNOTSUPP; |
| 1760 | goto bad_res; |
| 1761 | } |
| 1762 | |
| 1763 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1764 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1765 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1766 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1767 | * available antenna masks, except for the "all" mask */ |
| 1768 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1769 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1770 | result = -EINVAL; |
| 1771 | goto bad_res; |
| 1772 | } |
| 1773 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1774 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1775 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1776 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1777 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1778 | if (result) |
| 1779 | goto bad_res; |
| 1780 | } |
| 1781 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1782 | changed = 0; |
| 1783 | |
| 1784 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1785 | retry_short = nla_get_u8( |
| 1786 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1787 | if (retry_short == 0) { |
| 1788 | result = -EINVAL; |
| 1789 | goto bad_res; |
| 1790 | } |
| 1791 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1792 | } |
| 1793 | |
| 1794 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1795 | retry_long = nla_get_u8( |
| 1796 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1797 | if (retry_long == 0) { |
| 1798 | result = -EINVAL; |
| 1799 | goto bad_res; |
| 1800 | } |
| 1801 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1802 | } |
| 1803 | |
| 1804 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1805 | frag_threshold = nla_get_u32( |
| 1806 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1807 | if (frag_threshold < 256) { |
| 1808 | result = -EINVAL; |
| 1809 | goto bad_res; |
| 1810 | } |
| 1811 | if (frag_threshold != (u32) -1) { |
| 1812 | /* |
| 1813 | * Fragments (apart from the last one) are required to |
| 1814 | * have even length. Make the fragmentation code |
| 1815 | * simpler by stripping LSB should someone try to use |
| 1816 | * odd threshold value. |
| 1817 | */ |
| 1818 | frag_threshold &= ~0x1; |
| 1819 | } |
| 1820 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1821 | } |
| 1822 | |
| 1823 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1824 | rts_threshold = nla_get_u32( |
| 1825 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1826 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1827 | } |
| 1828 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1829 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1830 | coverage_class = nla_get_u8( |
| 1831 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1832 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1833 | } |
| 1834 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1835 | if (changed) { |
| 1836 | u8 old_retry_short, old_retry_long; |
| 1837 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1838 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1839 | |
| 1840 | if (!rdev->ops->set_wiphy_params) { |
| 1841 | result = -EOPNOTSUPP; |
| 1842 | goto bad_res; |
| 1843 | } |
| 1844 | |
| 1845 | old_retry_short = rdev->wiphy.retry_short; |
| 1846 | old_retry_long = rdev->wiphy.retry_long; |
| 1847 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1848 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1849 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1850 | |
| 1851 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1852 | rdev->wiphy.retry_short = retry_short; |
| 1853 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1854 | rdev->wiphy.retry_long = retry_long; |
| 1855 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1856 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1857 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1858 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1859 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1860 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1861 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1862 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1863 | if (result) { |
| 1864 | rdev->wiphy.retry_short = old_retry_short; |
| 1865 | rdev->wiphy.retry_long = old_retry_long; |
| 1866 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1867 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1868 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1869 | } |
| 1870 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1871 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1872 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1873 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1874 | if (netdev) |
| 1875 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1876 | return result; |
| 1877 | } |
| 1878 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1879 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1880 | { |
| 1881 | return (u64)wdev->identifier | |
| 1882 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1883 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1884 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1885 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 1886 | struct cfg80211_chan_def *chandef) |
| 1887 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1888 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1889 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1890 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1891 | chandef->chan->center_freq)) |
| 1892 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1893 | switch (chandef->width) { |
| 1894 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1895 | case NL80211_CHAN_WIDTH_20: |
| 1896 | case NL80211_CHAN_WIDTH_40: |
| 1897 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1898 | cfg80211_get_chandef_type(chandef))) |
| 1899 | return -ENOBUFS; |
| 1900 | break; |
| 1901 | default: |
| 1902 | break; |
| 1903 | } |
| 1904 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 1905 | return -ENOBUFS; |
| 1906 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 1907 | return -ENOBUFS; |
| 1908 | if (chandef->center_freq2 && |
| 1909 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1910 | return -ENOBUFS; |
| 1911 | return 0; |
| 1912 | } |
| 1913 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1914 | 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] | 1915 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1916 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1917 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1918 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1919 | void *hdr; |
| 1920 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1921 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1922 | if (!hdr) |
| 1923 | return -1; |
| 1924 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1925 | if (dev && |
| 1926 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1927 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1928 | goto nla_put_failure; |
| 1929 | |
| 1930 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1931 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1932 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1933 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1934 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1935 | rdev->devlist_generation ^ |
| 1936 | (cfg80211_rdev_list_generation << 2))) |
| 1937 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1938 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1939 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1940 | int ret; |
| 1941 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1942 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1943 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 1944 | if (ret == 0) { |
| 1945 | if (nl80211_send_chandef(msg, &chandef)) |
| 1946 | goto nla_put_failure; |
| 1947 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1948 | } |
| 1949 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 1950 | if (wdev->ssid_len) { |
| 1951 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 1952 | goto nla_put_failure; |
| 1953 | } |
| 1954 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1955 | return genlmsg_end(msg, hdr); |
| 1956 | |
| 1957 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1958 | genlmsg_cancel(msg, hdr); |
| 1959 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1963 | { |
| 1964 | int wp_idx = 0; |
| 1965 | int if_idx = 0; |
| 1966 | int wp_start = cb->args[0]; |
| 1967 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1968 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1969 | struct wireless_dev *wdev; |
| 1970 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1971 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1972 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1973 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1974 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1975 | if (wp_idx < wp_start) { |
| 1976 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1977 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1978 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1979 | if_idx = 0; |
| 1980 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1981 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1982 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1983 | if (if_idx < if_start) { |
| 1984 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1985 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1986 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1987 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1988 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1989 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1990 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1991 | goto out; |
| 1992 | } |
| 1993 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1994 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1995 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1996 | |
| 1997 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1998 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1999 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2000 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2001 | |
| 2002 | cb->args[0] = wp_idx; |
| 2003 | cb->args[1] = if_idx; |
| 2004 | |
| 2005 | return skb->len; |
| 2006 | } |
| 2007 | |
| 2008 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2009 | { |
| 2010 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2011 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2012 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2013 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2014 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2015 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2016 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2017 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2018 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2019 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2020 | nlmsg_free(msg); |
| 2021 | return -ENOBUFS; |
| 2022 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2023 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2024 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2025 | } |
| 2026 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2027 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2028 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2029 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2030 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2031 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2032 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 2033 | }; |
| 2034 | |
| 2035 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2036 | { |
| 2037 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2038 | int flag; |
| 2039 | |
| 2040 | *mntrflags = 0; |
| 2041 | |
| 2042 | if (!nla) |
| 2043 | return -EINVAL; |
| 2044 | |
| 2045 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2046 | nla, mntr_flags_policy)) |
| 2047 | return -EINVAL; |
| 2048 | |
| 2049 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2050 | if (flags[flag]) |
| 2051 | *mntrflags |= (1<<flag); |
| 2052 | |
| 2053 | return 0; |
| 2054 | } |
| 2055 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2056 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2057 | struct net_device *netdev, u8 use_4addr, |
| 2058 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2059 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2060 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2061 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2062 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2063 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2064 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2065 | |
| 2066 | switch (iftype) { |
| 2067 | case NL80211_IFTYPE_AP_VLAN: |
| 2068 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2069 | return 0; |
| 2070 | break; |
| 2071 | case NL80211_IFTYPE_STATION: |
| 2072 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2073 | return 0; |
| 2074 | break; |
| 2075 | default: |
| 2076 | break; |
| 2077 | } |
| 2078 | |
| 2079 | return -EOPNOTSUPP; |
| 2080 | } |
| 2081 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2082 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2083 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2084 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2085 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2086 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2087 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2088 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2089 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2090 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2091 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2092 | memset(¶ms, 0, sizeof(params)); |
| 2093 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2094 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2095 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2096 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2097 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2098 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2099 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2100 | if (ntype > NL80211_IFTYPE_MAX) |
| 2101 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2102 | } |
| 2103 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2104 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2105 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2106 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2107 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2108 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2109 | if (netif_running(dev)) |
| 2110 | return -EBUSY; |
| 2111 | |
| 2112 | wdev_lock(wdev); |
| 2113 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2114 | IEEE80211_MAX_MESH_ID_LEN); |
| 2115 | wdev->mesh_id_up_len = |
| 2116 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2117 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2118 | wdev->mesh_id_up_len); |
| 2119 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2120 | } |
| 2121 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2122 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2123 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2124 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2125 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2126 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2127 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2128 | } else { |
| 2129 | params.use_4addr = -1; |
| 2130 | } |
| 2131 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2132 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2133 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2134 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2135 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2136 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2137 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2138 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2139 | |
| 2140 | flags = &_flags; |
| 2141 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2142 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2143 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2144 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2145 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2146 | else |
| 2147 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2148 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2149 | if (!err && params.use_4addr != -1) |
| 2150 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2151 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2152 | return err; |
| 2153 | } |
| 2154 | |
| 2155 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2156 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2157 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2158 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2159 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2160 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2161 | int err; |
| 2162 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2163 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2164 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2165 | memset(¶ms, 0, sizeof(params)); |
| 2166 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2167 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2168 | return -EINVAL; |
| 2169 | |
| 2170 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2171 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2172 | if (type > NL80211_IFTYPE_MAX) |
| 2173 | return -EINVAL; |
| 2174 | } |
| 2175 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2176 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2177 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2178 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2179 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2180 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2181 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2182 | ETH_ALEN); |
| 2183 | if (!is_valid_ether_addr(params.macaddr)) |
| 2184 | return -EADDRNOTAVAIL; |
| 2185 | } |
| 2186 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2187 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2188 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2189 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2190 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2191 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2192 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2193 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2194 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2195 | if (!msg) |
| 2196 | return -ENOMEM; |
| 2197 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2198 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2199 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2200 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2201 | wdev = rdev_add_virtual_intf(rdev, |
| 2202 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2203 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2204 | if (IS_ERR(wdev)) { |
| 2205 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2206 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2207 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2208 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2209 | switch (type) { |
| 2210 | case NL80211_IFTYPE_MESH_POINT: |
| 2211 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2212 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2213 | wdev_lock(wdev); |
| 2214 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2215 | IEEE80211_MAX_MESH_ID_LEN); |
| 2216 | wdev->mesh_id_up_len = |
| 2217 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2218 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2219 | wdev->mesh_id_up_len); |
| 2220 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2221 | break; |
| 2222 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2223 | /* |
| 2224 | * P2P Device doesn't have a netdev, so doesn't go |
| 2225 | * through the netdev notifier and must be added here |
| 2226 | */ |
| 2227 | mutex_init(&wdev->mtx); |
| 2228 | INIT_LIST_HEAD(&wdev->event_list); |
| 2229 | spin_lock_init(&wdev->event_lock); |
| 2230 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2231 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2232 | |
| 2233 | mutex_lock(&rdev->devlist_mtx); |
| 2234 | wdev->identifier = ++rdev->wdev_id; |
| 2235 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2236 | rdev->devlist_generation++; |
| 2237 | mutex_unlock(&rdev->devlist_mtx); |
| 2238 | break; |
| 2239 | default: |
| 2240 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2241 | } |
| 2242 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2243 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2244 | rdev, wdev) < 0) { |
| 2245 | nlmsg_free(msg); |
| 2246 | return -ENOBUFS; |
| 2247 | } |
| 2248 | |
| 2249 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2253 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2254 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2255 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2256 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2257 | if (!rdev->ops->del_virtual_intf) |
| 2258 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2259 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2260 | /* |
| 2261 | * If we remove a wireless device without a netdev then clear |
| 2262 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2263 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2264 | * since the wdev has been freed, unlike with a netdev where |
| 2265 | * we need the dev_put() for the netdev to really be freed. |
| 2266 | */ |
| 2267 | if (!wdev->netdev) |
| 2268 | info->user_ptr[1] = NULL; |
| 2269 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2270 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2271 | } |
| 2272 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2273 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2274 | { |
| 2275 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2276 | struct net_device *dev = info->user_ptr[1]; |
| 2277 | u16 noack_map; |
| 2278 | |
| 2279 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2280 | return -EINVAL; |
| 2281 | |
| 2282 | if (!rdev->ops->set_noack_map) |
| 2283 | return -EOPNOTSUPP; |
| 2284 | |
| 2285 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2286 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2287 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2288 | } |
| 2289 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2290 | struct get_key_cookie { |
| 2291 | struct sk_buff *msg; |
| 2292 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2293 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2294 | }; |
| 2295 | |
| 2296 | static void get_key_callback(void *c, struct key_params *params) |
| 2297 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2298 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2299 | struct get_key_cookie *cookie = c; |
| 2300 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2301 | if ((params->key && |
| 2302 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2303 | params->key_len, params->key)) || |
| 2304 | (params->seq && |
| 2305 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2306 | params->seq_len, params->seq)) || |
| 2307 | (params->cipher && |
| 2308 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2309 | params->cipher))) |
| 2310 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2311 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2312 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2313 | if (!key) |
| 2314 | goto nla_put_failure; |
| 2315 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2316 | if ((params->key && |
| 2317 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2318 | params->key_len, params->key)) || |
| 2319 | (params->seq && |
| 2320 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2321 | params->seq_len, params->seq)) || |
| 2322 | (params->cipher && |
| 2323 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2324 | params->cipher))) |
| 2325 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2326 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2327 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2328 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2329 | |
| 2330 | nla_nest_end(cookie->msg, key); |
| 2331 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2332 | return; |
| 2333 | nla_put_failure: |
| 2334 | cookie->error = 1; |
| 2335 | } |
| 2336 | |
| 2337 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2338 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2339 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2340 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2341 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2342 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2343 | const u8 *mac_addr = NULL; |
| 2344 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2345 | struct get_key_cookie cookie = { |
| 2346 | .error = 0, |
| 2347 | }; |
| 2348 | void *hdr; |
| 2349 | struct sk_buff *msg; |
| 2350 | |
| 2351 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2352 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2353 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2354 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2355 | return -EINVAL; |
| 2356 | |
| 2357 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2358 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2359 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2360 | pairwise = !!mac_addr; |
| 2361 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2362 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2363 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2364 | return -EINVAL; |
| 2365 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2366 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2367 | return -EINVAL; |
| 2368 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2369 | } |
| 2370 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2371 | if (!rdev->ops->get_key) |
| 2372 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2373 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2374 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2375 | if (!msg) |
| 2376 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2377 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2378 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2379 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2380 | if (IS_ERR(hdr)) |
| 2381 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2382 | |
| 2383 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2384 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2385 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2386 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2387 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2388 | goto nla_put_failure; |
| 2389 | if (mac_addr && |
| 2390 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2391 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2392 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2393 | if (pairwise && mac_addr && |
| 2394 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2395 | return -ENOENT; |
| 2396 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2397 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2398 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2399 | |
| 2400 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2401 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2402 | |
| 2403 | if (cookie.error) |
| 2404 | goto nla_put_failure; |
| 2405 | |
| 2406 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2407 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2408 | |
| 2409 | nla_put_failure: |
| 2410 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2411 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2412 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2413 | return err; |
| 2414 | } |
| 2415 | |
| 2416 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2417 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2418 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2419 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2420 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2421 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2422 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2423 | err = nl80211_parse_key(info, &key); |
| 2424 | if (err) |
| 2425 | return err; |
| 2426 | |
| 2427 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2428 | return -EINVAL; |
| 2429 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2430 | /* only support setting default key */ |
| 2431 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2432 | return -EINVAL; |
| 2433 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2434 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2435 | |
| 2436 | if (key.def) { |
| 2437 | if (!rdev->ops->set_default_key) { |
| 2438 | err = -EOPNOTSUPP; |
| 2439 | goto out; |
| 2440 | } |
| 2441 | |
| 2442 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2443 | if (err) |
| 2444 | goto out; |
| 2445 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2446 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2447 | key.def_uni, key.def_multi); |
| 2448 | |
| 2449 | if (err) |
| 2450 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2451 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2452 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2453 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2454 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2455 | } else { |
| 2456 | if (key.def_uni || !key.def_multi) { |
| 2457 | err = -EINVAL; |
| 2458 | goto out; |
| 2459 | } |
| 2460 | |
| 2461 | if (!rdev->ops->set_default_mgmt_key) { |
| 2462 | err = -EOPNOTSUPP; |
| 2463 | goto out; |
| 2464 | } |
| 2465 | |
| 2466 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2467 | if (err) |
| 2468 | goto out; |
| 2469 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2470 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2471 | if (err) |
| 2472 | goto out; |
| 2473 | |
| 2474 | #ifdef CONFIG_CFG80211_WEXT |
| 2475 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2476 | #endif |
| 2477 | } |
| 2478 | |
| 2479 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2480 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2481 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2482 | return err; |
| 2483 | } |
| 2484 | |
| 2485 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2486 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2488 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2489 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2490 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2491 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2492 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2493 | err = nl80211_parse_key(info, &key); |
| 2494 | if (err) |
| 2495 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2496 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2497 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2498 | return -EINVAL; |
| 2499 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2500 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2501 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2502 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2503 | if (key.type == -1) { |
| 2504 | if (mac_addr) |
| 2505 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2506 | else |
| 2507 | key.type = NL80211_KEYTYPE_GROUP; |
| 2508 | } |
| 2509 | |
| 2510 | /* for now */ |
| 2511 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2512 | key.type != NL80211_KEYTYPE_GROUP) |
| 2513 | return -EINVAL; |
| 2514 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2515 | if (!rdev->ops->add_key) |
| 2516 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2517 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2518 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2519 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2520 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2521 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2522 | |
| 2523 | wdev_lock(dev->ieee80211_ptr); |
| 2524 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2525 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2526 | err = rdev_add_key(rdev, dev, key.idx, |
| 2527 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2528 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2529 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2530 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2531 | return err; |
| 2532 | } |
| 2533 | |
| 2534 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2535 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2536 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2537 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2538 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2539 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2540 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2541 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2542 | err = nl80211_parse_key(info, &key); |
| 2543 | if (err) |
| 2544 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2545 | |
| 2546 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2547 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2548 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2549 | if (key.type == -1) { |
| 2550 | if (mac_addr) |
| 2551 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2552 | else |
| 2553 | key.type = NL80211_KEYTYPE_GROUP; |
| 2554 | } |
| 2555 | |
| 2556 | /* for now */ |
| 2557 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2558 | key.type != NL80211_KEYTYPE_GROUP) |
| 2559 | return -EINVAL; |
| 2560 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2561 | if (!rdev->ops->del_key) |
| 2562 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2563 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2564 | wdev_lock(dev->ieee80211_ptr); |
| 2565 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2566 | |
| 2567 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2568 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2569 | err = -ENOENT; |
| 2570 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2571 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2572 | err = rdev_del_key(rdev, dev, key.idx, |
| 2573 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2574 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2575 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2576 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2577 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2578 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2579 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2580 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2581 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2582 | } |
| 2583 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2584 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2585 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2586 | return err; |
| 2587 | } |
| 2588 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2589 | /* This function returns an error or the number of nested attributes */ |
| 2590 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2591 | { |
| 2592 | struct nlattr *attr; |
| 2593 | int n_entries = 0, tmp; |
| 2594 | |
| 2595 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2596 | if (nla_len(attr) != ETH_ALEN) |
| 2597 | return -EINVAL; |
| 2598 | |
| 2599 | n_entries++; |
| 2600 | } |
| 2601 | |
| 2602 | return n_entries; |
| 2603 | } |
| 2604 | |
| 2605 | /* |
| 2606 | * This function parses ACL information and allocates memory for ACL data. |
| 2607 | * On successful return, the calling function is responsible to free the |
| 2608 | * ACL buffer returned by this function. |
| 2609 | */ |
| 2610 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2611 | struct genl_info *info) |
| 2612 | { |
| 2613 | enum nl80211_acl_policy acl_policy; |
| 2614 | struct nlattr *attr; |
| 2615 | struct cfg80211_acl_data *acl; |
| 2616 | int i = 0, n_entries, tmp; |
| 2617 | |
| 2618 | if (!wiphy->max_acl_mac_addrs) |
| 2619 | return ERR_PTR(-EOPNOTSUPP); |
| 2620 | |
| 2621 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2622 | return ERR_PTR(-EINVAL); |
| 2623 | |
| 2624 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2625 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2626 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2627 | return ERR_PTR(-EINVAL); |
| 2628 | |
| 2629 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2630 | return ERR_PTR(-EINVAL); |
| 2631 | |
| 2632 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2633 | if (n_entries < 0) |
| 2634 | return ERR_PTR(n_entries); |
| 2635 | |
| 2636 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2637 | return ERR_PTR(-ENOTSUPP); |
| 2638 | |
| 2639 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2640 | GFP_KERNEL); |
| 2641 | if (!acl) |
| 2642 | return ERR_PTR(-ENOMEM); |
| 2643 | |
| 2644 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2645 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2646 | i++; |
| 2647 | } |
| 2648 | |
| 2649 | acl->n_acl_entries = n_entries; |
| 2650 | acl->acl_policy = acl_policy; |
| 2651 | |
| 2652 | return acl; |
| 2653 | } |
| 2654 | |
| 2655 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2656 | { |
| 2657 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2658 | struct net_device *dev = info->user_ptr[1]; |
| 2659 | struct cfg80211_acl_data *acl; |
| 2660 | int err; |
| 2661 | |
| 2662 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2663 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2664 | return -EOPNOTSUPP; |
| 2665 | |
| 2666 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2667 | return -EINVAL; |
| 2668 | |
| 2669 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2670 | if (IS_ERR(acl)) |
| 2671 | return PTR_ERR(acl); |
| 2672 | |
| 2673 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2674 | |
| 2675 | kfree(acl); |
| 2676 | |
| 2677 | return err; |
| 2678 | } |
| 2679 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2680 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2681 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2682 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2683 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2684 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2685 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2686 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2687 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2688 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2689 | return -EINVAL; |
| 2690 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2691 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2692 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2693 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2694 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2695 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2696 | if (!bcn->head_len) |
| 2697 | return -EINVAL; |
| 2698 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2702 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2703 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2704 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2705 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2706 | } |
| 2707 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2708 | if (!haveinfo) |
| 2709 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2710 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2711 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2712 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2713 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2717 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2718 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2719 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2720 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2721 | } |
| 2722 | |
| 2723 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2724 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2725 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2726 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2727 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2728 | } |
| 2729 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2730 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2731 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2732 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2733 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2734 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2735 | } |
| 2736 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2737 | return 0; |
| 2738 | } |
| 2739 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2740 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2741 | struct cfg80211_ap_settings *params) |
| 2742 | { |
| 2743 | struct wireless_dev *wdev; |
| 2744 | bool ret = false; |
| 2745 | |
| 2746 | mutex_lock(&rdev->devlist_mtx); |
| 2747 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2748 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2749 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2750 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2751 | continue; |
| 2752 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2753 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2754 | continue; |
| 2755 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2756 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2757 | ret = true; |
| 2758 | break; |
| 2759 | } |
| 2760 | |
| 2761 | mutex_unlock(&rdev->devlist_mtx); |
| 2762 | |
| 2763 | return ret; |
| 2764 | } |
| 2765 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2766 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2767 | enum nl80211_auth_type auth_type, |
| 2768 | enum nl80211_commands cmd) |
| 2769 | { |
| 2770 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2771 | return false; |
| 2772 | |
| 2773 | switch (cmd) { |
| 2774 | case NL80211_CMD_AUTHENTICATE: |
| 2775 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2776 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2777 | return false; |
| 2778 | return true; |
| 2779 | case NL80211_CMD_CONNECT: |
| 2780 | case NL80211_CMD_START_AP: |
| 2781 | /* SAE not supported yet */ |
| 2782 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2783 | return false; |
| 2784 | return true; |
| 2785 | default: |
| 2786 | return false; |
| 2787 | } |
| 2788 | } |
| 2789 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2790 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2791 | { |
| 2792 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2793 | struct net_device *dev = info->user_ptr[1]; |
| 2794 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2795 | struct cfg80211_ap_settings params; |
| 2796 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2797 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2798 | |
| 2799 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2800 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2801 | return -EOPNOTSUPP; |
| 2802 | |
| 2803 | if (!rdev->ops->start_ap) |
| 2804 | return -EOPNOTSUPP; |
| 2805 | |
| 2806 | if (wdev->beacon_interval) |
| 2807 | return -EALREADY; |
| 2808 | |
| 2809 | memset(¶ms, 0, sizeof(params)); |
| 2810 | |
| 2811 | /* these are required for START_AP */ |
| 2812 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2813 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2814 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2815 | return -EINVAL; |
| 2816 | |
| 2817 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2818 | if (err) |
| 2819 | return err; |
| 2820 | |
| 2821 | params.beacon_interval = |
| 2822 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2823 | params.dtim_period = |
| 2824 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2825 | |
| 2826 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2827 | if (err) |
| 2828 | return err; |
| 2829 | |
| 2830 | /* |
| 2831 | * In theory, some of these attributes should be required here |
| 2832 | * but since they were not used when the command was originally |
| 2833 | * added, keep them optional for old user space programs to let |
| 2834 | * them continue to work with drivers that do not need the |
| 2835 | * additional information -- drivers must check! |
| 2836 | */ |
| 2837 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2838 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2839 | params.ssid_len = |
| 2840 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2841 | if (params.ssid_len == 0 || |
| 2842 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2843 | return -EINVAL; |
| 2844 | } |
| 2845 | |
| 2846 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2847 | params.hidden_ssid = nla_get_u32( |
| 2848 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2849 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2850 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2851 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2852 | return -EINVAL; |
| 2853 | } |
| 2854 | |
| 2855 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2856 | |
| 2857 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2858 | params.auth_type = nla_get_u32( |
| 2859 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2860 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 2861 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2862 | return -EINVAL; |
| 2863 | } else |
| 2864 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2865 | |
| 2866 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2867 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2868 | if (err) |
| 2869 | return err; |
| 2870 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2871 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2872 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2873 | return -EOPNOTSUPP; |
| 2874 | params.inactivity_timeout = nla_get_u16( |
| 2875 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2876 | } |
| 2877 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 2878 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 2879 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2880 | return -EINVAL; |
| 2881 | params.p2p_ctwindow = |
| 2882 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 2883 | if (params.p2p_ctwindow > 127) |
| 2884 | return -EINVAL; |
| 2885 | if (params.p2p_ctwindow != 0 && |
| 2886 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 2887 | return -EINVAL; |
| 2888 | } |
| 2889 | |
| 2890 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 2891 | u8 tmp; |
| 2892 | |
| 2893 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2894 | return -EINVAL; |
| 2895 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 2896 | if (tmp > 1) |
| 2897 | return -EINVAL; |
| 2898 | params.p2p_opp_ps = tmp; |
| 2899 | if (params.p2p_opp_ps != 0 && |
| 2900 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 2901 | return -EINVAL; |
| 2902 | } |
| 2903 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2904 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2905 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 2906 | if (err) |
| 2907 | return err; |
| 2908 | } else if (wdev->preset_chandef.chan) { |
| 2909 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2910 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2911 | return -EINVAL; |
| 2912 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2913 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2914 | return -EINVAL; |
| 2915 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2916 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 2917 | if (err < 0) |
| 2918 | return err; |
| 2919 | if (err) { |
| 2920 | radar_detect_width = BIT(params.chandef.width); |
| 2921 | params.radar_required = true; |
| 2922 | } |
| 2923 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2924 | mutex_lock(&rdev->devlist_mtx); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2925 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 2926 | params.chandef.chan, |
| 2927 | CHAN_MODE_SHARED, |
| 2928 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2929 | mutex_unlock(&rdev->devlist_mtx); |
| 2930 | |
| 2931 | if (err) |
| 2932 | return err; |
| 2933 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2934 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 2935 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 2936 | if (IS_ERR(params.acl)) |
| 2937 | return PTR_ERR(params.acl); |
| 2938 | } |
| 2939 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2940 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2941 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2942 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2943 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2944 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 2945 | wdev->ssid_len = params.ssid_len; |
| 2946 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2947 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2948 | |
| 2949 | kfree(params.acl); |
| 2950 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2951 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2952 | } |
| 2953 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2954 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2955 | { |
| 2956 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2957 | struct net_device *dev = info->user_ptr[1]; |
| 2958 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2959 | struct cfg80211_beacon_data params; |
| 2960 | int err; |
| 2961 | |
| 2962 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2963 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2964 | return -EOPNOTSUPP; |
| 2965 | |
| 2966 | if (!rdev->ops->change_beacon) |
| 2967 | return -EOPNOTSUPP; |
| 2968 | |
| 2969 | if (!wdev->beacon_interval) |
| 2970 | return -EINVAL; |
| 2971 | |
| 2972 | err = nl80211_parse_beacon(info, ¶ms); |
| 2973 | if (err) |
| 2974 | return err; |
| 2975 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2976 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | 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] | 2980 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2982 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2983 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2984 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2985 | } |
| 2986 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2987 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2988 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2989 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2990 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2991 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2992 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2993 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2994 | }; |
| 2995 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2996 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2997 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2998 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2999 | { |
| 3000 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3001 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3002 | int flag; |
| 3003 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3004 | /* |
| 3005 | * Try parsing the new attribute first so userspace |
| 3006 | * can specify both for older kernels. |
| 3007 | */ |
| 3008 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3009 | if (nla) { |
| 3010 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3011 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3012 | sta_flags = nla_data(nla); |
| 3013 | params->sta_flags_mask = sta_flags->mask; |
| 3014 | params->sta_flags_set = sta_flags->set; |
| 3015 | if ((params->sta_flags_mask | |
| 3016 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3017 | return -EINVAL; |
| 3018 | return 0; |
| 3019 | } |
| 3020 | |
| 3021 | /* if present, parse the old attribute */ |
| 3022 | |
| 3023 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3024 | if (!nla) |
| 3025 | return 0; |
| 3026 | |
| 3027 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3028 | nla, sta_flags_policy)) |
| 3029 | return -EINVAL; |
| 3030 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3031 | /* |
| 3032 | * Only allow certain flags for interface types so that |
| 3033 | * other attributes are silently ignored. Remember that |
| 3034 | * this is backward compatibility code with old userspace |
| 3035 | * and shouldn't be hit in other cases anyway. |
| 3036 | */ |
| 3037 | switch (iftype) { |
| 3038 | case NL80211_IFTYPE_AP: |
| 3039 | case NL80211_IFTYPE_AP_VLAN: |
| 3040 | case NL80211_IFTYPE_P2P_GO: |
| 3041 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3042 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3043 | BIT(NL80211_STA_FLAG_WME) | |
| 3044 | BIT(NL80211_STA_FLAG_MFP); |
| 3045 | break; |
| 3046 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3047 | case NL80211_IFTYPE_STATION: |
| 3048 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3049 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3050 | break; |
| 3051 | case NL80211_IFTYPE_MESH_POINT: |
| 3052 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3053 | BIT(NL80211_STA_FLAG_MFP) | |
| 3054 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3055 | default: |
| 3056 | return -EINVAL; |
| 3057 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3058 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3059 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3060 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3061 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3062 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3063 | /* no longer support new API additions in old API */ |
| 3064 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3065 | return -EINVAL; |
| 3066 | } |
| 3067 | } |
| 3068 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3069 | return 0; |
| 3070 | } |
| 3071 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3072 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3073 | int attr) |
| 3074 | { |
| 3075 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3076 | u32 bitrate; |
| 3077 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3078 | |
| 3079 | rate = nla_nest_start(msg, attr); |
| 3080 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3081 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3082 | |
| 3083 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3084 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3085 | /* report 16-bit bitrate only if we can */ |
| 3086 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3087 | if (bitrate > 0 && |
| 3088 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3089 | return false; |
| 3090 | if (bitrate_compat > 0 && |
| 3091 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3092 | return false; |
| 3093 | |
| 3094 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3095 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3096 | return false; |
| 3097 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3098 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3099 | return false; |
| 3100 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3101 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3102 | return false; |
| 3103 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3104 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3105 | return false; |
| 3106 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3107 | return false; |
| 3108 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3109 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3110 | return false; |
| 3111 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3112 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3113 | return false; |
| 3114 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3115 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3116 | return false; |
| 3117 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3118 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3119 | return false; |
| 3120 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3121 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3122 | return false; |
| 3123 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3124 | |
| 3125 | nla_nest_end(msg, rate); |
| 3126 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3127 | } |
| 3128 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3129 | 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] | 3130 | int flags, |
| 3131 | struct cfg80211_registered_device *rdev, |
| 3132 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3133 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3134 | { |
| 3135 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3136 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3137 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3138 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3139 | if (!hdr) |
| 3140 | return -1; |
| 3141 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3142 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3143 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3144 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3145 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3146 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3147 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3148 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3149 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3150 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3151 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3152 | sinfo->connected_time)) |
| 3153 | goto nla_put_failure; |
| 3154 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3155 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3156 | sinfo->inactive_time)) |
| 3157 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3158 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3159 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3160 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3161 | (u32)sinfo->rx_bytes)) |
| 3162 | goto nla_put_failure; |
| 3163 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
| 3164 | NL80211_STA_INFO_TX_BYTES64)) && |
| 3165 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3166 | (u32)sinfo->tx_bytes)) |
| 3167 | goto nla_put_failure; |
| 3168 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3169 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3170 | sinfo->rx_bytes)) |
| 3171 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3172 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3173 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3174 | sinfo->tx_bytes)) |
| 3175 | goto nla_put_failure; |
| 3176 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3177 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3178 | goto nla_put_failure; |
| 3179 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3180 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3181 | goto nla_put_failure; |
| 3182 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3183 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3184 | sinfo->plink_state)) |
| 3185 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3186 | switch (rdev->wiphy.signal_type) { |
| 3187 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3188 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3189 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3190 | sinfo->signal)) |
| 3191 | goto nla_put_failure; |
| 3192 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3193 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3194 | sinfo->signal_avg)) |
| 3195 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3196 | break; |
| 3197 | default: |
| 3198 | break; |
| 3199 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3200 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3201 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3202 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3203 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3204 | } |
| 3205 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3206 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3207 | NL80211_STA_INFO_RX_BITRATE)) |
| 3208 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3209 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3210 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3211 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3212 | sinfo->rx_packets)) |
| 3213 | goto nla_put_failure; |
| 3214 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3215 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3216 | sinfo->tx_packets)) |
| 3217 | goto nla_put_failure; |
| 3218 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3219 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3220 | sinfo->tx_retries)) |
| 3221 | goto nla_put_failure; |
| 3222 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3223 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3224 | sinfo->tx_failed)) |
| 3225 | goto nla_put_failure; |
| 3226 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3227 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3228 | sinfo->beacon_loss_count)) |
| 3229 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3230 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3231 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3232 | sinfo->local_pm)) |
| 3233 | goto nla_put_failure; |
| 3234 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3235 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3236 | sinfo->peer_pm)) |
| 3237 | goto nla_put_failure; |
| 3238 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3239 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3240 | sinfo->nonpeer_pm)) |
| 3241 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3242 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3243 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3244 | if (!bss_param) |
| 3245 | goto nla_put_failure; |
| 3246 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3247 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3248 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3249 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3250 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3251 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3252 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3253 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3254 | sinfo->bss_param.dtim_period) || |
| 3255 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3256 | sinfo->bss_param.beacon_interval)) |
| 3257 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3258 | |
| 3259 | nla_nest_end(msg, bss_param); |
| 3260 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3261 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3262 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3263 | sizeof(struct nl80211_sta_flag_update), |
| 3264 | &sinfo->sta_flags)) |
| 3265 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3266 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3267 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3268 | sinfo->t_offset)) |
| 3269 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3270 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3271 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3272 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3273 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3274 | sinfo->assoc_req_ies)) |
| 3275 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3276 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3277 | return genlmsg_end(msg, hdr); |
| 3278 | |
| 3279 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3280 | genlmsg_cancel(msg, hdr); |
| 3281 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3282 | } |
| 3283 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3284 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3285 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3286 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3287 | struct station_info sinfo; |
| 3288 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3289 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3290 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3291 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3292 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3293 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3294 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3295 | if (err) |
| 3296 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3297 | |
| 3298 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3299 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3300 | goto out_err; |
| 3301 | } |
| 3302 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3303 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3304 | memset(&sinfo, 0, sizeof(sinfo)); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3305 | err = rdev_dump_station(dev, netdev, sta_idx, |
| 3306 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3307 | if (err == -ENOENT) |
| 3308 | break; |
| 3309 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3310 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3311 | |
| 3312 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3313 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3314 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3315 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3316 | &sinfo) < 0) |
| 3317 | goto out; |
| 3318 | |
| 3319 | sta_idx++; |
| 3320 | } |
| 3321 | |
| 3322 | |
| 3323 | out: |
| 3324 | cb->args[1] = sta_idx; |
| 3325 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3326 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3327 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3328 | |
| 3329 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3330 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3331 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3332 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3333 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3334 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3335 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3336 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3337 | struct sk_buff *msg; |
| 3338 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3339 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3340 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3341 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3342 | |
| 3343 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3344 | return -EINVAL; |
| 3345 | |
| 3346 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3347 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3348 | if (!rdev->ops->get_station) |
| 3349 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3350 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3351 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3352 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3353 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3354 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3355 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3356 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3357 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3358 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3359 | 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] | 3360 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3361 | nlmsg_free(msg); |
| 3362 | return -ENOBUFS; |
| 3363 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3364 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3365 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3366 | } |
| 3367 | |
| 3368 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3369 | * 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] | 3370 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3371 | static struct net_device *get_vlan(struct genl_info *info, |
| 3372 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3373 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3374 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3375 | struct net_device *v; |
| 3376 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3377 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3378 | if (!vlanattr) |
| 3379 | return NULL; |
| 3380 | |
| 3381 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3382 | if (!v) |
| 3383 | return ERR_PTR(-ENODEV); |
| 3384 | |
| 3385 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3386 | ret = -EINVAL; |
| 3387 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3388 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3389 | |
| 3390 | if (!netif_running(v)) { |
| 3391 | ret = -ENETDOWN; |
| 3392 | goto error; |
| 3393 | } |
| 3394 | |
| 3395 | return v; |
| 3396 | error: |
| 3397 | dev_put(v); |
| 3398 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3402 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3403 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3404 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3405 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3406 | struct station_parameters params; |
| 3407 | u8 *mac_addr = NULL; |
| 3408 | |
| 3409 | memset(¶ms, 0, sizeof(params)); |
| 3410 | |
| 3411 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 3412 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3413 | |
| 3414 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3415 | return -EINVAL; |
| 3416 | |
| 3417 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3418 | return -EINVAL; |
| 3419 | |
| 3420 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3421 | |
| 3422 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3423 | params.supported_rates = |
| 3424 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3425 | params.supported_rates_len = |
| 3426 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3427 | } |
| 3428 | |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3429 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL] || |
| 3430 | info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3431 | return -EINVAL; |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3432 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3433 | if (!rdev->ops->change_station) |
| 3434 | return -EOPNOTSUPP; |
| 3435 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3436 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3437 | return -EINVAL; |
| 3438 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3439 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3440 | params.plink_action = |
| 3441 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3442 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3443 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3444 | params.plink_state = |
| 3445 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3446 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3447 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3448 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3449 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3450 | |
| 3451 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3452 | pm > NL80211_MESH_POWER_MAX) |
| 3453 | return -EINVAL; |
| 3454 | |
| 3455 | params.local_pm = pm; |
| 3456 | } |
| 3457 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3458 | switch (dev->ieee80211_ptr->iftype) { |
| 3459 | case NL80211_IFTYPE_AP: |
| 3460 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3461 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3462 | /* disallow mesh-specific things */ |
| 3463 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3464 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3465 | if (params.local_pm) |
| 3466 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3467 | |
| 3468 | /* TDLS can't be set, ... */ |
| 3469 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3470 | return -EINVAL; |
| 3471 | /* |
| 3472 | * ... but don't bother the driver with it. This works around |
| 3473 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3474 | * TLDS_PEER flag in the mask even for AP mode. |
| 3475 | */ |
| 3476 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3477 | |
| 3478 | /* accept only the listed bits */ |
| 3479 | if (params.sta_flags_mask & |
| 3480 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3481 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3482 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3483 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3484 | BIT(NL80211_STA_FLAG_WME) | |
| 3485 | BIT(NL80211_STA_FLAG_MFP))) |
| 3486 | return -EINVAL; |
| 3487 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3488 | /* but authenticated/associated only if driver handles it */ |
| 3489 | if (!(rdev->wiphy.features & |
| 3490 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3491 | params.sta_flags_mask & |
| 3492 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3493 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3494 | return -EINVAL; |
| 3495 | |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3496 | /* reject other things that can't change */ |
| 3497 | if (params.supported_rates) |
| 3498 | return -EINVAL; |
| 3499 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3500 | /* must be last in here for error handling */ |
| 3501 | params.vlan = get_vlan(info, rdev); |
| 3502 | if (IS_ERR(params.vlan)) |
| 3503 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3504 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3505 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3506 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3507 | /* |
| 3508 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3509 | * but silently ignore attempts to change it since we |
| 3510 | * don't have state here to verify that it doesn't try |
| 3511 | * to change the flag. |
| 3512 | */ |
| 3513 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3514 | /* fall through */ |
| 3515 | case NL80211_IFTYPE_ADHOC: |
| 3516 | /* disallow things sta doesn't support */ |
| 3517 | if (params.plink_action) |
| 3518 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3519 | if (params.local_pm) |
| 3520 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3521 | /* reject any changes other than AUTHORIZED */ |
| 3522 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3523 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3524 | break; |
| 3525 | case NL80211_IFTYPE_MESH_POINT: |
| 3526 | /* disallow things mesh doesn't support */ |
| 3527 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3528 | return -EINVAL; |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3529 | if (params.supported_rates) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3530 | return -EINVAL; |
| 3531 | /* |
| 3532 | * No special handling for TDLS here -- the userspace |
| 3533 | * mesh code doesn't have this bug. |
| 3534 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3535 | if (params.sta_flags_mask & |
| 3536 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3537 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3538 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3539 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3540 | break; |
| 3541 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3542 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3543 | } |
| 3544 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3545 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3546 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3547 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3548 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3549 | if (params.vlan) |
| 3550 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3551 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3552 | return err; |
| 3553 | } |
| 3554 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3555 | static struct nla_policy |
| 3556 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3557 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3558 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3559 | }; |
| 3560 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3561 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3562 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3563 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3564 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3565 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3566 | struct station_parameters params; |
| 3567 | u8 *mac_addr = NULL; |
| 3568 | |
| 3569 | memset(¶ms, 0, sizeof(params)); |
| 3570 | |
| 3571 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3572 | return -EINVAL; |
| 3573 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3574 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3575 | return -EINVAL; |
| 3576 | |
| 3577 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3578 | return -EINVAL; |
| 3579 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3580 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3581 | return -EINVAL; |
| 3582 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3583 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3584 | params.supported_rates = |
| 3585 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3586 | params.supported_rates_len = |
| 3587 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3588 | params.listen_interval = |
| 3589 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3590 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3591 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3592 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3593 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3594 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3595 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3596 | params.ht_capa = |
| 3597 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3598 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3599 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3600 | params.vht_capa = |
| 3601 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3602 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3603 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3604 | params.plink_action = |
| 3605 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3606 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3607 | if (!rdev->ops->add_station) |
| 3608 | return -EOPNOTSUPP; |
| 3609 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3610 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3611 | return -EINVAL; |
| 3612 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3613 | switch (dev->ieee80211_ptr->iftype) { |
| 3614 | case NL80211_IFTYPE_AP: |
| 3615 | case NL80211_IFTYPE_AP_VLAN: |
| 3616 | case NL80211_IFTYPE_P2P_GO: |
| 3617 | /* parse WME attributes if sta is WME capable */ |
| 3618 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3619 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3620 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3621 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3622 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3623 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3624 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3625 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3626 | nl80211_sta_wme_policy); |
| 3627 | if (err) |
| 3628 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3629 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3630 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3631 | params.uapsd_queues = |
| 3632 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3633 | if (params.uapsd_queues & |
| 3634 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3635 | return -EINVAL; |
| 3636 | |
| 3637 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3638 | params.max_sp = |
| 3639 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3640 | |
| 3641 | if (params.max_sp & |
| 3642 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3643 | return -EINVAL; |
| 3644 | |
| 3645 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3646 | } |
| 3647 | /* TDLS peers cannot be added */ |
| 3648 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3649 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3650 | /* but don't bother the driver with it */ |
| 3651 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3652 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3653 | /* allow authenticated/associated only if driver handles it */ |
| 3654 | if (!(rdev->wiphy.features & |
| 3655 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3656 | params.sta_flags_mask & |
| 3657 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3658 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3659 | return -EINVAL; |
| 3660 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3661 | /* must be last in here for error handling */ |
| 3662 | params.vlan = get_vlan(info, rdev); |
| 3663 | if (IS_ERR(params.vlan)) |
| 3664 | return PTR_ERR(params.vlan); |
| 3665 | break; |
| 3666 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3667 | /* associated is disallowed */ |
| 3668 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3669 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3670 | /* TDLS peers cannot be added */ |
| 3671 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3672 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3673 | break; |
| 3674 | case NL80211_IFTYPE_STATION: |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3675 | /* associated is disallowed */ |
| 3676 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3677 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3678 | /* Only TDLS peers can be added */ |
| 3679 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3680 | return -EINVAL; |
| 3681 | /* Can only add if TDLS ... */ |
| 3682 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3683 | return -EOPNOTSUPP; |
| 3684 | /* ... with external setup is supported */ |
| 3685 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3686 | return -EOPNOTSUPP; |
| 3687 | break; |
| 3688 | default: |
| 3689 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3690 | } |
| 3691 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3692 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3693 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3694 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3695 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3696 | if (params.vlan) |
| 3697 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3698 | return err; |
| 3699 | } |
| 3700 | |
| 3701 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3702 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3703 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3704 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3705 | u8 *mac_addr = NULL; |
| 3706 | |
| 3707 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3708 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3709 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3710 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3711 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3712 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3713 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3714 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3715 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3716 | if (!rdev->ops->del_station) |
| 3717 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3718 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3719 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3720 | } |
| 3721 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3722 | 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] | 3723 | int flags, struct net_device *dev, |
| 3724 | u8 *dst, u8 *next_hop, |
| 3725 | struct mpath_info *pinfo) |
| 3726 | { |
| 3727 | void *hdr; |
| 3728 | struct nlattr *pinfoattr; |
| 3729 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3730 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3731 | if (!hdr) |
| 3732 | return -1; |
| 3733 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3734 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3735 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3736 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3737 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3738 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3739 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3740 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3741 | if (!pinfoattr) |
| 3742 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3743 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3744 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3745 | pinfo->frame_qlen)) |
| 3746 | goto nla_put_failure; |
| 3747 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3748 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3749 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3750 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3751 | pinfo->metric)) || |
| 3752 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3753 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3754 | pinfo->exptime)) || |
| 3755 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3756 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3757 | pinfo->flags)) || |
| 3758 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3759 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3760 | pinfo->discovery_timeout)) || |
| 3761 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3762 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3763 | pinfo->discovery_retries))) |
| 3764 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3765 | |
| 3766 | nla_nest_end(msg, pinfoattr); |
| 3767 | |
| 3768 | return genlmsg_end(msg, hdr); |
| 3769 | |
| 3770 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3771 | genlmsg_cancel(msg, hdr); |
| 3772 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3776 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3777 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3778 | struct mpath_info pinfo; |
| 3779 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3780 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3781 | u8 dst[ETH_ALEN]; |
| 3782 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3783 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3784 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3785 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3786 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3787 | if (err) |
| 3788 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3789 | |
| 3790 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3791 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3792 | goto out_err; |
| 3793 | } |
| 3794 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3795 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3796 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3797 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3798 | } |
| 3799 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3800 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3801 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 3802 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3803 | if (err == -ENOENT) |
| 3804 | break; |
| 3805 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3806 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3807 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3808 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3809 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3810 | netdev, dst, next_hop, |
| 3811 | &pinfo) < 0) |
| 3812 | goto out; |
| 3813 | |
| 3814 | path_idx++; |
| 3815 | } |
| 3816 | |
| 3817 | |
| 3818 | out: |
| 3819 | cb->args[1] = path_idx; |
| 3820 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3821 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3822 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3823 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3827 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3828 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3829 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3830 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3831 | struct mpath_info pinfo; |
| 3832 | struct sk_buff *msg; |
| 3833 | u8 *dst = NULL; |
| 3834 | u8 next_hop[ETH_ALEN]; |
| 3835 | |
| 3836 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3837 | |
| 3838 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3839 | return -EINVAL; |
| 3840 | |
| 3841 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3842 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3843 | if (!rdev->ops->get_mpath) |
| 3844 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3845 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3846 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3847 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3848 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3849 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3850 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3851 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3852 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3853 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3854 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3855 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3856 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3857 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3858 | dev, dst, next_hop, &pinfo) < 0) { |
| 3859 | nlmsg_free(msg); |
| 3860 | return -ENOBUFS; |
| 3861 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3862 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3863 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3864 | } |
| 3865 | |
| 3866 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3867 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3868 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3869 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3870 | u8 *dst = NULL; |
| 3871 | u8 *next_hop = NULL; |
| 3872 | |
| 3873 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3874 | return -EINVAL; |
| 3875 | |
| 3876 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3877 | return -EINVAL; |
| 3878 | |
| 3879 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3880 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3881 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3882 | if (!rdev->ops->change_mpath) |
| 3883 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3884 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3885 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3886 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3887 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3888 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3889 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3890 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3891 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3892 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3893 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3894 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3895 | u8 *dst = NULL; |
| 3896 | u8 *next_hop = NULL; |
| 3897 | |
| 3898 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3899 | return -EINVAL; |
| 3900 | |
| 3901 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3902 | return -EINVAL; |
| 3903 | |
| 3904 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3905 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3906 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3907 | if (!rdev->ops->add_mpath) |
| 3908 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3909 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3910 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3911 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3912 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3913 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3917 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3918 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3919 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3920 | u8 *dst = NULL; |
| 3921 | |
| 3922 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3923 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3924 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3925 | if (!rdev->ops->del_mpath) |
| 3926 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3927 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3928 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3929 | } |
| 3930 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3931 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3932 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3933 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3934 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3935 | struct bss_parameters params; |
| 3936 | |
| 3937 | memset(¶ms, 0, sizeof(params)); |
| 3938 | /* default to not changing parameters */ |
| 3939 | params.use_cts_prot = -1; |
| 3940 | params.use_short_preamble = -1; |
| 3941 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3942 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3943 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3944 | params.p2p_ctwindow = -1; |
| 3945 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3946 | |
| 3947 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3948 | params.use_cts_prot = |
| 3949 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3950 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3951 | params.use_short_preamble = |
| 3952 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3953 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3954 | params.use_short_slot_time = |
| 3955 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3956 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3957 | params.basic_rates = |
| 3958 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3959 | params.basic_rates_len = |
| 3960 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3961 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3962 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3963 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3964 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3965 | params.ht_opmode = |
| 3966 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3967 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3968 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3969 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3970 | return -EINVAL; |
| 3971 | params.p2p_ctwindow = |
| 3972 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3973 | if (params.p2p_ctwindow < 0) |
| 3974 | return -EINVAL; |
| 3975 | if (params.p2p_ctwindow != 0 && |
| 3976 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3977 | return -EINVAL; |
| 3978 | } |
| 3979 | |
| 3980 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3981 | u8 tmp; |
| 3982 | |
| 3983 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3984 | return -EINVAL; |
| 3985 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3986 | if (tmp > 1) |
| 3987 | return -EINVAL; |
| 3988 | params.p2p_opp_ps = tmp; |
| 3989 | if (params.p2p_opp_ps && |
| 3990 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3991 | return -EINVAL; |
| 3992 | } |
| 3993 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3994 | if (!rdev->ops->change_bss) |
| 3995 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3996 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3997 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3998 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3999 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4000 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4001 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4002 | } |
| 4003 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4004 | 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] | 4005 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4006 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4007 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4008 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4009 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4010 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4011 | }; |
| 4012 | |
| 4013 | static int parse_reg_rule(struct nlattr *tb[], |
| 4014 | struct ieee80211_reg_rule *reg_rule) |
| 4015 | { |
| 4016 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4017 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4018 | |
| 4019 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4020 | return -EINVAL; |
| 4021 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4022 | return -EINVAL; |
| 4023 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4024 | return -EINVAL; |
| 4025 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4026 | return -EINVAL; |
| 4027 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4028 | return -EINVAL; |
| 4029 | |
| 4030 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4031 | |
| 4032 | freq_range->start_freq_khz = |
| 4033 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4034 | freq_range->end_freq_khz = |
| 4035 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4036 | freq_range->max_bandwidth_khz = |
| 4037 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4038 | |
| 4039 | power_rule->max_eirp = |
| 4040 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4041 | |
| 4042 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4043 | power_rule->max_antenna_gain = |
| 4044 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4045 | |
| 4046 | return 0; |
| 4047 | } |
| 4048 | |
| 4049 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4050 | { |
| 4051 | int r; |
| 4052 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4053 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4054 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4055 | /* |
| 4056 | * You should only get this when cfg80211 hasn't yet initialized |
| 4057 | * completely when built-in to the kernel right between the time |
| 4058 | * window between nl80211_init() and regulatory_init(), if that is |
| 4059 | * even possible. |
| 4060 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4061 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4062 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4063 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4064 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4065 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4066 | |
| 4067 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4068 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4069 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4070 | user_reg_hint_type = |
| 4071 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4072 | else |
| 4073 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4074 | |
| 4075 | switch (user_reg_hint_type) { |
| 4076 | case NL80211_USER_REG_HINT_USER: |
| 4077 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4078 | break; |
| 4079 | default: |
| 4080 | return -EINVAL; |
| 4081 | } |
| 4082 | |
| 4083 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4084 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4085 | return r; |
| 4086 | } |
| 4087 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4088 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4089 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4090 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4092 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4093 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4094 | struct mesh_config cur_params; |
| 4095 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4096 | void *hdr; |
| 4097 | struct nlattr *pinfoattr; |
| 4098 | struct sk_buff *msg; |
| 4099 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4100 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4101 | return -EOPNOTSUPP; |
| 4102 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4103 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4104 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4105 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4106 | wdev_lock(wdev); |
| 4107 | /* If not connected, get default parameters */ |
| 4108 | if (!wdev->mesh_id_len) |
| 4109 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4110 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4111 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4112 | wdev_unlock(wdev); |
| 4113 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4114 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4115 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4116 | |
| 4117 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4118 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4119 | if (!msg) |
| 4120 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4121 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4122 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4123 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4124 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4125 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4126 | if (!pinfoattr) |
| 4127 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4128 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4129 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4130 | cur_params.dot11MeshRetryTimeout) || |
| 4131 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4132 | cur_params.dot11MeshConfirmTimeout) || |
| 4133 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4134 | cur_params.dot11MeshHoldingTimeout) || |
| 4135 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4136 | cur_params.dot11MeshMaxPeerLinks) || |
| 4137 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4138 | cur_params.dot11MeshMaxRetries) || |
| 4139 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4140 | cur_params.dot11MeshTTL) || |
| 4141 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4142 | cur_params.element_ttl) || |
| 4143 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4144 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4145 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4146 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4147 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4148 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4149 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4150 | cur_params.path_refresh_time) || |
| 4151 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4152 | cur_params.min_discovery_timeout) || |
| 4153 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4154 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4155 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4156 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4157 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4158 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4159 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4160 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4161 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4162 | cur_params.dot11MeshHWMPRootMode) || |
| 4163 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4164 | cur_params.dot11MeshHWMPRannInterval) || |
| 4165 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4166 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4167 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4168 | cur_params.dot11MeshForwarding) || |
| 4169 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4170 | cur_params.rssi_threshold) || |
| 4171 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4172 | cur_params.ht_opmode) || |
| 4173 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4174 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4175 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4176 | cur_params.dot11MeshHWMProotInterval) || |
| 4177 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4178 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4179 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4180 | cur_params.power_mode) || |
| 4181 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
| 4182 | cur_params.dot11MeshAwakeWindowDuration)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4183 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4184 | nla_nest_end(msg, pinfoattr); |
| 4185 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4186 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4187 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4188 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4189 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4190 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4191 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4192 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4193 | } |
| 4194 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4195 | 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] | 4196 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4197 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4198 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4199 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4200 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4201 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4202 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4203 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4204 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4205 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4206 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4207 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4208 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4209 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4210 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4211 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4212 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4213 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4214 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4215 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4216 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4217 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4218 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4219 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4220 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4221 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4222 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4223 | }; |
| 4224 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4225 | static const struct nla_policy |
| 4226 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4227 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4228 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4229 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4230 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4231 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4232 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4233 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4234 | }; |
| 4235 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4236 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4237 | struct mesh_config *cfg, |
| 4238 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4239 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4240 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4241 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4242 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4243 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4244 | do { \ |
| 4245 | if (tb[attr]) { \ |
| 4246 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4247 | return -EINVAL; \ |
| 4248 | cfg->param = fn(tb[attr]); \ |
| 4249 | mask |= (1 << (attr - 1)); \ |
| 4250 | } \ |
| 4251 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4252 | |
| 4253 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4254 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4255 | return -EINVAL; |
| 4256 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4257 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4258 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4259 | return -EINVAL; |
| 4260 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4261 | /* This makes sure that there aren't more than 32 mesh config |
| 4262 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4263 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4264 | |
| 4265 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4266 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4267 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4268 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4269 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4270 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4271 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4272 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4273 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4274 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4275 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4276 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4277 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4278 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4279 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4280 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4281 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4282 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4283 | 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] | 4284 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4285 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4286 | 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] | 4287 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4288 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4289 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4290 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4291 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4292 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4293 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4294 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4295 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4296 | 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] | 4297 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4298 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4299 | 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] | 4300 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4301 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4302 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4303 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4304 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4305 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4306 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4307 | 1, 65535, mask, |
| 4308 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4309 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4310 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4311 | 1, 65535, mask, |
| 4312 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4313 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4314 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4315 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4316 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4317 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4318 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4319 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4320 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4321 | nla_get_u8); |
| 4322 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4323 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4324 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4325 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4326 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4327 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4328 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4329 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4330 | mask, NL80211_MESHCONF_FORWARDING, |
| 4331 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4332 | 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] | 4333 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4334 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4335 | 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] | 4336 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4337 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4338 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4339 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4340 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4341 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4342 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4343 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4344 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4345 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4346 | dot11MeshHWMPconfirmationInterval, |
| 4347 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4348 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4349 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4350 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4351 | NL80211_MESH_POWER_ACTIVE, |
| 4352 | NL80211_MESH_POWER_MAX, |
| 4353 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4354 | nla_get_u32); |
| 4355 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4356 | 0, 65535, mask, |
| 4357 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4358 | if (mask_out) |
| 4359 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4360 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4361 | return 0; |
| 4362 | |
| 4363 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4364 | } |
| 4365 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4366 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4367 | struct mesh_setup *setup) |
| 4368 | { |
| 4369 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4370 | |
| 4371 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4372 | return -EINVAL; |
| 4373 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4374 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4375 | nl80211_mesh_setup_params_policy)) |
| 4376 | return -EINVAL; |
| 4377 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4378 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4379 | setup->sync_method = |
| 4380 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4381 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4382 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4383 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4384 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4385 | setup->path_sel_proto = |
| 4386 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4387 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4388 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4389 | |
| 4390 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4391 | setup->path_metric = |
| 4392 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4393 | IEEE80211_PATH_METRIC_VENDOR : |
| 4394 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4395 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4396 | |
| 4397 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4398 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4399 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4400 | if (!is_valid_ie_attr(ieattr)) |
| 4401 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4402 | setup->ie = nla_data(ieattr); |
| 4403 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4404 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4405 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4406 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4407 | |
| 4408 | return 0; |
| 4409 | } |
| 4410 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4411 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4412 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4413 | { |
| 4414 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4415 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4416 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4417 | struct mesh_config cfg; |
| 4418 | u32 mask; |
| 4419 | int err; |
| 4420 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4421 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4422 | return -EOPNOTSUPP; |
| 4423 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4424 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4425 | return -EOPNOTSUPP; |
| 4426 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4427 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4428 | if (err) |
| 4429 | return err; |
| 4430 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4431 | wdev_lock(wdev); |
| 4432 | if (!wdev->mesh_id_len) |
| 4433 | err = -ENOLINK; |
| 4434 | |
| 4435 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4436 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4437 | |
| 4438 | wdev_unlock(wdev); |
| 4439 | |
| 4440 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4441 | } |
| 4442 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4443 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4444 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4445 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4446 | struct sk_buff *msg; |
| 4447 | void *hdr = NULL; |
| 4448 | struct nlattr *nl_reg_rules; |
| 4449 | unsigned int i; |
| 4450 | int err = -EINVAL; |
| 4451 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4452 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4453 | |
| 4454 | if (!cfg80211_regdomain) |
| 4455 | goto out; |
| 4456 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4457 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4458 | if (!msg) { |
| 4459 | err = -ENOBUFS; |
| 4460 | goto out; |
| 4461 | } |
| 4462 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4463 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4464 | NL80211_CMD_GET_REG); |
| 4465 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4466 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4467 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4468 | if (reg_last_request_cell_base() && |
| 4469 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4470 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4471 | goto nla_put_failure; |
| 4472 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4473 | rcu_read_lock(); |
| 4474 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4475 | |
| 4476 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4477 | (regdom->dfs_region && |
| 4478 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4479 | goto nla_put_failure_rcu; |
| 4480 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4481 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4482 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4483 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4484 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4485 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4486 | struct nlattr *nl_reg_rule; |
| 4487 | const struct ieee80211_reg_rule *reg_rule; |
| 4488 | const struct ieee80211_freq_range *freq_range; |
| 4489 | const struct ieee80211_power_rule *power_rule; |
| 4490 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4491 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4492 | freq_range = ®_rule->freq_range; |
| 4493 | power_rule = ®_rule->power_rule; |
| 4494 | |
| 4495 | nl_reg_rule = nla_nest_start(msg, i); |
| 4496 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4497 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4498 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4499 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4500 | reg_rule->flags) || |
| 4501 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4502 | freq_range->start_freq_khz) || |
| 4503 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4504 | freq_range->end_freq_khz) || |
| 4505 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4506 | freq_range->max_bandwidth_khz) || |
| 4507 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4508 | power_rule->max_antenna_gain) || |
| 4509 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4510 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4511 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4512 | |
| 4513 | nla_nest_end(msg, nl_reg_rule); |
| 4514 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4515 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4516 | |
| 4517 | nla_nest_end(msg, nl_reg_rules); |
| 4518 | |
| 4519 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4520 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4521 | goto out; |
| 4522 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4523 | nla_put_failure_rcu: |
| 4524 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4525 | nla_put_failure: |
| 4526 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4527 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4528 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4529 | err = -EMSGSIZE; |
| 4530 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4531 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4532 | return err; |
| 4533 | } |
| 4534 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4535 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4536 | { |
| 4537 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4538 | struct nlattr *nl_reg_rule; |
| 4539 | char *alpha2 = NULL; |
| 4540 | int rem_reg_rules = 0, r = 0; |
| 4541 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4542 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4543 | struct ieee80211_regdomain *rd = NULL; |
| 4544 | |
| 4545 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4546 | return -EINVAL; |
| 4547 | |
| 4548 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4549 | return -EINVAL; |
| 4550 | |
| 4551 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4552 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4553 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4554 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4555 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4556 | 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] | 4557 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4558 | num_rules++; |
| 4559 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4560 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4561 | } |
| 4562 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4563 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4564 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4565 | |
| 4566 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4567 | if (!rd) |
| 4568 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4569 | |
| 4570 | rd->n_reg_rules = num_rules; |
| 4571 | rd->alpha2[0] = alpha2[0]; |
| 4572 | rd->alpha2[1] = alpha2[1]; |
| 4573 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4574 | /* |
| 4575 | * Disable DFS master mode if the DFS region was |
| 4576 | * not supported or known on this kernel. |
| 4577 | */ |
| 4578 | if (reg_supported_dfs_region(dfs_region)) |
| 4579 | rd->dfs_region = dfs_region; |
| 4580 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4581 | 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] | 4582 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4583 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4584 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4585 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4586 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4587 | if (r) |
| 4588 | goto bad_reg; |
| 4589 | |
| 4590 | rule_idx++; |
| 4591 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4592 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4593 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4594 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4595 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4596 | } |
| 4597 | |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4598 | mutex_lock(&cfg80211_mutex); |
| 4599 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4600 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4601 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4602 | rd = NULL; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4603 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4604 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4605 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4606 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4607 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4608 | } |
| 4609 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4610 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4611 | { |
| 4612 | struct nlattr *attr1, *attr2; |
| 4613 | int n_channels = 0, tmp1, tmp2; |
| 4614 | |
| 4615 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4616 | n_channels++; |
| 4617 | /* |
| 4618 | * Some hardware has a limited channel list for |
| 4619 | * scanning, and it is pretty much nonsensical |
| 4620 | * to scan for a channel twice, so disallow that |
| 4621 | * and don't require drivers to check that the |
| 4622 | * channel list they get isn't longer than what |
| 4623 | * they can scan, as long as they can scan all |
| 4624 | * the channels they registered at once. |
| 4625 | */ |
| 4626 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4627 | if (attr1 != attr2 && |
| 4628 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4629 | return 0; |
| 4630 | } |
| 4631 | |
| 4632 | return n_channels; |
| 4633 | } |
| 4634 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4635 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4636 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4638 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4639 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4640 | struct nlattr *attr; |
| 4641 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4642 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4643 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4644 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4645 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4646 | return -EINVAL; |
| 4647 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4648 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4649 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4650 | if (!rdev->ops->scan) |
| 4651 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4652 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4653 | if (rdev->scan_req) |
| 4654 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4655 | |
| 4656 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4657 | n_channels = validate_scan_freqs( |
| 4658 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4659 | if (!n_channels) |
| 4660 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4661 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4662 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4663 | n_channels = 0; |
| 4664 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4665 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4666 | if (wiphy->bands[band]) |
| 4667 | n_channels += wiphy->bands[band]->n_channels; |
| 4668 | } |
| 4669 | |
| 4670 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4671 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4672 | n_ssids++; |
| 4673 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4674 | if (n_ssids > wiphy->max_scan_ssids) |
| 4675 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4676 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4677 | if (info->attrs[NL80211_ATTR_IE]) |
| 4678 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4679 | else |
| 4680 | ie_len = 0; |
| 4681 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4682 | if (ie_len > wiphy->max_scan_ie_len) |
| 4683 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4684 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4685 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4686 | + sizeof(*request->ssids) * n_ssids |
| 4687 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4688 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4689 | if (!request) |
| 4690 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4691 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4692 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4693 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4694 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4695 | if (ie_len) { |
| 4696 | if (request->ssids) |
| 4697 | request->ie = (void *)(request->ssids + n_ssids); |
| 4698 | else |
| 4699 | request->ie = (void *)(request->channels + n_channels); |
| 4700 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4701 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4702 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4703 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4704 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4705 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4706 | struct ieee80211_channel *chan; |
| 4707 | |
| 4708 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4709 | |
| 4710 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4711 | err = -EINVAL; |
| 4712 | goto out_free; |
| 4713 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4714 | |
| 4715 | /* ignore disabled channels */ |
| 4716 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4717 | continue; |
| 4718 | |
| 4719 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4720 | i++; |
| 4721 | } |
| 4722 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4723 | enum ieee80211_band band; |
| 4724 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4725 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4726 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4727 | int j; |
| 4728 | if (!wiphy->bands[band]) |
| 4729 | continue; |
| 4730 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4731 | struct ieee80211_channel *chan; |
| 4732 | |
| 4733 | chan = &wiphy->bands[band]->channels[j]; |
| 4734 | |
| 4735 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4736 | continue; |
| 4737 | |
| 4738 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4739 | i++; |
| 4740 | } |
| 4741 | } |
| 4742 | } |
| 4743 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4744 | if (!i) { |
| 4745 | err = -EINVAL; |
| 4746 | goto out_free; |
| 4747 | } |
| 4748 | |
| 4749 | request->n_channels = i; |
| 4750 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4751 | i = 0; |
| 4752 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4753 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4754 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4755 | err = -EINVAL; |
| 4756 | goto out_free; |
| 4757 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4758 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4759 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4760 | i++; |
| 4761 | } |
| 4762 | } |
| 4763 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4764 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4765 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4766 | memcpy((void *)request->ie, |
| 4767 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4768 | request->ie_len); |
| 4769 | } |
| 4770 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4771 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4772 | if (wiphy->bands[i]) |
| 4773 | request->rates[i] = |
| 4774 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4775 | |
| 4776 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4777 | nla_for_each_nested(attr, |
| 4778 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4779 | tmp) { |
| 4780 | enum ieee80211_band band = nla_type(attr); |
| 4781 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4782 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4783 | err = -EINVAL; |
| 4784 | goto out_free; |
| 4785 | } |
| 4786 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4787 | nla_data(attr), |
| 4788 | nla_len(attr), |
| 4789 | &request->rates[band]); |
| 4790 | if (err) |
| 4791 | goto out_free; |
| 4792 | } |
| 4793 | } |
| 4794 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4795 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4796 | request->flags = nla_get_u32( |
| 4797 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4798 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4799 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4800 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4801 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4802 | err = -EOPNOTSUPP; |
| 4803 | goto out_free; |
| 4804 | } |
| 4805 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4806 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4807 | request->no_cck = |
| 4808 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4809 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4810 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4811 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4812 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4813 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4814 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4815 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4816 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4817 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4818 | nl80211_send_scan_start(rdev, wdev); |
| 4819 | if (wdev->netdev) |
| 4820 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4821 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4822 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4823 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4824 | kfree(request); |
| 4825 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4826 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4827 | return err; |
| 4828 | } |
| 4829 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4830 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4831 | struct genl_info *info) |
| 4832 | { |
| 4833 | struct cfg80211_sched_scan_request *request; |
| 4834 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4835 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4836 | struct nlattr *attr; |
| 4837 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4838 | 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] | 4839 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4840 | enum ieee80211_band band; |
| 4841 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4842 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4843 | |
| 4844 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4845 | !rdev->ops->sched_scan_start) |
| 4846 | return -EOPNOTSUPP; |
| 4847 | |
| 4848 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4849 | return -EINVAL; |
| 4850 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4851 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4852 | return -EINVAL; |
| 4853 | |
| 4854 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4855 | if (interval == 0) |
| 4856 | return -EINVAL; |
| 4857 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4858 | wiphy = &rdev->wiphy; |
| 4859 | |
| 4860 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4861 | n_channels = validate_scan_freqs( |
| 4862 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4863 | if (!n_channels) |
| 4864 | return -EINVAL; |
| 4865 | } else { |
| 4866 | n_channels = 0; |
| 4867 | |
| 4868 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4869 | if (wiphy->bands[band]) |
| 4870 | n_channels += wiphy->bands[band]->n_channels; |
| 4871 | } |
| 4872 | |
| 4873 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4874 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4875 | tmp) |
| 4876 | n_ssids++; |
| 4877 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4878 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4879 | return -EINVAL; |
| 4880 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4881 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4882 | nla_for_each_nested(attr, |
| 4883 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4884 | tmp) |
| 4885 | n_match_sets++; |
| 4886 | |
| 4887 | if (n_match_sets > wiphy->max_match_sets) |
| 4888 | return -EINVAL; |
| 4889 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4890 | if (info->attrs[NL80211_ATTR_IE]) |
| 4891 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4892 | else |
| 4893 | ie_len = 0; |
| 4894 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4895 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4896 | return -EINVAL; |
| 4897 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4898 | mutex_lock(&rdev->sched_scan_mtx); |
| 4899 | |
| 4900 | if (rdev->sched_scan_req) { |
| 4901 | err = -EINPROGRESS; |
| 4902 | goto out; |
| 4903 | } |
| 4904 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4905 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4906 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4907 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4908 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4909 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4910 | if (!request) { |
| 4911 | err = -ENOMEM; |
| 4912 | goto out; |
| 4913 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4914 | |
| 4915 | if (n_ssids) |
| 4916 | request->ssids = (void *)&request->channels[n_channels]; |
| 4917 | request->n_ssids = n_ssids; |
| 4918 | if (ie_len) { |
| 4919 | if (request->ssids) |
| 4920 | request->ie = (void *)(request->ssids + n_ssids); |
| 4921 | else |
| 4922 | request->ie = (void *)(request->channels + n_channels); |
| 4923 | } |
| 4924 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4925 | if (n_match_sets) { |
| 4926 | if (request->ie) |
| 4927 | request->match_sets = (void *)(request->ie + ie_len); |
| 4928 | else if (request->ssids) |
| 4929 | request->match_sets = |
| 4930 | (void *)(request->ssids + n_ssids); |
| 4931 | else |
| 4932 | request->match_sets = |
| 4933 | (void *)(request->channels + n_channels); |
| 4934 | } |
| 4935 | request->n_match_sets = n_match_sets; |
| 4936 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4937 | i = 0; |
| 4938 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4939 | /* user specified, bail out if channel not found */ |
| 4940 | nla_for_each_nested(attr, |
| 4941 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4942 | tmp) { |
| 4943 | struct ieee80211_channel *chan; |
| 4944 | |
| 4945 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4946 | |
| 4947 | if (!chan) { |
| 4948 | err = -EINVAL; |
| 4949 | goto out_free; |
| 4950 | } |
| 4951 | |
| 4952 | /* ignore disabled channels */ |
| 4953 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4954 | continue; |
| 4955 | |
| 4956 | request->channels[i] = chan; |
| 4957 | i++; |
| 4958 | } |
| 4959 | } else { |
| 4960 | /* all channels */ |
| 4961 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4962 | int j; |
| 4963 | if (!wiphy->bands[band]) |
| 4964 | continue; |
| 4965 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4966 | struct ieee80211_channel *chan; |
| 4967 | |
| 4968 | chan = &wiphy->bands[band]->channels[j]; |
| 4969 | |
| 4970 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4971 | continue; |
| 4972 | |
| 4973 | request->channels[i] = chan; |
| 4974 | i++; |
| 4975 | } |
| 4976 | } |
| 4977 | } |
| 4978 | |
| 4979 | if (!i) { |
| 4980 | err = -EINVAL; |
| 4981 | goto out_free; |
| 4982 | } |
| 4983 | |
| 4984 | request->n_channels = i; |
| 4985 | |
| 4986 | i = 0; |
| 4987 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4988 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4989 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4990 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4991 | err = -EINVAL; |
| 4992 | goto out_free; |
| 4993 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4994 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4995 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4996 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4997 | i++; |
| 4998 | } |
| 4999 | } |
| 5000 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5001 | i = 0; |
| 5002 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5003 | nla_for_each_nested(attr, |
| 5004 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5005 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5006 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5007 | |
| 5008 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5009 | nla_data(attr), nla_len(attr), |
| 5010 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5011 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5012 | if (ssid) { |
| 5013 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5014 | err = -EINVAL; |
| 5015 | goto out_free; |
| 5016 | } |
| 5017 | memcpy(request->match_sets[i].ssid.ssid, |
| 5018 | nla_data(ssid), nla_len(ssid)); |
| 5019 | request->match_sets[i].ssid.ssid_len = |
| 5020 | nla_len(ssid); |
| 5021 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5022 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5023 | if (rssi) |
| 5024 | request->rssi_thold = nla_get_u32(rssi); |
| 5025 | else |
| 5026 | request->rssi_thold = |
| 5027 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5028 | i++; |
| 5029 | } |
| 5030 | } |
| 5031 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5032 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5033 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5034 | memcpy((void *)request->ie, |
| 5035 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5036 | request->ie_len); |
| 5037 | } |
| 5038 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5039 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5040 | request->flags = nla_get_u32( |
| 5041 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5042 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5043 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5044 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5045 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5046 | err = -EOPNOTSUPP; |
| 5047 | goto out_free; |
| 5048 | } |
| 5049 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5050 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5051 | request->dev = dev; |
| 5052 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5053 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5054 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5055 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5056 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5057 | if (!err) { |
| 5058 | rdev->sched_scan_req = request; |
| 5059 | nl80211_send_sched_scan(rdev, dev, |
| 5060 | NL80211_CMD_START_SCHED_SCAN); |
| 5061 | goto out; |
| 5062 | } |
| 5063 | |
| 5064 | out_free: |
| 5065 | kfree(request); |
| 5066 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5067 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5068 | return err; |
| 5069 | } |
| 5070 | |
| 5071 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5072 | struct genl_info *info) |
| 5073 | { |
| 5074 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5075 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5076 | |
| 5077 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5078 | !rdev->ops->sched_scan_stop) |
| 5079 | return -EOPNOTSUPP; |
| 5080 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5081 | mutex_lock(&rdev->sched_scan_mtx); |
| 5082 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 5083 | mutex_unlock(&rdev->sched_scan_mtx); |
| 5084 | |
| 5085 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5086 | } |
| 5087 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5088 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5089 | struct genl_info *info) |
| 5090 | { |
| 5091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5092 | struct net_device *dev = info->user_ptr[1]; |
| 5093 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5094 | struct cfg80211_chan_def chandef; |
| 5095 | int err; |
| 5096 | |
| 5097 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5098 | if (err) |
| 5099 | return err; |
| 5100 | |
| 5101 | if (wdev->cac_started) |
| 5102 | return -EBUSY; |
| 5103 | |
| 5104 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5105 | if (err < 0) |
| 5106 | return err; |
| 5107 | |
| 5108 | if (err == 0) |
| 5109 | return -EINVAL; |
| 5110 | |
| 5111 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5112 | return -EINVAL; |
| 5113 | |
| 5114 | if (!rdev->ops->start_radar_detection) |
| 5115 | return -EOPNOTSUPP; |
| 5116 | |
| 5117 | mutex_lock(&rdev->devlist_mtx); |
| 5118 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5119 | chandef.chan, CHAN_MODE_SHARED, |
| 5120 | BIT(chandef.width)); |
| 5121 | if (err) |
| 5122 | goto err_locked; |
| 5123 | |
| 5124 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5125 | if (!err) { |
| 5126 | wdev->channel = chandef.chan; |
| 5127 | wdev->cac_started = true; |
| 5128 | wdev->cac_start_time = jiffies; |
| 5129 | } |
| 5130 | err_locked: |
| 5131 | mutex_unlock(&rdev->devlist_mtx); |
| 5132 | |
| 5133 | return err; |
| 5134 | } |
| 5135 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5136 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5137 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5138 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5139 | struct wireless_dev *wdev, |
| 5140 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5141 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5142 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5143 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5144 | void *hdr; |
| 5145 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5146 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5147 | |
| 5148 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5149 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5150 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5151 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5152 | if (!hdr) |
| 5153 | return -1; |
| 5154 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5155 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5156 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5157 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 5158 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5159 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5160 | |
| 5161 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5162 | if (!bss) |
| 5163 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5164 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5165 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5166 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5167 | |
| 5168 | rcu_read_lock(); |
| 5169 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5170 | if (ies) { |
| 5171 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5172 | goto fail_unlock_rcu; |
| 5173 | tsf = true; |
| 5174 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5175 | ies->len, ies->data)) |
| 5176 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5177 | } |
| 5178 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5179 | if (ies) { |
| 5180 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5181 | goto fail_unlock_rcu; |
| 5182 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5183 | ies->len, ies->data)) |
| 5184 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5185 | } |
| 5186 | rcu_read_unlock(); |
| 5187 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5188 | if (res->beacon_interval && |
| 5189 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5190 | goto nla_put_failure; |
| 5191 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5192 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5193 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5194 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5195 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5196 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5197 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5198 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5199 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5200 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5201 | break; |
| 5202 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5203 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5204 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5205 | break; |
| 5206 | default: |
| 5207 | break; |
| 5208 | } |
| 5209 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5210 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5211 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5212 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5213 | if (intbss == wdev->current_bss && |
| 5214 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5215 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5216 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5217 | break; |
| 5218 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5219 | if (intbss == wdev->current_bss && |
| 5220 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5221 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5222 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5223 | break; |
| 5224 | default: |
| 5225 | break; |
| 5226 | } |
| 5227 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5228 | nla_nest_end(msg, bss); |
| 5229 | |
| 5230 | return genlmsg_end(msg, hdr); |
| 5231 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5232 | fail_unlock_rcu: |
| 5233 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5234 | nla_put_failure: |
| 5235 | genlmsg_cancel(msg, hdr); |
| 5236 | return -EMSGSIZE; |
| 5237 | } |
| 5238 | |
| 5239 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 5240 | struct netlink_callback *cb) |
| 5241 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5242 | struct cfg80211_registered_device *rdev; |
| 5243 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5244 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5245 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5246 | int start = cb->args[1], idx = 0; |
| 5247 | int err; |
| 5248 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5249 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 5250 | if (err) |
| 5251 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5252 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5253 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5254 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5255 | wdev_lock(wdev); |
| 5256 | spin_lock_bh(&rdev->bss_lock); |
| 5257 | cfg80211_bss_expire(rdev); |
| 5258 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5259 | cb->seq = rdev->bss_generation; |
| 5260 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5261 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5262 | if (++idx <= start) |
| 5263 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5264 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5265 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5266 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5267 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5268 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5269 | } |
| 5270 | } |
| 5271 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5272 | spin_unlock_bh(&rdev->bss_lock); |
| 5273 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5274 | |
| 5275 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5276 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5277 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5278 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5279 | } |
| 5280 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5281 | 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] | 5282 | int flags, struct net_device *dev, |
| 5283 | struct survey_info *survey) |
| 5284 | { |
| 5285 | void *hdr; |
| 5286 | struct nlattr *infoattr; |
| 5287 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5288 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5289 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5290 | if (!hdr) |
| 5291 | return -ENOMEM; |
| 5292 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5293 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5294 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5295 | |
| 5296 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5297 | if (!infoattr) |
| 5298 | goto nla_put_failure; |
| 5299 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5300 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5301 | survey->channel->center_freq)) |
| 5302 | goto nla_put_failure; |
| 5303 | |
| 5304 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5305 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5306 | goto nla_put_failure; |
| 5307 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5308 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5309 | goto nla_put_failure; |
| 5310 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5311 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5312 | survey->channel_time)) |
| 5313 | goto nla_put_failure; |
| 5314 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5315 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5316 | survey->channel_time_busy)) |
| 5317 | goto nla_put_failure; |
| 5318 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5319 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5320 | survey->channel_time_ext_busy)) |
| 5321 | goto nla_put_failure; |
| 5322 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5323 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5324 | survey->channel_time_rx)) |
| 5325 | goto nla_put_failure; |
| 5326 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5327 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5328 | survey->channel_time_tx)) |
| 5329 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5330 | |
| 5331 | nla_nest_end(msg, infoattr); |
| 5332 | |
| 5333 | return genlmsg_end(msg, hdr); |
| 5334 | |
| 5335 | nla_put_failure: |
| 5336 | genlmsg_cancel(msg, hdr); |
| 5337 | return -EMSGSIZE; |
| 5338 | } |
| 5339 | |
| 5340 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5341 | struct netlink_callback *cb) |
| 5342 | { |
| 5343 | struct survey_info survey; |
| 5344 | struct cfg80211_registered_device *dev; |
| 5345 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5346 | int survey_idx = cb->args[1]; |
| 5347 | int res; |
| 5348 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5349 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 5350 | if (res) |
| 5351 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5352 | |
| 5353 | if (!dev->ops->dump_survey) { |
| 5354 | res = -EOPNOTSUPP; |
| 5355 | goto out_err; |
| 5356 | } |
| 5357 | |
| 5358 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5359 | struct ieee80211_channel *chan; |
| 5360 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5361 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5362 | if (res == -ENOENT) |
| 5363 | break; |
| 5364 | if (res) |
| 5365 | goto out_err; |
| 5366 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5367 | /* Survey without a channel doesn't make sense */ |
| 5368 | if (!survey.channel) { |
| 5369 | res = -EINVAL; |
| 5370 | goto out; |
| 5371 | } |
| 5372 | |
| 5373 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5374 | survey.channel->center_freq); |
| 5375 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5376 | survey_idx++; |
| 5377 | continue; |
| 5378 | } |
| 5379 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5380 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5381 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5382 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5383 | netdev, |
| 5384 | &survey) < 0) |
| 5385 | goto out; |
| 5386 | survey_idx++; |
| 5387 | } |
| 5388 | |
| 5389 | out: |
| 5390 | cb->args[1] = survey_idx; |
| 5391 | res = skb->len; |
| 5392 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5393 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5394 | return res; |
| 5395 | } |
| 5396 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5397 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5398 | { |
| 5399 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5400 | NL80211_WPA_VERSION_2)); |
| 5401 | } |
| 5402 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5403 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5404 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5405 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5406 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5407 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5408 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5409 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5410 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5411 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5412 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5413 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5414 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5415 | return -EINVAL; |
| 5416 | |
| 5417 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5418 | return -EINVAL; |
| 5419 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5420 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5421 | return -EINVAL; |
| 5422 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5423 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5424 | return -EINVAL; |
| 5425 | |
| 5426 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5427 | return -EINVAL; |
| 5428 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5429 | err = nl80211_parse_key(info, &key); |
| 5430 | if (err) |
| 5431 | return err; |
| 5432 | |
| 5433 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5434 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5435 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5436 | if (!key.p.key || !key.p.key_len) |
| 5437 | return -EINVAL; |
| 5438 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5439 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5440 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5441 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5442 | return -EINVAL; |
| 5443 | if (key.idx > 4) |
| 5444 | return -EINVAL; |
| 5445 | } else { |
| 5446 | key.p.key_len = 0; |
| 5447 | key.p.key = NULL; |
| 5448 | } |
| 5449 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5450 | if (key.idx >= 0) { |
| 5451 | int i; |
| 5452 | bool ok = false; |
| 5453 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5454 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5455 | ok = true; |
| 5456 | break; |
| 5457 | } |
| 5458 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5459 | if (!ok) |
| 5460 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5461 | } |
| 5462 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5463 | if (!rdev->ops->auth) |
| 5464 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5465 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5466 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5467 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5468 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5469 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5470 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5471 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5472 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5473 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5474 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5475 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5476 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5477 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5478 | |
| 5479 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5480 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5481 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5482 | } |
| 5483 | |
| 5484 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5485 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5486 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5487 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5488 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5489 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5490 | return -EINVAL; |
| 5491 | |
| 5492 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5493 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5494 | return -EINVAL; |
| 5495 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5496 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5497 | /* need to include at least Auth Transaction and Status Code */ |
| 5498 | if (sae_data_len < 4) |
| 5499 | return -EINVAL; |
| 5500 | } |
| 5501 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5502 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5503 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5504 | /* |
| 5505 | * Since we no longer track auth state, ignore |
| 5506 | * requests to only change local state. |
| 5507 | */ |
| 5508 | if (local_state_change) |
| 5509 | return 0; |
| 5510 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5511 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5512 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5513 | key.p.key, key.p.key_len, key.idx, |
| 5514 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5515 | } |
| 5516 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5517 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5518 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5519 | struct cfg80211_crypto_settings *settings, |
| 5520 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5521 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5522 | memset(settings, 0, sizeof(*settings)); |
| 5523 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5524 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5525 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5526 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5527 | u16 proto; |
| 5528 | proto = nla_get_u16( |
| 5529 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5530 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5531 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5532 | proto != ETH_P_PAE) |
| 5533 | return -EINVAL; |
| 5534 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5535 | settings->control_port_no_encrypt = true; |
| 5536 | } else |
| 5537 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5538 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5539 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5540 | void *data; |
| 5541 | int len, i; |
| 5542 | |
| 5543 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5544 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5545 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5546 | |
| 5547 | if (len % sizeof(u32)) |
| 5548 | return -EINVAL; |
| 5549 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5550 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5551 | return -EINVAL; |
| 5552 | |
| 5553 | memcpy(settings->ciphers_pairwise, data, len); |
| 5554 | |
| 5555 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5556 | if (!cfg80211_supported_cipher_suite( |
| 5557 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5558 | settings->ciphers_pairwise[i])) |
| 5559 | return -EINVAL; |
| 5560 | } |
| 5561 | |
| 5562 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5563 | settings->cipher_group = |
| 5564 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5565 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5566 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5567 | return -EINVAL; |
| 5568 | } |
| 5569 | |
| 5570 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5571 | settings->wpa_versions = |
| 5572 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5573 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5574 | return -EINVAL; |
| 5575 | } |
| 5576 | |
| 5577 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5578 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5579 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5580 | |
| 5581 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5582 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5583 | settings->n_akm_suites = len / sizeof(u32); |
| 5584 | |
| 5585 | if (len % sizeof(u32)) |
| 5586 | return -EINVAL; |
| 5587 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5588 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5589 | return -EINVAL; |
| 5590 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5591 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5592 | } |
| 5593 | |
| 5594 | return 0; |
| 5595 | } |
| 5596 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5597 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5598 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5599 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5600 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5601 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5602 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5603 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5604 | int err, ssid_len, ie_len = 0; |
| 5605 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5606 | u32 flags = 0; |
| 5607 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5608 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5609 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5610 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5611 | return -EINVAL; |
| 5612 | |
| 5613 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5614 | !info->attrs[NL80211_ATTR_SSID] || |
| 5615 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5616 | return -EINVAL; |
| 5617 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5618 | if (!rdev->ops->assoc) |
| 5619 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5620 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5621 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5622 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5623 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5624 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5625 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5626 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5627 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5628 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5629 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5630 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5631 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5632 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5633 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5634 | |
| 5635 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5636 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5637 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5638 | } |
| 5639 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5640 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5641 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5642 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5643 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5644 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5645 | else if (mfp != NL80211_MFP_NO) |
| 5646 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5647 | } |
| 5648 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5649 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5650 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5651 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5652 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5653 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5654 | |
| 5655 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5656 | ht_capa_mask = |
| 5657 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5658 | |
| 5659 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5660 | if (!ht_capa_mask) |
| 5661 | return -EINVAL; |
| 5662 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5663 | } |
| 5664 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5665 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5666 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5667 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5668 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5669 | &crypto, flags, ht_capa, |
| 5670 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5671 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5672 | return err; |
| 5673 | } |
| 5674 | |
| 5675 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5676 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5678 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5679 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5680 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5681 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5682 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5683 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5684 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5685 | return -EINVAL; |
| 5686 | |
| 5687 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5688 | return -EINVAL; |
| 5689 | |
| 5690 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5691 | return -EINVAL; |
| 5692 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5693 | if (!rdev->ops->deauth) |
| 5694 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5695 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5696 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5697 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5698 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5699 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5700 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5701 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5702 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5703 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5704 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5705 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5706 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5707 | |
| 5708 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5709 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5710 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5711 | } |
| 5712 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5713 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5714 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5715 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5716 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5717 | } |
| 5718 | |
| 5719 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5720 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5721 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5722 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5723 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5724 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5725 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5726 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5727 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5728 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5729 | return -EINVAL; |
| 5730 | |
| 5731 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5732 | return -EINVAL; |
| 5733 | |
| 5734 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5735 | return -EINVAL; |
| 5736 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5737 | if (!rdev->ops->disassoc) |
| 5738 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5739 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5740 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5741 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5742 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5743 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5744 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5745 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5746 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5747 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5748 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5749 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5750 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5751 | |
| 5752 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5753 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5754 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5755 | } |
| 5756 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5757 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5758 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5759 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5760 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5761 | } |
| 5762 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5763 | static bool |
| 5764 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5765 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5766 | int rateval) |
| 5767 | { |
| 5768 | struct wiphy *wiphy = &rdev->wiphy; |
| 5769 | bool found = false; |
| 5770 | int band, i; |
| 5771 | |
| 5772 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5773 | struct ieee80211_supported_band *sband; |
| 5774 | |
| 5775 | sband = wiphy->bands[band]; |
| 5776 | if (!sband) |
| 5777 | continue; |
| 5778 | |
| 5779 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5780 | if (sband->bitrates[i].bitrate == rateval) { |
| 5781 | mcast_rate[band] = i + 1; |
| 5782 | found = true; |
| 5783 | break; |
| 5784 | } |
| 5785 | } |
| 5786 | } |
| 5787 | |
| 5788 | return found; |
| 5789 | } |
| 5790 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5791 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5792 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5793 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5794 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5795 | struct cfg80211_ibss_params ibss; |
| 5796 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5797 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5798 | int err; |
| 5799 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5800 | memset(&ibss, 0, sizeof(ibss)); |
| 5801 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5802 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5803 | return -EINVAL; |
| 5804 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5805 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5806 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5807 | return -EINVAL; |
| 5808 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5809 | ibss.beacon_interval = 100; |
| 5810 | |
| 5811 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5812 | ibss.beacon_interval = |
| 5813 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5814 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5815 | return -EINVAL; |
| 5816 | } |
| 5817 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5818 | if (!rdev->ops->join_ibss) |
| 5819 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5820 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5821 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5822 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5823 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5824 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5825 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5826 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5827 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5828 | |
| 5829 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5830 | return -EINVAL; |
| 5831 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5832 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5833 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5834 | |
| 5835 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5836 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5837 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5838 | } |
| 5839 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5840 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 5841 | if (err) |
| 5842 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5843 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5844 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5845 | return -EINVAL; |
| 5846 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5847 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 5848 | return -EINVAL; |
| 5849 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 5850 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 5851 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5852 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5853 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5854 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5855 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5856 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5857 | u8 *rates = |
| 5858 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5859 | int n_rates = |
| 5860 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5861 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5862 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5863 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5864 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5865 | &ibss.basic_rates); |
| 5866 | if (err) |
| 5867 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5868 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5869 | |
| 5870 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5871 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5872 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5873 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5874 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5875 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5876 | bool no_ht = false; |
| 5877 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5878 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5879 | info->attrs[NL80211_ATTR_KEYS], |
| 5880 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5881 | if (IS_ERR(connkeys)) |
| 5882 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5883 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 5884 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 5885 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5886 | kfree(connkeys); |
| 5887 | return -EINVAL; |
| 5888 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5889 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5890 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5891 | ibss.control_port = |
| 5892 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5893 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5894 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5895 | if (err) |
| 5896 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5897 | return err; |
| 5898 | } |
| 5899 | |
| 5900 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5901 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5903 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5904 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5905 | if (!rdev->ops->leave_ibss) |
| 5906 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5907 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5908 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5909 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5910 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5911 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5912 | } |
| 5913 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 5914 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 5915 | { |
| 5916 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5917 | struct net_device *dev = info->user_ptr[1]; |
| 5918 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 5919 | u32 nla_rate; |
| 5920 | int err; |
| 5921 | |
| 5922 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5923 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5924 | return -EOPNOTSUPP; |
| 5925 | |
| 5926 | if (!rdev->ops->set_mcast_rate) |
| 5927 | return -EOPNOTSUPP; |
| 5928 | |
| 5929 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 5930 | |
| 5931 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 5932 | return -EINVAL; |
| 5933 | |
| 5934 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 5935 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 5936 | return -EINVAL; |
| 5937 | |
| 5938 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 5939 | |
| 5940 | return err; |
| 5941 | } |
| 5942 | |
| 5943 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5944 | #ifdef CONFIG_NL80211_TESTMODE |
| 5945 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5946 | .name = "testmode", |
| 5947 | }; |
| 5948 | |
| 5949 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5950 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5951 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5952 | int err; |
| 5953 | |
| 5954 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5955 | return -EINVAL; |
| 5956 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5957 | err = -EOPNOTSUPP; |
| 5958 | if (rdev->ops->testmode_cmd) { |
| 5959 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5960 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5961 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5962 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5963 | rdev->testmode_info = NULL; |
| 5964 | } |
| 5965 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5966 | return err; |
| 5967 | } |
| 5968 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5969 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5970 | struct netlink_callback *cb) |
| 5971 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5972 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5973 | int err; |
| 5974 | long phy_idx; |
| 5975 | void *data = NULL; |
| 5976 | int data_len = 0; |
| 5977 | |
| 5978 | if (cb->args[0]) { |
| 5979 | /* |
| 5980 | * 0 is a valid index, but not valid for args[0], |
| 5981 | * so we need to offset by 1. |
| 5982 | */ |
| 5983 | phy_idx = cb->args[0] - 1; |
| 5984 | } else { |
| 5985 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5986 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5987 | nl80211_policy); |
| 5988 | if (err) |
| 5989 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5990 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5991 | mutex_lock(&cfg80211_mutex); |
| 5992 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 5993 | nl80211_fam.attrbuf); |
| 5994 | if (IS_ERR(rdev)) { |
| 5995 | mutex_unlock(&cfg80211_mutex); |
| 5996 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5997 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5998 | phy_idx = rdev->wiphy_idx; |
| 5999 | rdev = NULL; |
| 6000 | mutex_unlock(&cfg80211_mutex); |
| 6001 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6002 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6003 | cb->args[1] = |
| 6004 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6005 | } |
| 6006 | |
| 6007 | if (cb->args[1]) { |
| 6008 | data = nla_data((void *)cb->args[1]); |
| 6009 | data_len = nla_len((void *)cb->args[1]); |
| 6010 | } |
| 6011 | |
| 6012 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6013 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6014 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6015 | mutex_unlock(&cfg80211_mutex); |
| 6016 | return -ENOENT; |
| 6017 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6018 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6019 | mutex_unlock(&cfg80211_mutex); |
| 6020 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6021 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6022 | err = -EOPNOTSUPP; |
| 6023 | goto out_err; |
| 6024 | } |
| 6025 | |
| 6026 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6027 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6028 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6029 | NL80211_CMD_TESTMODE); |
| 6030 | struct nlattr *tmdata; |
| 6031 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6032 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6033 | genlmsg_cancel(skb, hdr); |
| 6034 | break; |
| 6035 | } |
| 6036 | |
| 6037 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6038 | if (!tmdata) { |
| 6039 | genlmsg_cancel(skb, hdr); |
| 6040 | break; |
| 6041 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6042 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6043 | nla_nest_end(skb, tmdata); |
| 6044 | |
| 6045 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6046 | genlmsg_cancel(skb, hdr); |
| 6047 | break; |
| 6048 | } else if (err) { |
| 6049 | genlmsg_cancel(skb, hdr); |
| 6050 | goto out_err; |
| 6051 | } |
| 6052 | |
| 6053 | genlmsg_end(skb, hdr); |
| 6054 | } |
| 6055 | |
| 6056 | err = skb->len; |
| 6057 | /* see above */ |
| 6058 | cb->args[0] = phy_idx + 1; |
| 6059 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6060 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6061 | return err; |
| 6062 | } |
| 6063 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6064 | static struct sk_buff * |
| 6065 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6066 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6067 | { |
| 6068 | struct sk_buff *skb; |
| 6069 | void *hdr; |
| 6070 | struct nlattr *data; |
| 6071 | |
| 6072 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6073 | if (!skb) |
| 6074 | return NULL; |
| 6075 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6076 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6077 | if (!hdr) { |
| 6078 | kfree_skb(skb); |
| 6079 | return NULL; |
| 6080 | } |
| 6081 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6082 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6083 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6084 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6085 | |
| 6086 | ((void **)skb->cb)[0] = rdev; |
| 6087 | ((void **)skb->cb)[1] = hdr; |
| 6088 | ((void **)skb->cb)[2] = data; |
| 6089 | |
| 6090 | return skb; |
| 6091 | |
| 6092 | nla_put_failure: |
| 6093 | kfree_skb(skb); |
| 6094 | return NULL; |
| 6095 | } |
| 6096 | |
| 6097 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6098 | int approxlen) |
| 6099 | { |
| 6100 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6101 | |
| 6102 | if (WARN_ON(!rdev->testmode_info)) |
| 6103 | return NULL; |
| 6104 | |
| 6105 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6106 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6107 | rdev->testmode_info->snd_seq, |
| 6108 | GFP_KERNEL); |
| 6109 | } |
| 6110 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6111 | |
| 6112 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6113 | { |
| 6114 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6115 | void *hdr = ((void **)skb->cb)[1]; |
| 6116 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6117 | |
| 6118 | if (WARN_ON(!rdev->testmode_info)) { |
| 6119 | kfree_skb(skb); |
| 6120 | return -EINVAL; |
| 6121 | } |
| 6122 | |
| 6123 | nla_nest_end(skb, data); |
| 6124 | genlmsg_end(skb, hdr); |
| 6125 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6126 | } |
| 6127 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6128 | |
| 6129 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6130 | int approxlen, gfp_t gfp) |
| 6131 | { |
| 6132 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6133 | |
| 6134 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6135 | } |
| 6136 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6137 | |
| 6138 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6139 | { |
| 6140 | void *hdr = ((void **)skb->cb)[1]; |
| 6141 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6142 | |
| 6143 | nla_nest_end(skb, data); |
| 6144 | genlmsg_end(skb, hdr); |
| 6145 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6146 | } |
| 6147 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6148 | #endif |
| 6149 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6150 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6151 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6152 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6153 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6154 | struct cfg80211_connect_params connect; |
| 6155 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6156 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6157 | int err; |
| 6158 | |
| 6159 | memset(&connect, 0, sizeof(connect)); |
| 6160 | |
| 6161 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6162 | return -EINVAL; |
| 6163 | |
| 6164 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6165 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6166 | return -EINVAL; |
| 6167 | |
| 6168 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6169 | connect.auth_type = |
| 6170 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6171 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6172 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6173 | return -EINVAL; |
| 6174 | } else |
| 6175 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6176 | |
| 6177 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6178 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6179 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6180 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6181 | if (err) |
| 6182 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6183 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6184 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6185 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6186 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6187 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6188 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6189 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6190 | connect.bg_scan_period = -1; |
| 6191 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6192 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6193 | connect.bg_scan_period = |
| 6194 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6195 | } |
| 6196 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6197 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6198 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6199 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6200 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6201 | |
| 6202 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6203 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6204 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6205 | } |
| 6206 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6207 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6208 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6209 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6210 | connect.mfp != NL80211_MFP_NO) |
| 6211 | return -EINVAL; |
| 6212 | } else { |
| 6213 | connect.mfp = NL80211_MFP_NO; |
| 6214 | } |
| 6215 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6216 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6217 | connect.channel = |
| 6218 | ieee80211_get_channel(wiphy, |
| 6219 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6220 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6221 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6222 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6223 | } |
| 6224 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6225 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6226 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6227 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6228 | if (IS_ERR(connkeys)) |
| 6229 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6230 | } |
| 6231 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6232 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6233 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6234 | |
| 6235 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6236 | memcpy(&connect.ht_capa_mask, |
| 6237 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6238 | sizeof(connect.ht_capa_mask)); |
| 6239 | |
| 6240 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6241 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6242 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6243 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6244 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6245 | memcpy(&connect.ht_capa, |
| 6246 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6247 | sizeof(connect.ht_capa)); |
| 6248 | } |
| 6249 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6250 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6251 | if (err) |
| 6252 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6253 | return err; |
| 6254 | } |
| 6255 | |
| 6256 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6257 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6258 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6259 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6260 | u16 reason; |
| 6261 | |
| 6262 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6263 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6264 | else |
| 6265 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6266 | |
| 6267 | if (reason == 0) |
| 6268 | return -EINVAL; |
| 6269 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6270 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6271 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6272 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6273 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6274 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6275 | } |
| 6276 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6277 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6278 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6280 | struct net *net; |
| 6281 | int err; |
| 6282 | u32 pid; |
| 6283 | |
| 6284 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6285 | return -EINVAL; |
| 6286 | |
| 6287 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6288 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6289 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6290 | if (IS_ERR(net)) |
| 6291 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6292 | |
| 6293 | err = 0; |
| 6294 | |
| 6295 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6296 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6297 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6298 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6299 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6300 | return err; |
| 6301 | } |
| 6302 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6303 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6304 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6305 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6306 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6307 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6308 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6309 | struct cfg80211_pmksa pmksa; |
| 6310 | |
| 6311 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6312 | |
| 6313 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6314 | return -EINVAL; |
| 6315 | |
| 6316 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6317 | return -EINVAL; |
| 6318 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6319 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6320 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6321 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6322 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6323 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6324 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6325 | |
| 6326 | switch (info->genlhdr->cmd) { |
| 6327 | case NL80211_CMD_SET_PMKSA: |
| 6328 | rdev_ops = rdev->ops->set_pmksa; |
| 6329 | break; |
| 6330 | case NL80211_CMD_DEL_PMKSA: |
| 6331 | rdev_ops = rdev->ops->del_pmksa; |
| 6332 | break; |
| 6333 | default: |
| 6334 | WARN_ON(1); |
| 6335 | break; |
| 6336 | } |
| 6337 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6338 | if (!rdev_ops) |
| 6339 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6340 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6341 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6342 | } |
| 6343 | |
| 6344 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6345 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6346 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6347 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6348 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6349 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6350 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6351 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6352 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6353 | if (!rdev->ops->flush_pmksa) |
| 6354 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6355 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6356 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6357 | } |
| 6358 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6359 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6360 | { |
| 6361 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6362 | struct net_device *dev = info->user_ptr[1]; |
| 6363 | u8 action_code, dialog_token; |
| 6364 | u16 status_code; |
| 6365 | u8 *peer; |
| 6366 | |
| 6367 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6368 | !rdev->ops->tdls_mgmt) |
| 6369 | return -EOPNOTSUPP; |
| 6370 | |
| 6371 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6372 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6373 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6374 | !info->attrs[NL80211_ATTR_IE] || |
| 6375 | !info->attrs[NL80211_ATTR_MAC]) |
| 6376 | return -EINVAL; |
| 6377 | |
| 6378 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6379 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6380 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6381 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6382 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6383 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6384 | dialog_token, status_code, |
| 6385 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6386 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6387 | } |
| 6388 | |
| 6389 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6390 | { |
| 6391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6392 | struct net_device *dev = info->user_ptr[1]; |
| 6393 | enum nl80211_tdls_operation operation; |
| 6394 | u8 *peer; |
| 6395 | |
| 6396 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6397 | !rdev->ops->tdls_oper) |
| 6398 | return -EOPNOTSUPP; |
| 6399 | |
| 6400 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6401 | !info->attrs[NL80211_ATTR_MAC]) |
| 6402 | return -EINVAL; |
| 6403 | |
| 6404 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6405 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6406 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6407 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6408 | } |
| 6409 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6410 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6411 | struct genl_info *info) |
| 6412 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6413 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6414 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6415 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6416 | struct sk_buff *msg; |
| 6417 | void *hdr; |
| 6418 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6419 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6420 | int err; |
| 6421 | |
| 6422 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6423 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6424 | return -EINVAL; |
| 6425 | |
| 6426 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6427 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6428 | if (!rdev->ops->remain_on_channel || |
| 6429 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6430 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6431 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6432 | /* |
| 6433 | * We should be on that channel for at least a minimum amount of |
| 6434 | * time (10ms) but no longer than the driver supports. |
| 6435 | */ |
| 6436 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6437 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6438 | return -EINVAL; |
| 6439 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6440 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6441 | if (err) |
| 6442 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6443 | |
| 6444 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6445 | if (!msg) |
| 6446 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6447 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6448 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6449 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6450 | |
| 6451 | if (IS_ERR(hdr)) { |
| 6452 | err = PTR_ERR(hdr); |
| 6453 | goto free_msg; |
| 6454 | } |
| 6455 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6456 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6457 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6458 | |
| 6459 | if (err) |
| 6460 | goto free_msg; |
| 6461 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6462 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6463 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6464 | |
| 6465 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6466 | |
| 6467 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6468 | |
| 6469 | nla_put_failure: |
| 6470 | err = -ENOBUFS; |
| 6471 | free_msg: |
| 6472 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6473 | return err; |
| 6474 | } |
| 6475 | |
| 6476 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6477 | struct genl_info *info) |
| 6478 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6479 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6480 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6481 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6482 | |
| 6483 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6484 | return -EINVAL; |
| 6485 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6486 | if (!rdev->ops->cancel_remain_on_channel) |
| 6487 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6488 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6489 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6490 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6491 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6492 | } |
| 6493 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6494 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6495 | u8 *rates, u8 rates_len) |
| 6496 | { |
| 6497 | u8 i; |
| 6498 | u32 mask = 0; |
| 6499 | |
| 6500 | for (i = 0; i < rates_len; i++) { |
| 6501 | int rate = (rates[i] & 0x7f) * 5; |
| 6502 | int ridx; |
| 6503 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6504 | struct ieee80211_rate *srate = |
| 6505 | &sband->bitrates[ridx]; |
| 6506 | if (rate == srate->bitrate) { |
| 6507 | mask |= 1 << ridx; |
| 6508 | break; |
| 6509 | } |
| 6510 | } |
| 6511 | if (ridx == sband->n_bitrates) |
| 6512 | return 0; /* rate not found */ |
| 6513 | } |
| 6514 | |
| 6515 | return mask; |
| 6516 | } |
| 6517 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6518 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6519 | u8 *rates, u8 rates_len, |
| 6520 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6521 | { |
| 6522 | u8 i; |
| 6523 | |
| 6524 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6525 | |
| 6526 | for (i = 0; i < rates_len; i++) { |
| 6527 | int ridx, rbit; |
| 6528 | |
| 6529 | ridx = rates[i] / 8; |
| 6530 | rbit = BIT(rates[i] % 8); |
| 6531 | |
| 6532 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6533 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6534 | return false; |
| 6535 | |
| 6536 | /* check availability */ |
| 6537 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6538 | mcs[ridx] |= rbit; |
| 6539 | else |
| 6540 | return false; |
| 6541 | } |
| 6542 | |
| 6543 | return true; |
| 6544 | } |
| 6545 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6546 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6547 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6548 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6549 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6550 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6551 | }; |
| 6552 | |
| 6553 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6554 | struct genl_info *info) |
| 6555 | { |
| 6556 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6557 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6558 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6559 | int rem, i; |
| 6560 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6561 | struct nlattr *tx_rates; |
| 6562 | struct ieee80211_supported_band *sband; |
| 6563 | |
| 6564 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6565 | return -EINVAL; |
| 6566 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6567 | if (!rdev->ops->set_bitrate_mask) |
| 6568 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6569 | |
| 6570 | memset(&mask, 0, sizeof(mask)); |
| 6571 | /* Default to all rates enabled */ |
| 6572 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6573 | sband = rdev->wiphy.bands[i]; |
| 6574 | mask.control[i].legacy = |
| 6575 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6576 | if (sband) |
| 6577 | memcpy(mask.control[i].mcs, |
| 6578 | sband->ht_cap.mcs.rx_mask, |
| 6579 | sizeof(mask.control[i].mcs)); |
| 6580 | else |
| 6581 | memset(mask.control[i].mcs, 0, |
| 6582 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6583 | } |
| 6584 | |
| 6585 | /* |
| 6586 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6587 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6588 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6589 | 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] | 6590 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6591 | { |
| 6592 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6593 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6594 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6595 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6596 | if (sband == NULL) |
| 6597 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6598 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6599 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6600 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6601 | mask.control[band].legacy = rateset_to_mask( |
| 6602 | sband, |
| 6603 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6604 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6605 | if ((mask.control[band].legacy == 0) && |
| 6606 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6607 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6608 | } |
| 6609 | if (tb[NL80211_TXRATE_MCS]) { |
| 6610 | if (!ht_rateset_to_mask( |
| 6611 | sband, |
| 6612 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6613 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6614 | mask.control[band].mcs)) |
| 6615 | return -EINVAL; |
| 6616 | } |
| 6617 | |
| 6618 | if (mask.control[band].legacy == 0) { |
| 6619 | /* don't allow empty legacy rates if HT |
| 6620 | * is not even supported. */ |
| 6621 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6622 | return -EINVAL; |
| 6623 | |
| 6624 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6625 | if (mask.control[band].mcs[i]) |
| 6626 | break; |
| 6627 | |
| 6628 | /* legacy and mcs rates may not be both empty */ |
| 6629 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6630 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6631 | } |
| 6632 | } |
| 6633 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6634 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6635 | } |
| 6636 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6637 | 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] | 6638 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6639 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6640 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6641 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6642 | |
| 6643 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6644 | return -EINVAL; |
| 6645 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6646 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6647 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6648 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6649 | switch (wdev->iftype) { |
| 6650 | case NL80211_IFTYPE_STATION: |
| 6651 | case NL80211_IFTYPE_ADHOC: |
| 6652 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6653 | case NL80211_IFTYPE_AP: |
| 6654 | case NL80211_IFTYPE_AP_VLAN: |
| 6655 | case NL80211_IFTYPE_MESH_POINT: |
| 6656 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6657 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6658 | break; |
| 6659 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6660 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6661 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6662 | |
| 6663 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6664 | if (!rdev->ops->mgmt_tx) |
| 6665 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6666 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6667 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6668 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6669 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6670 | } |
| 6671 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6672 | 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] | 6673 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6674 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6675 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6676 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6677 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6678 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6679 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6680 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6681 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6682 | bool offchan, no_cck, dont_wait_for_ack; |
| 6683 | |
| 6684 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6685 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6686 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6687 | return -EINVAL; |
| 6688 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6689 | if (!rdev->ops->mgmt_tx) |
| 6690 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6691 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6692 | switch (wdev->iftype) { |
| 6693 | case NL80211_IFTYPE_STATION: |
| 6694 | case NL80211_IFTYPE_ADHOC: |
| 6695 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6696 | case NL80211_IFTYPE_AP: |
| 6697 | case NL80211_IFTYPE_AP_VLAN: |
| 6698 | case NL80211_IFTYPE_MESH_POINT: |
| 6699 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6700 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6701 | break; |
| 6702 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6703 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6704 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6705 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6706 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6707 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6708 | return -EINVAL; |
| 6709 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6710 | |
| 6711 | /* |
| 6712 | * We should wait on the channel for at least a minimum amount |
| 6713 | * of time (10ms) but no longer than the driver supports. |
| 6714 | */ |
| 6715 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6716 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6717 | return -EINVAL; |
| 6718 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6719 | } |
| 6720 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6721 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6722 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6723 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6724 | return -EINVAL; |
| 6725 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6726 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6727 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6728 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6729 | if (err) |
| 6730 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6731 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6732 | if (!dont_wait_for_ack) { |
| 6733 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6734 | if (!msg) |
| 6735 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6736 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6737 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6738 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6739 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6740 | if (IS_ERR(hdr)) { |
| 6741 | err = PTR_ERR(hdr); |
| 6742 | goto free_msg; |
| 6743 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6744 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6745 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6746 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6747 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6748 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6749 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6750 | if (err) |
| 6751 | goto free_msg; |
| 6752 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6753 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6754 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6755 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6756 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6757 | genlmsg_end(msg, hdr); |
| 6758 | return genlmsg_reply(msg, info); |
| 6759 | } |
| 6760 | |
| 6761 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6762 | |
| 6763 | nla_put_failure: |
| 6764 | err = -ENOBUFS; |
| 6765 | free_msg: |
| 6766 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6767 | return err; |
| 6768 | } |
| 6769 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6770 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6771 | { |
| 6772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6773 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6774 | u64 cookie; |
| 6775 | |
| 6776 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6777 | return -EINVAL; |
| 6778 | |
| 6779 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6780 | return -EOPNOTSUPP; |
| 6781 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6782 | switch (wdev->iftype) { |
| 6783 | case NL80211_IFTYPE_STATION: |
| 6784 | case NL80211_IFTYPE_ADHOC: |
| 6785 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6786 | case NL80211_IFTYPE_AP: |
| 6787 | case NL80211_IFTYPE_AP_VLAN: |
| 6788 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6789 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6790 | break; |
| 6791 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6792 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6793 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6794 | |
| 6795 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6796 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6797 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6798 | } |
| 6799 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6800 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6801 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6802 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6803 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6804 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6805 | u8 ps_state; |
| 6806 | bool state; |
| 6807 | int err; |
| 6808 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6809 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6810 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6811 | |
| 6812 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6813 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6814 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6815 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6816 | |
| 6817 | wdev = dev->ieee80211_ptr; |
| 6818 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6819 | if (!rdev->ops->set_power_mgmt) |
| 6820 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6821 | |
| 6822 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6823 | |
| 6824 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6825 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6826 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6827 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6828 | if (!err) |
| 6829 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6830 | return err; |
| 6831 | } |
| 6832 | |
| 6833 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6834 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6835 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6836 | enum nl80211_ps_state ps_state; |
| 6837 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6838 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6839 | struct sk_buff *msg; |
| 6840 | void *hdr; |
| 6841 | int err; |
| 6842 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6843 | wdev = dev->ieee80211_ptr; |
| 6844 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6845 | if (!rdev->ops->set_power_mgmt) |
| 6846 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6847 | |
| 6848 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6849 | if (!msg) |
| 6850 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6851 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6852 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6853 | NL80211_CMD_GET_POWER_SAVE); |
| 6854 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6855 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6856 | goto free_msg; |
| 6857 | } |
| 6858 | |
| 6859 | if (wdev->ps) |
| 6860 | ps_state = NL80211_PS_ENABLED; |
| 6861 | else |
| 6862 | ps_state = NL80211_PS_DISABLED; |
| 6863 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6864 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6865 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6866 | |
| 6867 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6868 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6869 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6870 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6871 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6872 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6873 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6874 | return err; |
| 6875 | } |
| 6876 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6877 | static struct nla_policy |
| 6878 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6879 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6880 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6881 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6882 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 6883 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 6884 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6885 | }; |
| 6886 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6887 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6888 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6889 | { |
| 6890 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6891 | struct wireless_dev *wdev; |
| 6892 | struct net_device *dev = info->user_ptr[1]; |
| 6893 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6894 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6895 | return -EINVAL; |
| 6896 | |
| 6897 | wdev = dev->ieee80211_ptr; |
| 6898 | |
| 6899 | if (!rdev->ops->set_cqm_txe_config) |
| 6900 | return -EOPNOTSUPP; |
| 6901 | |
| 6902 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 6903 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6904 | return -EOPNOTSUPP; |
| 6905 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6906 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6907 | } |
| 6908 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6909 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6910 | s32 threshold, u32 hysteresis) |
| 6911 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6912 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6913 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6914 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6915 | |
| 6916 | if (threshold > 0) |
| 6917 | return -EINVAL; |
| 6918 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6919 | wdev = dev->ieee80211_ptr; |
| 6920 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6921 | if (!rdev->ops->set_cqm_rssi_config) |
| 6922 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6923 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6924 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6925 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6926 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6927 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6928 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6929 | } |
| 6930 | |
| 6931 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6932 | { |
| 6933 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6934 | struct nlattr *cqm; |
| 6935 | int err; |
| 6936 | |
| 6937 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6938 | if (!cqm) { |
| 6939 | err = -EINVAL; |
| 6940 | goto out; |
| 6941 | } |
| 6942 | |
| 6943 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6944 | nl80211_attr_cqm_policy); |
| 6945 | if (err) |
| 6946 | goto out; |
| 6947 | |
| 6948 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6949 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6950 | s32 threshold; |
| 6951 | u32 hysteresis; |
| 6952 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6953 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6954 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6955 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 6956 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 6957 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 6958 | u32 rate, pkts, intvl; |
| 6959 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 6960 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 6961 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 6962 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6963 | } else |
| 6964 | err = -EINVAL; |
| 6965 | |
| 6966 | out: |
| 6967 | return err; |
| 6968 | } |
| 6969 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6970 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6971 | { |
| 6972 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6973 | struct net_device *dev = info->user_ptr[1]; |
| 6974 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6975 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6976 | int err; |
| 6977 | |
| 6978 | /* start with default */ |
| 6979 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6980 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6981 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6982 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6983 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6984 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6985 | if (err) |
| 6986 | return err; |
| 6987 | } |
| 6988 | |
| 6989 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6990 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 6991 | return -EINVAL; |
| 6992 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6993 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6994 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6995 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 6996 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6997 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 6998 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6999 | return -EINVAL; |
| 7000 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7001 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7002 | setup.beacon_interval = |
| 7003 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7004 | if (setup.beacon_interval < 10 || |
| 7005 | setup.beacon_interval > 10000) |
| 7006 | return -EINVAL; |
| 7007 | } |
| 7008 | |
| 7009 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7010 | setup.dtim_period = |
| 7011 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7012 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7013 | return -EINVAL; |
| 7014 | } |
| 7015 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7016 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7017 | /* parse additional setup parameters if given */ |
| 7018 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7019 | if (err) |
| 7020 | return err; |
| 7021 | } |
| 7022 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7023 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7024 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7025 | if (err) |
| 7026 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7027 | } else { |
| 7028 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7029 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7030 | } |
| 7031 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7032 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7033 | } |
| 7034 | |
| 7035 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7036 | { |
| 7037 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7038 | struct net_device *dev = info->user_ptr[1]; |
| 7039 | |
| 7040 | return cfg80211_leave_mesh(rdev, dev); |
| 7041 | } |
| 7042 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7043 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7044 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7045 | struct cfg80211_registered_device *rdev) |
| 7046 | { |
| 7047 | struct nlattr *nl_pats, *nl_pat; |
| 7048 | int i, pat_len; |
| 7049 | |
| 7050 | if (!rdev->wowlan->n_patterns) |
| 7051 | return 0; |
| 7052 | |
| 7053 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7054 | if (!nl_pats) |
| 7055 | return -ENOBUFS; |
| 7056 | |
| 7057 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 7058 | nl_pat = nla_nest_start(msg, i + 1); |
| 7059 | if (!nl_pat) |
| 7060 | return -ENOBUFS; |
| 7061 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 7062 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 7063 | DIV_ROUND_UP(pat_len, 8), |
| 7064 | rdev->wowlan->patterns[i].mask) || |
| 7065 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 7066 | pat_len, rdev->wowlan->patterns[i].pattern) || |
| 7067 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
| 7068 | rdev->wowlan->patterns[i].pkt_offset)) |
| 7069 | return -ENOBUFS; |
| 7070 | nla_nest_end(msg, nl_pat); |
| 7071 | } |
| 7072 | nla_nest_end(msg, nl_pats); |
| 7073 | |
| 7074 | return 0; |
| 7075 | } |
| 7076 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7077 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7078 | struct cfg80211_wowlan_tcp *tcp) |
| 7079 | { |
| 7080 | struct nlattr *nl_tcp; |
| 7081 | |
| 7082 | if (!tcp) |
| 7083 | return 0; |
| 7084 | |
| 7085 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7086 | if (!nl_tcp) |
| 7087 | return -ENOBUFS; |
| 7088 | |
| 7089 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7090 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7091 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7092 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7093 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7094 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7095 | tcp->payload_len, tcp->payload) || |
| 7096 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7097 | tcp->data_interval) || |
| 7098 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7099 | tcp->wake_len, tcp->wake_data) || |
| 7100 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7101 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7102 | return -ENOBUFS; |
| 7103 | |
| 7104 | if (tcp->payload_seq.len && |
| 7105 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7106 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7107 | return -ENOBUFS; |
| 7108 | |
| 7109 | if (tcp->payload_tok.len && |
| 7110 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7111 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7112 | &tcp->payload_tok)) |
| 7113 | return -ENOBUFS; |
| 7114 | |
| 7115 | return 0; |
| 7116 | } |
| 7117 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7118 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7119 | { |
| 7120 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7121 | struct sk_buff *msg; |
| 7122 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7123 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7124 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7125 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7126 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7127 | return -EOPNOTSUPP; |
| 7128 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7129 | if (rdev->wowlan && rdev->wowlan->tcp) { |
| 7130 | /* adjust size to have room for all the data */ |
| 7131 | size += rdev->wowlan->tcp->tokens_size + |
| 7132 | rdev->wowlan->tcp->payload_len + |
| 7133 | rdev->wowlan->tcp->wake_len + |
| 7134 | rdev->wowlan->tcp->wake_len / 8; |
| 7135 | } |
| 7136 | |
| 7137 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7138 | if (!msg) |
| 7139 | return -ENOMEM; |
| 7140 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7141 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7142 | NL80211_CMD_GET_WOWLAN); |
| 7143 | if (!hdr) |
| 7144 | goto nla_put_failure; |
| 7145 | |
| 7146 | if (rdev->wowlan) { |
| 7147 | struct nlattr *nl_wowlan; |
| 7148 | |
| 7149 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7150 | if (!nl_wowlan) |
| 7151 | goto nla_put_failure; |
| 7152 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7153 | if ((rdev->wowlan->any && |
| 7154 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7155 | (rdev->wowlan->disconnect && |
| 7156 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7157 | (rdev->wowlan->magic_pkt && |
| 7158 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7159 | (rdev->wowlan->gtk_rekey_failure && |
| 7160 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7161 | (rdev->wowlan->eap_identity_req && |
| 7162 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7163 | (rdev->wowlan->four_way_handshake && |
| 7164 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7165 | (rdev->wowlan->rfkill_release && |
| 7166 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7167 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7168 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7169 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7170 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7171 | |
| 7172 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) |
| 7173 | goto nla_put_failure; |
| 7174 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7175 | nla_nest_end(msg, nl_wowlan); |
| 7176 | } |
| 7177 | |
| 7178 | genlmsg_end(msg, hdr); |
| 7179 | return genlmsg_reply(msg, info); |
| 7180 | |
| 7181 | nla_put_failure: |
| 7182 | nlmsg_free(msg); |
| 7183 | return -ENOBUFS; |
| 7184 | } |
| 7185 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7186 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7187 | struct nlattr *attr, |
| 7188 | struct cfg80211_wowlan *trig) |
| 7189 | { |
| 7190 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7191 | struct cfg80211_wowlan_tcp *cfg; |
| 7192 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7193 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7194 | u32 size; |
| 7195 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7196 | int err, port; |
| 7197 | |
| 7198 | if (!rdev->wiphy.wowlan.tcp) |
| 7199 | return -EINVAL; |
| 7200 | |
| 7201 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7202 | nla_data(attr), nla_len(attr), |
| 7203 | nl80211_wowlan_tcp_policy); |
| 7204 | if (err) |
| 7205 | return err; |
| 7206 | |
| 7207 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7208 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7209 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7210 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7211 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7212 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7213 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7214 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7215 | return -EINVAL; |
| 7216 | |
| 7217 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
| 7218 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) |
| 7219 | return -EINVAL; |
| 7220 | |
| 7221 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
| 7222 | rdev->wiphy.wowlan.tcp->data_interval_max) |
| 7223 | return -EINVAL; |
| 7224 | |
| 7225 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
| 7226 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) |
| 7227 | return -EINVAL; |
| 7228 | |
| 7229 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7230 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7231 | return -EINVAL; |
| 7232 | |
| 7233 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7234 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7235 | |
| 7236 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7237 | tokens_size = tokln - sizeof(*tok); |
| 7238 | |
| 7239 | if (!tok->len || tokens_size % tok->len) |
| 7240 | return -EINVAL; |
| 7241 | if (!rdev->wiphy.wowlan.tcp->tok) |
| 7242 | return -EINVAL; |
| 7243 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) |
| 7244 | return -EINVAL; |
| 7245 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) |
| 7246 | return -EINVAL; |
| 7247 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) |
| 7248 | return -EINVAL; |
| 7249 | if (tok->offset + tok->len > data_size) |
| 7250 | return -EINVAL; |
| 7251 | } |
| 7252 | |
| 7253 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7254 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
| 7255 | if (!rdev->wiphy.wowlan.tcp->seq) |
| 7256 | return -EINVAL; |
| 7257 | if (seq->len == 0 || seq->len > 4) |
| 7258 | return -EINVAL; |
| 7259 | if (seq->len + seq->offset > data_size) |
| 7260 | return -EINVAL; |
| 7261 | } |
| 7262 | |
| 7263 | size = sizeof(*cfg); |
| 7264 | size += data_size; |
| 7265 | size += wake_size + wake_mask_size; |
| 7266 | size += tokens_size; |
| 7267 | |
| 7268 | cfg = kzalloc(size, GFP_KERNEL); |
| 7269 | if (!cfg) |
| 7270 | return -ENOMEM; |
| 7271 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7272 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7273 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7274 | ETH_ALEN); |
| 7275 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7276 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7277 | else |
| 7278 | port = 0; |
| 7279 | #ifdef CONFIG_INET |
| 7280 | /* allocate a socket and port for it and use it */ |
| 7281 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7282 | IPPROTO_TCP, &cfg->sock, 1); |
| 7283 | if (err) { |
| 7284 | kfree(cfg); |
| 7285 | return err; |
| 7286 | } |
| 7287 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7288 | sock_release(cfg->sock); |
| 7289 | kfree(cfg); |
| 7290 | return -EADDRINUSE; |
| 7291 | } |
| 7292 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7293 | #else |
| 7294 | if (!port) { |
| 7295 | kfree(cfg); |
| 7296 | return -EINVAL; |
| 7297 | } |
| 7298 | cfg->src_port = port; |
| 7299 | #endif |
| 7300 | |
| 7301 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7302 | cfg->payload_len = data_size; |
| 7303 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7304 | memcpy((void *)cfg->payload, |
| 7305 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7306 | data_size); |
| 7307 | if (seq) |
| 7308 | cfg->payload_seq = *seq; |
| 7309 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7310 | cfg->wake_len = wake_size; |
| 7311 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7312 | memcpy((void *)cfg->wake_data, |
| 7313 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7314 | wake_size); |
| 7315 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7316 | data_size + wake_size; |
| 7317 | memcpy((void *)cfg->wake_mask, |
| 7318 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7319 | wake_mask_size); |
| 7320 | if (tok) { |
| 7321 | cfg->tokens_size = tokens_size; |
| 7322 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7323 | } |
| 7324 | |
| 7325 | trig->tcp = cfg; |
| 7326 | |
| 7327 | return 0; |
| 7328 | } |
| 7329 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7330 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7331 | { |
| 7332 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7333 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7334 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7335 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7336 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 7337 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7338 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7339 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7340 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7341 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7342 | return -EOPNOTSUPP; |
| 7343 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7344 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7345 | cfg80211_rdev_free_wowlan(rdev); |
| 7346 | rdev->wowlan = NULL; |
| 7347 | goto set_wakeup; |
| 7348 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7349 | |
| 7350 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7351 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7352 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7353 | nl80211_wowlan_policy); |
| 7354 | if (err) |
| 7355 | return err; |
| 7356 | |
| 7357 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7358 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7359 | return -EINVAL; |
| 7360 | new_triggers.any = true; |
| 7361 | } |
| 7362 | |
| 7363 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7364 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7365 | return -EINVAL; |
| 7366 | new_triggers.disconnect = true; |
| 7367 | } |
| 7368 | |
| 7369 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7370 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7371 | return -EINVAL; |
| 7372 | new_triggers.magic_pkt = true; |
| 7373 | } |
| 7374 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7375 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7376 | return -EINVAL; |
| 7377 | |
| 7378 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7379 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7380 | return -EINVAL; |
| 7381 | new_triggers.gtk_rekey_failure = true; |
| 7382 | } |
| 7383 | |
| 7384 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7385 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7386 | return -EINVAL; |
| 7387 | new_triggers.eap_identity_req = true; |
| 7388 | } |
| 7389 | |
| 7390 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7391 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7392 | return -EINVAL; |
| 7393 | new_triggers.four_way_handshake = true; |
| 7394 | } |
| 7395 | |
| 7396 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7397 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7398 | return -EINVAL; |
| 7399 | new_triggers.rfkill_release = true; |
| 7400 | } |
| 7401 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7402 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7403 | struct nlattr *pat; |
| 7404 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7405 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7406 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7407 | |
| 7408 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7409 | rem) |
| 7410 | n_patterns++; |
| 7411 | if (n_patterns > wowlan->n_patterns) |
| 7412 | return -EINVAL; |
| 7413 | |
| 7414 | new_triggers.patterns = kcalloc(n_patterns, |
| 7415 | sizeof(new_triggers.patterns[0]), |
| 7416 | GFP_KERNEL); |
| 7417 | if (!new_triggers.patterns) |
| 7418 | return -ENOMEM; |
| 7419 | |
| 7420 | new_triggers.n_patterns = n_patterns; |
| 7421 | i = 0; |
| 7422 | |
| 7423 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7424 | rem) { |
| 7425 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7426 | nla_data(pat), nla_len(pat), NULL); |
| 7427 | err = -EINVAL; |
| 7428 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7429 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7430 | goto error; |
| 7431 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7432 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7433 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7434 | mask_len) |
| 7435 | goto error; |
| 7436 | if (pat_len > wowlan->pattern_max_len || |
| 7437 | pat_len < wowlan->pattern_min_len) |
| 7438 | goto error; |
| 7439 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7440 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7441 | pkt_offset = 0; |
| 7442 | else |
| 7443 | pkt_offset = nla_get_u32( |
| 7444 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7445 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7446 | goto error; |
| 7447 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7448 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7449 | new_triggers.patterns[i].mask = |
| 7450 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7451 | if (!new_triggers.patterns[i].mask) { |
| 7452 | err = -ENOMEM; |
| 7453 | goto error; |
| 7454 | } |
| 7455 | new_triggers.patterns[i].pattern = |
| 7456 | new_triggers.patterns[i].mask + mask_len; |
| 7457 | memcpy(new_triggers.patterns[i].mask, |
| 7458 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7459 | mask_len); |
| 7460 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7461 | memcpy(new_triggers.patterns[i].pattern, |
| 7462 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7463 | pat_len); |
| 7464 | i++; |
| 7465 | } |
| 7466 | } |
| 7467 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7468 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 7469 | err = nl80211_parse_wowlan_tcp( |
| 7470 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 7471 | &new_triggers); |
| 7472 | if (err) |
| 7473 | goto error; |
| 7474 | } |
| 7475 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7476 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7477 | if (!ntrig) { |
| 7478 | err = -ENOMEM; |
| 7479 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7480 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7481 | cfg80211_rdev_free_wowlan(rdev); |
| 7482 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7483 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7484 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7485 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7486 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7487 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7488 | return 0; |
| 7489 | error: |
| 7490 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7491 | kfree(new_triggers.patterns[i].mask); |
| 7492 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7493 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 7494 | sock_release(new_triggers.tcp->sock); |
| 7495 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7496 | return err; |
| 7497 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7498 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7499 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7500 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 7501 | { |
| 7502 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7503 | struct net_device *dev = info->user_ptr[1]; |
| 7504 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7505 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 7506 | struct cfg80211_gtk_rekey_data rekey_data; |
| 7507 | int err; |
| 7508 | |
| 7509 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 7510 | return -EINVAL; |
| 7511 | |
| 7512 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 7513 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7514 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7515 | nl80211_rekey_policy); |
| 7516 | if (err) |
| 7517 | return err; |
| 7518 | |
| 7519 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 7520 | return -ERANGE; |
| 7521 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 7522 | return -ERANGE; |
| 7523 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 7524 | return -ERANGE; |
| 7525 | |
| 7526 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 7527 | NL80211_KEK_LEN); |
| 7528 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 7529 | NL80211_KCK_LEN); |
| 7530 | memcpy(rekey_data.replay_ctr, |
| 7531 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 7532 | NL80211_REPLAY_CTR_LEN); |
| 7533 | |
| 7534 | wdev_lock(wdev); |
| 7535 | if (!wdev->current_bss) { |
| 7536 | err = -ENOTCONN; |
| 7537 | goto out; |
| 7538 | } |
| 7539 | |
| 7540 | if (!rdev->ops->set_rekey_data) { |
| 7541 | err = -EOPNOTSUPP; |
| 7542 | goto out; |
| 7543 | } |
| 7544 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7545 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7546 | out: |
| 7547 | wdev_unlock(wdev); |
| 7548 | return err; |
| 7549 | } |
| 7550 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7551 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 7552 | struct genl_info *info) |
| 7553 | { |
| 7554 | struct net_device *dev = info->user_ptr[1]; |
| 7555 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7556 | |
| 7557 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7558 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7559 | return -EINVAL; |
| 7560 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7561 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7562 | return -EBUSY; |
| 7563 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7564 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7565 | return 0; |
| 7566 | } |
| 7567 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7568 | static int nl80211_probe_client(struct sk_buff *skb, |
| 7569 | struct genl_info *info) |
| 7570 | { |
| 7571 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7572 | struct net_device *dev = info->user_ptr[1]; |
| 7573 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7574 | struct sk_buff *msg; |
| 7575 | void *hdr; |
| 7576 | const u8 *addr; |
| 7577 | u64 cookie; |
| 7578 | int err; |
| 7579 | |
| 7580 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7581 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7582 | return -EOPNOTSUPP; |
| 7583 | |
| 7584 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7585 | return -EINVAL; |
| 7586 | |
| 7587 | if (!rdev->ops->probe_client) |
| 7588 | return -EOPNOTSUPP; |
| 7589 | |
| 7590 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7591 | if (!msg) |
| 7592 | return -ENOMEM; |
| 7593 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7594 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7595 | NL80211_CMD_PROBE_CLIENT); |
| 7596 | |
| 7597 | if (IS_ERR(hdr)) { |
| 7598 | err = PTR_ERR(hdr); |
| 7599 | goto free_msg; |
| 7600 | } |
| 7601 | |
| 7602 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7603 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7604 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7605 | if (err) |
| 7606 | goto free_msg; |
| 7607 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7608 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7609 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7610 | |
| 7611 | genlmsg_end(msg, hdr); |
| 7612 | |
| 7613 | return genlmsg_reply(msg, info); |
| 7614 | |
| 7615 | nla_put_failure: |
| 7616 | err = -ENOBUFS; |
| 7617 | free_msg: |
| 7618 | nlmsg_free(msg); |
| 7619 | return err; |
| 7620 | } |
| 7621 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7622 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 7623 | { |
| 7624 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7625 | struct cfg80211_beacon_registration *reg, *nreg; |
| 7626 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7627 | |
| 7628 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 7629 | return -EOPNOTSUPP; |
| 7630 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7631 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 7632 | if (!nreg) |
| 7633 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7634 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7635 | /* First, check if already registered. */ |
| 7636 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 7637 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 7638 | if (reg->nlportid == info->snd_portid) { |
| 7639 | rv = -EALREADY; |
| 7640 | goto out_err; |
| 7641 | } |
| 7642 | } |
| 7643 | /* Add it to the list */ |
| 7644 | nreg->nlportid = info->snd_portid; |
| 7645 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 7646 | |
| 7647 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7648 | |
| 7649 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7650 | out_err: |
| 7651 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 7652 | kfree(nreg); |
| 7653 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7654 | } |
| 7655 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7656 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7657 | { |
| 7658 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7659 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7660 | int err; |
| 7661 | |
| 7662 | if (!rdev->ops->start_p2p_device) |
| 7663 | return -EOPNOTSUPP; |
| 7664 | |
| 7665 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7666 | return -EOPNOTSUPP; |
| 7667 | |
| 7668 | if (wdev->p2p_started) |
| 7669 | return 0; |
| 7670 | |
| 7671 | mutex_lock(&rdev->devlist_mtx); |
| 7672 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 7673 | mutex_unlock(&rdev->devlist_mtx); |
| 7674 | if (err) |
| 7675 | return err; |
| 7676 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7677 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7678 | if (err) |
| 7679 | return err; |
| 7680 | |
| 7681 | wdev->p2p_started = true; |
| 7682 | mutex_lock(&rdev->devlist_mtx); |
| 7683 | rdev->opencount++; |
| 7684 | mutex_unlock(&rdev->devlist_mtx); |
| 7685 | |
| 7686 | return 0; |
| 7687 | } |
| 7688 | |
| 7689 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7690 | { |
| 7691 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7692 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7693 | |
| 7694 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7695 | return -EOPNOTSUPP; |
| 7696 | |
| 7697 | if (!rdev->ops->stop_p2p_device) |
| 7698 | return -EOPNOTSUPP; |
| 7699 | |
| 7700 | if (!wdev->p2p_started) |
| 7701 | return 0; |
| 7702 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7703 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7704 | wdev->p2p_started = false; |
| 7705 | |
| 7706 | mutex_lock(&rdev->devlist_mtx); |
| 7707 | rdev->opencount--; |
| 7708 | mutex_unlock(&rdev->devlist_mtx); |
| 7709 | |
| 7710 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 7711 | rdev->scan_req->aborted = true; |
| 7712 | ___cfg80211_scan_done(rdev, true); |
| 7713 | } |
| 7714 | |
| 7715 | return 0; |
| 7716 | } |
| 7717 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7718 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 7719 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 7720 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7721 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 7722 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 7723 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7724 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7725 | /* 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] | 7726 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 7727 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7728 | |
| 7729 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7730 | struct genl_info *info) |
| 7731 | { |
| 7732 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7733 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7734 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7735 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 7736 | |
| 7737 | if (rtnl) |
| 7738 | rtnl_lock(); |
| 7739 | |
| 7740 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 7741 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7742 | if (IS_ERR(rdev)) { |
| 7743 | if (rtnl) |
| 7744 | rtnl_unlock(); |
| 7745 | return PTR_ERR(rdev); |
| 7746 | } |
| 7747 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7748 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7749 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7750 | mutex_lock(&cfg80211_mutex); |
| 7751 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7752 | info->attrs); |
| 7753 | if (IS_ERR(wdev)) { |
| 7754 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7755 | if (rtnl) |
| 7756 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7757 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7758 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7759 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7760 | dev = wdev->netdev; |
| 7761 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7762 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7763 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7764 | if (!dev) { |
| 7765 | mutex_unlock(&cfg80211_mutex); |
| 7766 | if (rtnl) |
| 7767 | rtnl_unlock(); |
| 7768 | return -EINVAL; |
| 7769 | } |
| 7770 | |
| 7771 | info->user_ptr[1] = dev; |
| 7772 | } else { |
| 7773 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7774 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7775 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7776 | if (dev) { |
| 7777 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7778 | !netif_running(dev)) { |
| 7779 | mutex_unlock(&cfg80211_mutex); |
| 7780 | if (rtnl) |
| 7781 | rtnl_unlock(); |
| 7782 | return -ENETDOWN; |
| 7783 | } |
| 7784 | |
| 7785 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7786 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7787 | if (!wdev->p2p_started) { |
| 7788 | mutex_unlock(&cfg80211_mutex); |
| 7789 | if (rtnl) |
| 7790 | rtnl_unlock(); |
| 7791 | return -ENETDOWN; |
| 7792 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7793 | } |
| 7794 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7795 | cfg80211_lock_rdev(rdev); |
| 7796 | |
| 7797 | mutex_unlock(&cfg80211_mutex); |
| 7798 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7799 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7800 | } |
| 7801 | |
| 7802 | return 0; |
| 7803 | } |
| 7804 | |
| 7805 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7806 | struct genl_info *info) |
| 7807 | { |
| 7808 | if (info->user_ptr[0]) |
| 7809 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7810 | if (info->user_ptr[1]) { |
| 7811 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7812 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7813 | |
| 7814 | if (wdev->netdev) |
| 7815 | dev_put(wdev->netdev); |
| 7816 | } else { |
| 7817 | dev_put(info->user_ptr[1]); |
| 7818 | } |
| 7819 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7820 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7821 | rtnl_unlock(); |
| 7822 | } |
| 7823 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7824 | static struct genl_ops nl80211_ops[] = { |
| 7825 | { |
| 7826 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7827 | .doit = nl80211_get_wiphy, |
| 7828 | .dumpit = nl80211_dump_wiphy, |
| 7829 | .policy = nl80211_policy, |
| 7830 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7831 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7832 | }, |
| 7833 | { |
| 7834 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7835 | .doit = nl80211_set_wiphy, |
| 7836 | .policy = nl80211_policy, |
| 7837 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7838 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7839 | }, |
| 7840 | { |
| 7841 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7842 | .doit = nl80211_get_interface, |
| 7843 | .dumpit = nl80211_dump_interface, |
| 7844 | .policy = nl80211_policy, |
| 7845 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7846 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7847 | }, |
| 7848 | { |
| 7849 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7850 | .doit = nl80211_set_interface, |
| 7851 | .policy = nl80211_policy, |
| 7852 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7853 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7854 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7855 | }, |
| 7856 | { |
| 7857 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7858 | .doit = nl80211_new_interface, |
| 7859 | .policy = nl80211_policy, |
| 7860 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7861 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7862 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7863 | }, |
| 7864 | { |
| 7865 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7866 | .doit = nl80211_del_interface, |
| 7867 | .policy = nl80211_policy, |
| 7868 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7869 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7870 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7871 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7872 | { |
| 7873 | .cmd = NL80211_CMD_GET_KEY, |
| 7874 | .doit = nl80211_get_key, |
| 7875 | .policy = nl80211_policy, |
| 7876 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7877 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7878 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7879 | }, |
| 7880 | { |
| 7881 | .cmd = NL80211_CMD_SET_KEY, |
| 7882 | .doit = nl80211_set_key, |
| 7883 | .policy = nl80211_policy, |
| 7884 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7885 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7886 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7887 | }, |
| 7888 | { |
| 7889 | .cmd = NL80211_CMD_NEW_KEY, |
| 7890 | .doit = nl80211_new_key, |
| 7891 | .policy = nl80211_policy, |
| 7892 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7893 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7894 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7895 | }, |
| 7896 | { |
| 7897 | .cmd = NL80211_CMD_DEL_KEY, |
| 7898 | .doit = nl80211_del_key, |
| 7899 | .policy = nl80211_policy, |
| 7900 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7901 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7902 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7903 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7904 | { |
| 7905 | .cmd = NL80211_CMD_SET_BEACON, |
| 7906 | .policy = nl80211_policy, |
| 7907 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7908 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7909 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7910 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7911 | }, |
| 7912 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7913 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7914 | .policy = nl80211_policy, |
| 7915 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7916 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7917 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7918 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7919 | }, |
| 7920 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7921 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7922 | .policy = nl80211_policy, |
| 7923 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7924 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7925 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7926 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7927 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7928 | { |
| 7929 | .cmd = NL80211_CMD_GET_STATION, |
| 7930 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7931 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7932 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7933 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7934 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7935 | }, |
| 7936 | { |
| 7937 | .cmd = NL80211_CMD_SET_STATION, |
| 7938 | .doit = nl80211_set_station, |
| 7939 | .policy = nl80211_policy, |
| 7940 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7941 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7942 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7943 | }, |
| 7944 | { |
| 7945 | .cmd = NL80211_CMD_NEW_STATION, |
| 7946 | .doit = nl80211_new_station, |
| 7947 | .policy = nl80211_policy, |
| 7948 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7949 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7950 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7951 | }, |
| 7952 | { |
| 7953 | .cmd = NL80211_CMD_DEL_STATION, |
| 7954 | .doit = nl80211_del_station, |
| 7955 | .policy = nl80211_policy, |
| 7956 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7957 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7958 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7959 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7960 | { |
| 7961 | .cmd = NL80211_CMD_GET_MPATH, |
| 7962 | .doit = nl80211_get_mpath, |
| 7963 | .dumpit = nl80211_dump_mpath, |
| 7964 | .policy = nl80211_policy, |
| 7965 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7966 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7967 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7968 | }, |
| 7969 | { |
| 7970 | .cmd = NL80211_CMD_SET_MPATH, |
| 7971 | .doit = nl80211_set_mpath, |
| 7972 | .policy = nl80211_policy, |
| 7973 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7974 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7975 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7976 | }, |
| 7977 | { |
| 7978 | .cmd = NL80211_CMD_NEW_MPATH, |
| 7979 | .doit = nl80211_new_mpath, |
| 7980 | .policy = nl80211_policy, |
| 7981 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7982 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7983 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7984 | }, |
| 7985 | { |
| 7986 | .cmd = NL80211_CMD_DEL_MPATH, |
| 7987 | .doit = nl80211_del_mpath, |
| 7988 | .policy = nl80211_policy, |
| 7989 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7990 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7991 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7992 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7993 | { |
| 7994 | .cmd = NL80211_CMD_SET_BSS, |
| 7995 | .doit = nl80211_set_bss, |
| 7996 | .policy = nl80211_policy, |
| 7997 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7998 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7999 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8000 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8001 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8002 | .cmd = NL80211_CMD_GET_REG, |
| 8003 | .doit = nl80211_get_reg, |
| 8004 | .policy = nl80211_policy, |
| 8005 | /* can be retrieved by unprivileged users */ |
| 8006 | }, |
| 8007 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8008 | .cmd = NL80211_CMD_SET_REG, |
| 8009 | .doit = nl80211_set_reg, |
| 8010 | .policy = nl80211_policy, |
| 8011 | .flags = GENL_ADMIN_PERM, |
| 8012 | }, |
| 8013 | { |
| 8014 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8015 | .doit = nl80211_req_set_reg, |
| 8016 | .policy = nl80211_policy, |
| 8017 | .flags = GENL_ADMIN_PERM, |
| 8018 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8019 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8020 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8021 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8022 | .policy = nl80211_policy, |
| 8023 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8024 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8025 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8026 | }, |
| 8027 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8028 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8029 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8030 | .policy = nl80211_policy, |
| 8031 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8032 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8033 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8034 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8035 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8036 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8037 | .doit = nl80211_trigger_scan, |
| 8038 | .policy = nl80211_policy, |
| 8039 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8040 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8041 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8042 | }, |
| 8043 | { |
| 8044 | .cmd = NL80211_CMD_GET_SCAN, |
| 8045 | .policy = nl80211_policy, |
| 8046 | .dumpit = nl80211_dump_scan, |
| 8047 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8048 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8049 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8050 | .doit = nl80211_start_sched_scan, |
| 8051 | .policy = nl80211_policy, |
| 8052 | .flags = GENL_ADMIN_PERM, |
| 8053 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8054 | NL80211_FLAG_NEED_RTNL, |
| 8055 | }, |
| 8056 | { |
| 8057 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8058 | .doit = nl80211_stop_sched_scan, |
| 8059 | .policy = nl80211_policy, |
| 8060 | .flags = GENL_ADMIN_PERM, |
| 8061 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8062 | NL80211_FLAG_NEED_RTNL, |
| 8063 | }, |
| 8064 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8065 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8066 | .doit = nl80211_authenticate, |
| 8067 | .policy = nl80211_policy, |
| 8068 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8069 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8070 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8071 | }, |
| 8072 | { |
| 8073 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8074 | .doit = nl80211_associate, |
| 8075 | .policy = nl80211_policy, |
| 8076 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8077 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8078 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8079 | }, |
| 8080 | { |
| 8081 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8082 | .doit = nl80211_deauthenticate, |
| 8083 | .policy = nl80211_policy, |
| 8084 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8085 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8086 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8087 | }, |
| 8088 | { |
| 8089 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8090 | .doit = nl80211_disassociate, |
| 8091 | .policy = nl80211_policy, |
| 8092 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8093 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8094 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8095 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8096 | { |
| 8097 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8098 | .doit = nl80211_join_ibss, |
| 8099 | .policy = nl80211_policy, |
| 8100 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8101 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8102 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8103 | }, |
| 8104 | { |
| 8105 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8106 | .doit = nl80211_leave_ibss, |
| 8107 | .policy = nl80211_policy, |
| 8108 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8109 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8110 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8111 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8112 | #ifdef CONFIG_NL80211_TESTMODE |
| 8113 | { |
| 8114 | .cmd = NL80211_CMD_TESTMODE, |
| 8115 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8116 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8117 | .policy = nl80211_policy, |
| 8118 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8119 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8120 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8121 | }, |
| 8122 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8123 | { |
| 8124 | .cmd = NL80211_CMD_CONNECT, |
| 8125 | .doit = nl80211_connect, |
| 8126 | .policy = nl80211_policy, |
| 8127 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8128 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8129 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8130 | }, |
| 8131 | { |
| 8132 | .cmd = NL80211_CMD_DISCONNECT, |
| 8133 | .doit = nl80211_disconnect, |
| 8134 | .policy = nl80211_policy, |
| 8135 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8136 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8137 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8138 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8139 | { |
| 8140 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8141 | .doit = nl80211_wiphy_netns, |
| 8142 | .policy = nl80211_policy, |
| 8143 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8144 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8145 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8146 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8147 | { |
| 8148 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8149 | .policy = nl80211_policy, |
| 8150 | .dumpit = nl80211_dump_survey, |
| 8151 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8152 | { |
| 8153 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8154 | .doit = nl80211_setdel_pmksa, |
| 8155 | .policy = nl80211_policy, |
| 8156 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8157 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8158 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8159 | }, |
| 8160 | { |
| 8161 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8162 | .doit = nl80211_setdel_pmksa, |
| 8163 | .policy = nl80211_policy, |
| 8164 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8165 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8166 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8167 | }, |
| 8168 | { |
| 8169 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8170 | .doit = nl80211_flush_pmksa, |
| 8171 | .policy = nl80211_policy, |
| 8172 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8173 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8174 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8175 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8176 | { |
| 8177 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8178 | .doit = nl80211_remain_on_channel, |
| 8179 | .policy = nl80211_policy, |
| 8180 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8181 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8182 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8183 | }, |
| 8184 | { |
| 8185 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8186 | .doit = nl80211_cancel_remain_on_channel, |
| 8187 | .policy = nl80211_policy, |
| 8188 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8189 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8190 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8191 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8192 | { |
| 8193 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8194 | .doit = nl80211_set_tx_bitrate_mask, |
| 8195 | .policy = nl80211_policy, |
| 8196 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8197 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8198 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8199 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8200 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8201 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8202 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8203 | .policy = nl80211_policy, |
| 8204 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8205 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8206 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8207 | }, |
| 8208 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8209 | .cmd = NL80211_CMD_FRAME, |
| 8210 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8211 | .policy = nl80211_policy, |
| 8212 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8213 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8214 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8215 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8216 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8217 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8218 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8219 | .policy = nl80211_policy, |
| 8220 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8221 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8222 | NL80211_FLAG_NEED_RTNL, |
| 8223 | }, |
| 8224 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8225 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8226 | .doit = nl80211_set_power_save, |
| 8227 | .policy = nl80211_policy, |
| 8228 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8229 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8230 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8231 | }, |
| 8232 | { |
| 8233 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8234 | .doit = nl80211_get_power_save, |
| 8235 | .policy = nl80211_policy, |
| 8236 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8237 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8238 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8239 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8240 | { |
| 8241 | .cmd = NL80211_CMD_SET_CQM, |
| 8242 | .doit = nl80211_set_cqm, |
| 8243 | .policy = nl80211_policy, |
| 8244 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8245 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8246 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8247 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8248 | { |
| 8249 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8250 | .doit = nl80211_set_channel, |
| 8251 | .policy = nl80211_policy, |
| 8252 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8253 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8254 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8255 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8256 | { |
| 8257 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8258 | .doit = nl80211_set_wds_peer, |
| 8259 | .policy = nl80211_policy, |
| 8260 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8261 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8262 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8263 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8264 | { |
| 8265 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8266 | .doit = nl80211_join_mesh, |
| 8267 | .policy = nl80211_policy, |
| 8268 | .flags = GENL_ADMIN_PERM, |
| 8269 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8270 | NL80211_FLAG_NEED_RTNL, |
| 8271 | }, |
| 8272 | { |
| 8273 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8274 | .doit = nl80211_leave_mesh, |
| 8275 | .policy = nl80211_policy, |
| 8276 | .flags = GENL_ADMIN_PERM, |
| 8277 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8278 | NL80211_FLAG_NEED_RTNL, |
| 8279 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8280 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8281 | { |
| 8282 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8283 | .doit = nl80211_get_wowlan, |
| 8284 | .policy = nl80211_policy, |
| 8285 | /* can be retrieved by unprivileged users */ |
| 8286 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8287 | NL80211_FLAG_NEED_RTNL, |
| 8288 | }, |
| 8289 | { |
| 8290 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8291 | .doit = nl80211_set_wowlan, |
| 8292 | .policy = nl80211_policy, |
| 8293 | .flags = GENL_ADMIN_PERM, |
| 8294 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8295 | NL80211_FLAG_NEED_RTNL, |
| 8296 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8297 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8298 | { |
| 8299 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8300 | .doit = nl80211_set_rekey_data, |
| 8301 | .policy = nl80211_policy, |
| 8302 | .flags = GENL_ADMIN_PERM, |
| 8303 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8304 | NL80211_FLAG_NEED_RTNL, |
| 8305 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8306 | { |
| 8307 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8308 | .doit = nl80211_tdls_mgmt, |
| 8309 | .policy = nl80211_policy, |
| 8310 | .flags = GENL_ADMIN_PERM, |
| 8311 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8312 | NL80211_FLAG_NEED_RTNL, |
| 8313 | }, |
| 8314 | { |
| 8315 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8316 | .doit = nl80211_tdls_oper, |
| 8317 | .policy = nl80211_policy, |
| 8318 | .flags = GENL_ADMIN_PERM, |
| 8319 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8320 | NL80211_FLAG_NEED_RTNL, |
| 8321 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8322 | { |
| 8323 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8324 | .doit = nl80211_register_unexpected_frame, |
| 8325 | .policy = nl80211_policy, |
| 8326 | .flags = GENL_ADMIN_PERM, |
| 8327 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8328 | NL80211_FLAG_NEED_RTNL, |
| 8329 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8330 | { |
| 8331 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8332 | .doit = nl80211_probe_client, |
| 8333 | .policy = nl80211_policy, |
| 8334 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8335 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8336 | NL80211_FLAG_NEED_RTNL, |
| 8337 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8338 | { |
| 8339 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8340 | .doit = nl80211_register_beacons, |
| 8341 | .policy = nl80211_policy, |
| 8342 | .flags = GENL_ADMIN_PERM, |
| 8343 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8344 | NL80211_FLAG_NEED_RTNL, |
| 8345 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8346 | { |
| 8347 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8348 | .doit = nl80211_set_noack_map, |
| 8349 | .policy = nl80211_policy, |
| 8350 | .flags = GENL_ADMIN_PERM, |
| 8351 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8352 | NL80211_FLAG_NEED_RTNL, |
| 8353 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8354 | { |
| 8355 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8356 | .doit = nl80211_start_p2p_device, |
| 8357 | .policy = nl80211_policy, |
| 8358 | .flags = GENL_ADMIN_PERM, |
| 8359 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8360 | NL80211_FLAG_NEED_RTNL, |
| 8361 | }, |
| 8362 | { |
| 8363 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8364 | .doit = nl80211_stop_p2p_device, |
| 8365 | .policy = nl80211_policy, |
| 8366 | .flags = GENL_ADMIN_PERM, |
| 8367 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8368 | NL80211_FLAG_NEED_RTNL, |
| 8369 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8370 | { |
| 8371 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8372 | .doit = nl80211_set_mcast_rate, |
| 8373 | .policy = nl80211_policy, |
| 8374 | .flags = GENL_ADMIN_PERM, |
| 8375 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8376 | NL80211_FLAG_NEED_RTNL, |
| 8377 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8378 | { |
| 8379 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8380 | .doit = nl80211_set_mac_acl, |
| 8381 | .policy = nl80211_policy, |
| 8382 | .flags = GENL_ADMIN_PERM, |
| 8383 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8384 | NL80211_FLAG_NEED_RTNL, |
| 8385 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8386 | { |
| 8387 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 8388 | .doit = nl80211_start_radar_detection, |
| 8389 | .policy = nl80211_policy, |
| 8390 | .flags = GENL_ADMIN_PERM, |
| 8391 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8392 | NL80211_FLAG_NEED_RTNL, |
| 8393 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8394 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8395 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8396 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 8397 | .name = "mlme", |
| 8398 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8399 | |
| 8400 | /* multicast groups */ |
| 8401 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 8402 | .name = "config", |
| 8403 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8404 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 8405 | .name = "scan", |
| 8406 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8407 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 8408 | .name = "regulatory", |
| 8409 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8410 | |
| 8411 | /* notification functions */ |
| 8412 | |
| 8413 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 8414 | { |
| 8415 | struct sk_buff *msg; |
| 8416 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8417 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8418 | if (!msg) |
| 8419 | return; |
| 8420 | |
| 8421 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 8422 | nlmsg_free(msg); |
| 8423 | return; |
| 8424 | } |
| 8425 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8426 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8427 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8428 | } |
| 8429 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8430 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 8431 | struct cfg80211_registered_device *rdev) |
| 8432 | { |
| 8433 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 8434 | struct nlattr *nest; |
| 8435 | int i; |
| 8436 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8437 | ASSERT_RDEV_LOCK(rdev); |
| 8438 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8439 | if (WARN_ON(!req)) |
| 8440 | return 0; |
| 8441 | |
| 8442 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 8443 | if (!nest) |
| 8444 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8445 | for (i = 0; i < req->n_ssids; i++) { |
| 8446 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 8447 | goto nla_put_failure; |
| 8448 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8449 | nla_nest_end(msg, nest); |
| 8450 | |
| 8451 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 8452 | if (!nest) |
| 8453 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8454 | for (i = 0; i < req->n_channels; i++) { |
| 8455 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 8456 | goto nla_put_failure; |
| 8457 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8458 | nla_nest_end(msg, nest); |
| 8459 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8460 | if (req->ie && |
| 8461 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 8462 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8463 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8464 | if (req->flags) |
| 8465 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 8466 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8467 | return 0; |
| 8468 | nla_put_failure: |
| 8469 | return -ENOBUFS; |
| 8470 | } |
| 8471 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8472 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 8473 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8474 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8475 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8476 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8477 | { |
| 8478 | void *hdr; |
| 8479 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8480 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8481 | if (!hdr) |
| 8482 | return -1; |
| 8483 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8484 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8485 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8486 | wdev->netdev->ifindex)) || |
| 8487 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8488 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8489 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8490 | /* ignore errors and send incomplete event anyway */ |
| 8491 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8492 | |
| 8493 | return genlmsg_end(msg, hdr); |
| 8494 | |
| 8495 | nla_put_failure: |
| 8496 | genlmsg_cancel(msg, hdr); |
| 8497 | return -EMSGSIZE; |
| 8498 | } |
| 8499 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8500 | static int |
| 8501 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 8502 | struct cfg80211_registered_device *rdev, |
| 8503 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8504 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8505 | { |
| 8506 | void *hdr; |
| 8507 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8508 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8509 | if (!hdr) |
| 8510 | return -1; |
| 8511 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8512 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8513 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8514 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8515 | |
| 8516 | return genlmsg_end(msg, hdr); |
| 8517 | |
| 8518 | nla_put_failure: |
| 8519 | genlmsg_cancel(msg, hdr); |
| 8520 | return -EMSGSIZE; |
| 8521 | } |
| 8522 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8523 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8524 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8525 | { |
| 8526 | struct sk_buff *msg; |
| 8527 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8528 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8529 | if (!msg) |
| 8530 | return; |
| 8531 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8532 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8533 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 8534 | nlmsg_free(msg); |
| 8535 | return; |
| 8536 | } |
| 8537 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8538 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8539 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8540 | } |
| 8541 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8542 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8543 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8544 | { |
| 8545 | struct sk_buff *msg; |
| 8546 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8547 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8548 | if (!msg) |
| 8549 | return; |
| 8550 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8551 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8552 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8553 | nlmsg_free(msg); |
| 8554 | return; |
| 8555 | } |
| 8556 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8557 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8558 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8559 | } |
| 8560 | |
| 8561 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8562 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8563 | { |
| 8564 | struct sk_buff *msg; |
| 8565 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8566 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8567 | if (!msg) |
| 8568 | return; |
| 8569 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8570 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8571 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8572 | nlmsg_free(msg); |
| 8573 | return; |
| 8574 | } |
| 8575 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8576 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8577 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8578 | } |
| 8579 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8580 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 8581 | struct net_device *netdev) |
| 8582 | { |
| 8583 | struct sk_buff *msg; |
| 8584 | |
| 8585 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8586 | if (!msg) |
| 8587 | return; |
| 8588 | |
| 8589 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 8590 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 8591 | nlmsg_free(msg); |
| 8592 | return; |
| 8593 | } |
| 8594 | |
| 8595 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8596 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8597 | } |
| 8598 | |
| 8599 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 8600 | struct net_device *netdev, u32 cmd) |
| 8601 | { |
| 8602 | struct sk_buff *msg; |
| 8603 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8604 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8605 | if (!msg) |
| 8606 | return; |
| 8607 | |
| 8608 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 8609 | nlmsg_free(msg); |
| 8610 | return; |
| 8611 | } |
| 8612 | |
| 8613 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8614 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8615 | } |
| 8616 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8617 | /* |
| 8618 | * This can happen on global regulatory changes or device specific settings |
| 8619 | * based on custom world regulatory domains. |
| 8620 | */ |
| 8621 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 8622 | { |
| 8623 | struct sk_buff *msg; |
| 8624 | void *hdr; |
| 8625 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8626 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8627 | if (!msg) |
| 8628 | return; |
| 8629 | |
| 8630 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 8631 | if (!hdr) { |
| 8632 | nlmsg_free(msg); |
| 8633 | return; |
| 8634 | } |
| 8635 | |
| 8636 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8637 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 8638 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8639 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8640 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 8641 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8642 | NL80211_REGDOM_TYPE_WORLD)) |
| 8643 | goto nla_put_failure; |
| 8644 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 8645 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8646 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 8647 | goto nla_put_failure; |
| 8648 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 8649 | request->intersect) { |
| 8650 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8651 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 8652 | goto nla_put_failure; |
| 8653 | } else { |
| 8654 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8655 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 8656 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 8657 | request->alpha2)) |
| 8658 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8659 | } |
| 8660 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 8661 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8662 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 8663 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8664 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8665 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8666 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8667 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8668 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8669 | GFP_ATOMIC); |
| 8670 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8671 | |
| 8672 | return; |
| 8673 | |
| 8674 | nla_put_failure: |
| 8675 | genlmsg_cancel(msg, hdr); |
| 8676 | nlmsg_free(msg); |
| 8677 | } |
| 8678 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8679 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 8680 | struct net_device *netdev, |
| 8681 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8682 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8683 | { |
| 8684 | struct sk_buff *msg; |
| 8685 | void *hdr; |
| 8686 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8687 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8688 | if (!msg) |
| 8689 | return; |
| 8690 | |
| 8691 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8692 | if (!hdr) { |
| 8693 | nlmsg_free(msg); |
| 8694 | return; |
| 8695 | } |
| 8696 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8697 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8698 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8699 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8700 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8701 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8702 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8703 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8704 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8705 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8706 | return; |
| 8707 | |
| 8708 | nla_put_failure: |
| 8709 | genlmsg_cancel(msg, hdr); |
| 8710 | nlmsg_free(msg); |
| 8711 | } |
| 8712 | |
| 8713 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8714 | struct net_device *netdev, const u8 *buf, |
| 8715 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8716 | { |
| 8717 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8718 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8719 | } |
| 8720 | |
| 8721 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 8722 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8723 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8724 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8725 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8726 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8727 | } |
| 8728 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8729 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8730 | struct net_device *netdev, const u8 *buf, |
| 8731 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8732 | { |
| 8733 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8734 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8735 | } |
| 8736 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8737 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 8738 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8739 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8740 | { |
| 8741 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8742 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8743 | } |
| 8744 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 8745 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 8746 | struct net_device *netdev, const u8 *buf, |
| 8747 | size_t len, gfp_t gfp) |
| 8748 | { |
| 8749 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8750 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 8751 | } |
| 8752 | |
| 8753 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 8754 | struct net_device *netdev, const u8 *buf, |
| 8755 | size_t len, gfp_t gfp) |
| 8756 | { |
| 8757 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8758 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 8759 | } |
| 8760 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 8761 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 8762 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8763 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8764 | { |
| 8765 | struct sk_buff *msg; |
| 8766 | void *hdr; |
| 8767 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8768 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8769 | if (!msg) |
| 8770 | return; |
| 8771 | |
| 8772 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8773 | if (!hdr) { |
| 8774 | nlmsg_free(msg); |
| 8775 | return; |
| 8776 | } |
| 8777 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8778 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8779 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8780 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8781 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8782 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8783 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8784 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8785 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8786 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8787 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8788 | return; |
| 8789 | |
| 8790 | nla_put_failure: |
| 8791 | genlmsg_cancel(msg, hdr); |
| 8792 | nlmsg_free(msg); |
| 8793 | } |
| 8794 | |
| 8795 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8796 | struct net_device *netdev, const u8 *addr, |
| 8797 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8798 | { |
| 8799 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8800 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8801 | } |
| 8802 | |
| 8803 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8804 | struct net_device *netdev, const u8 *addr, |
| 8805 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8806 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8807 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8808 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8809 | } |
| 8810 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8811 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8812 | struct net_device *netdev, const u8 *bssid, |
| 8813 | const u8 *req_ie, size_t req_ie_len, |
| 8814 | const u8 *resp_ie, size_t resp_ie_len, |
| 8815 | u16 status, gfp_t gfp) |
| 8816 | { |
| 8817 | struct sk_buff *msg; |
| 8818 | void *hdr; |
| 8819 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8820 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8821 | if (!msg) |
| 8822 | return; |
| 8823 | |
| 8824 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8825 | if (!hdr) { |
| 8826 | nlmsg_free(msg); |
| 8827 | return; |
| 8828 | } |
| 8829 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8830 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8831 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8832 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8833 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8834 | (req_ie && |
| 8835 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8836 | (resp_ie && |
| 8837 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8838 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8839 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8840 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8841 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8842 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8843 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8844 | return; |
| 8845 | |
| 8846 | nla_put_failure: |
| 8847 | genlmsg_cancel(msg, hdr); |
| 8848 | nlmsg_free(msg); |
| 8849 | |
| 8850 | } |
| 8851 | |
| 8852 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8853 | struct net_device *netdev, const u8 *bssid, |
| 8854 | const u8 *req_ie, size_t req_ie_len, |
| 8855 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8856 | { |
| 8857 | struct sk_buff *msg; |
| 8858 | void *hdr; |
| 8859 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8860 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8861 | if (!msg) |
| 8862 | return; |
| 8863 | |
| 8864 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8865 | if (!hdr) { |
| 8866 | nlmsg_free(msg); |
| 8867 | return; |
| 8868 | } |
| 8869 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8870 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8871 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8872 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8873 | (req_ie && |
| 8874 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8875 | (resp_ie && |
| 8876 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8877 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8878 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8879 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8880 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8881 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8882 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8883 | return; |
| 8884 | |
| 8885 | nla_put_failure: |
| 8886 | genlmsg_cancel(msg, hdr); |
| 8887 | nlmsg_free(msg); |
| 8888 | |
| 8889 | } |
| 8890 | |
| 8891 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 8892 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8893 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8894 | { |
| 8895 | struct sk_buff *msg; |
| 8896 | void *hdr; |
| 8897 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8898 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8899 | if (!msg) |
| 8900 | return; |
| 8901 | |
| 8902 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 8903 | if (!hdr) { |
| 8904 | nlmsg_free(msg); |
| 8905 | return; |
| 8906 | } |
| 8907 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8908 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8909 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8910 | (from_ap && reason && |
| 8911 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 8912 | (from_ap && |
| 8913 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 8914 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 8915 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8916 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8917 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8918 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8919 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8920 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8921 | return; |
| 8922 | |
| 8923 | nla_put_failure: |
| 8924 | genlmsg_cancel(msg, hdr); |
| 8925 | nlmsg_free(msg); |
| 8926 | |
| 8927 | } |
| 8928 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8929 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 8930 | struct net_device *netdev, const u8 *bssid, |
| 8931 | gfp_t gfp) |
| 8932 | { |
| 8933 | struct sk_buff *msg; |
| 8934 | void *hdr; |
| 8935 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8936 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8937 | if (!msg) |
| 8938 | return; |
| 8939 | |
| 8940 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 8941 | if (!hdr) { |
| 8942 | nlmsg_free(msg); |
| 8943 | return; |
| 8944 | } |
| 8945 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8946 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8947 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8948 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8949 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8950 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8951 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8952 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8953 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8954 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8955 | return; |
| 8956 | |
| 8957 | nla_put_failure: |
| 8958 | genlmsg_cancel(msg, hdr); |
| 8959 | nlmsg_free(msg); |
| 8960 | } |
| 8961 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8962 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 8963 | struct net_device *netdev, |
| 8964 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 8965 | gfp_t gfp) |
| 8966 | { |
| 8967 | struct sk_buff *msg; |
| 8968 | void *hdr; |
| 8969 | |
| 8970 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8971 | if (!msg) |
| 8972 | return; |
| 8973 | |
| 8974 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 8975 | if (!hdr) { |
| 8976 | nlmsg_free(msg); |
| 8977 | return; |
| 8978 | } |
| 8979 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8980 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8981 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8982 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 8983 | (ie_len && ie && |
| 8984 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 8985 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8986 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8987 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8988 | |
| 8989 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8990 | nl80211_mlme_mcgrp.id, gfp); |
| 8991 | return; |
| 8992 | |
| 8993 | nla_put_failure: |
| 8994 | genlmsg_cancel(msg, hdr); |
| 8995 | nlmsg_free(msg); |
| 8996 | } |
| 8997 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8998 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 8999 | struct net_device *netdev, const u8 *addr, |
| 9000 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9001 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9002 | { |
| 9003 | struct sk_buff *msg; |
| 9004 | void *hdr; |
| 9005 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9006 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9007 | if (!msg) |
| 9008 | return; |
| 9009 | |
| 9010 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9011 | if (!hdr) { |
| 9012 | nlmsg_free(msg); |
| 9013 | return; |
| 9014 | } |
| 9015 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9016 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9017 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9018 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9019 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9020 | (key_id != -1 && |
| 9021 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9022 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9023 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9024 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9025 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9026 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9027 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9028 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9029 | return; |
| 9030 | |
| 9031 | nla_put_failure: |
| 9032 | genlmsg_cancel(msg, hdr); |
| 9033 | nlmsg_free(msg); |
| 9034 | } |
| 9035 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9036 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9037 | struct ieee80211_channel *channel_before, |
| 9038 | struct ieee80211_channel *channel_after) |
| 9039 | { |
| 9040 | struct sk_buff *msg; |
| 9041 | void *hdr; |
| 9042 | struct nlattr *nl_freq; |
| 9043 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9044 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9045 | if (!msg) |
| 9046 | return; |
| 9047 | |
| 9048 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9049 | if (!hdr) { |
| 9050 | nlmsg_free(msg); |
| 9051 | return; |
| 9052 | } |
| 9053 | |
| 9054 | /* |
| 9055 | * Since we are applying the beacon hint to a wiphy we know its |
| 9056 | * wiphy_idx is valid |
| 9057 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9058 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9059 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9060 | |
| 9061 | /* Before */ |
| 9062 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9063 | if (!nl_freq) |
| 9064 | goto nla_put_failure; |
| 9065 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 9066 | goto nla_put_failure; |
| 9067 | nla_nest_end(msg, nl_freq); |
| 9068 | |
| 9069 | /* After */ |
| 9070 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9071 | if (!nl_freq) |
| 9072 | goto nla_put_failure; |
| 9073 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 9074 | goto nla_put_failure; |
| 9075 | nla_nest_end(msg, nl_freq); |
| 9076 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9077 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9078 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9079 | rcu_read_lock(); |
| 9080 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9081 | GFP_ATOMIC); |
| 9082 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9083 | |
| 9084 | return; |
| 9085 | |
| 9086 | nla_put_failure: |
| 9087 | genlmsg_cancel(msg, hdr); |
| 9088 | nlmsg_free(msg); |
| 9089 | } |
| 9090 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9091 | static void nl80211_send_remain_on_chan_event( |
| 9092 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9093 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9094 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9095 | unsigned int duration, gfp_t gfp) |
| 9096 | { |
| 9097 | struct sk_buff *msg; |
| 9098 | void *hdr; |
| 9099 | |
| 9100 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9101 | if (!msg) |
| 9102 | return; |
| 9103 | |
| 9104 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9105 | if (!hdr) { |
| 9106 | nlmsg_free(msg); |
| 9107 | return; |
| 9108 | } |
| 9109 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9110 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9111 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9112 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9113 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9114 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9115 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9116 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9117 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9118 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9119 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9120 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9121 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9122 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9123 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9124 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9125 | |
| 9126 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9127 | nl80211_mlme_mcgrp.id, gfp); |
| 9128 | return; |
| 9129 | |
| 9130 | nla_put_failure: |
| 9131 | genlmsg_cancel(msg, hdr); |
| 9132 | nlmsg_free(msg); |
| 9133 | } |
| 9134 | |
| 9135 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9136 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9137 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9138 | unsigned int duration, gfp_t gfp) |
| 9139 | { |
| 9140 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9141 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9142 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9143 | } |
| 9144 | |
| 9145 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9146 | struct cfg80211_registered_device *rdev, |
| 9147 | struct wireless_dev *wdev, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9148 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9149 | { |
| 9150 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9151 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9152 | } |
| 9153 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9154 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 9155 | struct net_device *dev, const u8 *mac_addr, |
| 9156 | struct station_info *sinfo, gfp_t gfp) |
| 9157 | { |
| 9158 | struct sk_buff *msg; |
| 9159 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9160 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9161 | if (!msg) |
| 9162 | return; |
| 9163 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9164 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9165 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9166 | nlmsg_free(msg); |
| 9167 | return; |
| 9168 | } |
| 9169 | |
| 9170 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9171 | nl80211_mlme_mcgrp.id, gfp); |
| 9172 | } |
| 9173 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9174 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 9175 | struct net_device *dev, const u8 *mac_addr, |
| 9176 | gfp_t gfp) |
| 9177 | { |
| 9178 | struct sk_buff *msg; |
| 9179 | void *hdr; |
| 9180 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9181 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9182 | if (!msg) |
| 9183 | return; |
| 9184 | |
| 9185 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9186 | if (!hdr) { |
| 9187 | nlmsg_free(msg); |
| 9188 | return; |
| 9189 | } |
| 9190 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9191 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9192 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9193 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9194 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9195 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9196 | |
| 9197 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9198 | nl80211_mlme_mcgrp.id, gfp); |
| 9199 | return; |
| 9200 | |
| 9201 | nla_put_failure: |
| 9202 | genlmsg_cancel(msg, hdr); |
| 9203 | nlmsg_free(msg); |
| 9204 | } |
| 9205 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9206 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 9207 | struct net_device *dev, const u8 *mac_addr, |
| 9208 | enum nl80211_connect_failed_reason reason, |
| 9209 | gfp_t gfp) |
| 9210 | { |
| 9211 | struct sk_buff *msg; |
| 9212 | void *hdr; |
| 9213 | |
| 9214 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9215 | if (!msg) |
| 9216 | return; |
| 9217 | |
| 9218 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9219 | if (!hdr) { |
| 9220 | nlmsg_free(msg); |
| 9221 | return; |
| 9222 | } |
| 9223 | |
| 9224 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9225 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9226 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9227 | goto nla_put_failure; |
| 9228 | |
| 9229 | genlmsg_end(msg, hdr); |
| 9230 | |
| 9231 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9232 | nl80211_mlme_mcgrp.id, gfp); |
| 9233 | return; |
| 9234 | |
| 9235 | nla_put_failure: |
| 9236 | genlmsg_cancel(msg, hdr); |
| 9237 | nlmsg_free(msg); |
| 9238 | } |
| 9239 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9240 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9241 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9242 | { |
| 9243 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9244 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9245 | struct sk_buff *msg; |
| 9246 | void *hdr; |
| 9247 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9248 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9249 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9250 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9251 | return false; |
| 9252 | |
| 9253 | msg = nlmsg_new(100, gfp); |
| 9254 | if (!msg) |
| 9255 | return true; |
| 9256 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9257 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9258 | if (!hdr) { |
| 9259 | nlmsg_free(msg); |
| 9260 | return true; |
| 9261 | } |
| 9262 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9263 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9264 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9265 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9266 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9267 | |
| 9268 | err = genlmsg_end(msg, hdr); |
| 9269 | if (err < 0) { |
| 9270 | nlmsg_free(msg); |
| 9271 | return true; |
| 9272 | } |
| 9273 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9274 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9275 | return true; |
| 9276 | |
| 9277 | nla_put_failure: |
| 9278 | genlmsg_cancel(msg, hdr); |
| 9279 | nlmsg_free(msg); |
| 9280 | return true; |
| 9281 | } |
| 9282 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9283 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 9284 | { |
| 9285 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9286 | addr, gfp); |
| 9287 | } |
| 9288 | |
| 9289 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 9290 | const u8 *addr, gfp_t gfp) |
| 9291 | { |
| 9292 | return __nl80211_unexpected_frame(dev, |
| 9293 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9294 | addr, gfp); |
| 9295 | } |
| 9296 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9297 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9298 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9299 | int freq, int sig_dbm, |
| 9300 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9301 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9302 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9303 | struct sk_buff *msg; |
| 9304 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9305 | |
| 9306 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9307 | if (!msg) |
| 9308 | return -ENOMEM; |
| 9309 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9310 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9311 | if (!hdr) { |
| 9312 | nlmsg_free(msg); |
| 9313 | return -ENOMEM; |
| 9314 | } |
| 9315 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9316 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9317 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9318 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9319 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 9320 | (sig_dbm && |
| 9321 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9322 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9323 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9324 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9325 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9326 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9327 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9328 | |
| 9329 | nla_put_failure: |
| 9330 | genlmsg_cancel(msg, hdr); |
| 9331 | nlmsg_free(msg); |
| 9332 | return -ENOBUFS; |
| 9333 | } |
| 9334 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9335 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9336 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9337 | const u8 *buf, size_t len, bool ack, |
| 9338 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9339 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9340 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9341 | struct sk_buff *msg; |
| 9342 | void *hdr; |
| 9343 | |
| 9344 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9345 | if (!msg) |
| 9346 | return; |
| 9347 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9348 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9349 | if (!hdr) { |
| 9350 | nlmsg_free(msg); |
| 9351 | return; |
| 9352 | } |
| 9353 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9354 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9355 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9356 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9357 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 9358 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9359 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9360 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9361 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9362 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9363 | |
| 9364 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 9365 | return; |
| 9366 | |
| 9367 | nla_put_failure: |
| 9368 | genlmsg_cancel(msg, hdr); |
| 9369 | nlmsg_free(msg); |
| 9370 | } |
| 9371 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9372 | void |
| 9373 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 9374 | struct net_device *netdev, |
| 9375 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 9376 | gfp_t gfp) |
| 9377 | { |
| 9378 | struct sk_buff *msg; |
| 9379 | struct nlattr *pinfoattr; |
| 9380 | void *hdr; |
| 9381 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9382 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9383 | if (!msg) |
| 9384 | return; |
| 9385 | |
| 9386 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9387 | if (!hdr) { |
| 9388 | nlmsg_free(msg); |
| 9389 | return; |
| 9390 | } |
| 9391 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9392 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9393 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9394 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9395 | |
| 9396 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9397 | if (!pinfoattr) |
| 9398 | goto nla_put_failure; |
| 9399 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9400 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 9401 | rssi_event)) |
| 9402 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9403 | |
| 9404 | nla_nest_end(msg, pinfoattr); |
| 9405 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9406 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9407 | |
| 9408 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9409 | nl80211_mlme_mcgrp.id, gfp); |
| 9410 | return; |
| 9411 | |
| 9412 | nla_put_failure: |
| 9413 | genlmsg_cancel(msg, hdr); |
| 9414 | nlmsg_free(msg); |
| 9415 | } |
| 9416 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9417 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 9418 | struct net_device *netdev, const u8 *bssid, |
| 9419 | const u8 *replay_ctr, gfp_t gfp) |
| 9420 | { |
| 9421 | struct sk_buff *msg; |
| 9422 | struct nlattr *rekey_attr; |
| 9423 | void *hdr; |
| 9424 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9425 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9426 | if (!msg) |
| 9427 | return; |
| 9428 | |
| 9429 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 9430 | if (!hdr) { |
| 9431 | nlmsg_free(msg); |
| 9432 | return; |
| 9433 | } |
| 9434 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9435 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9436 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9437 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9438 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9439 | |
| 9440 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 9441 | if (!rekey_attr) |
| 9442 | goto nla_put_failure; |
| 9443 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9444 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 9445 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 9446 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9447 | |
| 9448 | nla_nest_end(msg, rekey_attr); |
| 9449 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9450 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9451 | |
| 9452 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9453 | nl80211_mlme_mcgrp.id, gfp); |
| 9454 | return; |
| 9455 | |
| 9456 | nla_put_failure: |
| 9457 | genlmsg_cancel(msg, hdr); |
| 9458 | nlmsg_free(msg); |
| 9459 | } |
| 9460 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9461 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 9462 | struct net_device *netdev, int index, |
| 9463 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 9464 | { |
| 9465 | struct sk_buff *msg; |
| 9466 | struct nlattr *attr; |
| 9467 | void *hdr; |
| 9468 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9469 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9470 | if (!msg) |
| 9471 | return; |
| 9472 | |
| 9473 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 9474 | if (!hdr) { |
| 9475 | nlmsg_free(msg); |
| 9476 | return; |
| 9477 | } |
| 9478 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9479 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9480 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9481 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9482 | |
| 9483 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 9484 | if (!attr) |
| 9485 | goto nla_put_failure; |
| 9486 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9487 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 9488 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 9489 | (preauth && |
| 9490 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 9491 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9492 | |
| 9493 | nla_nest_end(msg, attr); |
| 9494 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9495 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9496 | |
| 9497 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9498 | nl80211_mlme_mcgrp.id, gfp); |
| 9499 | return; |
| 9500 | |
| 9501 | nla_put_failure: |
| 9502 | genlmsg_cancel(msg, hdr); |
| 9503 | nlmsg_free(msg); |
| 9504 | } |
| 9505 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9506 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9507 | struct net_device *netdev, |
| 9508 | struct cfg80211_chan_def *chandef, gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9509 | { |
| 9510 | struct sk_buff *msg; |
| 9511 | void *hdr; |
| 9512 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9513 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9514 | if (!msg) |
| 9515 | return; |
| 9516 | |
| 9517 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 9518 | if (!hdr) { |
| 9519 | nlmsg_free(msg); |
| 9520 | return; |
| 9521 | } |
| 9522 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9523 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9524 | goto nla_put_failure; |
| 9525 | |
| 9526 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 9527 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9528 | |
| 9529 | genlmsg_end(msg, hdr); |
| 9530 | |
| 9531 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9532 | nl80211_mlme_mcgrp.id, gfp); |
| 9533 | return; |
| 9534 | |
| 9535 | nla_put_failure: |
| 9536 | genlmsg_cancel(msg, hdr); |
| 9537 | nlmsg_free(msg); |
| 9538 | } |
| 9539 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9540 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9541 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 9542 | struct net_device *netdev, const u8 *peer, |
| 9543 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 9544 | { |
| 9545 | struct sk_buff *msg; |
| 9546 | struct nlattr *pinfoattr; |
| 9547 | void *hdr; |
| 9548 | |
| 9549 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9550 | if (!msg) |
| 9551 | return; |
| 9552 | |
| 9553 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9554 | if (!hdr) { |
| 9555 | nlmsg_free(msg); |
| 9556 | return; |
| 9557 | } |
| 9558 | |
| 9559 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9560 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9561 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9562 | goto nla_put_failure; |
| 9563 | |
| 9564 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9565 | if (!pinfoattr) |
| 9566 | goto nla_put_failure; |
| 9567 | |
| 9568 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 9569 | goto nla_put_failure; |
| 9570 | |
| 9571 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 9572 | goto nla_put_failure; |
| 9573 | |
| 9574 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 9575 | goto nla_put_failure; |
| 9576 | |
| 9577 | nla_nest_end(msg, pinfoattr); |
| 9578 | |
| 9579 | genlmsg_end(msg, hdr); |
| 9580 | |
| 9581 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9582 | nl80211_mlme_mcgrp.id, gfp); |
| 9583 | return; |
| 9584 | |
| 9585 | nla_put_failure: |
| 9586 | genlmsg_cancel(msg, hdr); |
| 9587 | nlmsg_free(msg); |
| 9588 | } |
| 9589 | |
| 9590 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9591 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 9592 | struct cfg80211_chan_def *chandef, |
| 9593 | enum nl80211_radar_event event, |
| 9594 | struct net_device *netdev, gfp_t gfp) |
| 9595 | { |
| 9596 | struct sk_buff *msg; |
| 9597 | void *hdr; |
| 9598 | |
| 9599 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9600 | if (!msg) |
| 9601 | return; |
| 9602 | |
| 9603 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 9604 | if (!hdr) { |
| 9605 | nlmsg_free(msg); |
| 9606 | return; |
| 9607 | } |
| 9608 | |
| 9609 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 9610 | goto nla_put_failure; |
| 9611 | |
| 9612 | /* NOP and radar events don't need a netdev parameter */ |
| 9613 | if (netdev) { |
| 9614 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 9615 | |
| 9616 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9617 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 9618 | goto nla_put_failure; |
| 9619 | } |
| 9620 | |
| 9621 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 9622 | goto nla_put_failure; |
| 9623 | |
| 9624 | if (nl80211_send_chandef(msg, chandef)) |
| 9625 | goto nla_put_failure; |
| 9626 | |
| 9627 | if (genlmsg_end(msg, hdr) < 0) { |
| 9628 | nlmsg_free(msg); |
| 9629 | return; |
| 9630 | } |
| 9631 | |
| 9632 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9633 | nl80211_mlme_mcgrp.id, gfp); |
| 9634 | return; |
| 9635 | |
| 9636 | nla_put_failure: |
| 9637 | genlmsg_cancel(msg, hdr); |
| 9638 | nlmsg_free(msg); |
| 9639 | } |
| 9640 | |
| 9641 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9642 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 9643 | struct net_device *netdev, const u8 *peer, |
| 9644 | u32 num_packets, gfp_t gfp) |
| 9645 | { |
| 9646 | struct sk_buff *msg; |
| 9647 | struct nlattr *pinfoattr; |
| 9648 | void *hdr; |
| 9649 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9650 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9651 | if (!msg) |
| 9652 | return; |
| 9653 | |
| 9654 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9655 | if (!hdr) { |
| 9656 | nlmsg_free(msg); |
| 9657 | return; |
| 9658 | } |
| 9659 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9660 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9661 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9662 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9663 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9664 | |
| 9665 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9666 | if (!pinfoattr) |
| 9667 | goto nla_put_failure; |
| 9668 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9669 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 9670 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9671 | |
| 9672 | nla_nest_end(msg, pinfoattr); |
| 9673 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9674 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9675 | |
| 9676 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9677 | nl80211_mlme_mcgrp.id, gfp); |
| 9678 | return; |
| 9679 | |
| 9680 | nla_put_failure: |
| 9681 | genlmsg_cancel(msg, hdr); |
| 9682 | nlmsg_free(msg); |
| 9683 | } |
| 9684 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9685 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 9686 | u64 cookie, bool acked, gfp_t gfp) |
| 9687 | { |
| 9688 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9689 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9690 | struct sk_buff *msg; |
| 9691 | void *hdr; |
| 9692 | int err; |
| 9693 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9694 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 9695 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9696 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9697 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9698 | if (!msg) |
| 9699 | return; |
| 9700 | |
| 9701 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 9702 | if (!hdr) { |
| 9703 | nlmsg_free(msg); |
| 9704 | return; |
| 9705 | } |
| 9706 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9707 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9708 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9709 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9710 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9711 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9712 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9713 | |
| 9714 | err = genlmsg_end(msg, hdr); |
| 9715 | if (err < 0) { |
| 9716 | nlmsg_free(msg); |
| 9717 | return; |
| 9718 | } |
| 9719 | |
| 9720 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9721 | nl80211_mlme_mcgrp.id, gfp); |
| 9722 | return; |
| 9723 | |
| 9724 | nla_put_failure: |
| 9725 | genlmsg_cancel(msg, hdr); |
| 9726 | nlmsg_free(msg); |
| 9727 | } |
| 9728 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 9729 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9730 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 9731 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9732 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9733 | { |
| 9734 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9735 | struct sk_buff *msg; |
| 9736 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9737 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9738 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9739 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 9740 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9741 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9742 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9743 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 9744 | if (!msg) { |
| 9745 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9746 | return; |
| 9747 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9748 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9749 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 9750 | if (!hdr) |
| 9751 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9752 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9753 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9754 | (freq && |
| 9755 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9756 | (sig_dbm && |
| 9757 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9758 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 9759 | goto nla_put_failure; |
| 9760 | |
| 9761 | genlmsg_end(msg, hdr); |
| 9762 | |
| 9763 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9764 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9765 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9766 | return; |
| 9767 | |
| 9768 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9769 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9770 | if (hdr) |
| 9771 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9772 | nlmsg_free(msg); |
| 9773 | } |
| 9774 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 9775 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 9776 | #ifdef CONFIG_PM |
| 9777 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 9778 | struct cfg80211_wowlan_wakeup *wakeup, |
| 9779 | gfp_t gfp) |
| 9780 | { |
| 9781 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9782 | struct sk_buff *msg; |
| 9783 | void *hdr; |
| 9784 | int err, size = 200; |
| 9785 | |
| 9786 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 9787 | |
| 9788 | if (wakeup) |
| 9789 | size += wakeup->packet_present_len; |
| 9790 | |
| 9791 | msg = nlmsg_new(size, gfp); |
| 9792 | if (!msg) |
| 9793 | return; |
| 9794 | |
| 9795 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 9796 | if (!hdr) |
| 9797 | goto free_msg; |
| 9798 | |
| 9799 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9800 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 9801 | goto free_msg; |
| 9802 | |
| 9803 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9804 | wdev->netdev->ifindex)) |
| 9805 | goto free_msg; |
| 9806 | |
| 9807 | if (wakeup) { |
| 9808 | struct nlattr *reasons; |
| 9809 | |
| 9810 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9811 | |
| 9812 | if (wakeup->disconnect && |
| 9813 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 9814 | goto free_msg; |
| 9815 | if (wakeup->magic_pkt && |
| 9816 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 9817 | goto free_msg; |
| 9818 | if (wakeup->gtk_rekey_failure && |
| 9819 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 9820 | goto free_msg; |
| 9821 | if (wakeup->eap_identity_req && |
| 9822 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 9823 | goto free_msg; |
| 9824 | if (wakeup->four_way_handshake && |
| 9825 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 9826 | goto free_msg; |
| 9827 | if (wakeup->rfkill_release && |
| 9828 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 9829 | goto free_msg; |
| 9830 | |
| 9831 | if (wakeup->pattern_idx >= 0 && |
| 9832 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 9833 | wakeup->pattern_idx)) |
| 9834 | goto free_msg; |
| 9835 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9836 | if (wakeup->tcp_match) |
| 9837 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 9838 | |
| 9839 | if (wakeup->tcp_connlost) |
| 9840 | nla_put_flag(msg, |
| 9841 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 9842 | |
| 9843 | if (wakeup->tcp_nomoretokens) |
| 9844 | nla_put_flag(msg, |
| 9845 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 9846 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 9847 | if (wakeup->packet) { |
| 9848 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 9849 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 9850 | |
| 9851 | if (!wakeup->packet_80211) { |
| 9852 | pkt_attr = |
| 9853 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 9854 | len_attr = |
| 9855 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 9856 | } |
| 9857 | |
| 9858 | if (wakeup->packet_len && |
| 9859 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 9860 | goto free_msg; |
| 9861 | |
| 9862 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 9863 | wakeup->packet)) |
| 9864 | goto free_msg; |
| 9865 | } |
| 9866 | |
| 9867 | nla_nest_end(msg, reasons); |
| 9868 | } |
| 9869 | |
| 9870 | err = genlmsg_end(msg, hdr); |
| 9871 | if (err < 0) |
| 9872 | goto free_msg; |
| 9873 | |
| 9874 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9875 | nl80211_mlme_mcgrp.id, gfp); |
| 9876 | return; |
| 9877 | |
| 9878 | free_msg: |
| 9879 | nlmsg_free(msg); |
| 9880 | } |
| 9881 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 9882 | #endif |
| 9883 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 9884 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 9885 | enum nl80211_tdls_operation oper, |
| 9886 | u16 reason_code, gfp_t gfp) |
| 9887 | { |
| 9888 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9889 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9890 | struct sk_buff *msg; |
| 9891 | void *hdr; |
| 9892 | int err; |
| 9893 | |
| 9894 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 9895 | reason_code); |
| 9896 | |
| 9897 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9898 | if (!msg) |
| 9899 | return; |
| 9900 | |
| 9901 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 9902 | if (!hdr) { |
| 9903 | nlmsg_free(msg); |
| 9904 | return; |
| 9905 | } |
| 9906 | |
| 9907 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9908 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9909 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 9910 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 9911 | (reason_code > 0 && |
| 9912 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 9913 | goto nla_put_failure; |
| 9914 | |
| 9915 | err = genlmsg_end(msg, hdr); |
| 9916 | if (err < 0) { |
| 9917 | nlmsg_free(msg); |
| 9918 | return; |
| 9919 | } |
| 9920 | |
| 9921 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9922 | nl80211_mlme_mcgrp.id, gfp); |
| 9923 | return; |
| 9924 | |
| 9925 | nla_put_failure: |
| 9926 | genlmsg_cancel(msg, hdr); |
| 9927 | nlmsg_free(msg); |
| 9928 | } |
| 9929 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 9930 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9931 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 9932 | unsigned long state, |
| 9933 | void *_notify) |
| 9934 | { |
| 9935 | struct netlink_notify *notify = _notify; |
| 9936 | struct cfg80211_registered_device *rdev; |
| 9937 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9938 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9939 | |
| 9940 | if (state != NETLINK_URELEASE) |
| 9941 | return NOTIFY_DONE; |
| 9942 | |
| 9943 | rcu_read_lock(); |
| 9944 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9945 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9946 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9947 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9948 | |
| 9949 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9950 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 9951 | list) { |
| 9952 | if (reg->nlportid == notify->portid) { |
| 9953 | list_del(®->list); |
| 9954 | kfree(reg); |
| 9955 | break; |
| 9956 | } |
| 9957 | } |
| 9958 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9959 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9960 | |
| 9961 | rcu_read_unlock(); |
| 9962 | |
| 9963 | return NOTIFY_DONE; |
| 9964 | } |
| 9965 | |
| 9966 | static struct notifier_block nl80211_netlink_notifier = { |
| 9967 | .notifier_call = nl80211_netlink_notify, |
| 9968 | }; |
| 9969 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9970 | /* initialisation/exit functions */ |
| 9971 | |
| 9972 | int nl80211_init(void) |
| 9973 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9974 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9975 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9976 | err = genl_register_family_with_ops(&nl80211_fam, |
| 9977 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9978 | if (err) |
| 9979 | return err; |
| 9980 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9981 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 9982 | if (err) |
| 9983 | goto err_out; |
| 9984 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9985 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 9986 | if (err) |
| 9987 | goto err_out; |
| 9988 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9989 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 9990 | if (err) |
| 9991 | goto err_out; |
| 9992 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9993 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 9994 | if (err) |
| 9995 | goto err_out; |
| 9996 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9997 | #ifdef CONFIG_NL80211_TESTMODE |
| 9998 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 9999 | if (err) |
| 10000 | goto err_out; |
| 10001 | #endif |
| 10002 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10003 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10004 | if (err) |
| 10005 | goto err_out; |
| 10006 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10007 | return 0; |
| 10008 | err_out: |
| 10009 | genl_unregister_family(&nl80211_fam); |
| 10010 | return err; |
| 10011 | } |
| 10012 | |
| 10013 | void nl80211_exit(void) |
| 10014 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10015 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10016 | genl_unregister_family(&nl80211_fam); |
| 10017 | } |