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 | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 283 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 284 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 285 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 286 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 287 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 288 | |
| 289 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 290 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 291 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 292 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 293 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 294 | |
| 295 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 296 | .len = IEEE80211_MAX_SSID_LEN }, |
| 297 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 298 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | 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 | 5e76023 | 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 | 5e76023 | 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 | a50df0c | 2013-02-11 14:20:05 +0100 | [diff] [blame] | 1366 | if (dev->wiphy.extended_capabilities && |
| 1367 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1368 | dev->wiphy.extended_capabilities_len, |
| 1369 | dev->wiphy.extended_capabilities) || |
| 1370 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1371 | dev->wiphy.extended_capabilities_len, |
| 1372 | dev->wiphy.extended_capabilities_mask))) |
| 1373 | goto nla_put_failure; |
| 1374 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1375 | return genlmsg_end(msg, hdr); |
| 1376 | |
| 1377 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1378 | genlmsg_cancel(msg, hdr); |
| 1379 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1383 | { |
| 1384 | int idx = 0; |
| 1385 | int start = cb->args[0]; |
| 1386 | struct cfg80211_registered_device *dev; |
| 1387 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1388 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1389 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1390 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1391 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1392 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1393 | continue; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1394 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1395 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1396 | dev) < 0) { |
| 1397 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1398 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1399 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1400 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1401 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1402 | |
| 1403 | cb->args[0] = idx; |
| 1404 | |
| 1405 | return skb->len; |
| 1406 | } |
| 1407 | |
| 1408 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1409 | { |
| 1410 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1411 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1412 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1413 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1414 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1415 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1416 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1417 | 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] | 1418 | nlmsg_free(msg); |
| 1419 | return -ENOBUFS; |
| 1420 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1421 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1422 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1423 | } |
| 1424 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1425 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1426 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1427 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1428 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1429 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1430 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1431 | }; |
| 1432 | |
| 1433 | static int parse_txq_params(struct nlattr *tb[], |
| 1434 | struct ieee80211_txq_params *txq_params) |
| 1435 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1436 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1437 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1438 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1439 | return -EINVAL; |
| 1440 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1441 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1442 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1443 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1444 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1445 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1446 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1447 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1448 | return -EINVAL; |
| 1449 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1450 | return 0; |
| 1451 | } |
| 1452 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1453 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1454 | { |
| 1455 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1456 | * You can only set the channel explicitly for WDS interfaces, |
| 1457 | * all others have their channel managed via their respective |
| 1458 | * "establish a connection" command (connect, join, ...) |
| 1459 | * |
| 1460 | * For AP/GO and mesh mode, the channel can be set with the |
| 1461 | * channel userspace API, but is only stored and passed to the |
| 1462 | * low-level driver when the AP starts or the mesh is joined. |
| 1463 | * This is for backward compatibility, userspace can also give |
| 1464 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1465 | * |
| 1466 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1467 | * whatever else is going on, so they have their own special |
| 1468 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1469 | */ |
| 1470 | return !wdev || |
| 1471 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1472 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1473 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1474 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1475 | } |
| 1476 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1477 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1478 | struct genl_info *info, |
| 1479 | struct cfg80211_chan_def *chandef) |
| 1480 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1481 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1482 | |
| 1483 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1484 | return -EINVAL; |
| 1485 | |
| 1486 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1487 | |
| 1488 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1489 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1490 | chandef->center_freq1 = control_freq; |
| 1491 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1492 | |
| 1493 | /* Primary channel not allowed */ |
| 1494 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1495 | return -EINVAL; |
| 1496 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1497 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1498 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1499 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1500 | chantype = nla_get_u32( |
| 1501 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1502 | |
| 1503 | switch (chantype) { |
| 1504 | case NL80211_CHAN_NO_HT: |
| 1505 | case NL80211_CHAN_HT20: |
| 1506 | case NL80211_CHAN_HT40PLUS: |
| 1507 | case NL80211_CHAN_HT40MINUS: |
| 1508 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1509 | chantype); |
| 1510 | break; |
| 1511 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1512 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1513 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1514 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1515 | chandef->width = |
| 1516 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1517 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1518 | chandef->center_freq1 = |
| 1519 | nla_get_u32( |
| 1520 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1521 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1522 | chandef->center_freq2 = |
| 1523 | nla_get_u32( |
| 1524 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1525 | } |
| 1526 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1527 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1528 | return -EINVAL; |
| 1529 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1530 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1531 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1532 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1533 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1534 | return 0; |
| 1535 | } |
| 1536 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1537 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1538 | struct wireless_dev *wdev, |
| 1539 | struct genl_info *info) |
| 1540 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1541 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1542 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1543 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1544 | |
| 1545 | if (wdev) |
| 1546 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1547 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1548 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1549 | return -EOPNOTSUPP; |
| 1550 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1551 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1552 | if (result) |
| 1553 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1554 | |
| 1555 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1556 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1557 | case NL80211_IFTYPE_AP: |
| 1558 | case NL80211_IFTYPE_P2P_GO: |
| 1559 | if (wdev->beacon_interval) { |
| 1560 | result = -EBUSY; |
| 1561 | break; |
| 1562 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1563 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1564 | result = -EINVAL; |
| 1565 | break; |
| 1566 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1567 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1568 | result = 0; |
| 1569 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1570 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1571 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1572 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1573 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1574 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1575 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1576 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1577 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1578 | } |
| 1579 | mutex_unlock(&rdev->devlist_mtx); |
| 1580 | |
| 1581 | return result; |
| 1582 | } |
| 1583 | |
| 1584 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1585 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1586 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1587 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1588 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1589 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1590 | } |
| 1591 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1592 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1593 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1594 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1595 | struct net_device *dev = info->user_ptr[1]; |
| 1596 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1597 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1598 | |
| 1599 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1600 | return -EINVAL; |
| 1601 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1602 | if (netif_running(dev)) |
| 1603 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1604 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1605 | if (!rdev->ops->set_wds_peer) |
| 1606 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1607 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1608 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1609 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1610 | |
| 1611 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1612 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1616 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1617 | { |
| 1618 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1619 | struct net_device *netdev = NULL; |
| 1620 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1621 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1622 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1623 | u32 changed; |
| 1624 | u8 retry_short = 0, retry_long = 0; |
| 1625 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1626 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1627 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1628 | /* |
| 1629 | * Try to find the wiphy and netdev. Normally this |
| 1630 | * function shouldn't need the netdev, but this is |
| 1631 | * done for backward compatibility -- previously |
| 1632 | * setting the channel was done per wiphy, but now |
| 1633 | * it is per netdev. Previous userland like hostapd |
| 1634 | * also passed a netdev to set_wiphy, so that it is |
| 1635 | * possible to let that go to the right netdev! |
| 1636 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1637 | mutex_lock(&cfg80211_mutex); |
| 1638 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1639 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1640 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1641 | |
| 1642 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1643 | if (netdev && netdev->ieee80211_ptr) { |
| 1644 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1645 | mutex_lock(&rdev->mtx); |
| 1646 | } else |
| 1647 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1648 | } |
| 1649 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1650 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1651 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1652 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1653 | if (IS_ERR(rdev)) { |
| 1654 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1655 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1656 | } |
| 1657 | wdev = NULL; |
| 1658 | netdev = NULL; |
| 1659 | result = 0; |
| 1660 | |
| 1661 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1662 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1663 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1664 | |
| 1665 | /* |
| 1666 | * end workaround code, by now the rdev is available |
| 1667 | * and locked, and wdev may or may not be NULL. |
| 1668 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1669 | |
| 1670 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1671 | result = cfg80211_dev_rename( |
| 1672 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1673 | |
| 1674 | mutex_unlock(&cfg80211_mutex); |
| 1675 | |
| 1676 | if (result) |
| 1677 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1678 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1679 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1680 | struct ieee80211_txq_params txq_params; |
| 1681 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1682 | |
| 1683 | if (!rdev->ops->set_txq_params) { |
| 1684 | result = -EOPNOTSUPP; |
| 1685 | goto bad_res; |
| 1686 | } |
| 1687 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1688 | if (!netdev) { |
| 1689 | result = -EINVAL; |
| 1690 | goto bad_res; |
| 1691 | } |
| 1692 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1693 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1694 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1695 | result = -EINVAL; |
| 1696 | goto bad_res; |
| 1697 | } |
| 1698 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1699 | if (!netif_running(netdev)) { |
| 1700 | result = -ENETDOWN; |
| 1701 | goto bad_res; |
| 1702 | } |
| 1703 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1704 | nla_for_each_nested(nl_txq_params, |
| 1705 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1706 | rem_txq_params) { |
| 1707 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1708 | nla_data(nl_txq_params), |
| 1709 | nla_len(nl_txq_params), |
| 1710 | txq_params_policy); |
| 1711 | result = parse_txq_params(tb, &txq_params); |
| 1712 | if (result) |
| 1713 | goto bad_res; |
| 1714 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1715 | result = rdev_set_txq_params(rdev, netdev, |
| 1716 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1717 | if (result) |
| 1718 | goto bad_res; |
| 1719 | } |
| 1720 | } |
| 1721 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1722 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1723 | result = __nl80211_set_channel(rdev, |
| 1724 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1725 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1726 | if (result) |
| 1727 | goto bad_res; |
| 1728 | } |
| 1729 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1730 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1731 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1732 | enum nl80211_tx_power_setting type; |
| 1733 | int idx, mbm = 0; |
| 1734 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1735 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1736 | txp_wdev = NULL; |
| 1737 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1738 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1739 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1740 | goto bad_res; |
| 1741 | } |
| 1742 | |
| 1743 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1744 | type = nla_get_u32(info->attrs[idx]); |
| 1745 | |
| 1746 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1747 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1748 | result = -EINVAL; |
| 1749 | goto bad_res; |
| 1750 | } |
| 1751 | |
| 1752 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1753 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1754 | mbm = nla_get_u32(info->attrs[idx]); |
| 1755 | } |
| 1756 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1757 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1758 | if (result) |
| 1759 | goto bad_res; |
| 1760 | } |
| 1761 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1762 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1763 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1764 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1765 | if ((!rdev->wiphy.available_antennas_tx && |
| 1766 | !rdev->wiphy.available_antennas_rx) || |
| 1767 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1768 | result = -EOPNOTSUPP; |
| 1769 | goto bad_res; |
| 1770 | } |
| 1771 | |
| 1772 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1773 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1774 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1775 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1776 | * available antenna masks, except for the "all" mask */ |
| 1777 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1778 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1779 | result = -EINVAL; |
| 1780 | goto bad_res; |
| 1781 | } |
| 1782 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1783 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1784 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1785 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1786 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1787 | if (result) |
| 1788 | goto bad_res; |
| 1789 | } |
| 1790 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1791 | changed = 0; |
| 1792 | |
| 1793 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1794 | retry_short = nla_get_u8( |
| 1795 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1796 | if (retry_short == 0) { |
| 1797 | result = -EINVAL; |
| 1798 | goto bad_res; |
| 1799 | } |
| 1800 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1801 | } |
| 1802 | |
| 1803 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1804 | retry_long = nla_get_u8( |
| 1805 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1806 | if (retry_long == 0) { |
| 1807 | result = -EINVAL; |
| 1808 | goto bad_res; |
| 1809 | } |
| 1810 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1811 | } |
| 1812 | |
| 1813 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1814 | frag_threshold = nla_get_u32( |
| 1815 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1816 | if (frag_threshold < 256) { |
| 1817 | result = -EINVAL; |
| 1818 | goto bad_res; |
| 1819 | } |
| 1820 | if (frag_threshold != (u32) -1) { |
| 1821 | /* |
| 1822 | * Fragments (apart from the last one) are required to |
| 1823 | * have even length. Make the fragmentation code |
| 1824 | * simpler by stripping LSB should someone try to use |
| 1825 | * odd threshold value. |
| 1826 | */ |
| 1827 | frag_threshold &= ~0x1; |
| 1828 | } |
| 1829 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1830 | } |
| 1831 | |
| 1832 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1833 | rts_threshold = nla_get_u32( |
| 1834 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1835 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1836 | } |
| 1837 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1838 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1839 | coverage_class = nla_get_u8( |
| 1840 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1841 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1842 | } |
| 1843 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1844 | if (changed) { |
| 1845 | u8 old_retry_short, old_retry_long; |
| 1846 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1847 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1848 | |
| 1849 | if (!rdev->ops->set_wiphy_params) { |
| 1850 | result = -EOPNOTSUPP; |
| 1851 | goto bad_res; |
| 1852 | } |
| 1853 | |
| 1854 | old_retry_short = rdev->wiphy.retry_short; |
| 1855 | old_retry_long = rdev->wiphy.retry_long; |
| 1856 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1857 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1858 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1859 | |
| 1860 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1861 | rdev->wiphy.retry_short = retry_short; |
| 1862 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1863 | rdev->wiphy.retry_long = retry_long; |
| 1864 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1865 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1866 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1867 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1868 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1869 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1870 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1871 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1872 | if (result) { |
| 1873 | rdev->wiphy.retry_short = old_retry_short; |
| 1874 | rdev->wiphy.retry_long = old_retry_long; |
| 1875 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1876 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1877 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1878 | } |
| 1879 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1880 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1881 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1882 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1883 | if (netdev) |
| 1884 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1885 | return result; |
| 1886 | } |
| 1887 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1888 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1889 | { |
| 1890 | return (u64)wdev->identifier | |
| 1891 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1892 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1893 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1894 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 1895 | struct cfg80211_chan_def *chandef) |
| 1896 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1897 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1898 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1899 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1900 | chandef->chan->center_freq)) |
| 1901 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1902 | switch (chandef->width) { |
| 1903 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1904 | case NL80211_CHAN_WIDTH_20: |
| 1905 | case NL80211_CHAN_WIDTH_40: |
| 1906 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1907 | cfg80211_get_chandef_type(chandef))) |
| 1908 | return -ENOBUFS; |
| 1909 | break; |
| 1910 | default: |
| 1911 | break; |
| 1912 | } |
| 1913 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 1914 | return -ENOBUFS; |
| 1915 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 1916 | return -ENOBUFS; |
| 1917 | if (chandef->center_freq2 && |
| 1918 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1919 | return -ENOBUFS; |
| 1920 | return 0; |
| 1921 | } |
| 1922 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1923 | 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] | 1924 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1925 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1926 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1927 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1928 | void *hdr; |
| 1929 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1930 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1931 | if (!hdr) |
| 1932 | return -1; |
| 1933 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1934 | if (dev && |
| 1935 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1936 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1937 | goto nla_put_failure; |
| 1938 | |
| 1939 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1940 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1941 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1942 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1943 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1944 | rdev->devlist_generation ^ |
| 1945 | (cfg80211_rdev_list_generation << 2))) |
| 1946 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1947 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1948 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1949 | int ret; |
| 1950 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1951 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1952 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 1953 | if (ret == 0) { |
| 1954 | if (nl80211_send_chandef(msg, &chandef)) |
| 1955 | goto nla_put_failure; |
| 1956 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1957 | } |
| 1958 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 1959 | if (wdev->ssid_len) { |
| 1960 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 1961 | goto nla_put_failure; |
| 1962 | } |
| 1963 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1964 | return genlmsg_end(msg, hdr); |
| 1965 | |
| 1966 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1967 | genlmsg_cancel(msg, hdr); |
| 1968 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1972 | { |
| 1973 | int wp_idx = 0; |
| 1974 | int if_idx = 0; |
| 1975 | int wp_start = cb->args[0]; |
| 1976 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1977 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1978 | struct wireless_dev *wdev; |
| 1979 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1980 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1981 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1982 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1983 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1984 | if (wp_idx < wp_start) { |
| 1985 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1986 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1987 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1988 | if_idx = 0; |
| 1989 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1990 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1991 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1992 | if (if_idx < if_start) { |
| 1993 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1994 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1995 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1996 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1997 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1998 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1999 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2000 | goto out; |
| 2001 | } |
| 2002 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2003 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2004 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2005 | |
| 2006 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2007 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2008 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2009 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2010 | |
| 2011 | cb->args[0] = wp_idx; |
| 2012 | cb->args[1] = if_idx; |
| 2013 | |
| 2014 | return skb->len; |
| 2015 | } |
| 2016 | |
| 2017 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2018 | { |
| 2019 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2020 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2021 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2022 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2023 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2024 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2025 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2026 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2027 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2028 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2029 | nlmsg_free(msg); |
| 2030 | return -ENOBUFS; |
| 2031 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2032 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2033 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2034 | } |
| 2035 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2036 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2037 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2038 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2039 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2040 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2041 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 2042 | }; |
| 2043 | |
| 2044 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2045 | { |
| 2046 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2047 | int flag; |
| 2048 | |
| 2049 | *mntrflags = 0; |
| 2050 | |
| 2051 | if (!nla) |
| 2052 | return -EINVAL; |
| 2053 | |
| 2054 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2055 | nla, mntr_flags_policy)) |
| 2056 | return -EINVAL; |
| 2057 | |
| 2058 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2059 | if (flags[flag]) |
| 2060 | *mntrflags |= (1<<flag); |
| 2061 | |
| 2062 | return 0; |
| 2063 | } |
| 2064 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2065 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2066 | struct net_device *netdev, u8 use_4addr, |
| 2067 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2068 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2069 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2070 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2071 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2072 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2073 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2074 | |
| 2075 | switch (iftype) { |
| 2076 | case NL80211_IFTYPE_AP_VLAN: |
| 2077 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2078 | return 0; |
| 2079 | break; |
| 2080 | case NL80211_IFTYPE_STATION: |
| 2081 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2082 | return 0; |
| 2083 | break; |
| 2084 | default: |
| 2085 | break; |
| 2086 | } |
| 2087 | |
| 2088 | return -EOPNOTSUPP; |
| 2089 | } |
| 2090 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2091 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2092 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2094 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2095 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2096 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2097 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2098 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2099 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2100 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2101 | memset(¶ms, 0, sizeof(params)); |
| 2102 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2103 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2104 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2105 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2106 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2107 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2108 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2109 | if (ntype > NL80211_IFTYPE_MAX) |
| 2110 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2111 | } |
| 2112 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2113 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2114 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2115 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2116 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2117 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2118 | if (netif_running(dev)) |
| 2119 | return -EBUSY; |
| 2120 | |
| 2121 | wdev_lock(wdev); |
| 2122 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2123 | IEEE80211_MAX_MESH_ID_LEN); |
| 2124 | wdev->mesh_id_up_len = |
| 2125 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2126 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2127 | wdev->mesh_id_up_len); |
| 2128 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2129 | } |
| 2130 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2131 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2132 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2133 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2134 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2135 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2136 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2137 | } else { |
| 2138 | params.use_4addr = -1; |
| 2139 | } |
| 2140 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2141 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2142 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2143 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2144 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2145 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2146 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2147 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2148 | |
| 2149 | flags = &_flags; |
| 2150 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2151 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2152 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2153 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2154 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2155 | else |
| 2156 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2157 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2158 | if (!err && params.use_4addr != -1) |
| 2159 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2160 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2161 | return err; |
| 2162 | } |
| 2163 | |
| 2164 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2165 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2166 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2167 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2168 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2169 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2170 | int err; |
| 2171 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2172 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2173 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2174 | memset(¶ms, 0, sizeof(params)); |
| 2175 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2176 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2177 | return -EINVAL; |
| 2178 | |
| 2179 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2180 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2181 | if (type > NL80211_IFTYPE_MAX) |
| 2182 | return -EINVAL; |
| 2183 | } |
| 2184 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2185 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2186 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2187 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2188 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2189 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2190 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2191 | ETH_ALEN); |
| 2192 | if (!is_valid_ether_addr(params.macaddr)) |
| 2193 | return -EADDRNOTAVAIL; |
| 2194 | } |
| 2195 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2196 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2197 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2198 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2199 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2200 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2201 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2202 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2203 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2204 | if (!msg) |
| 2205 | return -ENOMEM; |
| 2206 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2207 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2208 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2209 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2210 | wdev = rdev_add_virtual_intf(rdev, |
| 2211 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2212 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2213 | if (IS_ERR(wdev)) { |
| 2214 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2215 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2216 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2217 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2218 | switch (type) { |
| 2219 | case NL80211_IFTYPE_MESH_POINT: |
| 2220 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2221 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2222 | wdev_lock(wdev); |
| 2223 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2224 | IEEE80211_MAX_MESH_ID_LEN); |
| 2225 | wdev->mesh_id_up_len = |
| 2226 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2227 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2228 | wdev->mesh_id_up_len); |
| 2229 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2230 | break; |
| 2231 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2232 | /* |
| 2233 | * P2P Device doesn't have a netdev, so doesn't go |
| 2234 | * through the netdev notifier and must be added here |
| 2235 | */ |
| 2236 | mutex_init(&wdev->mtx); |
| 2237 | INIT_LIST_HEAD(&wdev->event_list); |
| 2238 | spin_lock_init(&wdev->event_lock); |
| 2239 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2240 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2241 | |
| 2242 | mutex_lock(&rdev->devlist_mtx); |
| 2243 | wdev->identifier = ++rdev->wdev_id; |
| 2244 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2245 | rdev->devlist_generation++; |
| 2246 | mutex_unlock(&rdev->devlist_mtx); |
| 2247 | break; |
| 2248 | default: |
| 2249 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2250 | } |
| 2251 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2252 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2253 | rdev, wdev) < 0) { |
| 2254 | nlmsg_free(msg); |
| 2255 | return -ENOBUFS; |
| 2256 | } |
| 2257 | |
| 2258 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2262 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2263 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2264 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2265 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2266 | if (!rdev->ops->del_virtual_intf) |
| 2267 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2268 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2269 | /* |
| 2270 | * If we remove a wireless device without a netdev then clear |
| 2271 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2272 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2273 | * since the wdev has been freed, unlike with a netdev where |
| 2274 | * we need the dev_put() for the netdev to really be freed. |
| 2275 | */ |
| 2276 | if (!wdev->netdev) |
| 2277 | info->user_ptr[1] = NULL; |
| 2278 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2279 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2280 | } |
| 2281 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2282 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2283 | { |
| 2284 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2285 | struct net_device *dev = info->user_ptr[1]; |
| 2286 | u16 noack_map; |
| 2287 | |
| 2288 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2289 | return -EINVAL; |
| 2290 | |
| 2291 | if (!rdev->ops->set_noack_map) |
| 2292 | return -EOPNOTSUPP; |
| 2293 | |
| 2294 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2295 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2296 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2297 | } |
| 2298 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2299 | struct get_key_cookie { |
| 2300 | struct sk_buff *msg; |
| 2301 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2302 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2303 | }; |
| 2304 | |
| 2305 | static void get_key_callback(void *c, struct key_params *params) |
| 2306 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2307 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2308 | struct get_key_cookie *cookie = c; |
| 2309 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2310 | if ((params->key && |
| 2311 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2312 | params->key_len, params->key)) || |
| 2313 | (params->seq && |
| 2314 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2315 | params->seq_len, params->seq)) || |
| 2316 | (params->cipher && |
| 2317 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2318 | params->cipher))) |
| 2319 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2320 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2321 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2322 | if (!key) |
| 2323 | goto nla_put_failure; |
| 2324 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2325 | if ((params->key && |
| 2326 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2327 | params->key_len, params->key)) || |
| 2328 | (params->seq && |
| 2329 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2330 | params->seq_len, params->seq)) || |
| 2331 | (params->cipher && |
| 2332 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2333 | params->cipher))) |
| 2334 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2335 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2336 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2337 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2338 | |
| 2339 | nla_nest_end(cookie->msg, key); |
| 2340 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2341 | return; |
| 2342 | nla_put_failure: |
| 2343 | cookie->error = 1; |
| 2344 | } |
| 2345 | |
| 2346 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2347 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2348 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2349 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2350 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2351 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2352 | const u8 *mac_addr = NULL; |
| 2353 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2354 | struct get_key_cookie cookie = { |
| 2355 | .error = 0, |
| 2356 | }; |
| 2357 | void *hdr; |
| 2358 | struct sk_buff *msg; |
| 2359 | |
| 2360 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2361 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2362 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2363 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2364 | return -EINVAL; |
| 2365 | |
| 2366 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2367 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2368 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2369 | pairwise = !!mac_addr; |
| 2370 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2371 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2372 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2373 | return -EINVAL; |
| 2374 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2375 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2376 | return -EINVAL; |
| 2377 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2378 | } |
| 2379 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2380 | if (!rdev->ops->get_key) |
| 2381 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2382 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2383 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2384 | if (!msg) |
| 2385 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2386 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2387 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2388 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2389 | if (IS_ERR(hdr)) |
| 2390 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2391 | |
| 2392 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2393 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2394 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2395 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2396 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2397 | goto nla_put_failure; |
| 2398 | if (mac_addr && |
| 2399 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2400 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2401 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2402 | if (pairwise && mac_addr && |
| 2403 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2404 | return -ENOENT; |
| 2405 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2406 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2407 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2408 | |
| 2409 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2410 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2411 | |
| 2412 | if (cookie.error) |
| 2413 | goto nla_put_failure; |
| 2414 | |
| 2415 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2416 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2417 | |
| 2418 | nla_put_failure: |
| 2419 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2420 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2421 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2422 | return err; |
| 2423 | } |
| 2424 | |
| 2425 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2426 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2427 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2428 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2429 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2430 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2431 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2432 | err = nl80211_parse_key(info, &key); |
| 2433 | if (err) |
| 2434 | return err; |
| 2435 | |
| 2436 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2437 | return -EINVAL; |
| 2438 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2439 | /* only support setting default key */ |
| 2440 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2441 | return -EINVAL; |
| 2442 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2443 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2444 | |
| 2445 | if (key.def) { |
| 2446 | if (!rdev->ops->set_default_key) { |
| 2447 | err = -EOPNOTSUPP; |
| 2448 | goto out; |
| 2449 | } |
| 2450 | |
| 2451 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2452 | if (err) |
| 2453 | goto out; |
| 2454 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2455 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2456 | key.def_uni, key.def_multi); |
| 2457 | |
| 2458 | if (err) |
| 2459 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2460 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2461 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2462 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2463 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2464 | } else { |
| 2465 | if (key.def_uni || !key.def_multi) { |
| 2466 | err = -EINVAL; |
| 2467 | goto out; |
| 2468 | } |
| 2469 | |
| 2470 | if (!rdev->ops->set_default_mgmt_key) { |
| 2471 | err = -EOPNOTSUPP; |
| 2472 | goto out; |
| 2473 | } |
| 2474 | |
| 2475 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2476 | if (err) |
| 2477 | goto out; |
| 2478 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2479 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2480 | if (err) |
| 2481 | goto out; |
| 2482 | |
| 2483 | #ifdef CONFIG_CFG80211_WEXT |
| 2484 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2485 | #endif |
| 2486 | } |
| 2487 | |
| 2488 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2489 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2490 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2491 | return err; |
| 2492 | } |
| 2493 | |
| 2494 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2495 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2496 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2497 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2498 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2499 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2500 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2501 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2502 | err = nl80211_parse_key(info, &key); |
| 2503 | if (err) |
| 2504 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2505 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2506 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2507 | return -EINVAL; |
| 2508 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2509 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2510 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2511 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2512 | if (key.type == -1) { |
| 2513 | if (mac_addr) |
| 2514 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2515 | else |
| 2516 | key.type = NL80211_KEYTYPE_GROUP; |
| 2517 | } |
| 2518 | |
| 2519 | /* for now */ |
| 2520 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2521 | key.type != NL80211_KEYTYPE_GROUP) |
| 2522 | return -EINVAL; |
| 2523 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2524 | if (!rdev->ops->add_key) |
| 2525 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2526 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2527 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2528 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2529 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2530 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2531 | |
| 2532 | wdev_lock(dev->ieee80211_ptr); |
| 2533 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2534 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2535 | err = rdev_add_key(rdev, dev, key.idx, |
| 2536 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2537 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2538 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2539 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2540 | return err; |
| 2541 | } |
| 2542 | |
| 2543 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2544 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2545 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2546 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2547 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2548 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2549 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2550 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2551 | err = nl80211_parse_key(info, &key); |
| 2552 | if (err) |
| 2553 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2554 | |
| 2555 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2556 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2557 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2558 | if (key.type == -1) { |
| 2559 | if (mac_addr) |
| 2560 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2561 | else |
| 2562 | key.type = NL80211_KEYTYPE_GROUP; |
| 2563 | } |
| 2564 | |
| 2565 | /* for now */ |
| 2566 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2567 | key.type != NL80211_KEYTYPE_GROUP) |
| 2568 | return -EINVAL; |
| 2569 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2570 | if (!rdev->ops->del_key) |
| 2571 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2572 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2573 | wdev_lock(dev->ieee80211_ptr); |
| 2574 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2575 | |
| 2576 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2577 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2578 | err = -ENOENT; |
| 2579 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2580 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2581 | err = rdev_del_key(rdev, dev, key.idx, |
| 2582 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2583 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2584 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2585 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2586 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2587 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2588 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2589 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2590 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2591 | } |
| 2592 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2593 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2594 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2595 | return err; |
| 2596 | } |
| 2597 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2598 | /* This function returns an error or the number of nested attributes */ |
| 2599 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2600 | { |
| 2601 | struct nlattr *attr; |
| 2602 | int n_entries = 0, tmp; |
| 2603 | |
| 2604 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2605 | if (nla_len(attr) != ETH_ALEN) |
| 2606 | return -EINVAL; |
| 2607 | |
| 2608 | n_entries++; |
| 2609 | } |
| 2610 | |
| 2611 | return n_entries; |
| 2612 | } |
| 2613 | |
| 2614 | /* |
| 2615 | * This function parses ACL information and allocates memory for ACL data. |
| 2616 | * On successful return, the calling function is responsible to free the |
| 2617 | * ACL buffer returned by this function. |
| 2618 | */ |
| 2619 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2620 | struct genl_info *info) |
| 2621 | { |
| 2622 | enum nl80211_acl_policy acl_policy; |
| 2623 | struct nlattr *attr; |
| 2624 | struct cfg80211_acl_data *acl; |
| 2625 | int i = 0, n_entries, tmp; |
| 2626 | |
| 2627 | if (!wiphy->max_acl_mac_addrs) |
| 2628 | return ERR_PTR(-EOPNOTSUPP); |
| 2629 | |
| 2630 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2631 | return ERR_PTR(-EINVAL); |
| 2632 | |
| 2633 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2634 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2635 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2636 | return ERR_PTR(-EINVAL); |
| 2637 | |
| 2638 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2639 | return ERR_PTR(-EINVAL); |
| 2640 | |
| 2641 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2642 | if (n_entries < 0) |
| 2643 | return ERR_PTR(n_entries); |
| 2644 | |
| 2645 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2646 | return ERR_PTR(-ENOTSUPP); |
| 2647 | |
| 2648 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2649 | GFP_KERNEL); |
| 2650 | if (!acl) |
| 2651 | return ERR_PTR(-ENOMEM); |
| 2652 | |
| 2653 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2654 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2655 | i++; |
| 2656 | } |
| 2657 | |
| 2658 | acl->n_acl_entries = n_entries; |
| 2659 | acl->acl_policy = acl_policy; |
| 2660 | |
| 2661 | return acl; |
| 2662 | } |
| 2663 | |
| 2664 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2665 | { |
| 2666 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2667 | struct net_device *dev = info->user_ptr[1]; |
| 2668 | struct cfg80211_acl_data *acl; |
| 2669 | int err; |
| 2670 | |
| 2671 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2672 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2673 | return -EOPNOTSUPP; |
| 2674 | |
| 2675 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2676 | return -EINVAL; |
| 2677 | |
| 2678 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2679 | if (IS_ERR(acl)) |
| 2680 | return PTR_ERR(acl); |
| 2681 | |
| 2682 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2683 | |
| 2684 | kfree(acl); |
| 2685 | |
| 2686 | return err; |
| 2687 | } |
| 2688 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2689 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2690 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2691 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2692 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2693 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2694 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2695 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2696 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2697 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2698 | return -EINVAL; |
| 2699 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2700 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2701 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2702 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2703 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2704 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2705 | if (!bcn->head_len) |
| 2706 | return -EINVAL; |
| 2707 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2711 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2712 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2713 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2714 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2715 | } |
| 2716 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2717 | if (!haveinfo) |
| 2718 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2719 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2720 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2721 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2722 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2726 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2727 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2728 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2729 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2730 | } |
| 2731 | |
| 2732 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2733 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2734 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2735 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2736 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2737 | } |
| 2738 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2739 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2740 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2741 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2742 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2743 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2744 | } |
| 2745 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2746 | return 0; |
| 2747 | } |
| 2748 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2749 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2750 | struct cfg80211_ap_settings *params) |
| 2751 | { |
| 2752 | struct wireless_dev *wdev; |
| 2753 | bool ret = false; |
| 2754 | |
| 2755 | mutex_lock(&rdev->devlist_mtx); |
| 2756 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2757 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2758 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2759 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2760 | continue; |
| 2761 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2762 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2763 | continue; |
| 2764 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2765 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2766 | ret = true; |
| 2767 | break; |
| 2768 | } |
| 2769 | |
| 2770 | mutex_unlock(&rdev->devlist_mtx); |
| 2771 | |
| 2772 | return ret; |
| 2773 | } |
| 2774 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2775 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2776 | enum nl80211_auth_type auth_type, |
| 2777 | enum nl80211_commands cmd) |
| 2778 | { |
| 2779 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2780 | return false; |
| 2781 | |
| 2782 | switch (cmd) { |
| 2783 | case NL80211_CMD_AUTHENTICATE: |
| 2784 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2785 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2786 | return false; |
| 2787 | return true; |
| 2788 | case NL80211_CMD_CONNECT: |
| 2789 | case NL80211_CMD_START_AP: |
| 2790 | /* SAE not supported yet */ |
| 2791 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2792 | return false; |
| 2793 | return true; |
| 2794 | default: |
| 2795 | return false; |
| 2796 | } |
| 2797 | } |
| 2798 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2799 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2800 | { |
| 2801 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2802 | struct net_device *dev = info->user_ptr[1]; |
| 2803 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2804 | struct cfg80211_ap_settings params; |
| 2805 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2806 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2807 | |
| 2808 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2809 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2810 | return -EOPNOTSUPP; |
| 2811 | |
| 2812 | if (!rdev->ops->start_ap) |
| 2813 | return -EOPNOTSUPP; |
| 2814 | |
| 2815 | if (wdev->beacon_interval) |
| 2816 | return -EALREADY; |
| 2817 | |
| 2818 | memset(¶ms, 0, sizeof(params)); |
| 2819 | |
| 2820 | /* these are required for START_AP */ |
| 2821 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2822 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2823 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2824 | return -EINVAL; |
| 2825 | |
| 2826 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2827 | if (err) |
| 2828 | return err; |
| 2829 | |
| 2830 | params.beacon_interval = |
| 2831 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2832 | params.dtim_period = |
| 2833 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2834 | |
| 2835 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2836 | if (err) |
| 2837 | return err; |
| 2838 | |
| 2839 | /* |
| 2840 | * In theory, some of these attributes should be required here |
| 2841 | * but since they were not used when the command was originally |
| 2842 | * added, keep them optional for old user space programs to let |
| 2843 | * them continue to work with drivers that do not need the |
| 2844 | * additional information -- drivers must check! |
| 2845 | */ |
| 2846 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2847 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2848 | params.ssid_len = |
| 2849 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2850 | if (params.ssid_len == 0 || |
| 2851 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2852 | return -EINVAL; |
| 2853 | } |
| 2854 | |
| 2855 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2856 | params.hidden_ssid = nla_get_u32( |
| 2857 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2858 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2859 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2860 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2861 | return -EINVAL; |
| 2862 | } |
| 2863 | |
| 2864 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2865 | |
| 2866 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2867 | params.auth_type = nla_get_u32( |
| 2868 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2869 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 2870 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2871 | return -EINVAL; |
| 2872 | } else |
| 2873 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2874 | |
| 2875 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2876 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2877 | if (err) |
| 2878 | return err; |
| 2879 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2880 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2881 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2882 | return -EOPNOTSUPP; |
| 2883 | params.inactivity_timeout = nla_get_u16( |
| 2884 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2885 | } |
| 2886 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 2887 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 2888 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2889 | return -EINVAL; |
| 2890 | params.p2p_ctwindow = |
| 2891 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 2892 | if (params.p2p_ctwindow > 127) |
| 2893 | return -EINVAL; |
| 2894 | if (params.p2p_ctwindow != 0 && |
| 2895 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 2896 | return -EINVAL; |
| 2897 | } |
| 2898 | |
| 2899 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 2900 | u8 tmp; |
| 2901 | |
| 2902 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2903 | return -EINVAL; |
| 2904 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 2905 | if (tmp > 1) |
| 2906 | return -EINVAL; |
| 2907 | params.p2p_opp_ps = tmp; |
| 2908 | if (params.p2p_opp_ps != 0 && |
| 2909 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 2910 | return -EINVAL; |
| 2911 | } |
| 2912 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2913 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2914 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 2915 | if (err) |
| 2916 | return err; |
| 2917 | } else if (wdev->preset_chandef.chan) { |
| 2918 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2919 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2920 | return -EINVAL; |
| 2921 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2922 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2923 | return -EINVAL; |
| 2924 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2925 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 2926 | if (err < 0) |
| 2927 | return err; |
| 2928 | if (err) { |
| 2929 | radar_detect_width = BIT(params.chandef.width); |
| 2930 | params.radar_required = true; |
| 2931 | } |
| 2932 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2933 | mutex_lock(&rdev->devlist_mtx); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2934 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 2935 | params.chandef.chan, |
| 2936 | CHAN_MODE_SHARED, |
| 2937 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2938 | mutex_unlock(&rdev->devlist_mtx); |
| 2939 | |
| 2940 | if (err) |
| 2941 | return err; |
| 2942 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2943 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 2944 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 2945 | if (IS_ERR(params.acl)) |
| 2946 | return PTR_ERR(params.acl); |
| 2947 | } |
| 2948 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2949 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2950 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2951 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2952 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2953 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 2954 | wdev->ssid_len = params.ssid_len; |
| 2955 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2956 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2957 | |
| 2958 | kfree(params.acl); |
| 2959 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2960 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2961 | } |
| 2962 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2963 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2964 | { |
| 2965 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2966 | struct net_device *dev = info->user_ptr[1]; |
| 2967 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2968 | struct cfg80211_beacon_data params; |
| 2969 | int err; |
| 2970 | |
| 2971 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2972 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2973 | return -EOPNOTSUPP; |
| 2974 | |
| 2975 | if (!rdev->ops->change_beacon) |
| 2976 | return -EOPNOTSUPP; |
| 2977 | |
| 2978 | if (!wdev->beacon_interval) |
| 2979 | return -EINVAL; |
| 2980 | |
| 2981 | err = nl80211_parse_beacon(info, ¶ms); |
| 2982 | if (err) |
| 2983 | return err; |
| 2984 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2985 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | 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] | 2989 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2990 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2991 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2992 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2993 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2994 | } |
| 2995 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2996 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2997 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2998 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2999 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3000 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3001 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3002 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3003 | }; |
| 3004 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3005 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3006 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3007 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3008 | { |
| 3009 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3010 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3011 | int flag; |
| 3012 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3013 | /* |
| 3014 | * Try parsing the new attribute first so userspace |
| 3015 | * can specify both for older kernels. |
| 3016 | */ |
| 3017 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3018 | if (nla) { |
| 3019 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3020 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3021 | sta_flags = nla_data(nla); |
| 3022 | params->sta_flags_mask = sta_flags->mask; |
| 3023 | params->sta_flags_set = sta_flags->set; |
| 3024 | if ((params->sta_flags_mask | |
| 3025 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3026 | return -EINVAL; |
| 3027 | return 0; |
| 3028 | } |
| 3029 | |
| 3030 | /* if present, parse the old attribute */ |
| 3031 | |
| 3032 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3033 | if (!nla) |
| 3034 | return 0; |
| 3035 | |
| 3036 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3037 | nla, sta_flags_policy)) |
| 3038 | return -EINVAL; |
| 3039 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3040 | /* |
| 3041 | * Only allow certain flags for interface types so that |
| 3042 | * other attributes are silently ignored. Remember that |
| 3043 | * this is backward compatibility code with old userspace |
| 3044 | * and shouldn't be hit in other cases anyway. |
| 3045 | */ |
| 3046 | switch (iftype) { |
| 3047 | case NL80211_IFTYPE_AP: |
| 3048 | case NL80211_IFTYPE_AP_VLAN: |
| 3049 | case NL80211_IFTYPE_P2P_GO: |
| 3050 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3051 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3052 | BIT(NL80211_STA_FLAG_WME) | |
| 3053 | BIT(NL80211_STA_FLAG_MFP); |
| 3054 | break; |
| 3055 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3056 | case NL80211_IFTYPE_STATION: |
| 3057 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3058 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3059 | break; |
| 3060 | case NL80211_IFTYPE_MESH_POINT: |
| 3061 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3062 | BIT(NL80211_STA_FLAG_MFP) | |
| 3063 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3064 | default: |
| 3065 | return -EINVAL; |
| 3066 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3067 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3068 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3069 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3070 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3071 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3072 | /* no longer support new API additions in old API */ |
| 3073 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3074 | return -EINVAL; |
| 3075 | } |
| 3076 | } |
| 3077 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3078 | return 0; |
| 3079 | } |
| 3080 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3081 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3082 | int attr) |
| 3083 | { |
| 3084 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3085 | u32 bitrate; |
| 3086 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3087 | |
| 3088 | rate = nla_nest_start(msg, attr); |
| 3089 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3090 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3091 | |
| 3092 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3093 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3094 | /* report 16-bit bitrate only if we can */ |
| 3095 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3096 | if (bitrate > 0 && |
| 3097 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3098 | return false; |
| 3099 | if (bitrate_compat > 0 && |
| 3100 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3101 | return false; |
| 3102 | |
| 3103 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3104 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3105 | return false; |
| 3106 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3107 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3108 | return false; |
| 3109 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3110 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3111 | return false; |
| 3112 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3113 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3114 | return false; |
| 3115 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3116 | return false; |
| 3117 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3118 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3119 | return false; |
| 3120 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3121 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3122 | return false; |
| 3123 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3124 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3125 | return false; |
| 3126 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3127 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3128 | return false; |
| 3129 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3130 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3131 | return false; |
| 3132 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3133 | |
| 3134 | nla_nest_end(msg, rate); |
| 3135 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3136 | } |
| 3137 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3138 | 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] | 3139 | int flags, |
| 3140 | struct cfg80211_registered_device *rdev, |
| 3141 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3142 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3143 | { |
| 3144 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3145 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3146 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3147 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3148 | if (!hdr) |
| 3149 | return -1; |
| 3150 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3151 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3152 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3153 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3154 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3155 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3156 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3157 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3158 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3159 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3160 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3161 | sinfo->connected_time)) |
| 3162 | goto nla_put_failure; |
| 3163 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3164 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3165 | sinfo->inactive_time)) |
| 3166 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3167 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3168 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3169 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3170 | (u32)sinfo->rx_bytes)) |
| 3171 | goto nla_put_failure; |
| 3172 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
| 3173 | NL80211_STA_INFO_TX_BYTES64)) && |
| 3174 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3175 | (u32)sinfo->tx_bytes)) |
| 3176 | goto nla_put_failure; |
| 3177 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3178 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3179 | sinfo->rx_bytes)) |
| 3180 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3181 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3182 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3183 | sinfo->tx_bytes)) |
| 3184 | goto nla_put_failure; |
| 3185 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3186 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3187 | goto nla_put_failure; |
| 3188 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3189 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3190 | goto nla_put_failure; |
| 3191 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3192 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3193 | sinfo->plink_state)) |
| 3194 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3195 | switch (rdev->wiphy.signal_type) { |
| 3196 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3197 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3198 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3199 | sinfo->signal)) |
| 3200 | goto nla_put_failure; |
| 3201 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3202 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3203 | sinfo->signal_avg)) |
| 3204 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3205 | break; |
| 3206 | default: |
| 3207 | break; |
| 3208 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3209 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3210 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3211 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3212 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3213 | } |
| 3214 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3215 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3216 | NL80211_STA_INFO_RX_BITRATE)) |
| 3217 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3218 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3219 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3220 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3221 | sinfo->rx_packets)) |
| 3222 | goto nla_put_failure; |
| 3223 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3224 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3225 | sinfo->tx_packets)) |
| 3226 | goto nla_put_failure; |
| 3227 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3228 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3229 | sinfo->tx_retries)) |
| 3230 | goto nla_put_failure; |
| 3231 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3232 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3233 | sinfo->tx_failed)) |
| 3234 | goto nla_put_failure; |
| 3235 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3236 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3237 | sinfo->beacon_loss_count)) |
| 3238 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3239 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3240 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3241 | sinfo->local_pm)) |
| 3242 | goto nla_put_failure; |
| 3243 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3244 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3245 | sinfo->peer_pm)) |
| 3246 | goto nla_put_failure; |
| 3247 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3248 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3249 | sinfo->nonpeer_pm)) |
| 3250 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3251 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3252 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3253 | if (!bss_param) |
| 3254 | goto nla_put_failure; |
| 3255 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3256 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3257 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3258 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3259 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3260 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3261 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3262 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3263 | sinfo->bss_param.dtim_period) || |
| 3264 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3265 | sinfo->bss_param.beacon_interval)) |
| 3266 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3267 | |
| 3268 | nla_nest_end(msg, bss_param); |
| 3269 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3270 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3271 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3272 | sizeof(struct nl80211_sta_flag_update), |
| 3273 | &sinfo->sta_flags)) |
| 3274 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3275 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3276 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3277 | sinfo->t_offset)) |
| 3278 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3279 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3280 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3281 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3282 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3283 | sinfo->assoc_req_ies)) |
| 3284 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3285 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3286 | return genlmsg_end(msg, hdr); |
| 3287 | |
| 3288 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3289 | genlmsg_cancel(msg, hdr); |
| 3290 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3291 | } |
| 3292 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3293 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3294 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3295 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3296 | struct station_info sinfo; |
| 3297 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3298 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3299 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3300 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3301 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3302 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3303 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3304 | if (err) |
| 3305 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3306 | |
| 3307 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3308 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3309 | goto out_err; |
| 3310 | } |
| 3311 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3312 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3313 | memset(&sinfo, 0, sizeof(sinfo)); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3314 | err = rdev_dump_station(dev, netdev, sta_idx, |
| 3315 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3316 | if (err == -ENOENT) |
| 3317 | break; |
| 3318 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3319 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3320 | |
| 3321 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3322 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3323 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3324 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3325 | &sinfo) < 0) |
| 3326 | goto out; |
| 3327 | |
| 3328 | sta_idx++; |
| 3329 | } |
| 3330 | |
| 3331 | |
| 3332 | out: |
| 3333 | cb->args[1] = sta_idx; |
| 3334 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3335 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3336 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3337 | |
| 3338 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3339 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3340 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3341 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3342 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3343 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3344 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3345 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3346 | struct sk_buff *msg; |
| 3347 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3348 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3349 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3350 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3351 | |
| 3352 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3353 | return -EINVAL; |
| 3354 | |
| 3355 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3356 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3357 | if (!rdev->ops->get_station) |
| 3358 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3359 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3360 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3361 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3362 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3363 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3364 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3365 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3366 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3367 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3368 | 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] | 3369 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3370 | nlmsg_free(msg); |
| 3371 | return -ENOBUFS; |
| 3372 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3373 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3374 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3378 | * 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] | 3379 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3380 | static struct net_device *get_vlan(struct genl_info *info, |
| 3381 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3382 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3383 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3384 | struct net_device *v; |
| 3385 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3386 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3387 | if (!vlanattr) |
| 3388 | return NULL; |
| 3389 | |
| 3390 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3391 | if (!v) |
| 3392 | return ERR_PTR(-ENODEV); |
| 3393 | |
| 3394 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3395 | ret = -EINVAL; |
| 3396 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3397 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3398 | |
| 3399 | if (!netif_running(v)) { |
| 3400 | ret = -ENETDOWN; |
| 3401 | goto error; |
| 3402 | } |
| 3403 | |
| 3404 | return v; |
| 3405 | error: |
| 3406 | dev_put(v); |
| 3407 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3408 | } |
| 3409 | |
| 3410 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3411 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3412 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3413 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3414 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3415 | struct station_parameters params; |
| 3416 | u8 *mac_addr = NULL; |
| 3417 | |
| 3418 | memset(¶ms, 0, sizeof(params)); |
| 3419 | |
| 3420 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 3421 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3422 | |
| 3423 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3424 | return -EINVAL; |
| 3425 | |
| 3426 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3427 | return -EINVAL; |
| 3428 | |
| 3429 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3430 | |
| 3431 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3432 | params.supported_rates = |
| 3433 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3434 | params.supported_rates_len = |
| 3435 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3436 | } |
| 3437 | |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3438 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL] || |
| 3439 | info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3440 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3441 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3442 | if (!rdev->ops->change_station) |
| 3443 | return -EOPNOTSUPP; |
| 3444 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3445 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3446 | return -EINVAL; |
| 3447 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3448 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3449 | params.plink_action = |
| 3450 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3451 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3452 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3453 | params.plink_state = |
| 3454 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3455 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3456 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3457 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3458 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3459 | |
| 3460 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3461 | pm > NL80211_MESH_POWER_MAX) |
| 3462 | return -EINVAL; |
| 3463 | |
| 3464 | params.local_pm = pm; |
| 3465 | } |
| 3466 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3467 | switch (dev->ieee80211_ptr->iftype) { |
| 3468 | case NL80211_IFTYPE_AP: |
| 3469 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3470 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3471 | /* disallow mesh-specific things */ |
| 3472 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3473 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3474 | if (params.local_pm) |
| 3475 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3476 | |
| 3477 | /* TDLS can't be set, ... */ |
| 3478 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3479 | return -EINVAL; |
| 3480 | /* |
| 3481 | * ... but don't bother the driver with it. This works around |
| 3482 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3483 | * TLDS_PEER flag in the mask even for AP mode. |
| 3484 | */ |
| 3485 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3486 | |
| 3487 | /* accept only the listed bits */ |
| 3488 | if (params.sta_flags_mask & |
| 3489 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3490 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3491 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3492 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3493 | BIT(NL80211_STA_FLAG_WME) | |
| 3494 | BIT(NL80211_STA_FLAG_MFP))) |
| 3495 | return -EINVAL; |
| 3496 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3497 | /* but authenticated/associated only if driver handles it */ |
| 3498 | if (!(rdev->wiphy.features & |
| 3499 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3500 | params.sta_flags_mask & |
| 3501 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3502 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3503 | return -EINVAL; |
| 3504 | |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3505 | /* reject other things that can't change */ |
| 3506 | if (params.supported_rates) |
| 3507 | return -EINVAL; |
| 3508 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3509 | /* must be last in here for error handling */ |
| 3510 | params.vlan = get_vlan(info, rdev); |
| 3511 | if (IS_ERR(params.vlan)) |
| 3512 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3513 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3514 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3515 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3516 | /* |
| 3517 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3518 | * but silently ignore attempts to change it since we |
| 3519 | * don't have state here to verify that it doesn't try |
| 3520 | * to change the flag. |
| 3521 | */ |
| 3522 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3523 | /* fall through */ |
| 3524 | case NL80211_IFTYPE_ADHOC: |
| 3525 | /* disallow things sta doesn't support */ |
| 3526 | if (params.plink_action) |
| 3527 | return -EINVAL; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3528 | if (params.local_pm) |
| 3529 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3530 | /* reject any changes other than AUTHORIZED */ |
| 3531 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3532 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3533 | break; |
| 3534 | case NL80211_IFTYPE_MESH_POINT: |
| 3535 | /* disallow things mesh doesn't support */ |
| 3536 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3537 | return -EINVAL; |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3538 | if (params.supported_rates) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3539 | return -EINVAL; |
| 3540 | /* |
| 3541 | * No special handling for TDLS here -- the userspace |
| 3542 | * mesh code doesn't have this bug. |
| 3543 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3544 | if (params.sta_flags_mask & |
| 3545 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3546 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3547 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3548 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3549 | break; |
| 3550 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3551 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3552 | } |
| 3553 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3554 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3555 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3556 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3557 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3558 | if (params.vlan) |
| 3559 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3560 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3561 | return err; |
| 3562 | } |
| 3563 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3564 | static struct nla_policy |
| 3565 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3566 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3567 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3568 | }; |
| 3569 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3570 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3571 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3572 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3573 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3574 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3575 | struct station_parameters params; |
| 3576 | u8 *mac_addr = NULL; |
| 3577 | |
| 3578 | memset(¶ms, 0, sizeof(params)); |
| 3579 | |
| 3580 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3581 | return -EINVAL; |
| 3582 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3583 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3584 | return -EINVAL; |
| 3585 | |
| 3586 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3587 | return -EINVAL; |
| 3588 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3589 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3590 | return -EINVAL; |
| 3591 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3592 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3593 | params.supported_rates = |
| 3594 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3595 | params.supported_rates_len = |
| 3596 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3597 | params.listen_interval = |
| 3598 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3599 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3600 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3601 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3602 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3603 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3604 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3605 | params.ht_capa = |
| 3606 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3607 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3608 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3609 | params.vht_capa = |
| 3610 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3611 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3612 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3613 | params.plink_action = |
| 3614 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3615 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3616 | if (!rdev->ops->add_station) |
| 3617 | return -EOPNOTSUPP; |
| 3618 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3619 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3620 | return -EINVAL; |
| 3621 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3622 | switch (dev->ieee80211_ptr->iftype) { |
| 3623 | case NL80211_IFTYPE_AP: |
| 3624 | case NL80211_IFTYPE_AP_VLAN: |
| 3625 | case NL80211_IFTYPE_P2P_GO: |
| 3626 | /* parse WME attributes if sta is WME capable */ |
| 3627 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3628 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3629 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3630 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3631 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3632 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3633 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3634 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3635 | nl80211_sta_wme_policy); |
| 3636 | if (err) |
| 3637 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3638 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3639 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3640 | params.uapsd_queues = |
| 3641 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3642 | if (params.uapsd_queues & |
| 3643 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3644 | return -EINVAL; |
| 3645 | |
| 3646 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3647 | params.max_sp = |
| 3648 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3649 | |
| 3650 | if (params.max_sp & |
| 3651 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3652 | return -EINVAL; |
| 3653 | |
| 3654 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3655 | } |
| 3656 | /* TDLS peers cannot be added */ |
| 3657 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3658 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3659 | /* but don't bother the driver with it */ |
| 3660 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3661 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3662 | /* allow authenticated/associated only if driver handles it */ |
| 3663 | if (!(rdev->wiphy.features & |
| 3664 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3665 | params.sta_flags_mask & |
| 3666 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3667 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3668 | return -EINVAL; |
| 3669 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3670 | /* must be last in here for error handling */ |
| 3671 | params.vlan = get_vlan(info, rdev); |
| 3672 | if (IS_ERR(params.vlan)) |
| 3673 | return PTR_ERR(params.vlan); |
| 3674 | break; |
| 3675 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3676 | /* associated is disallowed */ |
| 3677 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3678 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3679 | /* TDLS peers cannot be added */ |
| 3680 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3681 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3682 | break; |
| 3683 | case NL80211_IFTYPE_STATION: |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 3684 | /* associated is disallowed */ |
| 3685 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 3686 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3687 | /* Only TDLS peers can be added */ |
| 3688 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3689 | return -EINVAL; |
| 3690 | /* Can only add if TDLS ... */ |
| 3691 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3692 | return -EOPNOTSUPP; |
| 3693 | /* ... with external setup is supported */ |
| 3694 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3695 | return -EOPNOTSUPP; |
| 3696 | break; |
| 3697 | default: |
| 3698 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3699 | } |
| 3700 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3701 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3702 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3703 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3704 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3705 | if (params.vlan) |
| 3706 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3707 | return err; |
| 3708 | } |
| 3709 | |
| 3710 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3711 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3712 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3713 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3714 | u8 *mac_addr = NULL; |
| 3715 | |
| 3716 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3717 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3718 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3719 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3720 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3721 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3722 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3723 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3724 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3725 | if (!rdev->ops->del_station) |
| 3726 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3727 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3728 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3729 | } |
| 3730 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3731 | 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] | 3732 | int flags, struct net_device *dev, |
| 3733 | u8 *dst, u8 *next_hop, |
| 3734 | struct mpath_info *pinfo) |
| 3735 | { |
| 3736 | void *hdr; |
| 3737 | struct nlattr *pinfoattr; |
| 3738 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3739 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3740 | if (!hdr) |
| 3741 | return -1; |
| 3742 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3743 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3744 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3745 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3746 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3747 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3748 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3749 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3750 | if (!pinfoattr) |
| 3751 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3752 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3753 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3754 | pinfo->frame_qlen)) |
| 3755 | goto nla_put_failure; |
| 3756 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3757 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3758 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3759 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3760 | pinfo->metric)) || |
| 3761 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3762 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3763 | pinfo->exptime)) || |
| 3764 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3765 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3766 | pinfo->flags)) || |
| 3767 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3768 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3769 | pinfo->discovery_timeout)) || |
| 3770 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3771 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3772 | pinfo->discovery_retries))) |
| 3773 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3774 | |
| 3775 | nla_nest_end(msg, pinfoattr); |
| 3776 | |
| 3777 | return genlmsg_end(msg, hdr); |
| 3778 | |
| 3779 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3780 | genlmsg_cancel(msg, hdr); |
| 3781 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3785 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3786 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3787 | struct mpath_info pinfo; |
| 3788 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3789 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3790 | u8 dst[ETH_ALEN]; |
| 3791 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3792 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3793 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3794 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3795 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3796 | if (err) |
| 3797 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3798 | |
| 3799 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3800 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3801 | goto out_err; |
| 3802 | } |
| 3803 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3804 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3805 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3806 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3807 | } |
| 3808 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3809 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3810 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 3811 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3812 | if (err == -ENOENT) |
| 3813 | break; |
| 3814 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3815 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3816 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3817 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3818 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3819 | netdev, dst, next_hop, |
| 3820 | &pinfo) < 0) |
| 3821 | goto out; |
| 3822 | |
| 3823 | path_idx++; |
| 3824 | } |
| 3825 | |
| 3826 | |
| 3827 | out: |
| 3828 | cb->args[1] = path_idx; |
| 3829 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3830 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3831 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3832 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3836 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3837 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3838 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3839 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3840 | struct mpath_info pinfo; |
| 3841 | struct sk_buff *msg; |
| 3842 | u8 *dst = NULL; |
| 3843 | u8 next_hop[ETH_ALEN]; |
| 3844 | |
| 3845 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3846 | |
| 3847 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3848 | return -EINVAL; |
| 3849 | |
| 3850 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3851 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3852 | if (!rdev->ops->get_mpath) |
| 3853 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3854 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3855 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3856 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3857 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3858 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3859 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3860 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3861 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3862 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3863 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3864 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3865 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3866 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3867 | dev, dst, next_hop, &pinfo) < 0) { |
| 3868 | nlmsg_free(msg); |
| 3869 | return -ENOBUFS; |
| 3870 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3871 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3872 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3873 | } |
| 3874 | |
| 3875 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3876 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3877 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3878 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3879 | u8 *dst = NULL; |
| 3880 | u8 *next_hop = NULL; |
| 3881 | |
| 3882 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3883 | return -EINVAL; |
| 3884 | |
| 3885 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3886 | return -EINVAL; |
| 3887 | |
| 3888 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3889 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3890 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3891 | if (!rdev->ops->change_mpath) |
| 3892 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3893 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3894 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3895 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3896 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3897 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3898 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3899 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3900 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3901 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3903 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3904 | u8 *dst = NULL; |
| 3905 | u8 *next_hop = NULL; |
| 3906 | |
| 3907 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3908 | return -EINVAL; |
| 3909 | |
| 3910 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3911 | return -EINVAL; |
| 3912 | |
| 3913 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3914 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3915 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3916 | if (!rdev->ops->add_mpath) |
| 3917 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3918 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3919 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3920 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3921 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3922 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3926 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3927 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3928 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3929 | u8 *dst = NULL; |
| 3930 | |
| 3931 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3932 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3933 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3934 | if (!rdev->ops->del_mpath) |
| 3935 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3936 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3937 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3938 | } |
| 3939 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3940 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3941 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3942 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3943 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3944 | struct bss_parameters params; |
| 3945 | |
| 3946 | memset(¶ms, 0, sizeof(params)); |
| 3947 | /* default to not changing parameters */ |
| 3948 | params.use_cts_prot = -1; |
| 3949 | params.use_short_preamble = -1; |
| 3950 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3951 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3952 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3953 | params.p2p_ctwindow = -1; |
| 3954 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3955 | |
| 3956 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3957 | params.use_cts_prot = |
| 3958 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3959 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3960 | params.use_short_preamble = |
| 3961 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3962 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3963 | params.use_short_slot_time = |
| 3964 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3965 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3966 | params.basic_rates = |
| 3967 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3968 | params.basic_rates_len = |
| 3969 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3970 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3971 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3972 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3973 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3974 | params.ht_opmode = |
| 3975 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3976 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3977 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3978 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3979 | return -EINVAL; |
| 3980 | params.p2p_ctwindow = |
| 3981 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3982 | if (params.p2p_ctwindow < 0) |
| 3983 | return -EINVAL; |
| 3984 | if (params.p2p_ctwindow != 0 && |
| 3985 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3986 | return -EINVAL; |
| 3987 | } |
| 3988 | |
| 3989 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3990 | u8 tmp; |
| 3991 | |
| 3992 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3993 | return -EINVAL; |
| 3994 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3995 | if (tmp > 1) |
| 3996 | return -EINVAL; |
| 3997 | params.p2p_opp_ps = tmp; |
| 3998 | if (params.p2p_opp_ps && |
| 3999 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4000 | return -EINVAL; |
| 4001 | } |
| 4002 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4003 | if (!rdev->ops->change_bss) |
| 4004 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4005 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4006 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4007 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4008 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4009 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4010 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4011 | } |
| 4012 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4013 | 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] | 4014 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4015 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4016 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4017 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4018 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4019 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4020 | }; |
| 4021 | |
| 4022 | static int parse_reg_rule(struct nlattr *tb[], |
| 4023 | struct ieee80211_reg_rule *reg_rule) |
| 4024 | { |
| 4025 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4026 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4027 | |
| 4028 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4029 | return -EINVAL; |
| 4030 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4031 | return -EINVAL; |
| 4032 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4033 | return -EINVAL; |
| 4034 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4035 | return -EINVAL; |
| 4036 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4037 | return -EINVAL; |
| 4038 | |
| 4039 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4040 | |
| 4041 | freq_range->start_freq_khz = |
| 4042 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4043 | freq_range->end_freq_khz = |
| 4044 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4045 | freq_range->max_bandwidth_khz = |
| 4046 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4047 | |
| 4048 | power_rule->max_eirp = |
| 4049 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4050 | |
| 4051 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4052 | power_rule->max_antenna_gain = |
| 4053 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4054 | |
| 4055 | return 0; |
| 4056 | } |
| 4057 | |
| 4058 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4059 | { |
| 4060 | int r; |
| 4061 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4062 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4063 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4064 | /* |
| 4065 | * You should only get this when cfg80211 hasn't yet initialized |
| 4066 | * completely when built-in to the kernel right between the time |
| 4067 | * window between nl80211_init() and regulatory_init(), if that is |
| 4068 | * even possible. |
| 4069 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4070 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4071 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4072 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4073 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4074 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4075 | |
| 4076 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4077 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4078 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4079 | user_reg_hint_type = |
| 4080 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4081 | else |
| 4082 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4083 | |
| 4084 | switch (user_reg_hint_type) { |
| 4085 | case NL80211_USER_REG_HINT_USER: |
| 4086 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4087 | break; |
| 4088 | default: |
| 4089 | return -EINVAL; |
| 4090 | } |
| 4091 | |
| 4092 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4093 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4094 | return r; |
| 4095 | } |
| 4096 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4097 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4098 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4099 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4100 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4101 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4102 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4103 | struct mesh_config cur_params; |
| 4104 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4105 | void *hdr; |
| 4106 | struct nlattr *pinfoattr; |
| 4107 | struct sk_buff *msg; |
| 4108 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4109 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4110 | return -EOPNOTSUPP; |
| 4111 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4112 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4113 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4114 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4115 | wdev_lock(wdev); |
| 4116 | /* If not connected, get default parameters */ |
| 4117 | if (!wdev->mesh_id_len) |
| 4118 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4119 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4120 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4121 | wdev_unlock(wdev); |
| 4122 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4123 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4124 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4125 | |
| 4126 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4127 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4128 | if (!msg) |
| 4129 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4130 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4131 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4132 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4133 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4134 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4135 | if (!pinfoattr) |
| 4136 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4137 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4138 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4139 | cur_params.dot11MeshRetryTimeout) || |
| 4140 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4141 | cur_params.dot11MeshConfirmTimeout) || |
| 4142 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4143 | cur_params.dot11MeshHoldingTimeout) || |
| 4144 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4145 | cur_params.dot11MeshMaxPeerLinks) || |
| 4146 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4147 | cur_params.dot11MeshMaxRetries) || |
| 4148 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4149 | cur_params.dot11MeshTTL) || |
| 4150 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4151 | cur_params.element_ttl) || |
| 4152 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4153 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4154 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4155 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4156 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4157 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4158 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4159 | cur_params.path_refresh_time) || |
| 4160 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4161 | cur_params.min_discovery_timeout) || |
| 4162 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4163 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4164 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4165 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4166 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4167 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4168 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4169 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4170 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4171 | cur_params.dot11MeshHWMPRootMode) || |
| 4172 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4173 | cur_params.dot11MeshHWMPRannInterval) || |
| 4174 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4175 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4176 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4177 | cur_params.dot11MeshForwarding) || |
| 4178 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4179 | cur_params.rssi_threshold) || |
| 4180 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4181 | cur_params.ht_opmode) || |
| 4182 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4183 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4184 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4185 | cur_params.dot11MeshHWMProotInterval) || |
| 4186 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4187 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4188 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4189 | cur_params.power_mode) || |
| 4190 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
| 4191 | cur_params.dot11MeshAwakeWindowDuration)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4192 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4193 | nla_nest_end(msg, pinfoattr); |
| 4194 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4195 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4196 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4197 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4198 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4199 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4200 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4201 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4202 | } |
| 4203 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4204 | 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] | 4205 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4206 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4207 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4208 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4209 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4210 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4211 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4212 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4213 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4214 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4215 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4216 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4217 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4218 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4219 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4220 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4221 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4222 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4223 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4224 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4225 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4226 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4227 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4228 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4229 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4230 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4231 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4232 | }; |
| 4233 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4234 | static const struct nla_policy |
| 4235 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4236 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4237 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4238 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4239 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4240 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4241 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4242 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4243 | }; |
| 4244 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4245 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4246 | struct mesh_config *cfg, |
| 4247 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4248 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4249 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4250 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4251 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4252 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4253 | do { \ |
| 4254 | if (tb[attr]) { \ |
| 4255 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4256 | return -EINVAL; \ |
| 4257 | cfg->param = fn(tb[attr]); \ |
| 4258 | mask |= (1 << (attr - 1)); \ |
| 4259 | } \ |
| 4260 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4261 | |
| 4262 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4263 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4264 | return -EINVAL; |
| 4265 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4266 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4267 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4268 | return -EINVAL; |
| 4269 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4270 | /* This makes sure that there aren't more than 32 mesh config |
| 4271 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4272 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4273 | |
| 4274 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4275 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4276 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 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, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4279 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4280 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4281 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4282 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4283 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4284 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4285 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4286 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4287 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4288 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4289 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4290 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4291 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4292 | 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] | 4293 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4294 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4295 | 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] | 4296 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4297 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4298 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4299 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4300 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4301 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4302 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4303 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4304 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4305 | 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] | 4306 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4307 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4308 | 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] | 4309 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4310 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4311 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4312 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4313 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4314 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4315 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4316 | 1, 65535, mask, |
| 4317 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4318 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4319 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4320 | 1, 65535, mask, |
| 4321 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4322 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4323 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4324 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4325 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4326 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4327 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4328 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4329 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4330 | nla_get_u8); |
| 4331 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4332 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4333 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4334 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4335 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4336 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4337 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4338 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4339 | mask, NL80211_MESHCONF_FORWARDING, |
| 4340 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4341 | 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] | 4342 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4343 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4344 | 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] | 4345 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4346 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4347 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4348 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4349 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4350 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4351 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4352 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4353 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4354 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4355 | dot11MeshHWMPconfirmationInterval, |
| 4356 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4357 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4358 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4359 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4360 | NL80211_MESH_POWER_ACTIVE, |
| 4361 | NL80211_MESH_POWER_MAX, |
| 4362 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4363 | nla_get_u32); |
| 4364 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4365 | 0, 65535, mask, |
| 4366 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4367 | if (mask_out) |
| 4368 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4369 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4370 | return 0; |
| 4371 | |
| 4372 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4373 | } |
| 4374 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4375 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4376 | struct mesh_setup *setup) |
| 4377 | { |
| 4378 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4379 | |
| 4380 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4381 | return -EINVAL; |
| 4382 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4383 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4384 | nl80211_mesh_setup_params_policy)) |
| 4385 | return -EINVAL; |
| 4386 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4387 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4388 | setup->sync_method = |
| 4389 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4390 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4391 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4392 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4393 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4394 | setup->path_sel_proto = |
| 4395 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4396 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4397 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4398 | |
| 4399 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4400 | setup->path_metric = |
| 4401 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4402 | IEEE80211_PATH_METRIC_VENDOR : |
| 4403 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4404 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4405 | |
| 4406 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4407 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4408 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4409 | if (!is_valid_ie_attr(ieattr)) |
| 4410 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4411 | setup->ie = nla_data(ieattr); |
| 4412 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4413 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4414 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4415 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4416 | |
| 4417 | return 0; |
| 4418 | } |
| 4419 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4420 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4421 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4422 | { |
| 4423 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4424 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4425 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4426 | struct mesh_config cfg; |
| 4427 | u32 mask; |
| 4428 | int err; |
| 4429 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4430 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4431 | return -EOPNOTSUPP; |
| 4432 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4433 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4434 | return -EOPNOTSUPP; |
| 4435 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4436 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4437 | if (err) |
| 4438 | return err; |
| 4439 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4440 | wdev_lock(wdev); |
| 4441 | if (!wdev->mesh_id_len) |
| 4442 | err = -ENOLINK; |
| 4443 | |
| 4444 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4445 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4446 | |
| 4447 | wdev_unlock(wdev); |
| 4448 | |
| 4449 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4450 | } |
| 4451 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4452 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4453 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4454 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4455 | struct sk_buff *msg; |
| 4456 | void *hdr = NULL; |
| 4457 | struct nlattr *nl_reg_rules; |
| 4458 | unsigned int i; |
| 4459 | int err = -EINVAL; |
| 4460 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4461 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4462 | |
| 4463 | if (!cfg80211_regdomain) |
| 4464 | goto out; |
| 4465 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4466 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4467 | if (!msg) { |
| 4468 | err = -ENOBUFS; |
| 4469 | goto out; |
| 4470 | } |
| 4471 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4472 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4473 | NL80211_CMD_GET_REG); |
| 4474 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4475 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4476 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4477 | if (reg_last_request_cell_base() && |
| 4478 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4479 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4480 | goto nla_put_failure; |
| 4481 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4482 | rcu_read_lock(); |
| 4483 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4484 | |
| 4485 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4486 | (regdom->dfs_region && |
| 4487 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4488 | goto nla_put_failure_rcu; |
| 4489 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4490 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4491 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4492 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4493 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4494 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4495 | struct nlattr *nl_reg_rule; |
| 4496 | const struct ieee80211_reg_rule *reg_rule; |
| 4497 | const struct ieee80211_freq_range *freq_range; |
| 4498 | const struct ieee80211_power_rule *power_rule; |
| 4499 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4500 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4501 | freq_range = ®_rule->freq_range; |
| 4502 | power_rule = ®_rule->power_rule; |
| 4503 | |
| 4504 | nl_reg_rule = nla_nest_start(msg, i); |
| 4505 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4506 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4507 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4508 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4509 | reg_rule->flags) || |
| 4510 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4511 | freq_range->start_freq_khz) || |
| 4512 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4513 | freq_range->end_freq_khz) || |
| 4514 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4515 | freq_range->max_bandwidth_khz) || |
| 4516 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4517 | power_rule->max_antenna_gain) || |
| 4518 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4519 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4520 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4521 | |
| 4522 | nla_nest_end(msg, nl_reg_rule); |
| 4523 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4524 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4525 | |
| 4526 | nla_nest_end(msg, nl_reg_rules); |
| 4527 | |
| 4528 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4529 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4530 | goto out; |
| 4531 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4532 | nla_put_failure_rcu: |
| 4533 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4534 | nla_put_failure: |
| 4535 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4536 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4537 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4538 | err = -EMSGSIZE; |
| 4539 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4540 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4541 | return err; |
| 4542 | } |
| 4543 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4544 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4545 | { |
| 4546 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4547 | struct nlattr *nl_reg_rule; |
| 4548 | char *alpha2 = NULL; |
| 4549 | int rem_reg_rules = 0, r = 0; |
| 4550 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4551 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4552 | struct ieee80211_regdomain *rd = NULL; |
| 4553 | |
| 4554 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4555 | return -EINVAL; |
| 4556 | |
| 4557 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4558 | return -EINVAL; |
| 4559 | |
| 4560 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4561 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4562 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4563 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4564 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4565 | 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] | 4566 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4567 | num_rules++; |
| 4568 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4569 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4570 | } |
| 4571 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4572 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4573 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4574 | |
| 4575 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4576 | if (!rd) |
| 4577 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4578 | |
| 4579 | rd->n_reg_rules = num_rules; |
| 4580 | rd->alpha2[0] = alpha2[0]; |
| 4581 | rd->alpha2[1] = alpha2[1]; |
| 4582 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4583 | /* |
| 4584 | * Disable DFS master mode if the DFS region was |
| 4585 | * not supported or known on this kernel. |
| 4586 | */ |
| 4587 | if (reg_supported_dfs_region(dfs_region)) |
| 4588 | rd->dfs_region = dfs_region; |
| 4589 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4590 | 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] | 4591 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4592 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4593 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4594 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4595 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4596 | if (r) |
| 4597 | goto bad_reg; |
| 4598 | |
| 4599 | rule_idx++; |
| 4600 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4601 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4602 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4603 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4604 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4605 | } |
| 4606 | |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4607 | mutex_lock(&cfg80211_mutex); |
| 4608 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4609 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4610 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4611 | rd = NULL; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4612 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4613 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4614 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4615 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4616 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4617 | } |
| 4618 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4619 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4620 | { |
| 4621 | struct nlattr *attr1, *attr2; |
| 4622 | int n_channels = 0, tmp1, tmp2; |
| 4623 | |
| 4624 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4625 | n_channels++; |
| 4626 | /* |
| 4627 | * Some hardware has a limited channel list for |
| 4628 | * scanning, and it is pretty much nonsensical |
| 4629 | * to scan for a channel twice, so disallow that |
| 4630 | * and don't require drivers to check that the |
| 4631 | * channel list they get isn't longer than what |
| 4632 | * they can scan, as long as they can scan all |
| 4633 | * the channels they registered at once. |
| 4634 | */ |
| 4635 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4636 | if (attr1 != attr2 && |
| 4637 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4638 | return 0; |
| 4639 | } |
| 4640 | |
| 4641 | return n_channels; |
| 4642 | } |
| 4643 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4644 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4645 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4646 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4647 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4648 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4649 | struct nlattr *attr; |
| 4650 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4651 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4652 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4653 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4654 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4655 | return -EINVAL; |
| 4656 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4657 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4658 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4659 | if (!rdev->ops->scan) |
| 4660 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4661 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4662 | if (rdev->scan_req) |
| 4663 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4664 | |
| 4665 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4666 | n_channels = validate_scan_freqs( |
| 4667 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4668 | if (!n_channels) |
| 4669 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4670 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4671 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4672 | n_channels = 0; |
| 4673 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4674 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4675 | if (wiphy->bands[band]) |
| 4676 | n_channels += wiphy->bands[band]->n_channels; |
| 4677 | } |
| 4678 | |
| 4679 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4680 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4681 | n_ssids++; |
| 4682 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4683 | if (n_ssids > wiphy->max_scan_ssids) |
| 4684 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4685 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4686 | if (info->attrs[NL80211_ATTR_IE]) |
| 4687 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4688 | else |
| 4689 | ie_len = 0; |
| 4690 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4691 | if (ie_len > wiphy->max_scan_ie_len) |
| 4692 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4693 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4694 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4695 | + sizeof(*request->ssids) * n_ssids |
| 4696 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4697 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4698 | if (!request) |
| 4699 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4700 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4701 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4702 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4703 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4704 | if (ie_len) { |
| 4705 | if (request->ssids) |
| 4706 | request->ie = (void *)(request->ssids + n_ssids); |
| 4707 | else |
| 4708 | request->ie = (void *)(request->channels + n_channels); |
| 4709 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4710 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4711 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4712 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4713 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4714 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4715 | struct ieee80211_channel *chan; |
| 4716 | |
| 4717 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4718 | |
| 4719 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4720 | err = -EINVAL; |
| 4721 | goto out_free; |
| 4722 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4723 | |
| 4724 | /* ignore disabled channels */ |
| 4725 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4726 | continue; |
| 4727 | |
| 4728 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4729 | i++; |
| 4730 | } |
| 4731 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4732 | enum ieee80211_band band; |
| 4733 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4734 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4735 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4736 | int j; |
| 4737 | if (!wiphy->bands[band]) |
| 4738 | continue; |
| 4739 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4740 | struct ieee80211_channel *chan; |
| 4741 | |
| 4742 | chan = &wiphy->bands[band]->channels[j]; |
| 4743 | |
| 4744 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4745 | continue; |
| 4746 | |
| 4747 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4748 | i++; |
| 4749 | } |
| 4750 | } |
| 4751 | } |
| 4752 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4753 | if (!i) { |
| 4754 | err = -EINVAL; |
| 4755 | goto out_free; |
| 4756 | } |
| 4757 | |
| 4758 | request->n_channels = i; |
| 4759 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4760 | i = 0; |
| 4761 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4762 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4763 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4764 | err = -EINVAL; |
| 4765 | goto out_free; |
| 4766 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4767 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4768 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4769 | i++; |
| 4770 | } |
| 4771 | } |
| 4772 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4773 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4774 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4775 | memcpy((void *)request->ie, |
| 4776 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4777 | request->ie_len); |
| 4778 | } |
| 4779 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4780 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4781 | if (wiphy->bands[i]) |
| 4782 | request->rates[i] = |
| 4783 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4784 | |
| 4785 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4786 | nla_for_each_nested(attr, |
| 4787 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4788 | tmp) { |
| 4789 | enum ieee80211_band band = nla_type(attr); |
| 4790 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4791 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4792 | err = -EINVAL; |
| 4793 | goto out_free; |
| 4794 | } |
| 4795 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4796 | nla_data(attr), |
| 4797 | nla_len(attr), |
| 4798 | &request->rates[band]); |
| 4799 | if (err) |
| 4800 | goto out_free; |
| 4801 | } |
| 4802 | } |
| 4803 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4804 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4805 | request->flags = nla_get_u32( |
| 4806 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4807 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4808 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4809 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4810 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4811 | err = -EOPNOTSUPP; |
| 4812 | goto out_free; |
| 4813 | } |
| 4814 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4815 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4816 | request->no_cck = |
| 4817 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4818 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4819 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4820 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4821 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4822 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4823 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4824 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4825 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4826 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4827 | nl80211_send_scan_start(rdev, wdev); |
| 4828 | if (wdev->netdev) |
| 4829 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4830 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4831 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4832 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4833 | kfree(request); |
| 4834 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4835 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4836 | return err; |
| 4837 | } |
| 4838 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4839 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4840 | struct genl_info *info) |
| 4841 | { |
| 4842 | struct cfg80211_sched_scan_request *request; |
| 4843 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4844 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4845 | struct nlattr *attr; |
| 4846 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4847 | 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] | 4848 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4849 | enum ieee80211_band band; |
| 4850 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4851 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4852 | |
| 4853 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4854 | !rdev->ops->sched_scan_start) |
| 4855 | return -EOPNOTSUPP; |
| 4856 | |
| 4857 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4858 | return -EINVAL; |
| 4859 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4860 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4861 | return -EINVAL; |
| 4862 | |
| 4863 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4864 | if (interval == 0) |
| 4865 | return -EINVAL; |
| 4866 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4867 | wiphy = &rdev->wiphy; |
| 4868 | |
| 4869 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4870 | n_channels = validate_scan_freqs( |
| 4871 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4872 | if (!n_channels) |
| 4873 | return -EINVAL; |
| 4874 | } else { |
| 4875 | n_channels = 0; |
| 4876 | |
| 4877 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4878 | if (wiphy->bands[band]) |
| 4879 | n_channels += wiphy->bands[band]->n_channels; |
| 4880 | } |
| 4881 | |
| 4882 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4883 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4884 | tmp) |
| 4885 | n_ssids++; |
| 4886 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4887 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4888 | return -EINVAL; |
| 4889 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4890 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4891 | nla_for_each_nested(attr, |
| 4892 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4893 | tmp) |
| 4894 | n_match_sets++; |
| 4895 | |
| 4896 | if (n_match_sets > wiphy->max_match_sets) |
| 4897 | return -EINVAL; |
| 4898 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4899 | if (info->attrs[NL80211_ATTR_IE]) |
| 4900 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4901 | else |
| 4902 | ie_len = 0; |
| 4903 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4904 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4905 | return -EINVAL; |
| 4906 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4907 | mutex_lock(&rdev->sched_scan_mtx); |
| 4908 | |
| 4909 | if (rdev->sched_scan_req) { |
| 4910 | err = -EINPROGRESS; |
| 4911 | goto out; |
| 4912 | } |
| 4913 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4914 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4915 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4916 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4917 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4918 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4919 | if (!request) { |
| 4920 | err = -ENOMEM; |
| 4921 | goto out; |
| 4922 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4923 | |
| 4924 | if (n_ssids) |
| 4925 | request->ssids = (void *)&request->channels[n_channels]; |
| 4926 | request->n_ssids = n_ssids; |
| 4927 | if (ie_len) { |
| 4928 | if (request->ssids) |
| 4929 | request->ie = (void *)(request->ssids + n_ssids); |
| 4930 | else |
| 4931 | request->ie = (void *)(request->channels + n_channels); |
| 4932 | } |
| 4933 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4934 | if (n_match_sets) { |
| 4935 | if (request->ie) |
| 4936 | request->match_sets = (void *)(request->ie + ie_len); |
| 4937 | else if (request->ssids) |
| 4938 | request->match_sets = |
| 4939 | (void *)(request->ssids + n_ssids); |
| 4940 | else |
| 4941 | request->match_sets = |
| 4942 | (void *)(request->channels + n_channels); |
| 4943 | } |
| 4944 | request->n_match_sets = n_match_sets; |
| 4945 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4946 | i = 0; |
| 4947 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4948 | /* user specified, bail out if channel not found */ |
| 4949 | nla_for_each_nested(attr, |
| 4950 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4951 | tmp) { |
| 4952 | struct ieee80211_channel *chan; |
| 4953 | |
| 4954 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4955 | |
| 4956 | if (!chan) { |
| 4957 | err = -EINVAL; |
| 4958 | goto out_free; |
| 4959 | } |
| 4960 | |
| 4961 | /* ignore disabled channels */ |
| 4962 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4963 | continue; |
| 4964 | |
| 4965 | request->channels[i] = chan; |
| 4966 | i++; |
| 4967 | } |
| 4968 | } else { |
| 4969 | /* all channels */ |
| 4970 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4971 | int j; |
| 4972 | if (!wiphy->bands[band]) |
| 4973 | continue; |
| 4974 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4975 | struct ieee80211_channel *chan; |
| 4976 | |
| 4977 | chan = &wiphy->bands[band]->channels[j]; |
| 4978 | |
| 4979 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4980 | continue; |
| 4981 | |
| 4982 | request->channels[i] = chan; |
| 4983 | i++; |
| 4984 | } |
| 4985 | } |
| 4986 | } |
| 4987 | |
| 4988 | if (!i) { |
| 4989 | err = -EINVAL; |
| 4990 | goto out_free; |
| 4991 | } |
| 4992 | |
| 4993 | request->n_channels = i; |
| 4994 | |
| 4995 | i = 0; |
| 4996 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4997 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4998 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4999 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5000 | err = -EINVAL; |
| 5001 | goto out_free; |
| 5002 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5003 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5004 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5005 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5006 | i++; |
| 5007 | } |
| 5008 | } |
| 5009 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5010 | i = 0; |
| 5011 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5012 | nla_for_each_nested(attr, |
| 5013 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5014 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5015 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5016 | |
| 5017 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5018 | nla_data(attr), nla_len(attr), |
| 5019 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5020 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5021 | if (ssid) { |
| 5022 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5023 | err = -EINVAL; |
| 5024 | goto out_free; |
| 5025 | } |
| 5026 | memcpy(request->match_sets[i].ssid.ssid, |
| 5027 | nla_data(ssid), nla_len(ssid)); |
| 5028 | request->match_sets[i].ssid.ssid_len = |
| 5029 | nla_len(ssid); |
| 5030 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5031 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5032 | if (rssi) |
| 5033 | request->rssi_thold = nla_get_u32(rssi); |
| 5034 | else |
| 5035 | request->rssi_thold = |
| 5036 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5037 | i++; |
| 5038 | } |
| 5039 | } |
| 5040 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5041 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5042 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5043 | memcpy((void *)request->ie, |
| 5044 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5045 | request->ie_len); |
| 5046 | } |
| 5047 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5048 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5049 | request->flags = nla_get_u32( |
| 5050 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5051 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5052 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5053 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5054 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5055 | err = -EOPNOTSUPP; |
| 5056 | goto out_free; |
| 5057 | } |
| 5058 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5059 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5060 | request->dev = dev; |
| 5061 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5062 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5063 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5064 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5065 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5066 | if (!err) { |
| 5067 | rdev->sched_scan_req = request; |
| 5068 | nl80211_send_sched_scan(rdev, dev, |
| 5069 | NL80211_CMD_START_SCHED_SCAN); |
| 5070 | goto out; |
| 5071 | } |
| 5072 | |
| 5073 | out_free: |
| 5074 | kfree(request); |
| 5075 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5076 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5077 | return err; |
| 5078 | } |
| 5079 | |
| 5080 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5081 | struct genl_info *info) |
| 5082 | { |
| 5083 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5084 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5085 | |
| 5086 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5087 | !rdev->ops->sched_scan_stop) |
| 5088 | return -EOPNOTSUPP; |
| 5089 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5090 | mutex_lock(&rdev->sched_scan_mtx); |
| 5091 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 5092 | mutex_unlock(&rdev->sched_scan_mtx); |
| 5093 | |
| 5094 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5095 | } |
| 5096 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5097 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5098 | struct genl_info *info) |
| 5099 | { |
| 5100 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5101 | struct net_device *dev = info->user_ptr[1]; |
| 5102 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5103 | struct cfg80211_chan_def chandef; |
| 5104 | int err; |
| 5105 | |
| 5106 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5107 | if (err) |
| 5108 | return err; |
| 5109 | |
| 5110 | if (wdev->cac_started) |
| 5111 | return -EBUSY; |
| 5112 | |
| 5113 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5114 | if (err < 0) |
| 5115 | return err; |
| 5116 | |
| 5117 | if (err == 0) |
| 5118 | return -EINVAL; |
| 5119 | |
| 5120 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5121 | return -EINVAL; |
| 5122 | |
| 5123 | if (!rdev->ops->start_radar_detection) |
| 5124 | return -EOPNOTSUPP; |
| 5125 | |
| 5126 | mutex_lock(&rdev->devlist_mtx); |
| 5127 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5128 | chandef.chan, CHAN_MODE_SHARED, |
| 5129 | BIT(chandef.width)); |
| 5130 | if (err) |
| 5131 | goto err_locked; |
| 5132 | |
| 5133 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5134 | if (!err) { |
| 5135 | wdev->channel = chandef.chan; |
| 5136 | wdev->cac_started = true; |
| 5137 | wdev->cac_start_time = jiffies; |
| 5138 | } |
| 5139 | err_locked: |
| 5140 | mutex_unlock(&rdev->devlist_mtx); |
| 5141 | |
| 5142 | return err; |
| 5143 | } |
| 5144 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5145 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5146 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5147 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5148 | struct wireless_dev *wdev, |
| 5149 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5150 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5151 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5152 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5153 | void *hdr; |
| 5154 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5155 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5156 | |
| 5157 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5158 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5159 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5160 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5161 | if (!hdr) |
| 5162 | return -1; |
| 5163 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5164 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5165 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5166 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 5167 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5168 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5169 | |
| 5170 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5171 | if (!bss) |
| 5172 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5173 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5174 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5175 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5176 | |
| 5177 | rcu_read_lock(); |
| 5178 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5179 | if (ies) { |
| 5180 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5181 | goto fail_unlock_rcu; |
| 5182 | tsf = true; |
| 5183 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5184 | ies->len, ies->data)) |
| 5185 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5186 | } |
| 5187 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5188 | if (ies) { |
| 5189 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5190 | goto fail_unlock_rcu; |
| 5191 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5192 | ies->len, ies->data)) |
| 5193 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5194 | } |
| 5195 | rcu_read_unlock(); |
| 5196 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5197 | if (res->beacon_interval && |
| 5198 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5199 | goto nla_put_failure; |
| 5200 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5201 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5202 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5203 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5204 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5205 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5206 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5207 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5208 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5209 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5210 | break; |
| 5211 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5212 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5213 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5214 | break; |
| 5215 | default: |
| 5216 | break; |
| 5217 | } |
| 5218 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5219 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5220 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5221 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5222 | if (intbss == wdev->current_bss && |
| 5223 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5224 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5225 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5226 | break; |
| 5227 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5228 | if (intbss == wdev->current_bss && |
| 5229 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5230 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5231 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5232 | break; |
| 5233 | default: |
| 5234 | break; |
| 5235 | } |
| 5236 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5237 | nla_nest_end(msg, bss); |
| 5238 | |
| 5239 | return genlmsg_end(msg, hdr); |
| 5240 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5241 | fail_unlock_rcu: |
| 5242 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5243 | nla_put_failure: |
| 5244 | genlmsg_cancel(msg, hdr); |
| 5245 | return -EMSGSIZE; |
| 5246 | } |
| 5247 | |
| 5248 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 5249 | struct netlink_callback *cb) |
| 5250 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5251 | struct cfg80211_registered_device *rdev; |
| 5252 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5253 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5254 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5255 | int start = cb->args[1], idx = 0; |
| 5256 | int err; |
| 5257 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5258 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 5259 | if (err) |
| 5260 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5261 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5262 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5263 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5264 | wdev_lock(wdev); |
| 5265 | spin_lock_bh(&rdev->bss_lock); |
| 5266 | cfg80211_bss_expire(rdev); |
| 5267 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5268 | cb->seq = rdev->bss_generation; |
| 5269 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5270 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5271 | if (++idx <= start) |
| 5272 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5273 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5274 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5275 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5276 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5277 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5278 | } |
| 5279 | } |
| 5280 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5281 | spin_unlock_bh(&rdev->bss_lock); |
| 5282 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5283 | |
| 5284 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5285 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5286 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5287 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5288 | } |
| 5289 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5290 | 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] | 5291 | int flags, struct net_device *dev, |
| 5292 | struct survey_info *survey) |
| 5293 | { |
| 5294 | void *hdr; |
| 5295 | struct nlattr *infoattr; |
| 5296 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5297 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5298 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5299 | if (!hdr) |
| 5300 | return -ENOMEM; |
| 5301 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5302 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5303 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5304 | |
| 5305 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5306 | if (!infoattr) |
| 5307 | goto nla_put_failure; |
| 5308 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5309 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5310 | survey->channel->center_freq)) |
| 5311 | goto nla_put_failure; |
| 5312 | |
| 5313 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5314 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5315 | goto nla_put_failure; |
| 5316 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5317 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5318 | goto nla_put_failure; |
| 5319 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5320 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5321 | survey->channel_time)) |
| 5322 | goto nla_put_failure; |
| 5323 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5324 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5325 | survey->channel_time_busy)) |
| 5326 | goto nla_put_failure; |
| 5327 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5328 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5329 | survey->channel_time_ext_busy)) |
| 5330 | goto nla_put_failure; |
| 5331 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5332 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5333 | survey->channel_time_rx)) |
| 5334 | goto nla_put_failure; |
| 5335 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5336 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5337 | survey->channel_time_tx)) |
| 5338 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5339 | |
| 5340 | nla_nest_end(msg, infoattr); |
| 5341 | |
| 5342 | return genlmsg_end(msg, hdr); |
| 5343 | |
| 5344 | nla_put_failure: |
| 5345 | genlmsg_cancel(msg, hdr); |
| 5346 | return -EMSGSIZE; |
| 5347 | } |
| 5348 | |
| 5349 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5350 | struct netlink_callback *cb) |
| 5351 | { |
| 5352 | struct survey_info survey; |
| 5353 | struct cfg80211_registered_device *dev; |
| 5354 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5355 | int survey_idx = cb->args[1]; |
| 5356 | int res; |
| 5357 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5358 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 5359 | if (res) |
| 5360 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5361 | |
| 5362 | if (!dev->ops->dump_survey) { |
| 5363 | res = -EOPNOTSUPP; |
| 5364 | goto out_err; |
| 5365 | } |
| 5366 | |
| 5367 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5368 | struct ieee80211_channel *chan; |
| 5369 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5370 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5371 | if (res == -ENOENT) |
| 5372 | break; |
| 5373 | if (res) |
| 5374 | goto out_err; |
| 5375 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5376 | /* Survey without a channel doesn't make sense */ |
| 5377 | if (!survey.channel) { |
| 5378 | res = -EINVAL; |
| 5379 | goto out; |
| 5380 | } |
| 5381 | |
| 5382 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5383 | survey.channel->center_freq); |
| 5384 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5385 | survey_idx++; |
| 5386 | continue; |
| 5387 | } |
| 5388 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5389 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5390 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5391 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5392 | netdev, |
| 5393 | &survey) < 0) |
| 5394 | goto out; |
| 5395 | survey_idx++; |
| 5396 | } |
| 5397 | |
| 5398 | out: |
| 5399 | cb->args[1] = survey_idx; |
| 5400 | res = skb->len; |
| 5401 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5402 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5403 | return res; |
| 5404 | } |
| 5405 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5406 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5407 | { |
| 5408 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5409 | NL80211_WPA_VERSION_2)); |
| 5410 | } |
| 5411 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5412 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5413 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5414 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5415 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5416 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5417 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5418 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5419 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5420 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5421 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5422 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5423 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5424 | return -EINVAL; |
| 5425 | |
| 5426 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5427 | return -EINVAL; |
| 5428 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5429 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5430 | return -EINVAL; |
| 5431 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5432 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5433 | return -EINVAL; |
| 5434 | |
| 5435 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5436 | return -EINVAL; |
| 5437 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5438 | err = nl80211_parse_key(info, &key); |
| 5439 | if (err) |
| 5440 | return err; |
| 5441 | |
| 5442 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5443 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5444 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5445 | if (!key.p.key || !key.p.key_len) |
| 5446 | return -EINVAL; |
| 5447 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5448 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5449 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5450 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5451 | return -EINVAL; |
| 5452 | if (key.idx > 4) |
| 5453 | return -EINVAL; |
| 5454 | } else { |
| 5455 | key.p.key_len = 0; |
| 5456 | key.p.key = NULL; |
| 5457 | } |
| 5458 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5459 | if (key.idx >= 0) { |
| 5460 | int i; |
| 5461 | bool ok = false; |
| 5462 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5463 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5464 | ok = true; |
| 5465 | break; |
| 5466 | } |
| 5467 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5468 | if (!ok) |
| 5469 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5470 | } |
| 5471 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5472 | if (!rdev->ops->auth) |
| 5473 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5474 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5475 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5476 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5477 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5478 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5479 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5480 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5481 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5482 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5483 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5484 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5485 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5486 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5487 | |
| 5488 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5489 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5490 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5491 | } |
| 5492 | |
| 5493 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5494 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5495 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5496 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5497 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5498 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5499 | return -EINVAL; |
| 5500 | |
| 5501 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5502 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5503 | return -EINVAL; |
| 5504 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5505 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5506 | /* need to include at least Auth Transaction and Status Code */ |
| 5507 | if (sae_data_len < 4) |
| 5508 | return -EINVAL; |
| 5509 | } |
| 5510 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5511 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5512 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5513 | /* |
| 5514 | * Since we no longer track auth state, ignore |
| 5515 | * requests to only change local state. |
| 5516 | */ |
| 5517 | if (local_state_change) |
| 5518 | return 0; |
| 5519 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5520 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5521 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5522 | key.p.key, key.p.key_len, key.idx, |
| 5523 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5524 | } |
| 5525 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5526 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5527 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5528 | struct cfg80211_crypto_settings *settings, |
| 5529 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5530 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5531 | memset(settings, 0, sizeof(*settings)); |
| 5532 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5533 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5534 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5535 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5536 | u16 proto; |
| 5537 | proto = nla_get_u16( |
| 5538 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5539 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5540 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5541 | proto != ETH_P_PAE) |
| 5542 | return -EINVAL; |
| 5543 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5544 | settings->control_port_no_encrypt = true; |
| 5545 | } else |
| 5546 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5547 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5548 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5549 | void *data; |
| 5550 | int len, i; |
| 5551 | |
| 5552 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5553 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5554 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5555 | |
| 5556 | if (len % sizeof(u32)) |
| 5557 | return -EINVAL; |
| 5558 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5559 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5560 | return -EINVAL; |
| 5561 | |
| 5562 | memcpy(settings->ciphers_pairwise, data, len); |
| 5563 | |
| 5564 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5565 | if (!cfg80211_supported_cipher_suite( |
| 5566 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5567 | settings->ciphers_pairwise[i])) |
| 5568 | return -EINVAL; |
| 5569 | } |
| 5570 | |
| 5571 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5572 | settings->cipher_group = |
| 5573 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5574 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5575 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5576 | return -EINVAL; |
| 5577 | } |
| 5578 | |
| 5579 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5580 | settings->wpa_versions = |
| 5581 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5582 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5583 | return -EINVAL; |
| 5584 | } |
| 5585 | |
| 5586 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5587 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5588 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5589 | |
| 5590 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5591 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5592 | settings->n_akm_suites = len / sizeof(u32); |
| 5593 | |
| 5594 | if (len % sizeof(u32)) |
| 5595 | return -EINVAL; |
| 5596 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5597 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5598 | return -EINVAL; |
| 5599 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5600 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | return 0; |
| 5604 | } |
| 5605 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5606 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5607 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5608 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5609 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5610 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5611 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5612 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5613 | int err, ssid_len, ie_len = 0; |
| 5614 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5615 | u32 flags = 0; |
| 5616 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5617 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5618 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5619 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5620 | return -EINVAL; |
| 5621 | |
| 5622 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5623 | !info->attrs[NL80211_ATTR_SSID] || |
| 5624 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5625 | return -EINVAL; |
| 5626 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5627 | if (!rdev->ops->assoc) |
| 5628 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5629 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5630 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5631 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5632 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5633 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5634 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5635 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5636 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5637 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5638 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5639 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5640 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5641 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5642 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5643 | |
| 5644 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5645 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5646 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5647 | } |
| 5648 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5649 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5650 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5651 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5652 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5653 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5654 | else if (mfp != NL80211_MFP_NO) |
| 5655 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5656 | } |
| 5657 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5658 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5659 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5660 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5661 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5662 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5663 | |
| 5664 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5665 | ht_capa_mask = |
| 5666 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5667 | |
| 5668 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5669 | if (!ht_capa_mask) |
| 5670 | return -EINVAL; |
| 5671 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5672 | } |
| 5673 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5674 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5675 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5676 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5677 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5678 | &crypto, flags, ht_capa, |
| 5679 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5680 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5681 | return err; |
| 5682 | } |
| 5683 | |
| 5684 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5685 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5686 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5687 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5688 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5689 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5690 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5691 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5692 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5693 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5694 | return -EINVAL; |
| 5695 | |
| 5696 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5697 | return -EINVAL; |
| 5698 | |
| 5699 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5700 | return -EINVAL; |
| 5701 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5702 | if (!rdev->ops->deauth) |
| 5703 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5704 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5705 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5706 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5707 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5708 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5709 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5710 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5711 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5712 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5713 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5714 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5715 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5716 | |
| 5717 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5718 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5719 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5720 | } |
| 5721 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5722 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5723 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5724 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5725 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5726 | } |
| 5727 | |
| 5728 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5729 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5730 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5731 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5732 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5733 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5734 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5735 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5736 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5737 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5738 | return -EINVAL; |
| 5739 | |
| 5740 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5741 | return -EINVAL; |
| 5742 | |
| 5743 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5744 | return -EINVAL; |
| 5745 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5746 | if (!rdev->ops->disassoc) |
| 5747 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5748 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5749 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5750 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5751 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5752 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5753 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5754 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5755 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5756 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5757 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5758 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5759 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5760 | |
| 5761 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5762 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5763 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5764 | } |
| 5765 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5766 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5767 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5768 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5769 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5770 | } |
| 5771 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5772 | static bool |
| 5773 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5774 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5775 | int rateval) |
| 5776 | { |
| 5777 | struct wiphy *wiphy = &rdev->wiphy; |
| 5778 | bool found = false; |
| 5779 | int band, i; |
| 5780 | |
| 5781 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5782 | struct ieee80211_supported_band *sband; |
| 5783 | |
| 5784 | sband = wiphy->bands[band]; |
| 5785 | if (!sband) |
| 5786 | continue; |
| 5787 | |
| 5788 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5789 | if (sband->bitrates[i].bitrate == rateval) { |
| 5790 | mcast_rate[band] = i + 1; |
| 5791 | found = true; |
| 5792 | break; |
| 5793 | } |
| 5794 | } |
| 5795 | } |
| 5796 | |
| 5797 | return found; |
| 5798 | } |
| 5799 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5800 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5801 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5802 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5803 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5804 | struct cfg80211_ibss_params ibss; |
| 5805 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5806 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5807 | int err; |
| 5808 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5809 | memset(&ibss, 0, sizeof(ibss)); |
| 5810 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5811 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5812 | return -EINVAL; |
| 5813 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5814 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5815 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5816 | return -EINVAL; |
| 5817 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5818 | ibss.beacon_interval = 100; |
| 5819 | |
| 5820 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5821 | ibss.beacon_interval = |
| 5822 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5823 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5824 | return -EINVAL; |
| 5825 | } |
| 5826 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5827 | if (!rdev->ops->join_ibss) |
| 5828 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5829 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5830 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5831 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5832 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5833 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5834 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5835 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5836 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5837 | |
| 5838 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5839 | return -EINVAL; |
| 5840 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5841 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5842 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5843 | |
| 5844 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5845 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5846 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5847 | } |
| 5848 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5849 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 5850 | if (err) |
| 5851 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5852 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5853 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5854 | return -EINVAL; |
| 5855 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5856 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 5857 | return -EINVAL; |
| 5858 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 5859 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 5860 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5861 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5862 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5863 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5864 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5865 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5866 | u8 *rates = |
| 5867 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5868 | int n_rates = |
| 5869 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5870 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5871 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5872 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5873 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5874 | &ibss.basic_rates); |
| 5875 | if (err) |
| 5876 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5877 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5878 | |
| 5879 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5880 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5881 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5882 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5883 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5884 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5885 | bool no_ht = false; |
| 5886 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5887 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5888 | info->attrs[NL80211_ATTR_KEYS], |
| 5889 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5890 | if (IS_ERR(connkeys)) |
| 5891 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5892 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 5893 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 5894 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5895 | kfree(connkeys); |
| 5896 | return -EINVAL; |
| 5897 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5898 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5899 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5900 | ibss.control_port = |
| 5901 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5902 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5903 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5904 | if (err) |
| 5905 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5906 | return err; |
| 5907 | } |
| 5908 | |
| 5909 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5910 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5911 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5912 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5913 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5914 | if (!rdev->ops->leave_ibss) |
| 5915 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5916 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5917 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5918 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5919 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5920 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5921 | } |
| 5922 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 5923 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 5924 | { |
| 5925 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5926 | struct net_device *dev = info->user_ptr[1]; |
| 5927 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 5928 | u32 nla_rate; |
| 5929 | int err; |
| 5930 | |
| 5931 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5932 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5933 | return -EOPNOTSUPP; |
| 5934 | |
| 5935 | if (!rdev->ops->set_mcast_rate) |
| 5936 | return -EOPNOTSUPP; |
| 5937 | |
| 5938 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 5939 | |
| 5940 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 5941 | return -EINVAL; |
| 5942 | |
| 5943 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 5944 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 5945 | return -EINVAL; |
| 5946 | |
| 5947 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 5948 | |
| 5949 | return err; |
| 5950 | } |
| 5951 | |
| 5952 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5953 | #ifdef CONFIG_NL80211_TESTMODE |
| 5954 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5955 | .name = "testmode", |
| 5956 | }; |
| 5957 | |
| 5958 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5959 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5960 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5961 | int err; |
| 5962 | |
| 5963 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5964 | return -EINVAL; |
| 5965 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5966 | err = -EOPNOTSUPP; |
| 5967 | if (rdev->ops->testmode_cmd) { |
| 5968 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5969 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5970 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5971 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5972 | rdev->testmode_info = NULL; |
| 5973 | } |
| 5974 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5975 | return err; |
| 5976 | } |
| 5977 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5978 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5979 | struct netlink_callback *cb) |
| 5980 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5981 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5982 | int err; |
| 5983 | long phy_idx; |
| 5984 | void *data = NULL; |
| 5985 | int data_len = 0; |
| 5986 | |
| 5987 | if (cb->args[0]) { |
| 5988 | /* |
| 5989 | * 0 is a valid index, but not valid for args[0], |
| 5990 | * so we need to offset by 1. |
| 5991 | */ |
| 5992 | phy_idx = cb->args[0] - 1; |
| 5993 | } else { |
| 5994 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5995 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5996 | nl80211_policy); |
| 5997 | if (err) |
| 5998 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5999 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6000 | mutex_lock(&cfg80211_mutex); |
| 6001 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6002 | nl80211_fam.attrbuf); |
| 6003 | if (IS_ERR(rdev)) { |
| 6004 | mutex_unlock(&cfg80211_mutex); |
| 6005 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6006 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6007 | phy_idx = rdev->wiphy_idx; |
| 6008 | rdev = NULL; |
| 6009 | mutex_unlock(&cfg80211_mutex); |
| 6010 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6011 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6012 | cb->args[1] = |
| 6013 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6014 | } |
| 6015 | |
| 6016 | if (cb->args[1]) { |
| 6017 | data = nla_data((void *)cb->args[1]); |
| 6018 | data_len = nla_len((void *)cb->args[1]); |
| 6019 | } |
| 6020 | |
| 6021 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6022 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6023 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6024 | mutex_unlock(&cfg80211_mutex); |
| 6025 | return -ENOENT; |
| 6026 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6027 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6028 | mutex_unlock(&cfg80211_mutex); |
| 6029 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6030 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6031 | err = -EOPNOTSUPP; |
| 6032 | goto out_err; |
| 6033 | } |
| 6034 | |
| 6035 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6036 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6037 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6038 | NL80211_CMD_TESTMODE); |
| 6039 | struct nlattr *tmdata; |
| 6040 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6041 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6042 | genlmsg_cancel(skb, hdr); |
| 6043 | break; |
| 6044 | } |
| 6045 | |
| 6046 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6047 | if (!tmdata) { |
| 6048 | genlmsg_cancel(skb, hdr); |
| 6049 | break; |
| 6050 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6051 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6052 | nla_nest_end(skb, tmdata); |
| 6053 | |
| 6054 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6055 | genlmsg_cancel(skb, hdr); |
| 6056 | break; |
| 6057 | } else if (err) { |
| 6058 | genlmsg_cancel(skb, hdr); |
| 6059 | goto out_err; |
| 6060 | } |
| 6061 | |
| 6062 | genlmsg_end(skb, hdr); |
| 6063 | } |
| 6064 | |
| 6065 | err = skb->len; |
| 6066 | /* see above */ |
| 6067 | cb->args[0] = phy_idx + 1; |
| 6068 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6069 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6070 | return err; |
| 6071 | } |
| 6072 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6073 | static struct sk_buff * |
| 6074 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6075 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6076 | { |
| 6077 | struct sk_buff *skb; |
| 6078 | void *hdr; |
| 6079 | struct nlattr *data; |
| 6080 | |
| 6081 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6082 | if (!skb) |
| 6083 | return NULL; |
| 6084 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6085 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6086 | if (!hdr) { |
| 6087 | kfree_skb(skb); |
| 6088 | return NULL; |
| 6089 | } |
| 6090 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6091 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6092 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6093 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6094 | |
| 6095 | ((void **)skb->cb)[0] = rdev; |
| 6096 | ((void **)skb->cb)[1] = hdr; |
| 6097 | ((void **)skb->cb)[2] = data; |
| 6098 | |
| 6099 | return skb; |
| 6100 | |
| 6101 | nla_put_failure: |
| 6102 | kfree_skb(skb); |
| 6103 | return NULL; |
| 6104 | } |
| 6105 | |
| 6106 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6107 | int approxlen) |
| 6108 | { |
| 6109 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6110 | |
| 6111 | if (WARN_ON(!rdev->testmode_info)) |
| 6112 | return NULL; |
| 6113 | |
| 6114 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6115 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6116 | rdev->testmode_info->snd_seq, |
| 6117 | GFP_KERNEL); |
| 6118 | } |
| 6119 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6120 | |
| 6121 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6122 | { |
| 6123 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6124 | void *hdr = ((void **)skb->cb)[1]; |
| 6125 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6126 | |
| 6127 | if (WARN_ON(!rdev->testmode_info)) { |
| 6128 | kfree_skb(skb); |
| 6129 | return -EINVAL; |
| 6130 | } |
| 6131 | |
| 6132 | nla_nest_end(skb, data); |
| 6133 | genlmsg_end(skb, hdr); |
| 6134 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6135 | } |
| 6136 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6137 | |
| 6138 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6139 | int approxlen, gfp_t gfp) |
| 6140 | { |
| 6141 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6142 | |
| 6143 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6144 | } |
| 6145 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6146 | |
| 6147 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6148 | { |
| 6149 | void *hdr = ((void **)skb->cb)[1]; |
| 6150 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6151 | |
| 6152 | nla_nest_end(skb, data); |
| 6153 | genlmsg_end(skb, hdr); |
| 6154 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6155 | } |
| 6156 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6157 | #endif |
| 6158 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6159 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6160 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6161 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6162 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6163 | struct cfg80211_connect_params connect; |
| 6164 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6165 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6166 | int err; |
| 6167 | |
| 6168 | memset(&connect, 0, sizeof(connect)); |
| 6169 | |
| 6170 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6171 | return -EINVAL; |
| 6172 | |
| 6173 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6174 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6175 | return -EINVAL; |
| 6176 | |
| 6177 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6178 | connect.auth_type = |
| 6179 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6180 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6181 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6182 | return -EINVAL; |
| 6183 | } else |
| 6184 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6185 | |
| 6186 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6187 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6188 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6189 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6190 | if (err) |
| 6191 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6192 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6193 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6194 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6195 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6196 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6197 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6198 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6199 | connect.bg_scan_period = -1; |
| 6200 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6201 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6202 | connect.bg_scan_period = |
| 6203 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6204 | } |
| 6205 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6206 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6207 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6208 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6209 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6210 | |
| 6211 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6212 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6213 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6214 | } |
| 6215 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6216 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6217 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6218 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6219 | connect.mfp != NL80211_MFP_NO) |
| 6220 | return -EINVAL; |
| 6221 | } else { |
| 6222 | connect.mfp = NL80211_MFP_NO; |
| 6223 | } |
| 6224 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6225 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6226 | connect.channel = |
| 6227 | ieee80211_get_channel(wiphy, |
| 6228 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6229 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6230 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6231 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6232 | } |
| 6233 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6234 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6235 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6236 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6237 | if (IS_ERR(connkeys)) |
| 6238 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6239 | } |
| 6240 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6241 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6242 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6243 | |
| 6244 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6245 | memcpy(&connect.ht_capa_mask, |
| 6246 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6247 | sizeof(connect.ht_capa_mask)); |
| 6248 | |
| 6249 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6250 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6251 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6252 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6253 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6254 | memcpy(&connect.ht_capa, |
| 6255 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6256 | sizeof(connect.ht_capa)); |
| 6257 | } |
| 6258 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6259 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6260 | if (err) |
| 6261 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6262 | return err; |
| 6263 | } |
| 6264 | |
| 6265 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6266 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6267 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6268 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6269 | u16 reason; |
| 6270 | |
| 6271 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6272 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6273 | else |
| 6274 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6275 | |
| 6276 | if (reason == 0) |
| 6277 | return -EINVAL; |
| 6278 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6279 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6280 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6281 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6282 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6283 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6284 | } |
| 6285 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6286 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6287 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6288 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6289 | struct net *net; |
| 6290 | int err; |
| 6291 | u32 pid; |
| 6292 | |
| 6293 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6294 | return -EINVAL; |
| 6295 | |
| 6296 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6297 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6298 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6299 | if (IS_ERR(net)) |
| 6300 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6301 | |
| 6302 | err = 0; |
| 6303 | |
| 6304 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6305 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6306 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6307 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6308 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6309 | return err; |
| 6310 | } |
| 6311 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6312 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6313 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6314 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6315 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6316 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6317 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6318 | struct cfg80211_pmksa pmksa; |
| 6319 | |
| 6320 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6321 | |
| 6322 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6323 | return -EINVAL; |
| 6324 | |
| 6325 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6326 | return -EINVAL; |
| 6327 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6328 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6329 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6330 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6331 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6332 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6333 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6334 | |
| 6335 | switch (info->genlhdr->cmd) { |
| 6336 | case NL80211_CMD_SET_PMKSA: |
| 6337 | rdev_ops = rdev->ops->set_pmksa; |
| 6338 | break; |
| 6339 | case NL80211_CMD_DEL_PMKSA: |
| 6340 | rdev_ops = rdev->ops->del_pmksa; |
| 6341 | break; |
| 6342 | default: |
| 6343 | WARN_ON(1); |
| 6344 | break; |
| 6345 | } |
| 6346 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6347 | if (!rdev_ops) |
| 6348 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6349 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6350 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6351 | } |
| 6352 | |
| 6353 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6354 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6355 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6356 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6357 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6358 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6359 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6360 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6361 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6362 | if (!rdev->ops->flush_pmksa) |
| 6363 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6364 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6365 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6366 | } |
| 6367 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6368 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6369 | { |
| 6370 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6371 | struct net_device *dev = info->user_ptr[1]; |
| 6372 | u8 action_code, dialog_token; |
| 6373 | u16 status_code; |
| 6374 | u8 *peer; |
| 6375 | |
| 6376 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6377 | !rdev->ops->tdls_mgmt) |
| 6378 | return -EOPNOTSUPP; |
| 6379 | |
| 6380 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6381 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6382 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6383 | !info->attrs[NL80211_ATTR_IE] || |
| 6384 | !info->attrs[NL80211_ATTR_MAC]) |
| 6385 | return -EINVAL; |
| 6386 | |
| 6387 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6388 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6389 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6390 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6391 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6392 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6393 | dialog_token, status_code, |
| 6394 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6395 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6396 | } |
| 6397 | |
| 6398 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6399 | { |
| 6400 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6401 | struct net_device *dev = info->user_ptr[1]; |
| 6402 | enum nl80211_tdls_operation operation; |
| 6403 | u8 *peer; |
| 6404 | |
| 6405 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6406 | !rdev->ops->tdls_oper) |
| 6407 | return -EOPNOTSUPP; |
| 6408 | |
| 6409 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6410 | !info->attrs[NL80211_ATTR_MAC]) |
| 6411 | return -EINVAL; |
| 6412 | |
| 6413 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6414 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6415 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6416 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6417 | } |
| 6418 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6419 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6420 | struct genl_info *info) |
| 6421 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6422 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6423 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6424 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6425 | struct sk_buff *msg; |
| 6426 | void *hdr; |
| 6427 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6428 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6429 | int err; |
| 6430 | |
| 6431 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6432 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6433 | return -EINVAL; |
| 6434 | |
| 6435 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6436 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6437 | if (!rdev->ops->remain_on_channel || |
| 6438 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6439 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6440 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6441 | /* |
| 6442 | * We should be on that channel for at least a minimum amount of |
| 6443 | * time (10ms) but no longer than the driver supports. |
| 6444 | */ |
| 6445 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6446 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6447 | return -EINVAL; |
| 6448 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6449 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6450 | if (err) |
| 6451 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6452 | |
| 6453 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6454 | if (!msg) |
| 6455 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6456 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6457 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6458 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6459 | |
| 6460 | if (IS_ERR(hdr)) { |
| 6461 | err = PTR_ERR(hdr); |
| 6462 | goto free_msg; |
| 6463 | } |
| 6464 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6465 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6466 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6467 | |
| 6468 | if (err) |
| 6469 | goto free_msg; |
| 6470 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6471 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6472 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6473 | |
| 6474 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6475 | |
| 6476 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6477 | |
| 6478 | nla_put_failure: |
| 6479 | err = -ENOBUFS; |
| 6480 | free_msg: |
| 6481 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6482 | return err; |
| 6483 | } |
| 6484 | |
| 6485 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6486 | struct genl_info *info) |
| 6487 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6489 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6490 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6491 | |
| 6492 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6493 | return -EINVAL; |
| 6494 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6495 | if (!rdev->ops->cancel_remain_on_channel) |
| 6496 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6497 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6498 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6499 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6500 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6501 | } |
| 6502 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6503 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6504 | u8 *rates, u8 rates_len) |
| 6505 | { |
| 6506 | u8 i; |
| 6507 | u32 mask = 0; |
| 6508 | |
| 6509 | for (i = 0; i < rates_len; i++) { |
| 6510 | int rate = (rates[i] & 0x7f) * 5; |
| 6511 | int ridx; |
| 6512 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6513 | struct ieee80211_rate *srate = |
| 6514 | &sband->bitrates[ridx]; |
| 6515 | if (rate == srate->bitrate) { |
| 6516 | mask |= 1 << ridx; |
| 6517 | break; |
| 6518 | } |
| 6519 | } |
| 6520 | if (ridx == sband->n_bitrates) |
| 6521 | return 0; /* rate not found */ |
| 6522 | } |
| 6523 | |
| 6524 | return mask; |
| 6525 | } |
| 6526 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6527 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6528 | u8 *rates, u8 rates_len, |
| 6529 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6530 | { |
| 6531 | u8 i; |
| 6532 | |
| 6533 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6534 | |
| 6535 | for (i = 0; i < rates_len; i++) { |
| 6536 | int ridx, rbit; |
| 6537 | |
| 6538 | ridx = rates[i] / 8; |
| 6539 | rbit = BIT(rates[i] % 8); |
| 6540 | |
| 6541 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6542 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6543 | return false; |
| 6544 | |
| 6545 | /* check availability */ |
| 6546 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6547 | mcs[ridx] |= rbit; |
| 6548 | else |
| 6549 | return false; |
| 6550 | } |
| 6551 | |
| 6552 | return true; |
| 6553 | } |
| 6554 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6555 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6556 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6557 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6558 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6559 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6560 | }; |
| 6561 | |
| 6562 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6563 | struct genl_info *info) |
| 6564 | { |
| 6565 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6566 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6567 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6568 | int rem, i; |
| 6569 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6570 | struct nlattr *tx_rates; |
| 6571 | struct ieee80211_supported_band *sband; |
| 6572 | |
| 6573 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6574 | return -EINVAL; |
| 6575 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6576 | if (!rdev->ops->set_bitrate_mask) |
| 6577 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6578 | |
| 6579 | memset(&mask, 0, sizeof(mask)); |
| 6580 | /* Default to all rates enabled */ |
| 6581 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6582 | sband = rdev->wiphy.bands[i]; |
| 6583 | mask.control[i].legacy = |
| 6584 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6585 | if (sband) |
| 6586 | memcpy(mask.control[i].mcs, |
| 6587 | sband->ht_cap.mcs.rx_mask, |
| 6588 | sizeof(mask.control[i].mcs)); |
| 6589 | else |
| 6590 | memset(mask.control[i].mcs, 0, |
| 6591 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6592 | } |
| 6593 | |
| 6594 | /* |
| 6595 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6596 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6597 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6598 | 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] | 6599 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6600 | { |
| 6601 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6602 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6603 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6604 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6605 | if (sband == NULL) |
| 6606 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6607 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6608 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6609 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6610 | mask.control[band].legacy = rateset_to_mask( |
| 6611 | sband, |
| 6612 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6613 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6614 | if ((mask.control[band].legacy == 0) && |
| 6615 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6616 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6617 | } |
| 6618 | if (tb[NL80211_TXRATE_MCS]) { |
| 6619 | if (!ht_rateset_to_mask( |
| 6620 | sband, |
| 6621 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6622 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6623 | mask.control[band].mcs)) |
| 6624 | return -EINVAL; |
| 6625 | } |
| 6626 | |
| 6627 | if (mask.control[band].legacy == 0) { |
| 6628 | /* don't allow empty legacy rates if HT |
| 6629 | * is not even supported. */ |
| 6630 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6631 | return -EINVAL; |
| 6632 | |
| 6633 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6634 | if (mask.control[band].mcs[i]) |
| 6635 | break; |
| 6636 | |
| 6637 | /* legacy and mcs rates may not be both empty */ |
| 6638 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6639 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6640 | } |
| 6641 | } |
| 6642 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6643 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6644 | } |
| 6645 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6646 | 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] | 6647 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6648 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6649 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6650 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6651 | |
| 6652 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6653 | return -EINVAL; |
| 6654 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6655 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6656 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6657 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6658 | switch (wdev->iftype) { |
| 6659 | case NL80211_IFTYPE_STATION: |
| 6660 | case NL80211_IFTYPE_ADHOC: |
| 6661 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6662 | case NL80211_IFTYPE_AP: |
| 6663 | case NL80211_IFTYPE_AP_VLAN: |
| 6664 | case NL80211_IFTYPE_MESH_POINT: |
| 6665 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6666 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6667 | break; |
| 6668 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6669 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6670 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6671 | |
| 6672 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6673 | if (!rdev->ops->mgmt_tx) |
| 6674 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6675 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6676 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6677 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6678 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6679 | } |
| 6680 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6681 | 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] | 6682 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6683 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6684 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6685 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6686 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6687 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6688 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6689 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6690 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6691 | bool offchan, no_cck, dont_wait_for_ack; |
| 6692 | |
| 6693 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6694 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6695 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6696 | return -EINVAL; |
| 6697 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6698 | if (!rdev->ops->mgmt_tx) |
| 6699 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6700 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6701 | switch (wdev->iftype) { |
| 6702 | case NL80211_IFTYPE_STATION: |
| 6703 | case NL80211_IFTYPE_ADHOC: |
| 6704 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6705 | case NL80211_IFTYPE_AP: |
| 6706 | case NL80211_IFTYPE_AP_VLAN: |
| 6707 | case NL80211_IFTYPE_MESH_POINT: |
| 6708 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6709 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6710 | break; |
| 6711 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6712 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6713 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6714 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6715 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6716 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6717 | return -EINVAL; |
| 6718 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6719 | |
| 6720 | /* |
| 6721 | * We should wait on the channel for at least a minimum amount |
| 6722 | * of time (10ms) but no longer than the driver supports. |
| 6723 | */ |
| 6724 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6725 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6726 | return -EINVAL; |
| 6727 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6728 | } |
| 6729 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6730 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6731 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6732 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6733 | return -EINVAL; |
| 6734 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6735 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6736 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6737 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6738 | if (err) |
| 6739 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6740 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6741 | if (!dont_wait_for_ack) { |
| 6742 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6743 | if (!msg) |
| 6744 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6745 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6746 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6747 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6748 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6749 | if (IS_ERR(hdr)) { |
| 6750 | err = PTR_ERR(hdr); |
| 6751 | goto free_msg; |
| 6752 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6753 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6754 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6755 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6756 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6757 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6758 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6759 | if (err) |
| 6760 | goto free_msg; |
| 6761 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6762 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6763 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6764 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6765 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6766 | genlmsg_end(msg, hdr); |
| 6767 | return genlmsg_reply(msg, info); |
| 6768 | } |
| 6769 | |
| 6770 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6771 | |
| 6772 | nla_put_failure: |
| 6773 | err = -ENOBUFS; |
| 6774 | free_msg: |
| 6775 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6776 | return err; |
| 6777 | } |
| 6778 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6779 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6780 | { |
| 6781 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6782 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6783 | u64 cookie; |
| 6784 | |
| 6785 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6786 | return -EINVAL; |
| 6787 | |
| 6788 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6789 | return -EOPNOTSUPP; |
| 6790 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6791 | switch (wdev->iftype) { |
| 6792 | case NL80211_IFTYPE_STATION: |
| 6793 | case NL80211_IFTYPE_ADHOC: |
| 6794 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6795 | case NL80211_IFTYPE_AP: |
| 6796 | case NL80211_IFTYPE_AP_VLAN: |
| 6797 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6798 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6799 | break; |
| 6800 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6801 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6802 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6803 | |
| 6804 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6805 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6806 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6807 | } |
| 6808 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6809 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6810 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6811 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6812 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6813 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6814 | u8 ps_state; |
| 6815 | bool state; |
| 6816 | int err; |
| 6817 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6818 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6819 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6820 | |
| 6821 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6822 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6823 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6824 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6825 | |
| 6826 | wdev = dev->ieee80211_ptr; |
| 6827 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6828 | if (!rdev->ops->set_power_mgmt) |
| 6829 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6830 | |
| 6831 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6832 | |
| 6833 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6834 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6835 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6836 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6837 | if (!err) |
| 6838 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6839 | return err; |
| 6840 | } |
| 6841 | |
| 6842 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6843 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6844 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6845 | enum nl80211_ps_state ps_state; |
| 6846 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6847 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6848 | struct sk_buff *msg; |
| 6849 | void *hdr; |
| 6850 | int err; |
| 6851 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6852 | wdev = dev->ieee80211_ptr; |
| 6853 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6854 | if (!rdev->ops->set_power_mgmt) |
| 6855 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6856 | |
| 6857 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6858 | if (!msg) |
| 6859 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6860 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6861 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6862 | NL80211_CMD_GET_POWER_SAVE); |
| 6863 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6864 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6865 | goto free_msg; |
| 6866 | } |
| 6867 | |
| 6868 | if (wdev->ps) |
| 6869 | ps_state = NL80211_PS_ENABLED; |
| 6870 | else |
| 6871 | ps_state = NL80211_PS_DISABLED; |
| 6872 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6873 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6874 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6875 | |
| 6876 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6877 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6878 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6879 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6880 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6881 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6882 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6883 | return err; |
| 6884 | } |
| 6885 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6886 | static struct nla_policy |
| 6887 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6888 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6889 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6890 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6891 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 6892 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 6893 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6894 | }; |
| 6895 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6896 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6897 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6898 | { |
| 6899 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6900 | struct wireless_dev *wdev; |
| 6901 | struct net_device *dev = info->user_ptr[1]; |
| 6902 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6903 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6904 | return -EINVAL; |
| 6905 | |
| 6906 | wdev = dev->ieee80211_ptr; |
| 6907 | |
| 6908 | if (!rdev->ops->set_cqm_txe_config) |
| 6909 | return -EOPNOTSUPP; |
| 6910 | |
| 6911 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 6912 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6913 | return -EOPNOTSUPP; |
| 6914 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6915 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6916 | } |
| 6917 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6918 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6919 | s32 threshold, u32 hysteresis) |
| 6920 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6921 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6922 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6923 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6924 | |
| 6925 | if (threshold > 0) |
| 6926 | return -EINVAL; |
| 6927 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6928 | wdev = dev->ieee80211_ptr; |
| 6929 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6930 | if (!rdev->ops->set_cqm_rssi_config) |
| 6931 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6932 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6933 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6934 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6935 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6936 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6937 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6938 | } |
| 6939 | |
| 6940 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6941 | { |
| 6942 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6943 | struct nlattr *cqm; |
| 6944 | int err; |
| 6945 | |
| 6946 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6947 | if (!cqm) { |
| 6948 | err = -EINVAL; |
| 6949 | goto out; |
| 6950 | } |
| 6951 | |
| 6952 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6953 | nl80211_attr_cqm_policy); |
| 6954 | if (err) |
| 6955 | goto out; |
| 6956 | |
| 6957 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6958 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6959 | s32 threshold; |
| 6960 | u32 hysteresis; |
| 6961 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6962 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6963 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6964 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 6965 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 6966 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 6967 | u32 rate, pkts, intvl; |
| 6968 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 6969 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 6970 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 6971 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6972 | } else |
| 6973 | err = -EINVAL; |
| 6974 | |
| 6975 | out: |
| 6976 | return err; |
| 6977 | } |
| 6978 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6979 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6980 | { |
| 6981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6982 | struct net_device *dev = info->user_ptr[1]; |
| 6983 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6984 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6985 | int err; |
| 6986 | |
| 6987 | /* start with default */ |
| 6988 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6989 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6990 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6991 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6992 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6993 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6994 | if (err) |
| 6995 | return err; |
| 6996 | } |
| 6997 | |
| 6998 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6999 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7000 | return -EINVAL; |
| 7001 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7002 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7003 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7004 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7005 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7006 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7007 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7008 | return -EINVAL; |
| 7009 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7010 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7011 | setup.beacon_interval = |
| 7012 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7013 | if (setup.beacon_interval < 10 || |
| 7014 | setup.beacon_interval > 10000) |
| 7015 | return -EINVAL; |
| 7016 | } |
| 7017 | |
| 7018 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7019 | setup.dtim_period = |
| 7020 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7021 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7022 | return -EINVAL; |
| 7023 | } |
| 7024 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7025 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7026 | /* parse additional setup parameters if given */ |
| 7027 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7028 | if (err) |
| 7029 | return err; |
| 7030 | } |
| 7031 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7032 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7033 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7034 | if (err) |
| 7035 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7036 | } else { |
| 7037 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7038 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7039 | } |
| 7040 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7041 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7042 | } |
| 7043 | |
| 7044 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7045 | { |
| 7046 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7047 | struct net_device *dev = info->user_ptr[1]; |
| 7048 | |
| 7049 | return cfg80211_leave_mesh(rdev, dev); |
| 7050 | } |
| 7051 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7052 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7053 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7054 | struct cfg80211_registered_device *rdev) |
| 7055 | { |
| 7056 | struct nlattr *nl_pats, *nl_pat; |
| 7057 | int i, pat_len; |
| 7058 | |
| 7059 | if (!rdev->wowlan->n_patterns) |
| 7060 | return 0; |
| 7061 | |
| 7062 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7063 | if (!nl_pats) |
| 7064 | return -ENOBUFS; |
| 7065 | |
| 7066 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 7067 | nl_pat = nla_nest_start(msg, i + 1); |
| 7068 | if (!nl_pat) |
| 7069 | return -ENOBUFS; |
| 7070 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 7071 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 7072 | DIV_ROUND_UP(pat_len, 8), |
| 7073 | rdev->wowlan->patterns[i].mask) || |
| 7074 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 7075 | pat_len, rdev->wowlan->patterns[i].pattern) || |
| 7076 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
| 7077 | rdev->wowlan->patterns[i].pkt_offset)) |
| 7078 | return -ENOBUFS; |
| 7079 | nla_nest_end(msg, nl_pat); |
| 7080 | } |
| 7081 | nla_nest_end(msg, nl_pats); |
| 7082 | |
| 7083 | return 0; |
| 7084 | } |
| 7085 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7086 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7087 | struct cfg80211_wowlan_tcp *tcp) |
| 7088 | { |
| 7089 | struct nlattr *nl_tcp; |
| 7090 | |
| 7091 | if (!tcp) |
| 7092 | return 0; |
| 7093 | |
| 7094 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7095 | if (!nl_tcp) |
| 7096 | return -ENOBUFS; |
| 7097 | |
| 7098 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7099 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7100 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7101 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7102 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7103 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7104 | tcp->payload_len, tcp->payload) || |
| 7105 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7106 | tcp->data_interval) || |
| 7107 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7108 | tcp->wake_len, tcp->wake_data) || |
| 7109 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7110 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7111 | return -ENOBUFS; |
| 7112 | |
| 7113 | if (tcp->payload_seq.len && |
| 7114 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7115 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7116 | return -ENOBUFS; |
| 7117 | |
| 7118 | if (tcp->payload_tok.len && |
| 7119 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7120 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7121 | &tcp->payload_tok)) |
| 7122 | return -ENOBUFS; |
| 7123 | |
| 7124 | return 0; |
| 7125 | } |
| 7126 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7127 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7128 | { |
| 7129 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7130 | struct sk_buff *msg; |
| 7131 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7132 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7133 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7134 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7135 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7136 | return -EOPNOTSUPP; |
| 7137 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7138 | if (rdev->wowlan && rdev->wowlan->tcp) { |
| 7139 | /* adjust size to have room for all the data */ |
| 7140 | size += rdev->wowlan->tcp->tokens_size + |
| 7141 | rdev->wowlan->tcp->payload_len + |
| 7142 | rdev->wowlan->tcp->wake_len + |
| 7143 | rdev->wowlan->tcp->wake_len / 8; |
| 7144 | } |
| 7145 | |
| 7146 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7147 | if (!msg) |
| 7148 | return -ENOMEM; |
| 7149 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7150 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7151 | NL80211_CMD_GET_WOWLAN); |
| 7152 | if (!hdr) |
| 7153 | goto nla_put_failure; |
| 7154 | |
| 7155 | if (rdev->wowlan) { |
| 7156 | struct nlattr *nl_wowlan; |
| 7157 | |
| 7158 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7159 | if (!nl_wowlan) |
| 7160 | goto nla_put_failure; |
| 7161 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7162 | if ((rdev->wowlan->any && |
| 7163 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7164 | (rdev->wowlan->disconnect && |
| 7165 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7166 | (rdev->wowlan->magic_pkt && |
| 7167 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7168 | (rdev->wowlan->gtk_rekey_failure && |
| 7169 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7170 | (rdev->wowlan->eap_identity_req && |
| 7171 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7172 | (rdev->wowlan->four_way_handshake && |
| 7173 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7174 | (rdev->wowlan->rfkill_release && |
| 7175 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7176 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7177 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7178 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7179 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7180 | |
| 7181 | if (nl80211_send_wowlan_tcp(msg, rdev->wowlan->tcp)) |
| 7182 | goto nla_put_failure; |
| 7183 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7184 | nla_nest_end(msg, nl_wowlan); |
| 7185 | } |
| 7186 | |
| 7187 | genlmsg_end(msg, hdr); |
| 7188 | return genlmsg_reply(msg, info); |
| 7189 | |
| 7190 | nla_put_failure: |
| 7191 | nlmsg_free(msg); |
| 7192 | return -ENOBUFS; |
| 7193 | } |
| 7194 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7195 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7196 | struct nlattr *attr, |
| 7197 | struct cfg80211_wowlan *trig) |
| 7198 | { |
| 7199 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7200 | struct cfg80211_wowlan_tcp *cfg; |
| 7201 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7202 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7203 | u32 size; |
| 7204 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7205 | int err, port; |
| 7206 | |
| 7207 | if (!rdev->wiphy.wowlan.tcp) |
| 7208 | return -EINVAL; |
| 7209 | |
| 7210 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7211 | nla_data(attr), nla_len(attr), |
| 7212 | nl80211_wowlan_tcp_policy); |
| 7213 | if (err) |
| 7214 | return err; |
| 7215 | |
| 7216 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7217 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7218 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7219 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7220 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7221 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7222 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7223 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7224 | return -EINVAL; |
| 7225 | |
| 7226 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
| 7227 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) |
| 7228 | return -EINVAL; |
| 7229 | |
| 7230 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
| 7231 | rdev->wiphy.wowlan.tcp->data_interval_max) |
| 7232 | return -EINVAL; |
| 7233 | |
| 7234 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
| 7235 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) |
| 7236 | return -EINVAL; |
| 7237 | |
| 7238 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7239 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7240 | return -EINVAL; |
| 7241 | |
| 7242 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7243 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7244 | |
| 7245 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7246 | tokens_size = tokln - sizeof(*tok); |
| 7247 | |
| 7248 | if (!tok->len || tokens_size % tok->len) |
| 7249 | return -EINVAL; |
| 7250 | if (!rdev->wiphy.wowlan.tcp->tok) |
| 7251 | return -EINVAL; |
| 7252 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) |
| 7253 | return -EINVAL; |
| 7254 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) |
| 7255 | return -EINVAL; |
| 7256 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) |
| 7257 | return -EINVAL; |
| 7258 | if (tok->offset + tok->len > data_size) |
| 7259 | return -EINVAL; |
| 7260 | } |
| 7261 | |
| 7262 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7263 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
| 7264 | if (!rdev->wiphy.wowlan.tcp->seq) |
| 7265 | return -EINVAL; |
| 7266 | if (seq->len == 0 || seq->len > 4) |
| 7267 | return -EINVAL; |
| 7268 | if (seq->len + seq->offset > data_size) |
| 7269 | return -EINVAL; |
| 7270 | } |
| 7271 | |
| 7272 | size = sizeof(*cfg); |
| 7273 | size += data_size; |
| 7274 | size += wake_size + wake_mask_size; |
| 7275 | size += tokens_size; |
| 7276 | |
| 7277 | cfg = kzalloc(size, GFP_KERNEL); |
| 7278 | if (!cfg) |
| 7279 | return -ENOMEM; |
| 7280 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7281 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7282 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7283 | ETH_ALEN); |
| 7284 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7285 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7286 | else |
| 7287 | port = 0; |
| 7288 | #ifdef CONFIG_INET |
| 7289 | /* allocate a socket and port for it and use it */ |
| 7290 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7291 | IPPROTO_TCP, &cfg->sock, 1); |
| 7292 | if (err) { |
| 7293 | kfree(cfg); |
| 7294 | return err; |
| 7295 | } |
| 7296 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7297 | sock_release(cfg->sock); |
| 7298 | kfree(cfg); |
| 7299 | return -EADDRINUSE; |
| 7300 | } |
| 7301 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7302 | #else |
| 7303 | if (!port) { |
| 7304 | kfree(cfg); |
| 7305 | return -EINVAL; |
| 7306 | } |
| 7307 | cfg->src_port = port; |
| 7308 | #endif |
| 7309 | |
| 7310 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7311 | cfg->payload_len = data_size; |
| 7312 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7313 | memcpy((void *)cfg->payload, |
| 7314 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7315 | data_size); |
| 7316 | if (seq) |
| 7317 | cfg->payload_seq = *seq; |
| 7318 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7319 | cfg->wake_len = wake_size; |
| 7320 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7321 | memcpy((void *)cfg->wake_data, |
| 7322 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7323 | wake_size); |
| 7324 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7325 | data_size + wake_size; |
| 7326 | memcpy((void *)cfg->wake_mask, |
| 7327 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7328 | wake_mask_size); |
| 7329 | if (tok) { |
| 7330 | cfg->tokens_size = tokens_size; |
| 7331 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7332 | } |
| 7333 | |
| 7334 | trig->tcp = cfg; |
| 7335 | |
| 7336 | return 0; |
| 7337 | } |
| 7338 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7339 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7340 | { |
| 7341 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7342 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7343 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7344 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7345 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 7346 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7347 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7348 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7349 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7350 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7351 | return -EOPNOTSUPP; |
| 7352 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7353 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7354 | cfg80211_rdev_free_wowlan(rdev); |
| 7355 | rdev->wowlan = NULL; |
| 7356 | goto set_wakeup; |
| 7357 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7358 | |
| 7359 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7360 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7361 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7362 | nl80211_wowlan_policy); |
| 7363 | if (err) |
| 7364 | return err; |
| 7365 | |
| 7366 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7367 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7368 | return -EINVAL; |
| 7369 | new_triggers.any = true; |
| 7370 | } |
| 7371 | |
| 7372 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7373 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7374 | return -EINVAL; |
| 7375 | new_triggers.disconnect = true; |
| 7376 | } |
| 7377 | |
| 7378 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7379 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7380 | return -EINVAL; |
| 7381 | new_triggers.magic_pkt = true; |
| 7382 | } |
| 7383 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7384 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7385 | return -EINVAL; |
| 7386 | |
| 7387 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7388 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7389 | return -EINVAL; |
| 7390 | new_triggers.gtk_rekey_failure = true; |
| 7391 | } |
| 7392 | |
| 7393 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7394 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7395 | return -EINVAL; |
| 7396 | new_triggers.eap_identity_req = true; |
| 7397 | } |
| 7398 | |
| 7399 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7400 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7401 | return -EINVAL; |
| 7402 | new_triggers.four_way_handshake = true; |
| 7403 | } |
| 7404 | |
| 7405 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7406 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7407 | return -EINVAL; |
| 7408 | new_triggers.rfkill_release = true; |
| 7409 | } |
| 7410 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7411 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7412 | struct nlattr *pat; |
| 7413 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7414 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7415 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7416 | |
| 7417 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7418 | rem) |
| 7419 | n_patterns++; |
| 7420 | if (n_patterns > wowlan->n_patterns) |
| 7421 | return -EINVAL; |
| 7422 | |
| 7423 | new_triggers.patterns = kcalloc(n_patterns, |
| 7424 | sizeof(new_triggers.patterns[0]), |
| 7425 | GFP_KERNEL); |
| 7426 | if (!new_triggers.patterns) |
| 7427 | return -ENOMEM; |
| 7428 | |
| 7429 | new_triggers.n_patterns = n_patterns; |
| 7430 | i = 0; |
| 7431 | |
| 7432 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7433 | rem) { |
| 7434 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7435 | nla_data(pat), nla_len(pat), NULL); |
| 7436 | err = -EINVAL; |
| 7437 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7438 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7439 | goto error; |
| 7440 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7441 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7442 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7443 | mask_len) |
| 7444 | goto error; |
| 7445 | if (pat_len > wowlan->pattern_max_len || |
| 7446 | pat_len < wowlan->pattern_min_len) |
| 7447 | goto error; |
| 7448 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7449 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7450 | pkt_offset = 0; |
| 7451 | else |
| 7452 | pkt_offset = nla_get_u32( |
| 7453 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7454 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7455 | goto error; |
| 7456 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7457 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7458 | new_triggers.patterns[i].mask = |
| 7459 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7460 | if (!new_triggers.patterns[i].mask) { |
| 7461 | err = -ENOMEM; |
| 7462 | goto error; |
| 7463 | } |
| 7464 | new_triggers.patterns[i].pattern = |
| 7465 | new_triggers.patterns[i].mask + mask_len; |
| 7466 | memcpy(new_triggers.patterns[i].mask, |
| 7467 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7468 | mask_len); |
| 7469 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7470 | memcpy(new_triggers.patterns[i].pattern, |
| 7471 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7472 | pat_len); |
| 7473 | i++; |
| 7474 | } |
| 7475 | } |
| 7476 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7477 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 7478 | err = nl80211_parse_wowlan_tcp( |
| 7479 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 7480 | &new_triggers); |
| 7481 | if (err) |
| 7482 | goto error; |
| 7483 | } |
| 7484 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7485 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7486 | if (!ntrig) { |
| 7487 | err = -ENOMEM; |
| 7488 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7489 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7490 | cfg80211_rdev_free_wowlan(rdev); |
| 7491 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7492 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7493 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7494 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7495 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7496 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7497 | return 0; |
| 7498 | error: |
| 7499 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7500 | kfree(new_triggers.patterns[i].mask); |
| 7501 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7502 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 7503 | sock_release(new_triggers.tcp->sock); |
| 7504 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7505 | return err; |
| 7506 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7507 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7508 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7509 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 7510 | { |
| 7511 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7512 | struct net_device *dev = info->user_ptr[1]; |
| 7513 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7514 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 7515 | struct cfg80211_gtk_rekey_data rekey_data; |
| 7516 | int err; |
| 7517 | |
| 7518 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 7519 | return -EINVAL; |
| 7520 | |
| 7521 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 7522 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7523 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7524 | nl80211_rekey_policy); |
| 7525 | if (err) |
| 7526 | return err; |
| 7527 | |
| 7528 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 7529 | return -ERANGE; |
| 7530 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 7531 | return -ERANGE; |
| 7532 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 7533 | return -ERANGE; |
| 7534 | |
| 7535 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 7536 | NL80211_KEK_LEN); |
| 7537 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 7538 | NL80211_KCK_LEN); |
| 7539 | memcpy(rekey_data.replay_ctr, |
| 7540 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 7541 | NL80211_REPLAY_CTR_LEN); |
| 7542 | |
| 7543 | wdev_lock(wdev); |
| 7544 | if (!wdev->current_bss) { |
| 7545 | err = -ENOTCONN; |
| 7546 | goto out; |
| 7547 | } |
| 7548 | |
| 7549 | if (!rdev->ops->set_rekey_data) { |
| 7550 | err = -EOPNOTSUPP; |
| 7551 | goto out; |
| 7552 | } |
| 7553 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7554 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7555 | out: |
| 7556 | wdev_unlock(wdev); |
| 7557 | return err; |
| 7558 | } |
| 7559 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7560 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 7561 | struct genl_info *info) |
| 7562 | { |
| 7563 | struct net_device *dev = info->user_ptr[1]; |
| 7564 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7565 | |
| 7566 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7567 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7568 | return -EINVAL; |
| 7569 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7570 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7571 | return -EBUSY; |
| 7572 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7573 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7574 | return 0; |
| 7575 | } |
| 7576 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7577 | static int nl80211_probe_client(struct sk_buff *skb, |
| 7578 | struct genl_info *info) |
| 7579 | { |
| 7580 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7581 | struct net_device *dev = info->user_ptr[1]; |
| 7582 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7583 | struct sk_buff *msg; |
| 7584 | void *hdr; |
| 7585 | const u8 *addr; |
| 7586 | u64 cookie; |
| 7587 | int err; |
| 7588 | |
| 7589 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7590 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7591 | return -EOPNOTSUPP; |
| 7592 | |
| 7593 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7594 | return -EINVAL; |
| 7595 | |
| 7596 | if (!rdev->ops->probe_client) |
| 7597 | return -EOPNOTSUPP; |
| 7598 | |
| 7599 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7600 | if (!msg) |
| 7601 | return -ENOMEM; |
| 7602 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7603 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7604 | NL80211_CMD_PROBE_CLIENT); |
| 7605 | |
| 7606 | if (IS_ERR(hdr)) { |
| 7607 | err = PTR_ERR(hdr); |
| 7608 | goto free_msg; |
| 7609 | } |
| 7610 | |
| 7611 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7612 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7613 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7614 | if (err) |
| 7615 | goto free_msg; |
| 7616 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7617 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7618 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7619 | |
| 7620 | genlmsg_end(msg, hdr); |
| 7621 | |
| 7622 | return genlmsg_reply(msg, info); |
| 7623 | |
| 7624 | nla_put_failure: |
| 7625 | err = -ENOBUFS; |
| 7626 | free_msg: |
| 7627 | nlmsg_free(msg); |
| 7628 | return err; |
| 7629 | } |
| 7630 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7631 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 7632 | { |
| 7633 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7634 | struct cfg80211_beacon_registration *reg, *nreg; |
| 7635 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7636 | |
| 7637 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 7638 | return -EOPNOTSUPP; |
| 7639 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7640 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 7641 | if (!nreg) |
| 7642 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7643 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7644 | /* First, check if already registered. */ |
| 7645 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 7646 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 7647 | if (reg->nlportid == info->snd_portid) { |
| 7648 | rv = -EALREADY; |
| 7649 | goto out_err; |
| 7650 | } |
| 7651 | } |
| 7652 | /* Add it to the list */ |
| 7653 | nreg->nlportid = info->snd_portid; |
| 7654 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 7655 | |
| 7656 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7657 | |
| 7658 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7659 | out_err: |
| 7660 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 7661 | kfree(nreg); |
| 7662 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7663 | } |
| 7664 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7665 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7666 | { |
| 7667 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7668 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7669 | int err; |
| 7670 | |
| 7671 | if (!rdev->ops->start_p2p_device) |
| 7672 | return -EOPNOTSUPP; |
| 7673 | |
| 7674 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7675 | return -EOPNOTSUPP; |
| 7676 | |
| 7677 | if (wdev->p2p_started) |
| 7678 | return 0; |
| 7679 | |
| 7680 | mutex_lock(&rdev->devlist_mtx); |
| 7681 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 7682 | mutex_unlock(&rdev->devlist_mtx); |
| 7683 | if (err) |
| 7684 | return err; |
| 7685 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7686 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7687 | if (err) |
| 7688 | return err; |
| 7689 | |
| 7690 | wdev->p2p_started = true; |
| 7691 | mutex_lock(&rdev->devlist_mtx); |
| 7692 | rdev->opencount++; |
| 7693 | mutex_unlock(&rdev->devlist_mtx); |
| 7694 | |
| 7695 | return 0; |
| 7696 | } |
| 7697 | |
| 7698 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7699 | { |
| 7700 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7701 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7702 | |
| 7703 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7704 | return -EOPNOTSUPP; |
| 7705 | |
| 7706 | if (!rdev->ops->stop_p2p_device) |
| 7707 | return -EOPNOTSUPP; |
| 7708 | |
| 7709 | if (!wdev->p2p_started) |
| 7710 | return 0; |
| 7711 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7712 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7713 | wdev->p2p_started = false; |
| 7714 | |
| 7715 | mutex_lock(&rdev->devlist_mtx); |
| 7716 | rdev->opencount--; |
| 7717 | mutex_unlock(&rdev->devlist_mtx); |
| 7718 | |
| 7719 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 7720 | rdev->scan_req->aborted = true; |
| 7721 | ___cfg80211_scan_done(rdev, true); |
| 7722 | } |
| 7723 | |
| 7724 | return 0; |
| 7725 | } |
| 7726 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7727 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 7728 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 7729 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7730 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 7731 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 7732 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7733 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7734 | /* 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] | 7735 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 7736 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7737 | |
| 7738 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7739 | struct genl_info *info) |
| 7740 | { |
| 7741 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7742 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7743 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7744 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 7745 | |
| 7746 | if (rtnl) |
| 7747 | rtnl_lock(); |
| 7748 | |
| 7749 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 7750 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7751 | if (IS_ERR(rdev)) { |
| 7752 | if (rtnl) |
| 7753 | rtnl_unlock(); |
| 7754 | return PTR_ERR(rdev); |
| 7755 | } |
| 7756 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7757 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7758 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7759 | mutex_lock(&cfg80211_mutex); |
| 7760 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7761 | info->attrs); |
| 7762 | if (IS_ERR(wdev)) { |
| 7763 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7764 | if (rtnl) |
| 7765 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7766 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7767 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7768 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7769 | dev = wdev->netdev; |
| 7770 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7771 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7772 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7773 | if (!dev) { |
| 7774 | mutex_unlock(&cfg80211_mutex); |
| 7775 | if (rtnl) |
| 7776 | rtnl_unlock(); |
| 7777 | return -EINVAL; |
| 7778 | } |
| 7779 | |
| 7780 | info->user_ptr[1] = dev; |
| 7781 | } else { |
| 7782 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7783 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7784 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7785 | if (dev) { |
| 7786 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7787 | !netif_running(dev)) { |
| 7788 | mutex_unlock(&cfg80211_mutex); |
| 7789 | if (rtnl) |
| 7790 | rtnl_unlock(); |
| 7791 | return -ENETDOWN; |
| 7792 | } |
| 7793 | |
| 7794 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7795 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7796 | if (!wdev->p2p_started) { |
| 7797 | mutex_unlock(&cfg80211_mutex); |
| 7798 | if (rtnl) |
| 7799 | rtnl_unlock(); |
| 7800 | return -ENETDOWN; |
| 7801 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7802 | } |
| 7803 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7804 | cfg80211_lock_rdev(rdev); |
| 7805 | |
| 7806 | mutex_unlock(&cfg80211_mutex); |
| 7807 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7808 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7809 | } |
| 7810 | |
| 7811 | return 0; |
| 7812 | } |
| 7813 | |
| 7814 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7815 | struct genl_info *info) |
| 7816 | { |
| 7817 | if (info->user_ptr[0]) |
| 7818 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7819 | if (info->user_ptr[1]) { |
| 7820 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7821 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7822 | |
| 7823 | if (wdev->netdev) |
| 7824 | dev_put(wdev->netdev); |
| 7825 | } else { |
| 7826 | dev_put(info->user_ptr[1]); |
| 7827 | } |
| 7828 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7829 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7830 | rtnl_unlock(); |
| 7831 | } |
| 7832 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7833 | static struct genl_ops nl80211_ops[] = { |
| 7834 | { |
| 7835 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7836 | .doit = nl80211_get_wiphy, |
| 7837 | .dumpit = nl80211_dump_wiphy, |
| 7838 | .policy = nl80211_policy, |
| 7839 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7840 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7841 | }, |
| 7842 | { |
| 7843 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7844 | .doit = nl80211_set_wiphy, |
| 7845 | .policy = nl80211_policy, |
| 7846 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7847 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7848 | }, |
| 7849 | { |
| 7850 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7851 | .doit = nl80211_get_interface, |
| 7852 | .dumpit = nl80211_dump_interface, |
| 7853 | .policy = nl80211_policy, |
| 7854 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7855 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7856 | }, |
| 7857 | { |
| 7858 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7859 | .doit = nl80211_set_interface, |
| 7860 | .policy = nl80211_policy, |
| 7861 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7862 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7863 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7864 | }, |
| 7865 | { |
| 7866 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7867 | .doit = nl80211_new_interface, |
| 7868 | .policy = nl80211_policy, |
| 7869 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7870 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7871 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7872 | }, |
| 7873 | { |
| 7874 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7875 | .doit = nl80211_del_interface, |
| 7876 | .policy = nl80211_policy, |
| 7877 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7878 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7879 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7880 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7881 | { |
| 7882 | .cmd = NL80211_CMD_GET_KEY, |
| 7883 | .doit = nl80211_get_key, |
| 7884 | .policy = nl80211_policy, |
| 7885 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7886 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7887 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7888 | }, |
| 7889 | { |
| 7890 | .cmd = NL80211_CMD_SET_KEY, |
| 7891 | .doit = nl80211_set_key, |
| 7892 | .policy = nl80211_policy, |
| 7893 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7894 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7895 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7896 | }, |
| 7897 | { |
| 7898 | .cmd = NL80211_CMD_NEW_KEY, |
| 7899 | .doit = nl80211_new_key, |
| 7900 | .policy = nl80211_policy, |
| 7901 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7902 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7903 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7904 | }, |
| 7905 | { |
| 7906 | .cmd = NL80211_CMD_DEL_KEY, |
| 7907 | .doit = nl80211_del_key, |
| 7908 | .policy = nl80211_policy, |
| 7909 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7910 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7911 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7912 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7913 | { |
| 7914 | .cmd = NL80211_CMD_SET_BEACON, |
| 7915 | .policy = nl80211_policy, |
| 7916 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7917 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7918 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7919 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7920 | }, |
| 7921 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7922 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7923 | .policy = nl80211_policy, |
| 7924 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7925 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7926 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7927 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7928 | }, |
| 7929 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7930 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7931 | .policy = nl80211_policy, |
| 7932 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7933 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7934 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7935 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7936 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7937 | { |
| 7938 | .cmd = NL80211_CMD_GET_STATION, |
| 7939 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7940 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7941 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7942 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7943 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7944 | }, |
| 7945 | { |
| 7946 | .cmd = NL80211_CMD_SET_STATION, |
| 7947 | .doit = nl80211_set_station, |
| 7948 | .policy = nl80211_policy, |
| 7949 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7950 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7951 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7952 | }, |
| 7953 | { |
| 7954 | .cmd = NL80211_CMD_NEW_STATION, |
| 7955 | .doit = nl80211_new_station, |
| 7956 | .policy = nl80211_policy, |
| 7957 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7958 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7959 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7960 | }, |
| 7961 | { |
| 7962 | .cmd = NL80211_CMD_DEL_STATION, |
| 7963 | .doit = nl80211_del_station, |
| 7964 | .policy = nl80211_policy, |
| 7965 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7968 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7969 | { |
| 7970 | .cmd = NL80211_CMD_GET_MPATH, |
| 7971 | .doit = nl80211_get_mpath, |
| 7972 | .dumpit = nl80211_dump_mpath, |
| 7973 | .policy = nl80211_policy, |
| 7974 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7975 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7976 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7977 | }, |
| 7978 | { |
| 7979 | .cmd = NL80211_CMD_SET_MPATH, |
| 7980 | .doit = nl80211_set_mpath, |
| 7981 | .policy = nl80211_policy, |
| 7982 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7983 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7984 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7985 | }, |
| 7986 | { |
| 7987 | .cmd = NL80211_CMD_NEW_MPATH, |
| 7988 | .doit = nl80211_new_mpath, |
| 7989 | .policy = nl80211_policy, |
| 7990 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7991 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7992 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7993 | }, |
| 7994 | { |
| 7995 | .cmd = NL80211_CMD_DEL_MPATH, |
| 7996 | .doit = nl80211_del_mpath, |
| 7997 | .policy = nl80211_policy, |
| 7998 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7999 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8000 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8001 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8002 | { |
| 8003 | .cmd = NL80211_CMD_SET_BSS, |
| 8004 | .doit = nl80211_set_bss, |
| 8005 | .policy = nl80211_policy, |
| 8006 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8007 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8008 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8009 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8010 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8011 | .cmd = NL80211_CMD_GET_REG, |
| 8012 | .doit = nl80211_get_reg, |
| 8013 | .policy = nl80211_policy, |
| 8014 | /* can be retrieved by unprivileged users */ |
| 8015 | }, |
| 8016 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8017 | .cmd = NL80211_CMD_SET_REG, |
| 8018 | .doit = nl80211_set_reg, |
| 8019 | .policy = nl80211_policy, |
| 8020 | .flags = GENL_ADMIN_PERM, |
| 8021 | }, |
| 8022 | { |
| 8023 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8024 | .doit = nl80211_req_set_reg, |
| 8025 | .policy = nl80211_policy, |
| 8026 | .flags = GENL_ADMIN_PERM, |
| 8027 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8028 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8029 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8030 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8031 | .policy = nl80211_policy, |
| 8032 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8033 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8034 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8035 | }, |
| 8036 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8037 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8038 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8039 | .policy = nl80211_policy, |
| 8040 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8041 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8042 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8043 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8044 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8045 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8046 | .doit = nl80211_trigger_scan, |
| 8047 | .policy = nl80211_policy, |
| 8048 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8049 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8050 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8051 | }, |
| 8052 | { |
| 8053 | .cmd = NL80211_CMD_GET_SCAN, |
| 8054 | .policy = nl80211_policy, |
| 8055 | .dumpit = nl80211_dump_scan, |
| 8056 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8057 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8058 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8059 | .doit = nl80211_start_sched_scan, |
| 8060 | .policy = nl80211_policy, |
| 8061 | .flags = GENL_ADMIN_PERM, |
| 8062 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8063 | NL80211_FLAG_NEED_RTNL, |
| 8064 | }, |
| 8065 | { |
| 8066 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8067 | .doit = nl80211_stop_sched_scan, |
| 8068 | .policy = nl80211_policy, |
| 8069 | .flags = GENL_ADMIN_PERM, |
| 8070 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8071 | NL80211_FLAG_NEED_RTNL, |
| 8072 | }, |
| 8073 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8074 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8075 | .doit = nl80211_authenticate, |
| 8076 | .policy = nl80211_policy, |
| 8077 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8078 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8079 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8080 | }, |
| 8081 | { |
| 8082 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8083 | .doit = nl80211_associate, |
| 8084 | .policy = nl80211_policy, |
| 8085 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8086 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8087 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8088 | }, |
| 8089 | { |
| 8090 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8091 | .doit = nl80211_deauthenticate, |
| 8092 | .policy = nl80211_policy, |
| 8093 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8094 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8095 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8096 | }, |
| 8097 | { |
| 8098 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8099 | .doit = nl80211_disassociate, |
| 8100 | .policy = nl80211_policy, |
| 8101 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8102 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8103 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8104 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8105 | { |
| 8106 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8107 | .doit = nl80211_join_ibss, |
| 8108 | .policy = nl80211_policy, |
| 8109 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8110 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8111 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8112 | }, |
| 8113 | { |
| 8114 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8115 | .doit = nl80211_leave_ibss, |
| 8116 | .policy = nl80211_policy, |
| 8117 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8118 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8119 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8120 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8121 | #ifdef CONFIG_NL80211_TESTMODE |
| 8122 | { |
| 8123 | .cmd = NL80211_CMD_TESTMODE, |
| 8124 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8125 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8126 | .policy = nl80211_policy, |
| 8127 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8128 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8129 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8130 | }, |
| 8131 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8132 | { |
| 8133 | .cmd = NL80211_CMD_CONNECT, |
| 8134 | .doit = nl80211_connect, |
| 8135 | .policy = nl80211_policy, |
| 8136 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8137 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8138 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8139 | }, |
| 8140 | { |
| 8141 | .cmd = NL80211_CMD_DISCONNECT, |
| 8142 | .doit = nl80211_disconnect, |
| 8143 | .policy = nl80211_policy, |
| 8144 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8145 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8146 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8147 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8148 | { |
| 8149 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8150 | .doit = nl80211_wiphy_netns, |
| 8151 | .policy = nl80211_policy, |
| 8152 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8153 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8154 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8155 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8156 | { |
| 8157 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8158 | .policy = nl80211_policy, |
| 8159 | .dumpit = nl80211_dump_survey, |
| 8160 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8161 | { |
| 8162 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8163 | .doit = nl80211_setdel_pmksa, |
| 8164 | .policy = nl80211_policy, |
| 8165 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8166 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8167 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8168 | }, |
| 8169 | { |
| 8170 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8171 | .doit = nl80211_setdel_pmksa, |
| 8172 | .policy = nl80211_policy, |
| 8173 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8174 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8175 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8176 | }, |
| 8177 | { |
| 8178 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8179 | .doit = nl80211_flush_pmksa, |
| 8180 | .policy = nl80211_policy, |
| 8181 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8182 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8183 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8184 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8185 | { |
| 8186 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8187 | .doit = nl80211_remain_on_channel, |
| 8188 | .policy = nl80211_policy, |
| 8189 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8190 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8191 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8192 | }, |
| 8193 | { |
| 8194 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8195 | .doit = nl80211_cancel_remain_on_channel, |
| 8196 | .policy = nl80211_policy, |
| 8197 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8198 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8199 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8200 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8201 | { |
| 8202 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8203 | .doit = nl80211_set_tx_bitrate_mask, |
| 8204 | .policy = nl80211_policy, |
| 8205 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8206 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8207 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8208 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8209 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8210 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8211 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8212 | .policy = nl80211_policy, |
| 8213 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8214 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8215 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8216 | }, |
| 8217 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8218 | .cmd = NL80211_CMD_FRAME, |
| 8219 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8220 | .policy = nl80211_policy, |
| 8221 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8222 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8223 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8224 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8225 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8226 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8227 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8228 | .policy = nl80211_policy, |
| 8229 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8230 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8231 | NL80211_FLAG_NEED_RTNL, |
| 8232 | }, |
| 8233 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8234 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8235 | .doit = nl80211_set_power_save, |
| 8236 | .policy = nl80211_policy, |
| 8237 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8238 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8239 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8240 | }, |
| 8241 | { |
| 8242 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8243 | .doit = nl80211_get_power_save, |
| 8244 | .policy = nl80211_policy, |
| 8245 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8246 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8247 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8248 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8249 | { |
| 8250 | .cmd = NL80211_CMD_SET_CQM, |
| 8251 | .doit = nl80211_set_cqm, |
| 8252 | .policy = nl80211_policy, |
| 8253 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8254 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8255 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8256 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8257 | { |
| 8258 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8259 | .doit = nl80211_set_channel, |
| 8260 | .policy = nl80211_policy, |
| 8261 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8262 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8263 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8264 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8265 | { |
| 8266 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8267 | .doit = nl80211_set_wds_peer, |
| 8268 | .policy = nl80211_policy, |
| 8269 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8270 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8271 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8272 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8273 | { |
| 8274 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8275 | .doit = nl80211_join_mesh, |
| 8276 | .policy = nl80211_policy, |
| 8277 | .flags = GENL_ADMIN_PERM, |
| 8278 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8279 | NL80211_FLAG_NEED_RTNL, |
| 8280 | }, |
| 8281 | { |
| 8282 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8283 | .doit = nl80211_leave_mesh, |
| 8284 | .policy = nl80211_policy, |
| 8285 | .flags = GENL_ADMIN_PERM, |
| 8286 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8287 | NL80211_FLAG_NEED_RTNL, |
| 8288 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8289 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8290 | { |
| 8291 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8292 | .doit = nl80211_get_wowlan, |
| 8293 | .policy = nl80211_policy, |
| 8294 | /* can be retrieved by unprivileged users */ |
| 8295 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8296 | NL80211_FLAG_NEED_RTNL, |
| 8297 | }, |
| 8298 | { |
| 8299 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8300 | .doit = nl80211_set_wowlan, |
| 8301 | .policy = nl80211_policy, |
| 8302 | .flags = GENL_ADMIN_PERM, |
| 8303 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8304 | NL80211_FLAG_NEED_RTNL, |
| 8305 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8306 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8307 | { |
| 8308 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8309 | .doit = nl80211_set_rekey_data, |
| 8310 | .policy = nl80211_policy, |
| 8311 | .flags = GENL_ADMIN_PERM, |
| 8312 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8313 | NL80211_FLAG_NEED_RTNL, |
| 8314 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8315 | { |
| 8316 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8317 | .doit = nl80211_tdls_mgmt, |
| 8318 | .policy = nl80211_policy, |
| 8319 | .flags = GENL_ADMIN_PERM, |
| 8320 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8321 | NL80211_FLAG_NEED_RTNL, |
| 8322 | }, |
| 8323 | { |
| 8324 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8325 | .doit = nl80211_tdls_oper, |
| 8326 | .policy = nl80211_policy, |
| 8327 | .flags = GENL_ADMIN_PERM, |
| 8328 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8329 | NL80211_FLAG_NEED_RTNL, |
| 8330 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8331 | { |
| 8332 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8333 | .doit = nl80211_register_unexpected_frame, |
| 8334 | .policy = nl80211_policy, |
| 8335 | .flags = GENL_ADMIN_PERM, |
| 8336 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8337 | NL80211_FLAG_NEED_RTNL, |
| 8338 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8339 | { |
| 8340 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8341 | .doit = nl80211_probe_client, |
| 8342 | .policy = nl80211_policy, |
| 8343 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8344 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8345 | NL80211_FLAG_NEED_RTNL, |
| 8346 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8347 | { |
| 8348 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8349 | .doit = nl80211_register_beacons, |
| 8350 | .policy = nl80211_policy, |
| 8351 | .flags = GENL_ADMIN_PERM, |
| 8352 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8353 | NL80211_FLAG_NEED_RTNL, |
| 8354 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8355 | { |
| 8356 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8357 | .doit = nl80211_set_noack_map, |
| 8358 | .policy = nl80211_policy, |
| 8359 | .flags = GENL_ADMIN_PERM, |
| 8360 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8361 | NL80211_FLAG_NEED_RTNL, |
| 8362 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8363 | { |
| 8364 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8365 | .doit = nl80211_start_p2p_device, |
| 8366 | .policy = nl80211_policy, |
| 8367 | .flags = GENL_ADMIN_PERM, |
| 8368 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8369 | NL80211_FLAG_NEED_RTNL, |
| 8370 | }, |
| 8371 | { |
| 8372 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8373 | .doit = nl80211_stop_p2p_device, |
| 8374 | .policy = nl80211_policy, |
| 8375 | .flags = GENL_ADMIN_PERM, |
| 8376 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8377 | NL80211_FLAG_NEED_RTNL, |
| 8378 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8379 | { |
| 8380 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8381 | .doit = nl80211_set_mcast_rate, |
| 8382 | .policy = nl80211_policy, |
| 8383 | .flags = GENL_ADMIN_PERM, |
| 8384 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8385 | NL80211_FLAG_NEED_RTNL, |
| 8386 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8387 | { |
| 8388 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8389 | .doit = nl80211_set_mac_acl, |
| 8390 | .policy = nl80211_policy, |
| 8391 | .flags = GENL_ADMIN_PERM, |
| 8392 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8393 | NL80211_FLAG_NEED_RTNL, |
| 8394 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8395 | { |
| 8396 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 8397 | .doit = nl80211_start_radar_detection, |
| 8398 | .policy = nl80211_policy, |
| 8399 | .flags = GENL_ADMIN_PERM, |
| 8400 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8401 | NL80211_FLAG_NEED_RTNL, |
| 8402 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8403 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8404 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8405 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 8406 | .name = "mlme", |
| 8407 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8408 | |
| 8409 | /* multicast groups */ |
| 8410 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 8411 | .name = "config", |
| 8412 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8413 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 8414 | .name = "scan", |
| 8415 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8416 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 8417 | .name = "regulatory", |
| 8418 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8419 | |
| 8420 | /* notification functions */ |
| 8421 | |
| 8422 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 8423 | { |
| 8424 | struct sk_buff *msg; |
| 8425 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8426 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8427 | if (!msg) |
| 8428 | return; |
| 8429 | |
| 8430 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 8431 | nlmsg_free(msg); |
| 8432 | return; |
| 8433 | } |
| 8434 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8435 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8436 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8437 | } |
| 8438 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8439 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 8440 | struct cfg80211_registered_device *rdev) |
| 8441 | { |
| 8442 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 8443 | struct nlattr *nest; |
| 8444 | int i; |
| 8445 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8446 | ASSERT_RDEV_LOCK(rdev); |
| 8447 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8448 | if (WARN_ON(!req)) |
| 8449 | return 0; |
| 8450 | |
| 8451 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 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_ssids; i++) { |
| 8455 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 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 | |
| 8460 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 8461 | if (!nest) |
| 8462 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8463 | for (i = 0; i < req->n_channels; i++) { |
| 8464 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 8465 | goto nla_put_failure; |
| 8466 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8467 | nla_nest_end(msg, nest); |
| 8468 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8469 | if (req->ie && |
| 8470 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 8471 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8472 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8473 | if (req->flags) |
| 8474 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 8475 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8476 | return 0; |
| 8477 | nla_put_failure: |
| 8478 | return -ENOBUFS; |
| 8479 | } |
| 8480 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8481 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 8482 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8483 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8484 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8485 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8486 | { |
| 8487 | void *hdr; |
| 8488 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8489 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8490 | if (!hdr) |
| 8491 | return -1; |
| 8492 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8493 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8494 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8495 | wdev->netdev->ifindex)) || |
| 8496 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8497 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8498 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8499 | /* ignore errors and send incomplete event anyway */ |
| 8500 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8501 | |
| 8502 | return genlmsg_end(msg, hdr); |
| 8503 | |
| 8504 | nla_put_failure: |
| 8505 | genlmsg_cancel(msg, hdr); |
| 8506 | return -EMSGSIZE; |
| 8507 | } |
| 8508 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8509 | static int |
| 8510 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 8511 | struct cfg80211_registered_device *rdev, |
| 8512 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8513 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8514 | { |
| 8515 | void *hdr; |
| 8516 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8517 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8518 | if (!hdr) |
| 8519 | return -1; |
| 8520 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8521 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8522 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8523 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8524 | |
| 8525 | return genlmsg_end(msg, hdr); |
| 8526 | |
| 8527 | nla_put_failure: |
| 8528 | genlmsg_cancel(msg, hdr); |
| 8529 | return -EMSGSIZE; |
| 8530 | } |
| 8531 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8532 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8533 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8534 | { |
| 8535 | struct sk_buff *msg; |
| 8536 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8537 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8538 | if (!msg) |
| 8539 | return; |
| 8540 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8541 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8542 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 8543 | nlmsg_free(msg); |
| 8544 | return; |
| 8545 | } |
| 8546 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8547 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8548 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8549 | } |
| 8550 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8551 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8552 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8553 | { |
| 8554 | struct sk_buff *msg; |
| 8555 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8556 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8557 | if (!msg) |
| 8558 | return; |
| 8559 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8560 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8561 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8562 | nlmsg_free(msg); |
| 8563 | return; |
| 8564 | } |
| 8565 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8566 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8567 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8568 | } |
| 8569 | |
| 8570 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8571 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8572 | { |
| 8573 | struct sk_buff *msg; |
| 8574 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8575 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8576 | if (!msg) |
| 8577 | return; |
| 8578 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8579 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 8580 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8581 | nlmsg_free(msg); |
| 8582 | return; |
| 8583 | } |
| 8584 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8585 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8586 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8587 | } |
| 8588 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8589 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 8590 | struct net_device *netdev) |
| 8591 | { |
| 8592 | struct sk_buff *msg; |
| 8593 | |
| 8594 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8595 | if (!msg) |
| 8596 | return; |
| 8597 | |
| 8598 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 8599 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 8600 | nlmsg_free(msg); |
| 8601 | return; |
| 8602 | } |
| 8603 | |
| 8604 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8605 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8606 | } |
| 8607 | |
| 8608 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 8609 | struct net_device *netdev, u32 cmd) |
| 8610 | { |
| 8611 | struct sk_buff *msg; |
| 8612 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8613 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8614 | if (!msg) |
| 8615 | return; |
| 8616 | |
| 8617 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 8618 | nlmsg_free(msg); |
| 8619 | return; |
| 8620 | } |
| 8621 | |
| 8622 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8623 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8624 | } |
| 8625 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8626 | /* |
| 8627 | * This can happen on global regulatory changes or device specific settings |
| 8628 | * based on custom world regulatory domains. |
| 8629 | */ |
| 8630 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 8631 | { |
| 8632 | struct sk_buff *msg; |
| 8633 | void *hdr; |
| 8634 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8635 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8636 | if (!msg) |
| 8637 | return; |
| 8638 | |
| 8639 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 8640 | if (!hdr) { |
| 8641 | nlmsg_free(msg); |
| 8642 | return; |
| 8643 | } |
| 8644 | |
| 8645 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8646 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 8647 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8648 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8649 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 8650 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8651 | NL80211_REGDOM_TYPE_WORLD)) |
| 8652 | goto nla_put_failure; |
| 8653 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 8654 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8655 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 8656 | goto nla_put_failure; |
| 8657 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 8658 | request->intersect) { |
| 8659 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8660 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 8661 | goto nla_put_failure; |
| 8662 | } else { |
| 8663 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8664 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 8665 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 8666 | request->alpha2)) |
| 8667 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8668 | } |
| 8669 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 8670 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8671 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 8672 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8673 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8674 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8675 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8676 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8677 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8678 | GFP_ATOMIC); |
| 8679 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8680 | |
| 8681 | return; |
| 8682 | |
| 8683 | nla_put_failure: |
| 8684 | genlmsg_cancel(msg, hdr); |
| 8685 | nlmsg_free(msg); |
| 8686 | } |
| 8687 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8688 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 8689 | struct net_device *netdev, |
| 8690 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8691 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8692 | { |
| 8693 | struct sk_buff *msg; |
| 8694 | void *hdr; |
| 8695 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8696 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8697 | if (!msg) |
| 8698 | return; |
| 8699 | |
| 8700 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8701 | if (!hdr) { |
| 8702 | nlmsg_free(msg); |
| 8703 | return; |
| 8704 | } |
| 8705 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8706 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8707 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8708 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8709 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8710 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8711 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8712 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8713 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8714 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8715 | return; |
| 8716 | |
| 8717 | nla_put_failure: |
| 8718 | genlmsg_cancel(msg, hdr); |
| 8719 | nlmsg_free(msg); |
| 8720 | } |
| 8721 | |
| 8722 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8723 | struct net_device *netdev, const u8 *buf, |
| 8724 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8725 | { |
| 8726 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8727 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8728 | } |
| 8729 | |
| 8730 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 8731 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8732 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8733 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8734 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8735 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8736 | } |
| 8737 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8738 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8739 | struct net_device *netdev, const u8 *buf, |
| 8740 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8741 | { |
| 8742 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8743 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8744 | } |
| 8745 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8746 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 8747 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8748 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8749 | { |
| 8750 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8751 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8752 | } |
| 8753 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 8754 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 8755 | struct net_device *netdev, const u8 *buf, |
| 8756 | size_t len, gfp_t gfp) |
| 8757 | { |
| 8758 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8759 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 8760 | } |
| 8761 | |
| 8762 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 8763 | struct net_device *netdev, const u8 *buf, |
| 8764 | size_t len, gfp_t gfp) |
| 8765 | { |
| 8766 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8767 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 8768 | } |
| 8769 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 8770 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 8771 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8772 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8773 | { |
| 8774 | struct sk_buff *msg; |
| 8775 | void *hdr; |
| 8776 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8777 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8778 | if (!msg) |
| 8779 | return; |
| 8780 | |
| 8781 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8782 | if (!hdr) { |
| 8783 | nlmsg_free(msg); |
| 8784 | return; |
| 8785 | } |
| 8786 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8787 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8788 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8789 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8790 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8791 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8792 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8793 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8794 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8795 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8796 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8797 | return; |
| 8798 | |
| 8799 | nla_put_failure: |
| 8800 | genlmsg_cancel(msg, hdr); |
| 8801 | nlmsg_free(msg); |
| 8802 | } |
| 8803 | |
| 8804 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8805 | struct net_device *netdev, const u8 *addr, |
| 8806 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8807 | { |
| 8808 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8809 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8810 | } |
| 8811 | |
| 8812 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8813 | struct net_device *netdev, const u8 *addr, |
| 8814 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8815 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8816 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8817 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8818 | } |
| 8819 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8820 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8821 | struct net_device *netdev, const u8 *bssid, |
| 8822 | const u8 *req_ie, size_t req_ie_len, |
| 8823 | const u8 *resp_ie, size_t resp_ie_len, |
| 8824 | u16 status, gfp_t gfp) |
| 8825 | { |
| 8826 | struct sk_buff *msg; |
| 8827 | void *hdr; |
| 8828 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8829 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8830 | if (!msg) |
| 8831 | return; |
| 8832 | |
| 8833 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8834 | if (!hdr) { |
| 8835 | nlmsg_free(msg); |
| 8836 | return; |
| 8837 | } |
| 8838 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8839 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8840 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8841 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8842 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8843 | (req_ie && |
| 8844 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8845 | (resp_ie && |
| 8846 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8847 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8848 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8849 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8850 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8851 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8852 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8853 | return; |
| 8854 | |
| 8855 | nla_put_failure: |
| 8856 | genlmsg_cancel(msg, hdr); |
| 8857 | nlmsg_free(msg); |
| 8858 | |
| 8859 | } |
| 8860 | |
| 8861 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8862 | struct net_device *netdev, const u8 *bssid, |
| 8863 | const u8 *req_ie, size_t req_ie_len, |
| 8864 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8865 | { |
| 8866 | struct sk_buff *msg; |
| 8867 | void *hdr; |
| 8868 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8869 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8870 | if (!msg) |
| 8871 | return; |
| 8872 | |
| 8873 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8874 | if (!hdr) { |
| 8875 | nlmsg_free(msg); |
| 8876 | return; |
| 8877 | } |
| 8878 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8879 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8880 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8881 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8882 | (req_ie && |
| 8883 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8884 | (resp_ie && |
| 8885 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8886 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8887 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8888 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8889 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8890 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8891 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8892 | return; |
| 8893 | |
| 8894 | nla_put_failure: |
| 8895 | genlmsg_cancel(msg, hdr); |
| 8896 | nlmsg_free(msg); |
| 8897 | |
| 8898 | } |
| 8899 | |
| 8900 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 8901 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8902 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8903 | { |
| 8904 | struct sk_buff *msg; |
| 8905 | void *hdr; |
| 8906 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8907 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8908 | if (!msg) |
| 8909 | return; |
| 8910 | |
| 8911 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 8912 | if (!hdr) { |
| 8913 | nlmsg_free(msg); |
| 8914 | return; |
| 8915 | } |
| 8916 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8917 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8918 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8919 | (from_ap && reason && |
| 8920 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 8921 | (from_ap && |
| 8922 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 8923 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 8924 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8925 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8926 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8927 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8928 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8929 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8930 | return; |
| 8931 | |
| 8932 | nla_put_failure: |
| 8933 | genlmsg_cancel(msg, hdr); |
| 8934 | nlmsg_free(msg); |
| 8935 | |
| 8936 | } |
| 8937 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8938 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 8939 | struct net_device *netdev, const u8 *bssid, |
| 8940 | gfp_t gfp) |
| 8941 | { |
| 8942 | struct sk_buff *msg; |
| 8943 | void *hdr; |
| 8944 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8945 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8946 | if (!msg) |
| 8947 | return; |
| 8948 | |
| 8949 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 8950 | if (!hdr) { |
| 8951 | nlmsg_free(msg); |
| 8952 | return; |
| 8953 | } |
| 8954 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8955 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8956 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8957 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8958 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8959 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8960 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8961 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8962 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8963 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8964 | return; |
| 8965 | |
| 8966 | nla_put_failure: |
| 8967 | genlmsg_cancel(msg, hdr); |
| 8968 | nlmsg_free(msg); |
| 8969 | } |
| 8970 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8971 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 8972 | struct net_device *netdev, |
| 8973 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 8974 | gfp_t gfp) |
| 8975 | { |
| 8976 | struct sk_buff *msg; |
| 8977 | void *hdr; |
| 8978 | |
| 8979 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8980 | if (!msg) |
| 8981 | return; |
| 8982 | |
| 8983 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 8984 | if (!hdr) { |
| 8985 | nlmsg_free(msg); |
| 8986 | return; |
| 8987 | } |
| 8988 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8989 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8990 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8991 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 8992 | (ie_len && ie && |
| 8993 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 8994 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8995 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8996 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8997 | |
| 8998 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8999 | nl80211_mlme_mcgrp.id, gfp); |
| 9000 | return; |
| 9001 | |
| 9002 | nla_put_failure: |
| 9003 | genlmsg_cancel(msg, hdr); |
| 9004 | nlmsg_free(msg); |
| 9005 | } |
| 9006 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9007 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 9008 | struct net_device *netdev, const u8 *addr, |
| 9009 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9010 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9011 | { |
| 9012 | struct sk_buff *msg; |
| 9013 | void *hdr; |
| 9014 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9015 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9016 | if (!msg) |
| 9017 | return; |
| 9018 | |
| 9019 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9020 | if (!hdr) { |
| 9021 | nlmsg_free(msg); |
| 9022 | return; |
| 9023 | } |
| 9024 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9025 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9026 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9027 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9028 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9029 | (key_id != -1 && |
| 9030 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9031 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9032 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9033 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9034 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9035 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9036 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9037 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9038 | return; |
| 9039 | |
| 9040 | nla_put_failure: |
| 9041 | genlmsg_cancel(msg, hdr); |
| 9042 | nlmsg_free(msg); |
| 9043 | } |
| 9044 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9045 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9046 | struct ieee80211_channel *channel_before, |
| 9047 | struct ieee80211_channel *channel_after) |
| 9048 | { |
| 9049 | struct sk_buff *msg; |
| 9050 | void *hdr; |
| 9051 | struct nlattr *nl_freq; |
| 9052 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9053 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9054 | if (!msg) |
| 9055 | return; |
| 9056 | |
| 9057 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9058 | if (!hdr) { |
| 9059 | nlmsg_free(msg); |
| 9060 | return; |
| 9061 | } |
| 9062 | |
| 9063 | /* |
| 9064 | * Since we are applying the beacon hint to a wiphy we know its |
| 9065 | * wiphy_idx is valid |
| 9066 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9067 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9068 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9069 | |
| 9070 | /* Before */ |
| 9071 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9072 | if (!nl_freq) |
| 9073 | goto nla_put_failure; |
| 9074 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 9075 | goto nla_put_failure; |
| 9076 | nla_nest_end(msg, nl_freq); |
| 9077 | |
| 9078 | /* After */ |
| 9079 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9080 | if (!nl_freq) |
| 9081 | goto nla_put_failure; |
| 9082 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 9083 | goto nla_put_failure; |
| 9084 | nla_nest_end(msg, nl_freq); |
| 9085 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9086 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9087 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9088 | rcu_read_lock(); |
| 9089 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9090 | GFP_ATOMIC); |
| 9091 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9092 | |
| 9093 | return; |
| 9094 | |
| 9095 | nla_put_failure: |
| 9096 | genlmsg_cancel(msg, hdr); |
| 9097 | nlmsg_free(msg); |
| 9098 | } |
| 9099 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9100 | static void nl80211_send_remain_on_chan_event( |
| 9101 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9102 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9103 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9104 | unsigned int duration, gfp_t gfp) |
| 9105 | { |
| 9106 | struct sk_buff *msg; |
| 9107 | void *hdr; |
| 9108 | |
| 9109 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9110 | if (!msg) |
| 9111 | return; |
| 9112 | |
| 9113 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9114 | if (!hdr) { |
| 9115 | nlmsg_free(msg); |
| 9116 | return; |
| 9117 | } |
| 9118 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9119 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9120 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9121 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9122 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9123 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9124 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9125 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9126 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9127 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9128 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9129 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9130 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9131 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9132 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9133 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9134 | |
| 9135 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9136 | nl80211_mlme_mcgrp.id, gfp); |
| 9137 | return; |
| 9138 | |
| 9139 | nla_put_failure: |
| 9140 | genlmsg_cancel(msg, hdr); |
| 9141 | nlmsg_free(msg); |
| 9142 | } |
| 9143 | |
| 9144 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9145 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9146 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9147 | unsigned int duration, gfp_t gfp) |
| 9148 | { |
| 9149 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9150 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9151 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9152 | } |
| 9153 | |
| 9154 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9155 | struct cfg80211_registered_device *rdev, |
| 9156 | struct wireless_dev *wdev, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9157 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9158 | { |
| 9159 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9160 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9161 | } |
| 9162 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9163 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 9164 | struct net_device *dev, const u8 *mac_addr, |
| 9165 | struct station_info *sinfo, gfp_t gfp) |
| 9166 | { |
| 9167 | struct sk_buff *msg; |
| 9168 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9169 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9170 | if (!msg) |
| 9171 | return; |
| 9172 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9173 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9174 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9175 | nlmsg_free(msg); |
| 9176 | return; |
| 9177 | } |
| 9178 | |
| 9179 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9180 | nl80211_mlme_mcgrp.id, gfp); |
| 9181 | } |
| 9182 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9183 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 9184 | struct net_device *dev, const u8 *mac_addr, |
| 9185 | gfp_t gfp) |
| 9186 | { |
| 9187 | struct sk_buff *msg; |
| 9188 | void *hdr; |
| 9189 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9190 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9191 | if (!msg) |
| 9192 | return; |
| 9193 | |
| 9194 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9195 | if (!hdr) { |
| 9196 | nlmsg_free(msg); |
| 9197 | return; |
| 9198 | } |
| 9199 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9200 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9201 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9202 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9203 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9204 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9205 | |
| 9206 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9207 | nl80211_mlme_mcgrp.id, gfp); |
| 9208 | return; |
| 9209 | |
| 9210 | nla_put_failure: |
| 9211 | genlmsg_cancel(msg, hdr); |
| 9212 | nlmsg_free(msg); |
| 9213 | } |
| 9214 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9215 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 9216 | struct net_device *dev, const u8 *mac_addr, |
| 9217 | enum nl80211_connect_failed_reason reason, |
| 9218 | gfp_t gfp) |
| 9219 | { |
| 9220 | struct sk_buff *msg; |
| 9221 | void *hdr; |
| 9222 | |
| 9223 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9224 | if (!msg) |
| 9225 | return; |
| 9226 | |
| 9227 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9228 | if (!hdr) { |
| 9229 | nlmsg_free(msg); |
| 9230 | return; |
| 9231 | } |
| 9232 | |
| 9233 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9234 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9235 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9236 | goto nla_put_failure; |
| 9237 | |
| 9238 | genlmsg_end(msg, hdr); |
| 9239 | |
| 9240 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9241 | nl80211_mlme_mcgrp.id, gfp); |
| 9242 | return; |
| 9243 | |
| 9244 | nla_put_failure: |
| 9245 | genlmsg_cancel(msg, hdr); |
| 9246 | nlmsg_free(msg); |
| 9247 | } |
| 9248 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9249 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9250 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9251 | { |
| 9252 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9253 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9254 | struct sk_buff *msg; |
| 9255 | void *hdr; |
| 9256 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9257 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9258 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9259 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9260 | return false; |
| 9261 | |
| 9262 | msg = nlmsg_new(100, gfp); |
| 9263 | if (!msg) |
| 9264 | return true; |
| 9265 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9266 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9267 | if (!hdr) { |
| 9268 | nlmsg_free(msg); |
| 9269 | return true; |
| 9270 | } |
| 9271 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9272 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9273 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9274 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9275 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9276 | |
| 9277 | err = genlmsg_end(msg, hdr); |
| 9278 | if (err < 0) { |
| 9279 | nlmsg_free(msg); |
| 9280 | return true; |
| 9281 | } |
| 9282 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9283 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9284 | return true; |
| 9285 | |
| 9286 | nla_put_failure: |
| 9287 | genlmsg_cancel(msg, hdr); |
| 9288 | nlmsg_free(msg); |
| 9289 | return true; |
| 9290 | } |
| 9291 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9292 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 9293 | { |
| 9294 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9295 | addr, gfp); |
| 9296 | } |
| 9297 | |
| 9298 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 9299 | const u8 *addr, gfp_t gfp) |
| 9300 | { |
| 9301 | return __nl80211_unexpected_frame(dev, |
| 9302 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9303 | addr, gfp); |
| 9304 | } |
| 9305 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9306 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9307 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9308 | int freq, int sig_dbm, |
| 9309 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9310 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9311 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9312 | struct sk_buff *msg; |
| 9313 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9314 | |
| 9315 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9316 | if (!msg) |
| 9317 | return -ENOMEM; |
| 9318 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9319 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9320 | if (!hdr) { |
| 9321 | nlmsg_free(msg); |
| 9322 | return -ENOMEM; |
| 9323 | } |
| 9324 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9325 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9326 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9327 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9328 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 9329 | (sig_dbm && |
| 9330 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9331 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9332 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9333 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9334 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9335 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9336 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9337 | |
| 9338 | nla_put_failure: |
| 9339 | genlmsg_cancel(msg, hdr); |
| 9340 | nlmsg_free(msg); |
| 9341 | return -ENOBUFS; |
| 9342 | } |
| 9343 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9344 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9345 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9346 | const u8 *buf, size_t len, bool ack, |
| 9347 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9348 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9349 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9350 | struct sk_buff *msg; |
| 9351 | void *hdr; |
| 9352 | |
| 9353 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9354 | if (!msg) |
| 9355 | return; |
| 9356 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9357 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9358 | if (!hdr) { |
| 9359 | nlmsg_free(msg); |
| 9360 | return; |
| 9361 | } |
| 9362 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9363 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9364 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9365 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9366 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 9367 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9368 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9369 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9370 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9371 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9372 | |
| 9373 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 9374 | return; |
| 9375 | |
| 9376 | nla_put_failure: |
| 9377 | genlmsg_cancel(msg, hdr); |
| 9378 | nlmsg_free(msg); |
| 9379 | } |
| 9380 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9381 | void |
| 9382 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 9383 | struct net_device *netdev, |
| 9384 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 9385 | gfp_t gfp) |
| 9386 | { |
| 9387 | struct sk_buff *msg; |
| 9388 | struct nlattr *pinfoattr; |
| 9389 | void *hdr; |
| 9390 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9391 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9392 | if (!msg) |
| 9393 | return; |
| 9394 | |
| 9395 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9396 | if (!hdr) { |
| 9397 | nlmsg_free(msg); |
| 9398 | return; |
| 9399 | } |
| 9400 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9401 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9402 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9403 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9404 | |
| 9405 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9406 | if (!pinfoattr) |
| 9407 | goto nla_put_failure; |
| 9408 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9409 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 9410 | rssi_event)) |
| 9411 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9412 | |
| 9413 | nla_nest_end(msg, pinfoattr); |
| 9414 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9415 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9416 | |
| 9417 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9418 | nl80211_mlme_mcgrp.id, gfp); |
| 9419 | return; |
| 9420 | |
| 9421 | nla_put_failure: |
| 9422 | genlmsg_cancel(msg, hdr); |
| 9423 | nlmsg_free(msg); |
| 9424 | } |
| 9425 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9426 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 9427 | struct net_device *netdev, const u8 *bssid, |
| 9428 | const u8 *replay_ctr, gfp_t gfp) |
| 9429 | { |
| 9430 | struct sk_buff *msg; |
| 9431 | struct nlattr *rekey_attr; |
| 9432 | void *hdr; |
| 9433 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9434 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9435 | if (!msg) |
| 9436 | return; |
| 9437 | |
| 9438 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 9439 | if (!hdr) { |
| 9440 | nlmsg_free(msg); |
| 9441 | return; |
| 9442 | } |
| 9443 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9444 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9445 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9446 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9447 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9448 | |
| 9449 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 9450 | if (!rekey_attr) |
| 9451 | goto nla_put_failure; |
| 9452 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9453 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 9454 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 9455 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9456 | |
| 9457 | nla_nest_end(msg, rekey_attr); |
| 9458 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9459 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9460 | |
| 9461 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9462 | nl80211_mlme_mcgrp.id, gfp); |
| 9463 | return; |
| 9464 | |
| 9465 | nla_put_failure: |
| 9466 | genlmsg_cancel(msg, hdr); |
| 9467 | nlmsg_free(msg); |
| 9468 | } |
| 9469 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9470 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 9471 | struct net_device *netdev, int index, |
| 9472 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 9473 | { |
| 9474 | struct sk_buff *msg; |
| 9475 | struct nlattr *attr; |
| 9476 | void *hdr; |
| 9477 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9478 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9479 | if (!msg) |
| 9480 | return; |
| 9481 | |
| 9482 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 9483 | if (!hdr) { |
| 9484 | nlmsg_free(msg); |
| 9485 | return; |
| 9486 | } |
| 9487 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9488 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9489 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9490 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9491 | |
| 9492 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 9493 | if (!attr) |
| 9494 | goto nla_put_failure; |
| 9495 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9496 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 9497 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 9498 | (preauth && |
| 9499 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 9500 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9501 | |
| 9502 | nla_nest_end(msg, attr); |
| 9503 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9504 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 9505 | |
| 9506 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9507 | nl80211_mlme_mcgrp.id, gfp); |
| 9508 | return; |
| 9509 | |
| 9510 | nla_put_failure: |
| 9511 | genlmsg_cancel(msg, hdr); |
| 9512 | nlmsg_free(msg); |
| 9513 | } |
| 9514 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9515 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9516 | struct net_device *netdev, |
| 9517 | struct cfg80211_chan_def *chandef, gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9518 | { |
| 9519 | struct sk_buff *msg; |
| 9520 | void *hdr; |
| 9521 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9522 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9523 | if (!msg) |
| 9524 | return; |
| 9525 | |
| 9526 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 9527 | if (!hdr) { |
| 9528 | nlmsg_free(msg); |
| 9529 | return; |
| 9530 | } |
| 9531 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9532 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9533 | goto nla_put_failure; |
| 9534 | |
| 9535 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 9536 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 9537 | |
| 9538 | genlmsg_end(msg, hdr); |
| 9539 | |
| 9540 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9541 | nl80211_mlme_mcgrp.id, gfp); |
| 9542 | return; |
| 9543 | |
| 9544 | nla_put_failure: |
| 9545 | genlmsg_cancel(msg, hdr); |
| 9546 | nlmsg_free(msg); |
| 9547 | } |
| 9548 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9549 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9550 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 9551 | struct net_device *netdev, const u8 *peer, |
| 9552 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 9553 | { |
| 9554 | struct sk_buff *msg; |
| 9555 | struct nlattr *pinfoattr; |
| 9556 | void *hdr; |
| 9557 | |
| 9558 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9559 | if (!msg) |
| 9560 | return; |
| 9561 | |
| 9562 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9563 | if (!hdr) { |
| 9564 | nlmsg_free(msg); |
| 9565 | return; |
| 9566 | } |
| 9567 | |
| 9568 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9569 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9570 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9571 | goto nla_put_failure; |
| 9572 | |
| 9573 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9574 | if (!pinfoattr) |
| 9575 | goto nla_put_failure; |
| 9576 | |
| 9577 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 9578 | goto nla_put_failure; |
| 9579 | |
| 9580 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 9581 | goto nla_put_failure; |
| 9582 | |
| 9583 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 9584 | goto nla_put_failure; |
| 9585 | |
| 9586 | nla_nest_end(msg, pinfoattr); |
| 9587 | |
| 9588 | genlmsg_end(msg, hdr); |
| 9589 | |
| 9590 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9591 | nl80211_mlme_mcgrp.id, gfp); |
| 9592 | return; |
| 9593 | |
| 9594 | nla_put_failure: |
| 9595 | genlmsg_cancel(msg, hdr); |
| 9596 | nlmsg_free(msg); |
| 9597 | } |
| 9598 | |
| 9599 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9600 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 9601 | struct cfg80211_chan_def *chandef, |
| 9602 | enum nl80211_radar_event event, |
| 9603 | struct net_device *netdev, gfp_t gfp) |
| 9604 | { |
| 9605 | struct sk_buff *msg; |
| 9606 | void *hdr; |
| 9607 | |
| 9608 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9609 | if (!msg) |
| 9610 | return; |
| 9611 | |
| 9612 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 9613 | if (!hdr) { |
| 9614 | nlmsg_free(msg); |
| 9615 | return; |
| 9616 | } |
| 9617 | |
| 9618 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 9619 | goto nla_put_failure; |
| 9620 | |
| 9621 | /* NOP and radar events don't need a netdev parameter */ |
| 9622 | if (netdev) { |
| 9623 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 9624 | |
| 9625 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9626 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 9627 | goto nla_put_failure; |
| 9628 | } |
| 9629 | |
| 9630 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 9631 | goto nla_put_failure; |
| 9632 | |
| 9633 | if (nl80211_send_chandef(msg, chandef)) |
| 9634 | goto nla_put_failure; |
| 9635 | |
| 9636 | if (genlmsg_end(msg, hdr) < 0) { |
| 9637 | nlmsg_free(msg); |
| 9638 | return; |
| 9639 | } |
| 9640 | |
| 9641 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9642 | nl80211_mlme_mcgrp.id, gfp); |
| 9643 | return; |
| 9644 | |
| 9645 | nla_put_failure: |
| 9646 | genlmsg_cancel(msg, hdr); |
| 9647 | nlmsg_free(msg); |
| 9648 | } |
| 9649 | |
| 9650 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9651 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 9652 | struct net_device *netdev, const u8 *peer, |
| 9653 | u32 num_packets, gfp_t gfp) |
| 9654 | { |
| 9655 | struct sk_buff *msg; |
| 9656 | struct nlattr *pinfoattr; |
| 9657 | void *hdr; |
| 9658 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9659 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9660 | if (!msg) |
| 9661 | return; |
| 9662 | |
| 9663 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9664 | if (!hdr) { |
| 9665 | nlmsg_free(msg); |
| 9666 | return; |
| 9667 | } |
| 9668 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9669 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9670 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9671 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9672 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9673 | |
| 9674 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9675 | if (!pinfoattr) |
| 9676 | goto nla_put_failure; |
| 9677 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9678 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 9679 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9680 | |
| 9681 | nla_nest_end(msg, pinfoattr); |
| 9682 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9683 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9684 | |
| 9685 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9686 | nl80211_mlme_mcgrp.id, gfp); |
| 9687 | return; |
| 9688 | |
| 9689 | nla_put_failure: |
| 9690 | genlmsg_cancel(msg, hdr); |
| 9691 | nlmsg_free(msg); |
| 9692 | } |
| 9693 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9694 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 9695 | u64 cookie, bool acked, gfp_t gfp) |
| 9696 | { |
| 9697 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9698 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9699 | struct sk_buff *msg; |
| 9700 | void *hdr; |
| 9701 | int err; |
| 9702 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9703 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 9704 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9705 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9706 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9707 | if (!msg) |
| 9708 | return; |
| 9709 | |
| 9710 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 9711 | if (!hdr) { |
| 9712 | nlmsg_free(msg); |
| 9713 | return; |
| 9714 | } |
| 9715 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9716 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9717 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9718 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9719 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9720 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9721 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9722 | |
| 9723 | err = genlmsg_end(msg, hdr); |
| 9724 | if (err < 0) { |
| 9725 | nlmsg_free(msg); |
| 9726 | return; |
| 9727 | } |
| 9728 | |
| 9729 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9730 | nl80211_mlme_mcgrp.id, gfp); |
| 9731 | return; |
| 9732 | |
| 9733 | nla_put_failure: |
| 9734 | genlmsg_cancel(msg, hdr); |
| 9735 | nlmsg_free(msg); |
| 9736 | } |
| 9737 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 9738 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9739 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 9740 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9741 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9742 | { |
| 9743 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9744 | struct sk_buff *msg; |
| 9745 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9746 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9747 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9748 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 9749 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9750 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9751 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9752 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 9753 | if (!msg) { |
| 9754 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9755 | return; |
| 9756 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9757 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9758 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 9759 | if (!hdr) |
| 9760 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9761 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9762 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9763 | (freq && |
| 9764 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9765 | (sig_dbm && |
| 9766 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9767 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 9768 | goto nla_put_failure; |
| 9769 | |
| 9770 | genlmsg_end(msg, hdr); |
| 9771 | |
| 9772 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9773 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9774 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9775 | return; |
| 9776 | |
| 9777 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9778 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9779 | if (hdr) |
| 9780 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9781 | nlmsg_free(msg); |
| 9782 | } |
| 9783 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 9784 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 9785 | #ifdef CONFIG_PM |
| 9786 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 9787 | struct cfg80211_wowlan_wakeup *wakeup, |
| 9788 | gfp_t gfp) |
| 9789 | { |
| 9790 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9791 | struct sk_buff *msg; |
| 9792 | void *hdr; |
| 9793 | int err, size = 200; |
| 9794 | |
| 9795 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 9796 | |
| 9797 | if (wakeup) |
| 9798 | size += wakeup->packet_present_len; |
| 9799 | |
| 9800 | msg = nlmsg_new(size, gfp); |
| 9801 | if (!msg) |
| 9802 | return; |
| 9803 | |
| 9804 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 9805 | if (!hdr) |
| 9806 | goto free_msg; |
| 9807 | |
| 9808 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9809 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 9810 | goto free_msg; |
| 9811 | |
| 9812 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9813 | wdev->netdev->ifindex)) |
| 9814 | goto free_msg; |
| 9815 | |
| 9816 | if (wakeup) { |
| 9817 | struct nlattr *reasons; |
| 9818 | |
| 9819 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9820 | |
| 9821 | if (wakeup->disconnect && |
| 9822 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 9823 | goto free_msg; |
| 9824 | if (wakeup->magic_pkt && |
| 9825 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 9826 | goto free_msg; |
| 9827 | if (wakeup->gtk_rekey_failure && |
| 9828 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 9829 | goto free_msg; |
| 9830 | if (wakeup->eap_identity_req && |
| 9831 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 9832 | goto free_msg; |
| 9833 | if (wakeup->four_way_handshake && |
| 9834 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 9835 | goto free_msg; |
| 9836 | if (wakeup->rfkill_release && |
| 9837 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 9838 | goto free_msg; |
| 9839 | |
| 9840 | if (wakeup->pattern_idx >= 0 && |
| 9841 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 9842 | wakeup->pattern_idx)) |
| 9843 | goto free_msg; |
| 9844 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9845 | if (wakeup->tcp_match) |
| 9846 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 9847 | |
| 9848 | if (wakeup->tcp_connlost) |
| 9849 | nla_put_flag(msg, |
| 9850 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 9851 | |
| 9852 | if (wakeup->tcp_nomoretokens) |
| 9853 | nla_put_flag(msg, |
| 9854 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 9855 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 9856 | if (wakeup->packet) { |
| 9857 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 9858 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 9859 | |
| 9860 | if (!wakeup->packet_80211) { |
| 9861 | pkt_attr = |
| 9862 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 9863 | len_attr = |
| 9864 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 9865 | } |
| 9866 | |
| 9867 | if (wakeup->packet_len && |
| 9868 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 9869 | goto free_msg; |
| 9870 | |
| 9871 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 9872 | wakeup->packet)) |
| 9873 | goto free_msg; |
| 9874 | } |
| 9875 | |
| 9876 | nla_nest_end(msg, reasons); |
| 9877 | } |
| 9878 | |
| 9879 | err = genlmsg_end(msg, hdr); |
| 9880 | if (err < 0) |
| 9881 | goto free_msg; |
| 9882 | |
| 9883 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9884 | nl80211_mlme_mcgrp.id, gfp); |
| 9885 | return; |
| 9886 | |
| 9887 | free_msg: |
| 9888 | nlmsg_free(msg); |
| 9889 | } |
| 9890 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 9891 | #endif |
| 9892 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 9893 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 9894 | enum nl80211_tdls_operation oper, |
| 9895 | u16 reason_code, gfp_t gfp) |
| 9896 | { |
| 9897 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9898 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9899 | struct sk_buff *msg; |
| 9900 | void *hdr; |
| 9901 | int err; |
| 9902 | |
| 9903 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 9904 | reason_code); |
| 9905 | |
| 9906 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9907 | if (!msg) |
| 9908 | return; |
| 9909 | |
| 9910 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 9911 | if (!hdr) { |
| 9912 | nlmsg_free(msg); |
| 9913 | return; |
| 9914 | } |
| 9915 | |
| 9916 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9917 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9918 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 9919 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 9920 | (reason_code > 0 && |
| 9921 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 9922 | goto nla_put_failure; |
| 9923 | |
| 9924 | err = genlmsg_end(msg, hdr); |
| 9925 | if (err < 0) { |
| 9926 | nlmsg_free(msg); |
| 9927 | return; |
| 9928 | } |
| 9929 | |
| 9930 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9931 | nl80211_mlme_mcgrp.id, gfp); |
| 9932 | return; |
| 9933 | |
| 9934 | nla_put_failure: |
| 9935 | genlmsg_cancel(msg, hdr); |
| 9936 | nlmsg_free(msg); |
| 9937 | } |
| 9938 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 9939 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9940 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 9941 | unsigned long state, |
| 9942 | void *_notify) |
| 9943 | { |
| 9944 | struct netlink_notify *notify = _notify; |
| 9945 | struct cfg80211_registered_device *rdev; |
| 9946 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9947 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9948 | |
| 9949 | if (state != NETLINK_URELEASE) |
| 9950 | return NOTIFY_DONE; |
| 9951 | |
| 9952 | rcu_read_lock(); |
| 9953 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9954 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9955 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9956 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9957 | |
| 9958 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9959 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 9960 | list) { |
| 9961 | if (reg->nlportid == notify->portid) { |
| 9962 | list_del(®->list); |
| 9963 | kfree(reg); |
| 9964 | break; |
| 9965 | } |
| 9966 | } |
| 9967 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9968 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9969 | |
| 9970 | rcu_read_unlock(); |
| 9971 | |
| 9972 | return NOTIFY_DONE; |
| 9973 | } |
| 9974 | |
| 9975 | static struct notifier_block nl80211_netlink_notifier = { |
| 9976 | .notifier_call = nl80211_netlink_notify, |
| 9977 | }; |
| 9978 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9979 | /* initialisation/exit functions */ |
| 9980 | |
| 9981 | int nl80211_init(void) |
| 9982 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9983 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9984 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9985 | err = genl_register_family_with_ops(&nl80211_fam, |
| 9986 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9987 | if (err) |
| 9988 | return err; |
| 9989 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9990 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 9991 | if (err) |
| 9992 | goto err_out; |
| 9993 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9994 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 9995 | if (err) |
| 9996 | goto err_out; |
| 9997 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9998 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 9999 | if (err) |
| 10000 | goto err_out; |
| 10001 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10002 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 10003 | if (err) |
| 10004 | goto err_out; |
| 10005 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10006 | #ifdef CONFIG_NL80211_TESTMODE |
| 10007 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 10008 | if (err) |
| 10009 | goto err_out; |
| 10010 | #endif |
| 10011 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10012 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10013 | if (err) |
| 10014 | goto err_out; |
| 10015 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10016 | return 0; |
| 10017 | err_out: |
| 10018 | genl_unregister_family(&nl80211_fam); |
| 10019 | return err; |
| 10020 | } |
| 10021 | |
| 10022 | void nl80211_exit(void) |
| 10023 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10024 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10025 | genl_unregister_family(&nl80211_fam); |
| 10026 | } |