Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | #include "core.h" |
| 23 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 24 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 25 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 26 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 27 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 28 | struct genl_info *info, |
| 29 | struct cfg80211_crypto_settings *settings, |
| 30 | int cipher_limit); |
| 31 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 32 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 33 | struct genl_info *info); |
| 34 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 35 | struct genl_info *info); |
| 36 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | /* the netlink family */ |
| 38 | static struct genl_family nl80211_fam = { |
| 39 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 40 | .name = "nl80211", /* have users key off the name instead */ |
| 41 | .hdrsize = 0, /* no private header */ |
| 42 | .version = 1, /* no particular meaning now */ |
| 43 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 44 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 45 | .pre_doit = nl80211_pre_doit, |
| 46 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 49 | /* returns ERR_PTR values */ |
| 50 | static struct wireless_dev * |
| 51 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 52 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 53 | struct cfg80211_registered_device *rdev; |
| 54 | struct wireless_dev *result = NULL; |
| 55 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 56 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 57 | u64 wdev_id; |
| 58 | int wiphy_idx = -1; |
| 59 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 60 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 61 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 62 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 63 | if (!have_ifidx && !have_wdev_id) |
| 64 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 65 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 66 | if (have_ifidx) |
| 67 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 68 | if (have_wdev_id) { |
| 69 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 70 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 73 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 74 | struct wireless_dev *wdev; |
| 75 | |
| 76 | if (wiphy_net(&rdev->wiphy) != netns) |
| 77 | continue; |
| 78 | |
| 79 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 80 | continue; |
| 81 | |
| 82 | mutex_lock(&rdev->devlist_mtx); |
| 83 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 84 | if (have_ifidx && wdev->netdev && |
| 85 | wdev->netdev->ifindex == ifidx) { |
| 86 | result = wdev; |
| 87 | break; |
| 88 | } |
| 89 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 90 | result = wdev; |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | mutex_unlock(&rdev->devlist_mtx); |
| 95 | |
| 96 | if (result) |
| 97 | break; |
| 98 | } |
| 99 | |
| 100 | if (result) |
| 101 | return result; |
| 102 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 103 | } |
| 104 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 105 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 106 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 107 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 108 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 109 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 110 | |
| 111 | assert_cfg80211_lock(); |
| 112 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 113 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 114 | !attrs[NL80211_ATTR_IFINDEX] && |
| 115 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 116 | return ERR_PTR(-EINVAL); |
| 117 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 118 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 119 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 120 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 121 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 122 | if (attrs[NL80211_ATTR_WDEV]) { |
| 123 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 124 | struct wireless_dev *wdev; |
| 125 | bool found = false; |
| 126 | |
| 127 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 128 | if (tmp) { |
| 129 | /* make sure wdev exists */ |
| 130 | mutex_lock(&tmp->devlist_mtx); |
| 131 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 132 | if (wdev->identifier != (u32)wdev_id) |
| 133 | continue; |
| 134 | found = true; |
| 135 | break; |
| 136 | } |
| 137 | mutex_unlock(&tmp->devlist_mtx); |
| 138 | |
| 139 | if (!found) |
| 140 | tmp = NULL; |
| 141 | |
| 142 | if (rdev && tmp != rdev) |
| 143 | return ERR_PTR(-EINVAL); |
| 144 | rdev = tmp; |
| 145 | } |
| 146 | } |
| 147 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 148 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 149 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 150 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 151 | if (netdev) { |
| 152 | if (netdev->ieee80211_ptr) |
| 153 | tmp = wiphy_to_dev( |
| 154 | netdev->ieee80211_ptr->wiphy); |
| 155 | else |
| 156 | tmp = NULL; |
| 157 | |
| 158 | dev_put(netdev); |
| 159 | |
| 160 | /* not wireless device -- return error */ |
| 161 | if (!tmp) |
| 162 | return ERR_PTR(-EINVAL); |
| 163 | |
| 164 | /* mismatch -- return error */ |
| 165 | if (rdev && tmp != rdev) |
| 166 | return ERR_PTR(-EINVAL); |
| 167 | |
| 168 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 169 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 170 | } |
| 171 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 172 | if (!rdev) |
| 173 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 174 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 175 | if (netns != wiphy_net(&rdev->wiphy)) |
| 176 | return ERR_PTR(-ENODEV); |
| 177 | |
| 178 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* |
| 182 | * This function returns a pointer to the driver |
| 183 | * that the genl_info item that is passed refers to. |
| 184 | * If successful, it returns non-NULL and also locks |
| 185 | * the driver's mutex! |
| 186 | * |
| 187 | * This means that you need to call cfg80211_unlock_rdev() |
| 188 | * before being allowed to acquire &cfg80211_mutex! |
| 189 | * |
| 190 | * This is necessary because we need to lock the global |
| 191 | * mutex to get an item off the list safely, and then |
| 192 | * we lock the rdev mutex so it doesn't go away under us. |
| 193 | * |
| 194 | * We don't want to keep cfg80211_mutex locked |
| 195 | * for all the time in order to allow requests on |
| 196 | * other interfaces to go through at the same time. |
| 197 | * |
| 198 | * The result of this can be a PTR_ERR and hence must |
| 199 | * be checked with IS_ERR() for errors. |
| 200 | */ |
| 201 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 202 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 203 | { |
| 204 | struct cfg80211_registered_device *rdev; |
| 205 | |
| 206 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 207 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 208 | |
| 209 | /* if it is not an error we grab the lock on |
| 210 | * it to assure it won't be going away while |
| 211 | * we operate on it */ |
| 212 | if (!IS_ERR(rdev)) |
| 213 | mutex_lock(&rdev->mtx); |
| 214 | |
| 215 | mutex_unlock(&cfg80211_mutex); |
| 216 | |
| 217 | return rdev; |
| 218 | } |
| 219 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 220 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 221 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 222 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 223 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 224 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 225 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame^] | 226 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 227 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame^] | 229 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 230 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 232 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 233 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 234 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 235 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 236 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 238 | |
| 239 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 240 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 242 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 243 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 244 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 245 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 246 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 247 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 248 | .len = WLAN_MAX_KEY_LEN }, |
| 249 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 250 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 251 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 252 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 253 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 254 | |
| 255 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 256 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 257 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 258 | .len = IEEE80211_MAX_DATA_LEN }, |
| 259 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 260 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 262 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 263 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 264 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 265 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 266 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 268 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 269 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 270 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 271 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 272 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 273 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 274 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 275 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 276 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 277 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 278 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 279 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 280 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 281 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 282 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 283 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 284 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 285 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 286 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 287 | |
| 288 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 289 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 290 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 291 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 292 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 293 | |
| 294 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 295 | .len = IEEE80211_MAX_SSID_LEN }, |
| 296 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 297 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 298 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 299 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_STA_FLAGS2] = { |
| 302 | .len = sizeof(struct nl80211_sta_flag_update), |
| 303 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 304 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 306 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 308 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 309 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 311 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 313 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 314 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 315 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 318 | .len = IEEE80211_MAX_DATA_LEN }, |
| 319 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 320 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 322 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 323 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 324 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 325 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 327 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 328 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 329 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 330 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 331 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 333 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 335 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 336 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 337 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 339 | .len = IEEE80211_MAX_DATA_LEN }, |
| 340 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 341 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 342 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 343 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 344 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 345 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 346 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 347 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 348 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 349 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 350 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 351 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 352 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 353 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 354 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 355 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 356 | .len = NL80211_HT_CAPABILITY_LEN |
| 357 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 358 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 359 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 360 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 361 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 362 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 363 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 364 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 365 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 366 | }; |
| 367 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 368 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 369 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 370 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 371 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 372 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 373 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 374 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 375 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 376 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 377 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 378 | }; |
| 379 | |
| 380 | /* policy for the key default flags */ |
| 381 | static const struct nla_policy |
| 382 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 383 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 384 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 385 | }; |
| 386 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 387 | /* policy for WoWLAN attributes */ |
| 388 | static const struct nla_policy |
| 389 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 390 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 391 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 392 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 393 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 394 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 395 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 396 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 397 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 398 | }; |
| 399 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 400 | /* policy for GTK rekey offload attributes */ |
| 401 | static const struct nla_policy |
| 402 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 403 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 404 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 405 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 406 | }; |
| 407 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 408 | static const struct nla_policy |
| 409 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 410 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 411 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 412 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 413 | }; |
| 414 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 415 | /* ifidx get helper */ |
| 416 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 417 | { |
| 418 | int res; |
| 419 | |
| 420 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 421 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 422 | nl80211_policy); |
| 423 | if (res) |
| 424 | return res; |
| 425 | |
| 426 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 427 | return -EINVAL; |
| 428 | |
| 429 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 430 | if (!res) |
| 431 | return -EINVAL; |
| 432 | return res; |
| 433 | } |
| 434 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 435 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 436 | struct netlink_callback *cb, |
| 437 | struct cfg80211_registered_device **rdev, |
| 438 | struct net_device **dev) |
| 439 | { |
| 440 | int ifidx = cb->args[0]; |
| 441 | int err; |
| 442 | |
| 443 | if (!ifidx) |
| 444 | ifidx = nl80211_get_ifidx(cb); |
| 445 | if (ifidx < 0) |
| 446 | return ifidx; |
| 447 | |
| 448 | cb->args[0] = ifidx; |
| 449 | |
| 450 | rtnl_lock(); |
| 451 | |
| 452 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 453 | if (!*dev) { |
| 454 | err = -ENODEV; |
| 455 | goto out_rtnl; |
| 456 | } |
| 457 | |
| 458 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 459 | if (IS_ERR(*rdev)) { |
| 460 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 461 | goto out_rtnl; |
| 462 | } |
| 463 | |
| 464 | return 0; |
| 465 | out_rtnl: |
| 466 | rtnl_unlock(); |
| 467 | return err; |
| 468 | } |
| 469 | |
| 470 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 471 | { |
| 472 | cfg80211_unlock_rdev(rdev); |
| 473 | rtnl_unlock(); |
| 474 | } |
| 475 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 476 | /* IE validation */ |
| 477 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 478 | { |
| 479 | const u8 *pos; |
| 480 | int len; |
| 481 | |
| 482 | if (!attr) |
| 483 | return true; |
| 484 | |
| 485 | pos = nla_data(attr); |
| 486 | len = nla_len(attr); |
| 487 | |
| 488 | while (len) { |
| 489 | u8 elemlen; |
| 490 | |
| 491 | if (len < 2) |
| 492 | return false; |
| 493 | len -= 2; |
| 494 | |
| 495 | elemlen = pos[1]; |
| 496 | if (elemlen > len) |
| 497 | return false; |
| 498 | |
| 499 | len -= elemlen; |
| 500 | pos += 2 + elemlen; |
| 501 | } |
| 502 | |
| 503 | return true; |
| 504 | } |
| 505 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 506 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 507 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 508 | int flags, u8 cmd) |
| 509 | { |
| 510 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 511 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 512 | } |
| 513 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 514 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 515 | struct ieee80211_channel *chan) |
| 516 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 517 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 518 | chan->center_freq)) |
| 519 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 520 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 521 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 522 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 523 | goto nla_put_failure; |
| 524 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 525 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 526 | goto nla_put_failure; |
| 527 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 528 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 529 | goto nla_put_failure; |
| 530 | if ((chan->flags & IEEE80211_CHAN_RADAR) && |
| 531 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 532 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 533 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 534 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 535 | DBM_TO_MBM(chan->max_power))) |
| 536 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 537 | |
| 538 | return 0; |
| 539 | |
| 540 | nla_put_failure: |
| 541 | return -ENOBUFS; |
| 542 | } |
| 543 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 544 | /* netlink command implementations */ |
| 545 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 546 | struct key_parse { |
| 547 | struct key_params p; |
| 548 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 549 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 550 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 551 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 552 | }; |
| 553 | |
| 554 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 555 | { |
| 556 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 557 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 558 | nl80211_key_policy); |
| 559 | if (err) |
| 560 | return err; |
| 561 | |
| 562 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 563 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 564 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 565 | if (k->def) { |
| 566 | k->def_uni = true; |
| 567 | k->def_multi = true; |
| 568 | } |
| 569 | if (k->defmgmt) |
| 570 | k->def_multi = true; |
| 571 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 572 | if (tb[NL80211_KEY_IDX]) |
| 573 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 574 | |
| 575 | if (tb[NL80211_KEY_DATA]) { |
| 576 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 577 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 578 | } |
| 579 | |
| 580 | if (tb[NL80211_KEY_SEQ]) { |
| 581 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 582 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 583 | } |
| 584 | |
| 585 | if (tb[NL80211_KEY_CIPHER]) |
| 586 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 587 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 588 | if (tb[NL80211_KEY_TYPE]) { |
| 589 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 590 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 591 | return -EINVAL; |
| 592 | } |
| 593 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 594 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 595 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 596 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 597 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 598 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 599 | if (err) |
| 600 | return err; |
| 601 | |
| 602 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 603 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 604 | } |
| 605 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 610 | { |
| 611 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 612 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 613 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 614 | } |
| 615 | |
| 616 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 617 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 618 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 619 | } |
| 620 | |
| 621 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 622 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 623 | |
| 624 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 625 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 626 | |
| 627 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 628 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 629 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 630 | if (k->def) { |
| 631 | k->def_uni = true; |
| 632 | k->def_multi = true; |
| 633 | } |
| 634 | if (k->defmgmt) |
| 635 | k->def_multi = true; |
| 636 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 637 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 638 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 639 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 640 | return -EINVAL; |
| 641 | } |
| 642 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 643 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 644 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 645 | int err = nla_parse_nested( |
| 646 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 647 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 648 | nl80211_key_default_policy); |
| 649 | if (err) |
| 650 | return err; |
| 651 | |
| 652 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 653 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 654 | } |
| 655 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 660 | { |
| 661 | int err; |
| 662 | |
| 663 | memset(k, 0, sizeof(*k)); |
| 664 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 665 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 666 | |
| 667 | if (info->attrs[NL80211_ATTR_KEY]) |
| 668 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 669 | else |
| 670 | err = nl80211_parse_key_old(info, k); |
| 671 | |
| 672 | if (err) |
| 673 | return err; |
| 674 | |
| 675 | if (k->def && k->defmgmt) |
| 676 | return -EINVAL; |
| 677 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 678 | if (k->defmgmt) { |
| 679 | if (k->def_uni || !k->def_multi) |
| 680 | return -EINVAL; |
| 681 | } |
| 682 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 683 | if (k->idx != -1) { |
| 684 | if (k->defmgmt) { |
| 685 | if (k->idx < 4 || k->idx > 5) |
| 686 | return -EINVAL; |
| 687 | } else if (k->def) { |
| 688 | if (k->idx < 0 || k->idx > 3) |
| 689 | return -EINVAL; |
| 690 | } else { |
| 691 | if (k->idx < 0 || k->idx > 5) |
| 692 | return -EINVAL; |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 699 | static struct cfg80211_cached_keys * |
| 700 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 701 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 702 | { |
| 703 | struct key_parse parse; |
| 704 | struct nlattr *key; |
| 705 | struct cfg80211_cached_keys *result; |
| 706 | int rem, err, def = 0; |
| 707 | |
| 708 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 709 | if (!result) |
| 710 | return ERR_PTR(-ENOMEM); |
| 711 | |
| 712 | result->def = -1; |
| 713 | result->defmgmt = -1; |
| 714 | |
| 715 | nla_for_each_nested(key, keys, rem) { |
| 716 | memset(&parse, 0, sizeof(parse)); |
| 717 | parse.idx = -1; |
| 718 | |
| 719 | err = nl80211_parse_key_new(key, &parse); |
| 720 | if (err) |
| 721 | goto error; |
| 722 | err = -EINVAL; |
| 723 | if (!parse.p.key) |
| 724 | goto error; |
| 725 | if (parse.idx < 0 || parse.idx > 4) |
| 726 | goto error; |
| 727 | if (parse.def) { |
| 728 | if (def) |
| 729 | goto error; |
| 730 | def = 1; |
| 731 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 732 | if (!parse.def_uni || !parse.def_multi) |
| 733 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 734 | } else if (parse.defmgmt) |
| 735 | goto error; |
| 736 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 737 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 738 | if (err) |
| 739 | goto error; |
| 740 | result->params[parse.idx].cipher = parse.p.cipher; |
| 741 | result->params[parse.idx].key_len = parse.p.key_len; |
| 742 | result->params[parse.idx].key = result->data[parse.idx]; |
| 743 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 744 | |
| 745 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 746 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 747 | if (no_ht) |
| 748 | *no_ht = true; |
| 749 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | return result; |
| 753 | error: |
| 754 | kfree(result); |
| 755 | return ERR_PTR(err); |
| 756 | } |
| 757 | |
| 758 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 759 | { |
| 760 | ASSERT_WDEV_LOCK(wdev); |
| 761 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 762 | switch (wdev->iftype) { |
| 763 | case NL80211_IFTYPE_AP: |
| 764 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 765 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 766 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 767 | break; |
| 768 | case NL80211_IFTYPE_ADHOC: |
| 769 | if (!wdev->current_bss) |
| 770 | return -ENOLINK; |
| 771 | break; |
| 772 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 773 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 774 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 775 | return -ENOLINK; |
| 776 | break; |
| 777 | default: |
| 778 | return -EINVAL; |
| 779 | } |
| 780 | |
| 781 | return 0; |
| 782 | } |
| 783 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 784 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 785 | { |
| 786 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 787 | int i; |
| 788 | |
| 789 | if (!nl_modes) |
| 790 | goto nla_put_failure; |
| 791 | |
| 792 | i = 0; |
| 793 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 794 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 795 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 796 | ifmodes >>= 1; |
| 797 | i++; |
| 798 | } |
| 799 | |
| 800 | nla_nest_end(msg, nl_modes); |
| 801 | return 0; |
| 802 | |
| 803 | nla_put_failure: |
| 804 | return -ENOBUFS; |
| 805 | } |
| 806 | |
| 807 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 808 | struct sk_buff *msg) |
| 809 | { |
| 810 | struct nlattr *nl_combis; |
| 811 | int i, j; |
| 812 | |
| 813 | nl_combis = nla_nest_start(msg, |
| 814 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 815 | if (!nl_combis) |
| 816 | goto nla_put_failure; |
| 817 | |
| 818 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 819 | const struct ieee80211_iface_combination *c; |
| 820 | struct nlattr *nl_combi, *nl_limits; |
| 821 | |
| 822 | c = &wiphy->iface_combinations[i]; |
| 823 | |
| 824 | nl_combi = nla_nest_start(msg, i + 1); |
| 825 | if (!nl_combi) |
| 826 | goto nla_put_failure; |
| 827 | |
| 828 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 829 | if (!nl_limits) |
| 830 | goto nla_put_failure; |
| 831 | |
| 832 | for (j = 0; j < c->n_limits; j++) { |
| 833 | struct nlattr *nl_limit; |
| 834 | |
| 835 | nl_limit = nla_nest_start(msg, j + 1); |
| 836 | if (!nl_limit) |
| 837 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 838 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 839 | c->limits[j].max)) |
| 840 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 841 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 842 | c->limits[j].types)) |
| 843 | goto nla_put_failure; |
| 844 | nla_nest_end(msg, nl_limit); |
| 845 | } |
| 846 | |
| 847 | nla_nest_end(msg, nl_limits); |
| 848 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 849 | if (c->beacon_int_infra_match && |
| 850 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 851 | goto nla_put_failure; |
| 852 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 853 | c->num_different_channels) || |
| 854 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 855 | c->max_interfaces)) |
| 856 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 857 | |
| 858 | nla_nest_end(msg, nl_combi); |
| 859 | } |
| 860 | |
| 861 | nla_nest_end(msg, nl_combis); |
| 862 | |
| 863 | return 0; |
| 864 | nla_put_failure: |
| 865 | return -ENOBUFS; |
| 866 | } |
| 867 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 868 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 869 | struct cfg80211_registered_device *dev) |
| 870 | { |
| 871 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 872 | struct nlattr *nl_bands, *nl_band; |
| 873 | struct nlattr *nl_freqs, *nl_freq; |
| 874 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 875 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 876 | enum ieee80211_band band; |
| 877 | struct ieee80211_channel *chan; |
| 878 | struct ieee80211_rate *rate; |
| 879 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 880 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 881 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 882 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 883 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 884 | if (!hdr) |
| 885 | return -1; |
| 886 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 887 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
| 888 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || |
| 889 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 890 | cfg80211_rdev_list_generation) || |
| 891 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 892 | dev->wiphy.retry_short) || |
| 893 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 894 | dev->wiphy.retry_long) || |
| 895 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 896 | dev->wiphy.frag_threshold) || |
| 897 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 898 | dev->wiphy.rts_threshold) || |
| 899 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 900 | dev->wiphy.coverage_class) || |
| 901 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 902 | dev->wiphy.max_scan_ssids) || |
| 903 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 904 | dev->wiphy.max_sched_scan_ssids) || |
| 905 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 906 | dev->wiphy.max_scan_ie_len) || |
| 907 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 908 | dev->wiphy.max_sched_scan_ie_len) || |
| 909 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 910 | dev->wiphy.max_match_sets)) |
| 911 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 912 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 913 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 914 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 915 | goto nla_put_failure; |
| 916 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 917 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 918 | goto nla_put_failure; |
| 919 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 920 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 921 | goto nla_put_failure; |
| 922 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 923 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 924 | goto nla_put_failure; |
| 925 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 926 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 927 | goto nla_put_failure; |
| 928 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 929 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 930 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 931 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 932 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 933 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 934 | dev->wiphy.cipher_suites)) |
| 935 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 936 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 937 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 938 | dev->wiphy.max_num_pmkids)) |
| 939 | goto nla_put_failure; |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 940 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 941 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 942 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 943 | goto nla_put_failure; |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 944 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 945 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 946 | dev->wiphy.available_antennas_tx) || |
| 947 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 948 | dev->wiphy.available_antennas_rx)) |
| 949 | goto nla_put_failure; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 950 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 951 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 952 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 953 | dev->wiphy.probe_resp_offload)) |
| 954 | goto nla_put_failure; |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 955 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 956 | if ((dev->wiphy.available_antennas_tx || |
| 957 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 958 | u32 tx_ant = 0, rx_ant = 0; |
| 959 | int res; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 960 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 961 | if (!res) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 962 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 963 | tx_ant) || |
| 964 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 965 | rx_ant)) |
| 966 | goto nla_put_failure; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 970 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 971 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 972 | goto nla_put_failure; |
| 973 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 974 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 975 | if (!nl_bands) |
| 976 | goto nla_put_failure; |
| 977 | |
| 978 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 979 | if (!dev->wiphy.bands[band]) |
| 980 | continue; |
| 981 | |
| 982 | nl_band = nla_nest_start(msg, band); |
| 983 | if (!nl_band) |
| 984 | goto nla_put_failure; |
| 985 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 986 | /* add HT info */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 987 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
| 988 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 989 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 990 | &dev->wiphy.bands[band]->ht_cap.mcs) || |
| 991 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 992 | dev->wiphy.bands[band]->ht_cap.cap) || |
| 993 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 994 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || |
| 995 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 996 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) |
| 997 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 998 | |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 999 | /* add VHT info */ |
| 1000 | if (dev->wiphy.bands[band]->vht_cap.vht_supported && |
| 1001 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1002 | sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs), |
| 1003 | &dev->wiphy.bands[band]->vht_cap.vht_mcs) || |
| 1004 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1005 | dev->wiphy.bands[band]->vht_cap.cap))) |
| 1006 | goto nla_put_failure; |
| 1007 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1008 | /* add frequencies */ |
| 1009 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 1010 | if (!nl_freqs) |
| 1011 | goto nla_put_failure; |
| 1012 | |
| 1013 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 1014 | nl_freq = nla_nest_start(msg, i); |
| 1015 | if (!nl_freq) |
| 1016 | goto nla_put_failure; |
| 1017 | |
| 1018 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1019 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1020 | if (nl80211_msg_put_channel(msg, chan)) |
| 1021 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1022 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1023 | nla_nest_end(msg, nl_freq); |
| 1024 | } |
| 1025 | |
| 1026 | nla_nest_end(msg, nl_freqs); |
| 1027 | |
| 1028 | /* add bitrates */ |
| 1029 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1030 | if (!nl_rates) |
| 1031 | goto nla_put_failure; |
| 1032 | |
| 1033 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 1034 | nl_rate = nla_nest_start(msg, i); |
| 1035 | if (!nl_rate) |
| 1036 | goto nla_put_failure; |
| 1037 | |
| 1038 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1039 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1040 | rate->bitrate)) |
| 1041 | goto nla_put_failure; |
| 1042 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1043 | nla_put_flag(msg, |
| 1044 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1045 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1046 | |
| 1047 | nla_nest_end(msg, nl_rate); |
| 1048 | } |
| 1049 | |
| 1050 | nla_nest_end(msg, nl_rates); |
| 1051 | |
| 1052 | nla_nest_end(msg, nl_band); |
| 1053 | } |
| 1054 | nla_nest_end(msg, nl_bands); |
| 1055 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1056 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1057 | if (!nl_cmds) |
| 1058 | goto nla_put_failure; |
| 1059 | |
| 1060 | i = 0; |
| 1061 | #define CMD(op, n) \ |
| 1062 | do { \ |
| 1063 | if (dev->ops->op) { \ |
| 1064 | i++; \ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1065 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1066 | goto nla_put_failure; \ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1067 | } \ |
| 1068 | } while (0) |
| 1069 | |
| 1070 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1071 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1072 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1073 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1074 | CMD(add_station, NEW_STATION); |
| 1075 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 1076 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1077 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1078 | CMD(auth, AUTHENTICATE); |
| 1079 | CMD(assoc, ASSOCIATE); |
| 1080 | CMD(deauth, DEAUTHENTICATE); |
| 1081 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1082 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1083 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1084 | CMD(set_pmksa, SET_PMKSA); |
| 1085 | CMD(del_pmksa, DEL_PMKSA); |
| 1086 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1087 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1088 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 1089 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1090 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1091 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 1092 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1093 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1094 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1095 | goto nla_put_failure; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1096 | } |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1097 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1098 | dev->ops->join_mesh) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1099 | i++; |
| 1100 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1101 | goto nla_put_failure; |
| 1102 | } |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1103 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 1104 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1105 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1106 | CMD(tdls_oper, TDLS_OPER); |
| 1107 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 1108 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1109 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 1110 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1111 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1112 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1113 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1114 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1115 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1116 | } |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1117 | CMD(start_p2p_device, START_P2P_DEVICE); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 1118 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1119 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1120 | #ifdef CONFIG_NL80211_TESTMODE |
| 1121 | CMD(testmode_cmd, TESTMODE); |
| 1122 | #endif |
| 1123 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1124 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1125 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1126 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1127 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1128 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1129 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1132 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1133 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1134 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1135 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1136 | } |
| 1137 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1138 | nla_nest_end(msg, nl_cmds); |
| 1139 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1140 | if (dev->ops->remain_on_channel && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1141 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1142 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1143 | dev->wiphy.max_remain_on_channel_duration)) |
| 1144 | goto nla_put_failure; |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 1145 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1146 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1147 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1148 | goto nla_put_failure; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1149 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1150 | if (mgmt_stypes) { |
| 1151 | u16 stypes; |
| 1152 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1153 | enum nl80211_iftype ift; |
| 1154 | |
| 1155 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1156 | if (!nl_ifs) |
| 1157 | goto nla_put_failure; |
| 1158 | |
| 1159 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1160 | nl_ftypes = nla_nest_start(msg, ift); |
| 1161 | if (!nl_ftypes) |
| 1162 | goto nla_put_failure; |
| 1163 | i = 0; |
| 1164 | stypes = mgmt_stypes[ift].tx; |
| 1165 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1166 | if ((stypes & 1) && |
| 1167 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1168 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1169 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1170 | stypes >>= 1; |
| 1171 | i++; |
| 1172 | } |
| 1173 | nla_nest_end(msg, nl_ftypes); |
| 1174 | } |
| 1175 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1176 | nla_nest_end(msg, nl_ifs); |
| 1177 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1178 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1179 | if (!nl_ifs) |
| 1180 | goto nla_put_failure; |
| 1181 | |
| 1182 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1183 | nl_ftypes = nla_nest_start(msg, ift); |
| 1184 | if (!nl_ftypes) |
| 1185 | goto nla_put_failure; |
| 1186 | i = 0; |
| 1187 | stypes = mgmt_stypes[ift].rx; |
| 1188 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1189 | if ((stypes & 1) && |
| 1190 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1191 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1192 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1193 | stypes >>= 1; |
| 1194 | i++; |
| 1195 | } |
| 1196 | nla_nest_end(msg, nl_ftypes); |
| 1197 | } |
| 1198 | nla_nest_end(msg, nl_ifs); |
| 1199 | } |
| 1200 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1201 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1202 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 1203 | struct nlattr *nl_wowlan; |
| 1204 | |
| 1205 | nl_wowlan = nla_nest_start(msg, |
| 1206 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1207 | if (!nl_wowlan) |
| 1208 | goto nla_put_failure; |
| 1209 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1210 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 1211 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1212 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1213 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1214 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1215 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1216 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1217 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1218 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1219 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1220 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1221 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1222 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1223 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1224 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1225 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1226 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1227 | if (dev->wiphy.wowlan.n_patterns) { |
| 1228 | struct nl80211_wowlan_pattern_support pat = { |
| 1229 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1230 | .min_pattern_len = |
| 1231 | dev->wiphy.wowlan.pattern_min_len, |
| 1232 | .max_pattern_len = |
| 1233 | dev->wiphy.wowlan.pattern_max_len, |
| 1234 | }; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1235 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1236 | sizeof(pat), &pat)) |
| 1237 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | nla_nest_end(msg, nl_wowlan); |
| 1241 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1242 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1243 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1244 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1245 | dev->wiphy.software_iftypes)) |
| 1246 | goto nla_put_failure; |
| 1247 | |
| 1248 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1249 | goto nla_put_failure; |
| 1250 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1251 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1252 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1253 | dev->wiphy.ap_sme_capa)) |
| 1254 | goto nla_put_failure; |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1255 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1256 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
| 1257 | dev->wiphy.features)) |
| 1258 | goto nla_put_failure; |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1259 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1260 | if (dev->wiphy.ht_capa_mod_mask && |
| 1261 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1262 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1263 | dev->wiphy.ht_capa_mod_mask)) |
| 1264 | goto nla_put_failure; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1265 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1266 | return genlmsg_end(msg, hdr); |
| 1267 | |
| 1268 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1269 | genlmsg_cancel(msg, hdr); |
| 1270 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1274 | { |
| 1275 | int idx = 0; |
| 1276 | int start = cb->args[0]; |
| 1277 | struct cfg80211_registered_device *dev; |
| 1278 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1279 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1280 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1281 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1282 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1283 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1284 | continue; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1285 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1286 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1287 | dev) < 0) { |
| 1288 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1289 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1290 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1291 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1292 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1293 | |
| 1294 | cb->args[0] = idx; |
| 1295 | |
| 1296 | return skb->len; |
| 1297 | } |
| 1298 | |
| 1299 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1300 | { |
| 1301 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1302 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1303 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1304 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1305 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1306 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1307 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1308 | if (nl80211_send_wiphy(msg, info->snd_portid, info->snd_seq, 0, dev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1309 | nlmsg_free(msg); |
| 1310 | return -ENOBUFS; |
| 1311 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1312 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1313 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1314 | } |
| 1315 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1316 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1317 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1318 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1319 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1320 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1321 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1322 | }; |
| 1323 | |
| 1324 | static int parse_txq_params(struct nlattr *tb[], |
| 1325 | struct ieee80211_txq_params *txq_params) |
| 1326 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1327 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1328 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1329 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1330 | return -EINVAL; |
| 1331 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1332 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1333 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1334 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1335 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1336 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1337 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1338 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1339 | return -EINVAL; |
| 1340 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1341 | return 0; |
| 1342 | } |
| 1343 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1344 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1345 | { |
| 1346 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1347 | * You can only set the channel explicitly for WDS interfaces, |
| 1348 | * all others have their channel managed via their respective |
| 1349 | * "establish a connection" command (connect, join, ...) |
| 1350 | * |
| 1351 | * For AP/GO and mesh mode, the channel can be set with the |
| 1352 | * channel userspace API, but is only stored and passed to the |
| 1353 | * low-level driver when the AP starts or the mesh is joined. |
| 1354 | * This is for backward compatibility, userspace can also give |
| 1355 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1356 | * |
| 1357 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1358 | * whatever else is going on, so they have their own special |
| 1359 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1360 | */ |
| 1361 | return !wdev || |
| 1362 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1363 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1364 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1365 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1366 | } |
| 1367 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1368 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1369 | struct genl_info *info, |
| 1370 | struct cfg80211_chan_def *chandef) |
| 1371 | { |
| 1372 | struct ieee80211_sta_ht_cap *ht_cap; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame^] | 1373 | struct ieee80211_sta_vht_cap *vht_cap; |
| 1374 | u32 control_freq, width; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1375 | |
| 1376 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1377 | return -EINVAL; |
| 1378 | |
| 1379 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1380 | |
| 1381 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame^] | 1382 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1383 | chandef->center_freq1 = control_freq; |
| 1384 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1385 | |
| 1386 | /* Primary channel not allowed */ |
| 1387 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1388 | return -EINVAL; |
| 1389 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame^] | 1390 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1391 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1392 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame^] | 1393 | chantype = nla_get_u32( |
| 1394 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1395 | |
| 1396 | switch (chantype) { |
| 1397 | case NL80211_CHAN_NO_HT: |
| 1398 | case NL80211_CHAN_HT20: |
| 1399 | case NL80211_CHAN_HT40PLUS: |
| 1400 | case NL80211_CHAN_HT40MINUS: |
| 1401 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1402 | chantype); |
| 1403 | break; |
| 1404 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1405 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1406 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame^] | 1407 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1408 | chandef->width = |
| 1409 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1410 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1411 | chandef->center_freq1 = |
| 1412 | nla_get_u32( |
| 1413 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1414 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1415 | chandef->center_freq2 = |
| 1416 | nla_get_u32( |
| 1417 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1418 | } |
| 1419 | |
| 1420 | ht_cap = &rdev->wiphy.bands[chandef->chan->band]->ht_cap; |
| 1421 | vht_cap = &rdev->wiphy.bands[chandef->chan->band]->vht_cap; |
| 1422 | |
| 1423 | if (!cfg80211_chan_def_valid(chandef)) |
| 1424 | return -EINVAL; |
| 1425 | |
| 1426 | switch (chandef->width) { |
| 1427 | case NL80211_CHAN_WIDTH_20: |
| 1428 | if (!ht_cap->ht_supported) |
| 1429 | return -EINVAL; |
| 1430 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1431 | width = 20; |
| 1432 | break; |
| 1433 | case NL80211_CHAN_WIDTH_40: |
| 1434 | width = 40; |
| 1435 | /* quick early regulatory check */ |
| 1436 | if (chandef->center_freq1 < control_freq && |
| 1437 | chandef->chan->flags & IEEE80211_CHAN_NO_HT40MINUS) |
| 1438 | return -EINVAL; |
| 1439 | if (chandef->center_freq1 > control_freq && |
| 1440 | chandef->chan->flags & IEEE80211_CHAN_NO_HT40PLUS) |
| 1441 | return -EINVAL; |
| 1442 | if (!ht_cap->ht_supported) |
| 1443 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1444 | if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) || |
| 1445 | ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT) |
| 1446 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame^] | 1447 | break; |
| 1448 | case NL80211_CHAN_WIDTH_80: |
| 1449 | width = 80; |
| 1450 | if (!vht_cap->vht_supported) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1451 | return -EINVAL; |
| 1452 | break; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame^] | 1453 | case NL80211_CHAN_WIDTH_80P80: |
| 1454 | width = 80; |
| 1455 | if (!vht_cap->vht_supported) |
| 1456 | return -EINVAL; |
| 1457 | if (!(vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)) |
| 1458 | return -EINVAL; |
| 1459 | break; |
| 1460 | case NL80211_CHAN_WIDTH_160: |
| 1461 | width = 160; |
| 1462 | if (!vht_cap->vht_supported) |
| 1463 | return -EINVAL; |
| 1464 | if (!(vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)) |
| 1465 | return -EINVAL; |
| 1466 | break; |
| 1467 | default: |
| 1468 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1469 | } |
| 1470 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame^] | 1471 | if (!cfg80211_secondary_chans_ok(&rdev->wiphy, chandef->center_freq1, |
| 1472 | width, IEEE80211_CHAN_DISABLED)) |
| 1473 | return -EINVAL; |
| 1474 | if (chandef->center_freq2 && |
| 1475 | !cfg80211_secondary_chans_ok(&rdev->wiphy, chandef->center_freq2, |
| 1476 | width, IEEE80211_CHAN_DISABLED)) |
| 1477 | return -EINVAL; |
| 1478 | |
| 1479 | /* TODO: missing regulatory check on bandwidth */ |
| 1480 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1481 | return 0; |
| 1482 | } |
| 1483 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1484 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1485 | struct wireless_dev *wdev, |
| 1486 | struct genl_info *info) |
| 1487 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1488 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1489 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1490 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1491 | |
| 1492 | if (wdev) |
| 1493 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1494 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1495 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1496 | return -EOPNOTSUPP; |
| 1497 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1498 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1499 | if (result) |
| 1500 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1501 | |
| 1502 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1503 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1504 | case NL80211_IFTYPE_AP: |
| 1505 | case NL80211_IFTYPE_P2P_GO: |
| 1506 | if (wdev->beacon_interval) { |
| 1507 | result = -EBUSY; |
| 1508 | break; |
| 1509 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1510 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1511 | result = -EINVAL; |
| 1512 | break; |
| 1513 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1514 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1515 | result = 0; |
| 1516 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1517 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1518 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1519 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1520 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1521 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1522 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1523 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1524 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1525 | } |
| 1526 | mutex_unlock(&rdev->devlist_mtx); |
| 1527 | |
| 1528 | return result; |
| 1529 | } |
| 1530 | |
| 1531 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1532 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1534 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1535 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1536 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1537 | } |
| 1538 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1539 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1540 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1541 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1542 | struct net_device *dev = info->user_ptr[1]; |
| 1543 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1544 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1545 | |
| 1546 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1547 | return -EINVAL; |
| 1548 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1549 | if (netif_running(dev)) |
| 1550 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1551 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1552 | if (!rdev->ops->set_wds_peer) |
| 1553 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1554 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1555 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1556 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1557 | |
| 1558 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1559 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1563 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1564 | { |
| 1565 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1566 | struct net_device *netdev = NULL; |
| 1567 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1568 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1569 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1570 | u32 changed; |
| 1571 | u8 retry_short = 0, retry_long = 0; |
| 1572 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1573 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1574 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1575 | /* |
| 1576 | * Try to find the wiphy and netdev. Normally this |
| 1577 | * function shouldn't need the netdev, but this is |
| 1578 | * done for backward compatibility -- previously |
| 1579 | * setting the channel was done per wiphy, but now |
| 1580 | * it is per netdev. Previous userland like hostapd |
| 1581 | * also passed a netdev to set_wiphy, so that it is |
| 1582 | * possible to let that go to the right netdev! |
| 1583 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1584 | mutex_lock(&cfg80211_mutex); |
| 1585 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1586 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1587 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1588 | |
| 1589 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1590 | if (netdev && netdev->ieee80211_ptr) { |
| 1591 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1592 | mutex_lock(&rdev->mtx); |
| 1593 | } else |
| 1594 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1595 | } |
| 1596 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1597 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1598 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1599 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1600 | if (IS_ERR(rdev)) { |
| 1601 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1602 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1603 | } |
| 1604 | wdev = NULL; |
| 1605 | netdev = NULL; |
| 1606 | result = 0; |
| 1607 | |
| 1608 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1609 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1610 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1611 | |
| 1612 | /* |
| 1613 | * end workaround code, by now the rdev is available |
| 1614 | * and locked, and wdev may or may not be NULL. |
| 1615 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1616 | |
| 1617 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1618 | result = cfg80211_dev_rename( |
| 1619 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1620 | |
| 1621 | mutex_unlock(&cfg80211_mutex); |
| 1622 | |
| 1623 | if (result) |
| 1624 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1625 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1626 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1627 | struct ieee80211_txq_params txq_params; |
| 1628 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1629 | |
| 1630 | if (!rdev->ops->set_txq_params) { |
| 1631 | result = -EOPNOTSUPP; |
| 1632 | goto bad_res; |
| 1633 | } |
| 1634 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1635 | if (!netdev) { |
| 1636 | result = -EINVAL; |
| 1637 | goto bad_res; |
| 1638 | } |
| 1639 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1640 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1641 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1642 | result = -EINVAL; |
| 1643 | goto bad_res; |
| 1644 | } |
| 1645 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1646 | if (!netif_running(netdev)) { |
| 1647 | result = -ENETDOWN; |
| 1648 | goto bad_res; |
| 1649 | } |
| 1650 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1651 | nla_for_each_nested(nl_txq_params, |
| 1652 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1653 | rem_txq_params) { |
| 1654 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1655 | nla_data(nl_txq_params), |
| 1656 | nla_len(nl_txq_params), |
| 1657 | txq_params_policy); |
| 1658 | result = parse_txq_params(tb, &txq_params); |
| 1659 | if (result) |
| 1660 | goto bad_res; |
| 1661 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1662 | result = rdev_set_txq_params(rdev, netdev, |
| 1663 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1664 | if (result) |
| 1665 | goto bad_res; |
| 1666 | } |
| 1667 | } |
| 1668 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1669 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1670 | result = __nl80211_set_channel(rdev, |
| 1671 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1672 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1673 | if (result) |
| 1674 | goto bad_res; |
| 1675 | } |
| 1676 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1677 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1678 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1679 | enum nl80211_tx_power_setting type; |
| 1680 | int idx, mbm = 0; |
| 1681 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1682 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1683 | txp_wdev = NULL; |
| 1684 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1685 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1686 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1687 | goto bad_res; |
| 1688 | } |
| 1689 | |
| 1690 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1691 | type = nla_get_u32(info->attrs[idx]); |
| 1692 | |
| 1693 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1694 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1695 | result = -EINVAL; |
| 1696 | goto bad_res; |
| 1697 | } |
| 1698 | |
| 1699 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1700 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1701 | mbm = nla_get_u32(info->attrs[idx]); |
| 1702 | } |
| 1703 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1704 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1705 | if (result) |
| 1706 | goto bad_res; |
| 1707 | } |
| 1708 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1709 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1710 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1711 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1712 | if ((!rdev->wiphy.available_antennas_tx && |
| 1713 | !rdev->wiphy.available_antennas_rx) || |
| 1714 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1715 | result = -EOPNOTSUPP; |
| 1716 | goto bad_res; |
| 1717 | } |
| 1718 | |
| 1719 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1720 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1721 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1722 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1723 | * available antenna masks, except for the "all" mask */ |
| 1724 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1725 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1726 | result = -EINVAL; |
| 1727 | goto bad_res; |
| 1728 | } |
| 1729 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1730 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1731 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1732 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1733 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1734 | if (result) |
| 1735 | goto bad_res; |
| 1736 | } |
| 1737 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1738 | changed = 0; |
| 1739 | |
| 1740 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1741 | retry_short = nla_get_u8( |
| 1742 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1743 | if (retry_short == 0) { |
| 1744 | result = -EINVAL; |
| 1745 | goto bad_res; |
| 1746 | } |
| 1747 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1748 | } |
| 1749 | |
| 1750 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1751 | retry_long = nla_get_u8( |
| 1752 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1753 | if (retry_long == 0) { |
| 1754 | result = -EINVAL; |
| 1755 | goto bad_res; |
| 1756 | } |
| 1757 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1758 | } |
| 1759 | |
| 1760 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1761 | frag_threshold = nla_get_u32( |
| 1762 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1763 | if (frag_threshold < 256) { |
| 1764 | result = -EINVAL; |
| 1765 | goto bad_res; |
| 1766 | } |
| 1767 | if (frag_threshold != (u32) -1) { |
| 1768 | /* |
| 1769 | * Fragments (apart from the last one) are required to |
| 1770 | * have even length. Make the fragmentation code |
| 1771 | * simpler by stripping LSB should someone try to use |
| 1772 | * odd threshold value. |
| 1773 | */ |
| 1774 | frag_threshold &= ~0x1; |
| 1775 | } |
| 1776 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1777 | } |
| 1778 | |
| 1779 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1780 | rts_threshold = nla_get_u32( |
| 1781 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1782 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1783 | } |
| 1784 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1785 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1786 | coverage_class = nla_get_u8( |
| 1787 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1788 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1789 | } |
| 1790 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1791 | if (changed) { |
| 1792 | u8 old_retry_short, old_retry_long; |
| 1793 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1794 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1795 | |
| 1796 | if (!rdev->ops->set_wiphy_params) { |
| 1797 | result = -EOPNOTSUPP; |
| 1798 | goto bad_res; |
| 1799 | } |
| 1800 | |
| 1801 | old_retry_short = rdev->wiphy.retry_short; |
| 1802 | old_retry_long = rdev->wiphy.retry_long; |
| 1803 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1804 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1805 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1806 | |
| 1807 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1808 | rdev->wiphy.retry_short = retry_short; |
| 1809 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1810 | rdev->wiphy.retry_long = retry_long; |
| 1811 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1812 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1813 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1814 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1815 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1816 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1817 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1818 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1819 | if (result) { |
| 1820 | rdev->wiphy.retry_short = old_retry_short; |
| 1821 | rdev->wiphy.retry_long = old_retry_long; |
| 1822 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1823 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1824 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1825 | } |
| 1826 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1827 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1828 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1829 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1830 | if (netdev) |
| 1831 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1832 | return result; |
| 1833 | } |
| 1834 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1835 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1836 | { |
| 1837 | return (u64)wdev->identifier | |
| 1838 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1839 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1840 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1841 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 1842 | struct cfg80211_chan_def *chandef) |
| 1843 | { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame^] | 1844 | WARN_ON(!cfg80211_chan_def_valid(chandef)); |
| 1845 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1846 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1847 | chandef->chan->center_freq)) |
| 1848 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame^] | 1849 | switch (chandef->width) { |
| 1850 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1851 | case NL80211_CHAN_WIDTH_20: |
| 1852 | case NL80211_CHAN_WIDTH_40: |
| 1853 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1854 | cfg80211_get_chandef_type(chandef))) |
| 1855 | return -ENOBUFS; |
| 1856 | break; |
| 1857 | default: |
| 1858 | break; |
| 1859 | } |
| 1860 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 1861 | return -ENOBUFS; |
| 1862 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 1863 | return -ENOBUFS; |
| 1864 | if (chandef->center_freq2 && |
| 1865 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1866 | return -ENOBUFS; |
| 1867 | return 0; |
| 1868 | } |
| 1869 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1870 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1871 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1872 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1873 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1874 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1875 | void *hdr; |
| 1876 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1877 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1878 | if (!hdr) |
| 1879 | return -1; |
| 1880 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1881 | if (dev && |
| 1882 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1883 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1884 | goto nla_put_failure; |
| 1885 | |
| 1886 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1887 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1888 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1889 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1890 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1891 | rdev->devlist_generation ^ |
| 1892 | (cfg80211_rdev_list_generation << 2))) |
| 1893 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1894 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1895 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1896 | int ret; |
| 1897 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1898 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1899 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 1900 | if (ret == 0) { |
| 1901 | if (nl80211_send_chandef(msg, &chandef)) |
| 1902 | goto nla_put_failure; |
| 1903 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1904 | } |
| 1905 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 1906 | if (wdev->ssid_len) { |
| 1907 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 1908 | goto nla_put_failure; |
| 1909 | } |
| 1910 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1911 | return genlmsg_end(msg, hdr); |
| 1912 | |
| 1913 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1914 | genlmsg_cancel(msg, hdr); |
| 1915 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1919 | { |
| 1920 | int wp_idx = 0; |
| 1921 | int if_idx = 0; |
| 1922 | int wp_start = cb->args[0]; |
| 1923 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1924 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1925 | struct wireless_dev *wdev; |
| 1926 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1927 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1928 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1929 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1930 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1931 | if (wp_idx < wp_start) { |
| 1932 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1933 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1934 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1935 | if_idx = 0; |
| 1936 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1937 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1938 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1939 | if (if_idx < if_start) { |
| 1940 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1941 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1942 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1943 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1944 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1945 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1946 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1947 | goto out; |
| 1948 | } |
| 1949 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1950 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1951 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1952 | |
| 1953 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1954 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1955 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1956 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1957 | |
| 1958 | cb->args[0] = wp_idx; |
| 1959 | cb->args[1] = if_idx; |
| 1960 | |
| 1961 | return skb->len; |
| 1962 | } |
| 1963 | |
| 1964 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1965 | { |
| 1966 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1967 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1968 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1969 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1970 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1971 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1972 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1973 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1974 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1975 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1976 | nlmsg_free(msg); |
| 1977 | return -ENOBUFS; |
| 1978 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1979 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1980 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1981 | } |
| 1982 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1983 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1984 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1985 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1986 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1987 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1988 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1989 | }; |
| 1990 | |
| 1991 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1992 | { |
| 1993 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1994 | int flag; |
| 1995 | |
| 1996 | *mntrflags = 0; |
| 1997 | |
| 1998 | if (!nla) |
| 1999 | return -EINVAL; |
| 2000 | |
| 2001 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2002 | nla, mntr_flags_policy)) |
| 2003 | return -EINVAL; |
| 2004 | |
| 2005 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2006 | if (flags[flag]) |
| 2007 | *mntrflags |= (1<<flag); |
| 2008 | |
| 2009 | return 0; |
| 2010 | } |
| 2011 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2012 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2013 | struct net_device *netdev, u8 use_4addr, |
| 2014 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2015 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2016 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2017 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2018 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2019 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2020 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2021 | |
| 2022 | switch (iftype) { |
| 2023 | case NL80211_IFTYPE_AP_VLAN: |
| 2024 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2025 | return 0; |
| 2026 | break; |
| 2027 | case NL80211_IFTYPE_STATION: |
| 2028 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2029 | return 0; |
| 2030 | break; |
| 2031 | default: |
| 2032 | break; |
| 2033 | } |
| 2034 | |
| 2035 | return -EOPNOTSUPP; |
| 2036 | } |
| 2037 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2038 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2039 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2040 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2041 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2042 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2043 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2044 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2045 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2046 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2047 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2048 | memset(¶ms, 0, sizeof(params)); |
| 2049 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2050 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2051 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2052 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2053 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2054 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2055 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2056 | if (ntype > NL80211_IFTYPE_MAX) |
| 2057 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2058 | } |
| 2059 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2060 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2061 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2062 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2063 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2064 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2065 | if (netif_running(dev)) |
| 2066 | return -EBUSY; |
| 2067 | |
| 2068 | wdev_lock(wdev); |
| 2069 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2070 | IEEE80211_MAX_MESH_ID_LEN); |
| 2071 | wdev->mesh_id_up_len = |
| 2072 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2073 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2074 | wdev->mesh_id_up_len); |
| 2075 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2076 | } |
| 2077 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2078 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2079 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2080 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2081 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2082 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2083 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2084 | } else { |
| 2085 | params.use_4addr = -1; |
| 2086 | } |
| 2087 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2088 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2089 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2090 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2091 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2092 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2093 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2094 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2095 | |
| 2096 | flags = &_flags; |
| 2097 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2098 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2099 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2100 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2101 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2102 | else |
| 2103 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2104 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2105 | if (!err && params.use_4addr != -1) |
| 2106 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2107 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2108 | return err; |
| 2109 | } |
| 2110 | |
| 2111 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2112 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2113 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2114 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2115 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2116 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2117 | int err; |
| 2118 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2119 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2120 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2121 | memset(¶ms, 0, sizeof(params)); |
| 2122 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2123 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2124 | return -EINVAL; |
| 2125 | |
| 2126 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2127 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2128 | if (type > NL80211_IFTYPE_MAX) |
| 2129 | return -EINVAL; |
| 2130 | } |
| 2131 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2132 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2133 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2134 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2135 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2136 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2137 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2138 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2139 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2140 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2141 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2142 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2143 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2144 | if (!msg) |
| 2145 | return -ENOMEM; |
| 2146 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2147 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2148 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2149 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2150 | wdev = rdev_add_virtual_intf(rdev, |
| 2151 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2152 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2153 | if (IS_ERR(wdev)) { |
| 2154 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2155 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2156 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2157 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2158 | switch (type) { |
| 2159 | case NL80211_IFTYPE_MESH_POINT: |
| 2160 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2161 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2162 | wdev_lock(wdev); |
| 2163 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2164 | IEEE80211_MAX_MESH_ID_LEN); |
| 2165 | wdev->mesh_id_up_len = |
| 2166 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2167 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2168 | wdev->mesh_id_up_len); |
| 2169 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2170 | break; |
| 2171 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2172 | /* |
| 2173 | * P2P Device doesn't have a netdev, so doesn't go |
| 2174 | * through the netdev notifier and must be added here |
| 2175 | */ |
| 2176 | mutex_init(&wdev->mtx); |
| 2177 | INIT_LIST_HEAD(&wdev->event_list); |
| 2178 | spin_lock_init(&wdev->event_lock); |
| 2179 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2180 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2181 | |
| 2182 | mutex_lock(&rdev->devlist_mtx); |
| 2183 | wdev->identifier = ++rdev->wdev_id; |
| 2184 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2185 | rdev->devlist_generation++; |
| 2186 | mutex_unlock(&rdev->devlist_mtx); |
| 2187 | break; |
| 2188 | default: |
| 2189 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2190 | } |
| 2191 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2192 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2193 | rdev, wdev) < 0) { |
| 2194 | nlmsg_free(msg); |
| 2195 | return -ENOBUFS; |
| 2196 | } |
| 2197 | |
| 2198 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2202 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2203 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2204 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2205 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2206 | if (!rdev->ops->del_virtual_intf) |
| 2207 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2208 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2209 | /* |
| 2210 | * If we remove a wireless device without a netdev then clear |
| 2211 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2212 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2213 | * since the wdev has been freed, unlike with a netdev where |
| 2214 | * we need the dev_put() for the netdev to really be freed. |
| 2215 | */ |
| 2216 | if (!wdev->netdev) |
| 2217 | info->user_ptr[1] = NULL; |
| 2218 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2219 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2220 | } |
| 2221 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2222 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2223 | { |
| 2224 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2225 | struct net_device *dev = info->user_ptr[1]; |
| 2226 | u16 noack_map; |
| 2227 | |
| 2228 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2229 | return -EINVAL; |
| 2230 | |
| 2231 | if (!rdev->ops->set_noack_map) |
| 2232 | return -EOPNOTSUPP; |
| 2233 | |
| 2234 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2235 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2236 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2237 | } |
| 2238 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2239 | struct get_key_cookie { |
| 2240 | struct sk_buff *msg; |
| 2241 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2242 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2243 | }; |
| 2244 | |
| 2245 | static void get_key_callback(void *c, struct key_params *params) |
| 2246 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2247 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2248 | struct get_key_cookie *cookie = c; |
| 2249 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2250 | if ((params->key && |
| 2251 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2252 | params->key_len, params->key)) || |
| 2253 | (params->seq && |
| 2254 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2255 | params->seq_len, params->seq)) || |
| 2256 | (params->cipher && |
| 2257 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2258 | params->cipher))) |
| 2259 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2260 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2261 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2262 | if (!key) |
| 2263 | goto nla_put_failure; |
| 2264 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2265 | if ((params->key && |
| 2266 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2267 | params->key_len, params->key)) || |
| 2268 | (params->seq && |
| 2269 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2270 | params->seq_len, params->seq)) || |
| 2271 | (params->cipher && |
| 2272 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2273 | params->cipher))) |
| 2274 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2275 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2276 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2277 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2278 | |
| 2279 | nla_nest_end(cookie->msg, key); |
| 2280 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2281 | return; |
| 2282 | nla_put_failure: |
| 2283 | cookie->error = 1; |
| 2284 | } |
| 2285 | |
| 2286 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2287 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2288 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2289 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2290 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2291 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2292 | const u8 *mac_addr = NULL; |
| 2293 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2294 | struct get_key_cookie cookie = { |
| 2295 | .error = 0, |
| 2296 | }; |
| 2297 | void *hdr; |
| 2298 | struct sk_buff *msg; |
| 2299 | |
| 2300 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2301 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2302 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2303 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2304 | return -EINVAL; |
| 2305 | |
| 2306 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2307 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2308 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2309 | pairwise = !!mac_addr; |
| 2310 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2311 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2312 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2313 | return -EINVAL; |
| 2314 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2315 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2316 | return -EINVAL; |
| 2317 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2318 | } |
| 2319 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2320 | if (!rdev->ops->get_key) |
| 2321 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2322 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2323 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2324 | if (!msg) |
| 2325 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2326 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2327 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2328 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2329 | if (IS_ERR(hdr)) |
| 2330 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2331 | |
| 2332 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2333 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2334 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2335 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2336 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2337 | goto nla_put_failure; |
| 2338 | if (mac_addr && |
| 2339 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2340 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2341 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2342 | if (pairwise && mac_addr && |
| 2343 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2344 | return -ENOENT; |
| 2345 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2346 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2347 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2348 | |
| 2349 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2350 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2351 | |
| 2352 | if (cookie.error) |
| 2353 | goto nla_put_failure; |
| 2354 | |
| 2355 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2356 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2357 | |
| 2358 | nla_put_failure: |
| 2359 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2360 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2361 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2362 | return err; |
| 2363 | } |
| 2364 | |
| 2365 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2366 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2367 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2368 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2369 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2370 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2371 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2372 | err = nl80211_parse_key(info, &key); |
| 2373 | if (err) |
| 2374 | return err; |
| 2375 | |
| 2376 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2377 | return -EINVAL; |
| 2378 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2379 | /* only support setting default key */ |
| 2380 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2381 | return -EINVAL; |
| 2382 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2383 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2384 | |
| 2385 | if (key.def) { |
| 2386 | if (!rdev->ops->set_default_key) { |
| 2387 | err = -EOPNOTSUPP; |
| 2388 | goto out; |
| 2389 | } |
| 2390 | |
| 2391 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2392 | if (err) |
| 2393 | goto out; |
| 2394 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2395 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2396 | key.def_uni, key.def_multi); |
| 2397 | |
| 2398 | if (err) |
| 2399 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2400 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2401 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2402 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2403 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2404 | } else { |
| 2405 | if (key.def_uni || !key.def_multi) { |
| 2406 | err = -EINVAL; |
| 2407 | goto out; |
| 2408 | } |
| 2409 | |
| 2410 | if (!rdev->ops->set_default_mgmt_key) { |
| 2411 | err = -EOPNOTSUPP; |
| 2412 | goto out; |
| 2413 | } |
| 2414 | |
| 2415 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2416 | if (err) |
| 2417 | goto out; |
| 2418 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2419 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2420 | if (err) |
| 2421 | goto out; |
| 2422 | |
| 2423 | #ifdef CONFIG_CFG80211_WEXT |
| 2424 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2425 | #endif |
| 2426 | } |
| 2427 | |
| 2428 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2429 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2430 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2431 | return err; |
| 2432 | } |
| 2433 | |
| 2434 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2435 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2436 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2437 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2438 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2439 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2440 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2441 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2442 | err = nl80211_parse_key(info, &key); |
| 2443 | if (err) |
| 2444 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2445 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2446 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2447 | return -EINVAL; |
| 2448 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2449 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2450 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2451 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2452 | if (key.type == -1) { |
| 2453 | if (mac_addr) |
| 2454 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2455 | else |
| 2456 | key.type = NL80211_KEYTYPE_GROUP; |
| 2457 | } |
| 2458 | |
| 2459 | /* for now */ |
| 2460 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2461 | key.type != NL80211_KEYTYPE_GROUP) |
| 2462 | return -EINVAL; |
| 2463 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2464 | if (!rdev->ops->add_key) |
| 2465 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2466 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2467 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2468 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2469 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2470 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2471 | |
| 2472 | wdev_lock(dev->ieee80211_ptr); |
| 2473 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2474 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2475 | err = rdev_add_key(rdev, dev, key.idx, |
| 2476 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2477 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2478 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2479 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2480 | return err; |
| 2481 | } |
| 2482 | |
| 2483 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2484 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2485 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2486 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2487 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2488 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2489 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2490 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2491 | err = nl80211_parse_key(info, &key); |
| 2492 | if (err) |
| 2493 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2494 | |
| 2495 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2496 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2497 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2498 | if (key.type == -1) { |
| 2499 | if (mac_addr) |
| 2500 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2501 | else |
| 2502 | key.type = NL80211_KEYTYPE_GROUP; |
| 2503 | } |
| 2504 | |
| 2505 | /* for now */ |
| 2506 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2507 | key.type != NL80211_KEYTYPE_GROUP) |
| 2508 | return -EINVAL; |
| 2509 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2510 | if (!rdev->ops->del_key) |
| 2511 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2512 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2513 | wdev_lock(dev->ieee80211_ptr); |
| 2514 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2515 | |
| 2516 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2517 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2518 | err = -ENOENT; |
| 2519 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2520 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2521 | err = rdev_del_key(rdev, dev, key.idx, |
| 2522 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2523 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2524 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2525 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2526 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2527 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2528 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2529 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2530 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2531 | } |
| 2532 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2533 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2534 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2535 | return err; |
| 2536 | } |
| 2537 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2538 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2539 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2540 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2541 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2542 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2543 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2544 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2545 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2546 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2547 | return -EINVAL; |
| 2548 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2549 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2550 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2551 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2552 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2553 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2554 | if (!bcn->head_len) |
| 2555 | return -EINVAL; |
| 2556 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2560 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2561 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2562 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2563 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2564 | } |
| 2565 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2566 | if (!haveinfo) |
| 2567 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2568 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2569 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2570 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2571 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2575 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2576 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2577 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2578 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2579 | } |
| 2580 | |
| 2581 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2582 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2583 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2584 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2585 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2586 | } |
| 2587 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2588 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2589 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2590 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2591 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2592 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2593 | } |
| 2594 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2595 | return 0; |
| 2596 | } |
| 2597 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2598 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2599 | struct cfg80211_ap_settings *params) |
| 2600 | { |
| 2601 | struct wireless_dev *wdev; |
| 2602 | bool ret = false; |
| 2603 | |
| 2604 | mutex_lock(&rdev->devlist_mtx); |
| 2605 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2606 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2607 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2608 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2609 | continue; |
| 2610 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2611 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2612 | continue; |
| 2613 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2614 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2615 | ret = true; |
| 2616 | break; |
| 2617 | } |
| 2618 | |
| 2619 | mutex_unlock(&rdev->devlist_mtx); |
| 2620 | |
| 2621 | return ret; |
| 2622 | } |
| 2623 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2624 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2625 | enum nl80211_auth_type auth_type, |
| 2626 | enum nl80211_commands cmd) |
| 2627 | { |
| 2628 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2629 | return false; |
| 2630 | |
| 2631 | switch (cmd) { |
| 2632 | case NL80211_CMD_AUTHENTICATE: |
| 2633 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2634 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2635 | return false; |
| 2636 | return true; |
| 2637 | case NL80211_CMD_CONNECT: |
| 2638 | case NL80211_CMD_START_AP: |
| 2639 | /* SAE not supported yet */ |
| 2640 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2641 | return false; |
| 2642 | return true; |
| 2643 | default: |
| 2644 | return false; |
| 2645 | } |
| 2646 | } |
| 2647 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2648 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2649 | { |
| 2650 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2651 | struct net_device *dev = info->user_ptr[1]; |
| 2652 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2653 | struct cfg80211_ap_settings params; |
| 2654 | int err; |
| 2655 | |
| 2656 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2657 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2658 | return -EOPNOTSUPP; |
| 2659 | |
| 2660 | if (!rdev->ops->start_ap) |
| 2661 | return -EOPNOTSUPP; |
| 2662 | |
| 2663 | if (wdev->beacon_interval) |
| 2664 | return -EALREADY; |
| 2665 | |
| 2666 | memset(¶ms, 0, sizeof(params)); |
| 2667 | |
| 2668 | /* these are required for START_AP */ |
| 2669 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2670 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2671 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2672 | return -EINVAL; |
| 2673 | |
| 2674 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2675 | if (err) |
| 2676 | return err; |
| 2677 | |
| 2678 | params.beacon_interval = |
| 2679 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2680 | params.dtim_period = |
| 2681 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2682 | |
| 2683 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2684 | if (err) |
| 2685 | return err; |
| 2686 | |
| 2687 | /* |
| 2688 | * In theory, some of these attributes should be required here |
| 2689 | * but since they were not used when the command was originally |
| 2690 | * added, keep them optional for old user space programs to let |
| 2691 | * them continue to work with drivers that do not need the |
| 2692 | * additional information -- drivers must check! |
| 2693 | */ |
| 2694 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2695 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2696 | params.ssid_len = |
| 2697 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2698 | if (params.ssid_len == 0 || |
| 2699 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2700 | return -EINVAL; |
| 2701 | } |
| 2702 | |
| 2703 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2704 | params.hidden_ssid = nla_get_u32( |
| 2705 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2706 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2707 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2708 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2709 | return -EINVAL; |
| 2710 | } |
| 2711 | |
| 2712 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2713 | |
| 2714 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2715 | params.auth_type = nla_get_u32( |
| 2716 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2717 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 2718 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2719 | return -EINVAL; |
| 2720 | } else |
| 2721 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2722 | |
| 2723 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2724 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2725 | if (err) |
| 2726 | return err; |
| 2727 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2728 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2729 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2730 | return -EOPNOTSUPP; |
| 2731 | params.inactivity_timeout = nla_get_u16( |
| 2732 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2733 | } |
| 2734 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2735 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2736 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 2737 | if (err) |
| 2738 | return err; |
| 2739 | } else if (wdev->preset_chandef.chan) { |
| 2740 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2741 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2742 | return -EINVAL; |
| 2743 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2744 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2745 | return -EINVAL; |
| 2746 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2747 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2748 | err = cfg80211_can_use_chan(rdev, wdev, params.chandef.chan, |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2749 | CHAN_MODE_SHARED); |
| 2750 | mutex_unlock(&rdev->devlist_mtx); |
| 2751 | |
| 2752 | if (err) |
| 2753 | return err; |
| 2754 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2755 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2756 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2757 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2758 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2759 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 2760 | wdev->ssid_len = params.ssid_len; |
| 2761 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2762 | } |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2763 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2764 | } |
| 2765 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2766 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2767 | { |
| 2768 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2769 | struct net_device *dev = info->user_ptr[1]; |
| 2770 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2771 | struct cfg80211_beacon_data params; |
| 2772 | int err; |
| 2773 | |
| 2774 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2775 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2776 | return -EOPNOTSUPP; |
| 2777 | |
| 2778 | if (!rdev->ops->change_beacon) |
| 2779 | return -EOPNOTSUPP; |
| 2780 | |
| 2781 | if (!wdev->beacon_interval) |
| 2782 | return -EINVAL; |
| 2783 | |
| 2784 | err = nl80211_parse_beacon(info, ¶ms); |
| 2785 | if (err) |
| 2786 | return err; |
| 2787 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2788 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2792 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2793 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2794 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2795 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2796 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2797 | } |
| 2798 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2799 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2800 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2801 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2802 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2803 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2804 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2805 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2806 | }; |
| 2807 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2808 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2809 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2810 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2811 | { |
| 2812 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2813 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2814 | int flag; |
| 2815 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2816 | /* |
| 2817 | * Try parsing the new attribute first so userspace |
| 2818 | * can specify both for older kernels. |
| 2819 | */ |
| 2820 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2821 | if (nla) { |
| 2822 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2823 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2824 | sta_flags = nla_data(nla); |
| 2825 | params->sta_flags_mask = sta_flags->mask; |
| 2826 | params->sta_flags_set = sta_flags->set; |
| 2827 | if ((params->sta_flags_mask | |
| 2828 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2829 | return -EINVAL; |
| 2830 | return 0; |
| 2831 | } |
| 2832 | |
| 2833 | /* if present, parse the old attribute */ |
| 2834 | |
| 2835 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2836 | if (!nla) |
| 2837 | return 0; |
| 2838 | |
| 2839 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2840 | nla, sta_flags_policy)) |
| 2841 | return -EINVAL; |
| 2842 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2843 | /* |
| 2844 | * Only allow certain flags for interface types so that |
| 2845 | * other attributes are silently ignored. Remember that |
| 2846 | * this is backward compatibility code with old userspace |
| 2847 | * and shouldn't be hit in other cases anyway. |
| 2848 | */ |
| 2849 | switch (iftype) { |
| 2850 | case NL80211_IFTYPE_AP: |
| 2851 | case NL80211_IFTYPE_AP_VLAN: |
| 2852 | case NL80211_IFTYPE_P2P_GO: |
| 2853 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2854 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2855 | BIT(NL80211_STA_FLAG_WME) | |
| 2856 | BIT(NL80211_STA_FLAG_MFP); |
| 2857 | break; |
| 2858 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2859 | case NL80211_IFTYPE_STATION: |
| 2860 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2861 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2862 | break; |
| 2863 | case NL80211_IFTYPE_MESH_POINT: |
| 2864 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2865 | BIT(NL80211_STA_FLAG_MFP) | |
| 2866 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2867 | default: |
| 2868 | return -EINVAL; |
| 2869 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2870 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2871 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 2872 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2873 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2874 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2875 | /* no longer support new API additions in old API */ |
| 2876 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 2877 | return -EINVAL; |
| 2878 | } |
| 2879 | } |
| 2880 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2881 | return 0; |
| 2882 | } |
| 2883 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2884 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2885 | int attr) |
| 2886 | { |
| 2887 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2888 | u32 bitrate; |
| 2889 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2890 | |
| 2891 | rate = nla_nest_start(msg, attr); |
| 2892 | if (!rate) |
| 2893 | goto nla_put_failure; |
| 2894 | |
| 2895 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2896 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2897 | /* report 16-bit bitrate only if we can */ |
| 2898 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2899 | if ((bitrate > 0 && |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2900 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) || |
| 2901 | (bitrate_compat > 0 && |
| 2902 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2903 | ((info->flags & RATE_INFO_FLAGS_MCS) && |
| 2904 | nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) || |
| 2905 | ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) && |
| 2906 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) || |
| 2907 | ((info->flags & RATE_INFO_FLAGS_SHORT_GI) && |
| 2908 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))) |
| 2909 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2910 | |
| 2911 | nla_nest_end(msg, rate); |
| 2912 | return true; |
| 2913 | |
| 2914 | nla_put_failure: |
| 2915 | return false; |
| 2916 | } |
| 2917 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2918 | 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] | 2919 | int flags, |
| 2920 | struct cfg80211_registered_device *rdev, |
| 2921 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2922 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2923 | { |
| 2924 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2925 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2926 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2927 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2928 | if (!hdr) |
| 2929 | return -1; |
| 2930 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2931 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2932 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 2933 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 2934 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2935 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2936 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2937 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2938 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2939 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 2940 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2941 | sinfo->connected_time)) |
| 2942 | goto nla_put_failure; |
| 2943 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 2944 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2945 | sinfo->inactive_time)) |
| 2946 | goto nla_put_failure; |
| 2947 | if ((sinfo->filled & STATION_INFO_RX_BYTES) && |
| 2948 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2949 | sinfo->rx_bytes)) |
| 2950 | goto nla_put_failure; |
| 2951 | if ((sinfo->filled & STATION_INFO_TX_BYTES) && |
| 2952 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2953 | sinfo->tx_bytes)) |
| 2954 | goto nla_put_failure; |
| 2955 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 2956 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 2957 | goto nla_put_failure; |
| 2958 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 2959 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 2960 | goto nla_put_failure; |
| 2961 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 2962 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2963 | sinfo->plink_state)) |
| 2964 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2965 | switch (rdev->wiphy.signal_type) { |
| 2966 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2967 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 2968 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 2969 | sinfo->signal)) |
| 2970 | goto nla_put_failure; |
| 2971 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 2972 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2973 | sinfo->signal_avg)) |
| 2974 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2975 | break; |
| 2976 | default: |
| 2977 | break; |
| 2978 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2979 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2980 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2981 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2982 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2983 | } |
| 2984 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2985 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2986 | NL80211_STA_INFO_RX_BITRATE)) |
| 2987 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2988 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2989 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 2990 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2991 | sinfo->rx_packets)) |
| 2992 | goto nla_put_failure; |
| 2993 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 2994 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2995 | sinfo->tx_packets)) |
| 2996 | goto nla_put_failure; |
| 2997 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 2998 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2999 | sinfo->tx_retries)) |
| 3000 | goto nla_put_failure; |
| 3001 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3002 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3003 | sinfo->tx_failed)) |
| 3004 | goto nla_put_failure; |
| 3005 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3006 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3007 | sinfo->beacon_loss_count)) |
| 3008 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3009 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3010 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3011 | if (!bss_param) |
| 3012 | goto nla_put_failure; |
| 3013 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3014 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3015 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3016 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3017 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3018 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3019 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3020 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3021 | sinfo->bss_param.dtim_period) || |
| 3022 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3023 | sinfo->bss_param.beacon_interval)) |
| 3024 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3025 | |
| 3026 | nla_nest_end(msg, bss_param); |
| 3027 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3028 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3029 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3030 | sizeof(struct nl80211_sta_flag_update), |
| 3031 | &sinfo->sta_flags)) |
| 3032 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3033 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3034 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3035 | sinfo->t_offset)) |
| 3036 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3037 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3038 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3039 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3040 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3041 | sinfo->assoc_req_ies)) |
| 3042 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3043 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3044 | return genlmsg_end(msg, hdr); |
| 3045 | |
| 3046 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3047 | genlmsg_cancel(msg, hdr); |
| 3048 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3049 | } |
| 3050 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3051 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3052 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3053 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3054 | struct station_info sinfo; |
| 3055 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3056 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3057 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3058 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3059 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3060 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3061 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3062 | if (err) |
| 3063 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3064 | |
| 3065 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3066 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3067 | goto out_err; |
| 3068 | } |
| 3069 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3070 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3071 | memset(&sinfo, 0, sizeof(sinfo)); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3072 | err = rdev_dump_station(dev, netdev, sta_idx, |
| 3073 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3074 | if (err == -ENOENT) |
| 3075 | break; |
| 3076 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3077 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3078 | |
| 3079 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3080 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3081 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3082 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3083 | &sinfo) < 0) |
| 3084 | goto out; |
| 3085 | |
| 3086 | sta_idx++; |
| 3087 | } |
| 3088 | |
| 3089 | |
| 3090 | out: |
| 3091 | cb->args[1] = sta_idx; |
| 3092 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3093 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3094 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3095 | |
| 3096 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3097 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3098 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3099 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3100 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3101 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3102 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3103 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3104 | struct sk_buff *msg; |
| 3105 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3106 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3107 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3108 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3109 | |
| 3110 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3111 | return -EINVAL; |
| 3112 | |
| 3113 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3114 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3115 | if (!rdev->ops->get_station) |
| 3116 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3117 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3118 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3119 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3120 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3121 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3122 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3123 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3124 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3125 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3126 | 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] | 3127 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3128 | nlmsg_free(msg); |
| 3129 | return -ENOBUFS; |
| 3130 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3131 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3132 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3133 | } |
| 3134 | |
| 3135 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3136 | * 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] | 3137 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3138 | static struct net_device *get_vlan(struct genl_info *info, |
| 3139 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3140 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3141 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3142 | struct net_device *v; |
| 3143 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3144 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3145 | if (!vlanattr) |
| 3146 | return NULL; |
| 3147 | |
| 3148 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3149 | if (!v) |
| 3150 | return ERR_PTR(-ENODEV); |
| 3151 | |
| 3152 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3153 | ret = -EINVAL; |
| 3154 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3155 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3156 | |
| 3157 | if (!netif_running(v)) { |
| 3158 | ret = -ENETDOWN; |
| 3159 | goto error; |
| 3160 | } |
| 3161 | |
| 3162 | return v; |
| 3163 | error: |
| 3164 | dev_put(v); |
| 3165 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3169 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3170 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3171 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3172 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3173 | struct station_parameters params; |
| 3174 | u8 *mac_addr = NULL; |
| 3175 | |
| 3176 | memset(¶ms, 0, sizeof(params)); |
| 3177 | |
| 3178 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 3179 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3180 | |
| 3181 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3182 | return -EINVAL; |
| 3183 | |
| 3184 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3185 | return -EINVAL; |
| 3186 | |
| 3187 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3188 | |
| 3189 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3190 | params.supported_rates = |
| 3191 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3192 | params.supported_rates_len = |
| 3193 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3194 | } |
| 3195 | |
| 3196 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3197 | params.listen_interval = |
| 3198 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 3199 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3200 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3201 | params.ht_capa = |
| 3202 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3203 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3204 | if (!rdev->ops->change_station) |
| 3205 | return -EOPNOTSUPP; |
| 3206 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3207 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3208 | return -EINVAL; |
| 3209 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3210 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3211 | params.plink_action = |
| 3212 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3213 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3214 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3215 | params.plink_state = |
| 3216 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3217 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3218 | switch (dev->ieee80211_ptr->iftype) { |
| 3219 | case NL80211_IFTYPE_AP: |
| 3220 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3221 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3222 | /* disallow mesh-specific things */ |
| 3223 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3224 | return -EINVAL; |
| 3225 | |
| 3226 | /* TDLS can't be set, ... */ |
| 3227 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3228 | return -EINVAL; |
| 3229 | /* |
| 3230 | * ... but don't bother the driver with it. This works around |
| 3231 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3232 | * TLDS_PEER flag in the mask even for AP mode. |
| 3233 | */ |
| 3234 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3235 | |
| 3236 | /* accept only the listed bits */ |
| 3237 | if (params.sta_flags_mask & |
| 3238 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3239 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3240 | BIT(NL80211_STA_FLAG_WME) | |
| 3241 | BIT(NL80211_STA_FLAG_MFP))) |
| 3242 | return -EINVAL; |
| 3243 | |
| 3244 | /* must be last in here for error handling */ |
| 3245 | params.vlan = get_vlan(info, rdev); |
| 3246 | if (IS_ERR(params.vlan)) |
| 3247 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3248 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3249 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3250 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3251 | /* |
| 3252 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3253 | * but silently ignore attempts to change it since we |
| 3254 | * don't have state here to verify that it doesn't try |
| 3255 | * to change the flag. |
| 3256 | */ |
| 3257 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3258 | /* fall through */ |
| 3259 | case NL80211_IFTYPE_ADHOC: |
| 3260 | /* disallow things sta doesn't support */ |
| 3261 | if (params.plink_action) |
| 3262 | return -EINVAL; |
| 3263 | if (params.ht_capa) |
| 3264 | return -EINVAL; |
| 3265 | if (params.listen_interval >= 0) |
| 3266 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3267 | /* reject any changes other than AUTHORIZED */ |
| 3268 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3269 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3270 | break; |
| 3271 | case NL80211_IFTYPE_MESH_POINT: |
| 3272 | /* disallow things mesh doesn't support */ |
| 3273 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3274 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3275 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3276 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3277 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3278 | return -EINVAL; |
| 3279 | /* |
| 3280 | * No special handling for TDLS here -- the userspace |
| 3281 | * mesh code doesn't have this bug. |
| 3282 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3283 | if (params.sta_flags_mask & |
| 3284 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3285 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3286 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3287 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3288 | break; |
| 3289 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3290 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3291 | } |
| 3292 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3293 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3294 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3295 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3296 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3297 | if (params.vlan) |
| 3298 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3299 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3300 | return err; |
| 3301 | } |
| 3302 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3303 | static struct nla_policy |
| 3304 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3305 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3306 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3307 | }; |
| 3308 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3309 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3310 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3311 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3312 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3313 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3314 | struct station_parameters params; |
| 3315 | u8 *mac_addr = NULL; |
| 3316 | |
| 3317 | memset(¶ms, 0, sizeof(params)); |
| 3318 | |
| 3319 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3320 | return -EINVAL; |
| 3321 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3322 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3323 | return -EINVAL; |
| 3324 | |
| 3325 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3326 | return -EINVAL; |
| 3327 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3328 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3329 | return -EINVAL; |
| 3330 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3331 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3332 | params.supported_rates = |
| 3333 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3334 | params.supported_rates_len = |
| 3335 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3336 | params.listen_interval = |
| 3337 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3338 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3339 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3340 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3341 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3342 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3343 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3344 | params.ht_capa = |
| 3345 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3346 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3347 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3348 | params.vht_capa = |
| 3349 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3350 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3351 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3352 | params.plink_action = |
| 3353 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3354 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3355 | if (!rdev->ops->add_station) |
| 3356 | return -EOPNOTSUPP; |
| 3357 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3358 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3359 | return -EINVAL; |
| 3360 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3361 | switch (dev->ieee80211_ptr->iftype) { |
| 3362 | case NL80211_IFTYPE_AP: |
| 3363 | case NL80211_IFTYPE_AP_VLAN: |
| 3364 | case NL80211_IFTYPE_P2P_GO: |
| 3365 | /* parse WME attributes if sta is WME capable */ |
| 3366 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3367 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3368 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3369 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3370 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3371 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3372 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3373 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3374 | nl80211_sta_wme_policy); |
| 3375 | if (err) |
| 3376 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3377 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3378 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3379 | params.uapsd_queues = |
| 3380 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3381 | if (params.uapsd_queues & |
| 3382 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3383 | return -EINVAL; |
| 3384 | |
| 3385 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3386 | params.max_sp = |
| 3387 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3388 | |
| 3389 | if (params.max_sp & |
| 3390 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3391 | return -EINVAL; |
| 3392 | |
| 3393 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3394 | } |
| 3395 | /* TDLS peers cannot be added */ |
| 3396 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3397 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3398 | /* but don't bother the driver with it */ |
| 3399 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3400 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3401 | /* must be last in here for error handling */ |
| 3402 | params.vlan = get_vlan(info, rdev); |
| 3403 | if (IS_ERR(params.vlan)) |
| 3404 | return PTR_ERR(params.vlan); |
| 3405 | break; |
| 3406 | case NL80211_IFTYPE_MESH_POINT: |
| 3407 | /* TDLS peers cannot be added */ |
| 3408 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3409 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3410 | break; |
| 3411 | case NL80211_IFTYPE_STATION: |
| 3412 | /* Only TDLS peers can be added */ |
| 3413 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3414 | return -EINVAL; |
| 3415 | /* Can only add if TDLS ... */ |
| 3416 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3417 | return -EOPNOTSUPP; |
| 3418 | /* ... with external setup is supported */ |
| 3419 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3420 | return -EOPNOTSUPP; |
| 3421 | break; |
| 3422 | default: |
| 3423 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3424 | } |
| 3425 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3426 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3427 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3428 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3429 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3430 | if (params.vlan) |
| 3431 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3432 | return err; |
| 3433 | } |
| 3434 | |
| 3435 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3436 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3437 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3438 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3439 | u8 *mac_addr = NULL; |
| 3440 | |
| 3441 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3442 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3443 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3444 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3445 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3446 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3447 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3448 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3449 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3450 | if (!rdev->ops->del_station) |
| 3451 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3452 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3453 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3454 | } |
| 3455 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3456 | 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] | 3457 | int flags, struct net_device *dev, |
| 3458 | u8 *dst, u8 *next_hop, |
| 3459 | struct mpath_info *pinfo) |
| 3460 | { |
| 3461 | void *hdr; |
| 3462 | struct nlattr *pinfoattr; |
| 3463 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3464 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3465 | if (!hdr) |
| 3466 | return -1; |
| 3467 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3468 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3469 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3470 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3471 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3472 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3473 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3474 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3475 | if (!pinfoattr) |
| 3476 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3477 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3478 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3479 | pinfo->frame_qlen)) |
| 3480 | goto nla_put_failure; |
| 3481 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3482 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3483 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3484 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3485 | pinfo->metric)) || |
| 3486 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3487 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3488 | pinfo->exptime)) || |
| 3489 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3490 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3491 | pinfo->flags)) || |
| 3492 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3493 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3494 | pinfo->discovery_timeout)) || |
| 3495 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3496 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3497 | pinfo->discovery_retries))) |
| 3498 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3499 | |
| 3500 | nla_nest_end(msg, pinfoattr); |
| 3501 | |
| 3502 | return genlmsg_end(msg, hdr); |
| 3503 | |
| 3504 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3505 | genlmsg_cancel(msg, hdr); |
| 3506 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3510 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3511 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3512 | struct mpath_info pinfo; |
| 3513 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3514 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3515 | u8 dst[ETH_ALEN]; |
| 3516 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3517 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3518 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3519 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3520 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3521 | if (err) |
| 3522 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3523 | |
| 3524 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3525 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3526 | goto out_err; |
| 3527 | } |
| 3528 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3529 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3530 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3531 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3532 | } |
| 3533 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3534 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3535 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 3536 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3537 | if (err == -ENOENT) |
| 3538 | break; |
| 3539 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3540 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3541 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3542 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3543 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3544 | netdev, dst, next_hop, |
| 3545 | &pinfo) < 0) |
| 3546 | goto out; |
| 3547 | |
| 3548 | path_idx++; |
| 3549 | } |
| 3550 | |
| 3551 | |
| 3552 | out: |
| 3553 | cb->args[1] = path_idx; |
| 3554 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3555 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3556 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3557 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3561 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3562 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3563 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3564 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3565 | struct mpath_info pinfo; |
| 3566 | struct sk_buff *msg; |
| 3567 | u8 *dst = NULL; |
| 3568 | u8 next_hop[ETH_ALEN]; |
| 3569 | |
| 3570 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3571 | |
| 3572 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3573 | return -EINVAL; |
| 3574 | |
| 3575 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3576 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3577 | if (!rdev->ops->get_mpath) |
| 3578 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3579 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3580 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3581 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3582 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3583 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3584 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3585 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3586 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3587 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3588 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3589 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3590 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3591 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3592 | dev, dst, next_hop, &pinfo) < 0) { |
| 3593 | nlmsg_free(msg); |
| 3594 | return -ENOBUFS; |
| 3595 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3596 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3597 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3601 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3602 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3603 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3604 | u8 *dst = NULL; |
| 3605 | u8 *next_hop = NULL; |
| 3606 | |
| 3607 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3608 | return -EINVAL; |
| 3609 | |
| 3610 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3611 | return -EINVAL; |
| 3612 | |
| 3613 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3614 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3615 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3616 | if (!rdev->ops->change_mpath) |
| 3617 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3618 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3619 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3620 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3621 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3622 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3623 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3624 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3625 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3626 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3627 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3628 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3629 | u8 *dst = NULL; |
| 3630 | u8 *next_hop = NULL; |
| 3631 | |
| 3632 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3633 | return -EINVAL; |
| 3634 | |
| 3635 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3636 | return -EINVAL; |
| 3637 | |
| 3638 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3639 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3640 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3641 | if (!rdev->ops->add_mpath) |
| 3642 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3643 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3644 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3645 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3646 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3647 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3651 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3652 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3653 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3654 | u8 *dst = NULL; |
| 3655 | |
| 3656 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3657 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3658 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3659 | if (!rdev->ops->del_mpath) |
| 3660 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3661 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3662 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3663 | } |
| 3664 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3665 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3666 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3667 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3668 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3669 | struct bss_parameters params; |
| 3670 | |
| 3671 | memset(¶ms, 0, sizeof(params)); |
| 3672 | /* default to not changing parameters */ |
| 3673 | params.use_cts_prot = -1; |
| 3674 | params.use_short_preamble = -1; |
| 3675 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3676 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3677 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3678 | |
| 3679 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3680 | params.use_cts_prot = |
| 3681 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3682 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3683 | params.use_short_preamble = |
| 3684 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3685 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3686 | params.use_short_slot_time = |
| 3687 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3688 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3689 | params.basic_rates = |
| 3690 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3691 | params.basic_rates_len = |
| 3692 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3693 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3694 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3695 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3696 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3697 | params.ht_opmode = |
| 3698 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3699 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3700 | if (!rdev->ops->change_bss) |
| 3701 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3702 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3703 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3704 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3705 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3706 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3707 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3708 | } |
| 3709 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3710 | 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] | 3711 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3712 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3713 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3714 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3715 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3716 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3717 | }; |
| 3718 | |
| 3719 | static int parse_reg_rule(struct nlattr *tb[], |
| 3720 | struct ieee80211_reg_rule *reg_rule) |
| 3721 | { |
| 3722 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3723 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3724 | |
| 3725 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3726 | return -EINVAL; |
| 3727 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3728 | return -EINVAL; |
| 3729 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3730 | return -EINVAL; |
| 3731 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3732 | return -EINVAL; |
| 3733 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3734 | return -EINVAL; |
| 3735 | |
| 3736 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3737 | |
| 3738 | freq_range->start_freq_khz = |
| 3739 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3740 | freq_range->end_freq_khz = |
| 3741 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3742 | freq_range->max_bandwidth_khz = |
| 3743 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3744 | |
| 3745 | power_rule->max_eirp = |
| 3746 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3747 | |
| 3748 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3749 | power_rule->max_antenna_gain = |
| 3750 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3751 | |
| 3752 | return 0; |
| 3753 | } |
| 3754 | |
| 3755 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3756 | { |
| 3757 | int r; |
| 3758 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3759 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3760 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3761 | /* |
| 3762 | * You should only get this when cfg80211 hasn't yet initialized |
| 3763 | * completely when built-in to the kernel right between the time |
| 3764 | * window between nl80211_init() and regulatory_init(), if that is |
| 3765 | * even possible. |
| 3766 | */ |
| 3767 | mutex_lock(&cfg80211_mutex); |
| 3768 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3769 | mutex_unlock(&cfg80211_mutex); |
| 3770 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3771 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3772 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3773 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3774 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3775 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3776 | |
| 3777 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3778 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3779 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 3780 | user_reg_hint_type = |
| 3781 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 3782 | else |
| 3783 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 3784 | |
| 3785 | switch (user_reg_hint_type) { |
| 3786 | case NL80211_USER_REG_HINT_USER: |
| 3787 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 3788 | break; |
| 3789 | default: |
| 3790 | return -EINVAL; |
| 3791 | } |
| 3792 | |
| 3793 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3794 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3795 | return r; |
| 3796 | } |
| 3797 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3798 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3799 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3800 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3801 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3802 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3803 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3804 | struct mesh_config cur_params; |
| 3805 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3806 | void *hdr; |
| 3807 | struct nlattr *pinfoattr; |
| 3808 | struct sk_buff *msg; |
| 3809 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3810 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3811 | return -EOPNOTSUPP; |
| 3812 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3813 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3814 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3815 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3816 | wdev_lock(wdev); |
| 3817 | /* If not connected, get default parameters */ |
| 3818 | if (!wdev->mesh_id_len) |
| 3819 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3820 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3821 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3822 | wdev_unlock(wdev); |
| 3823 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3824 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3825 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3826 | |
| 3827 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3828 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3829 | if (!msg) |
| 3830 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3831 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3832 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3833 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3834 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3835 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3836 | if (!pinfoattr) |
| 3837 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3838 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3839 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3840 | cur_params.dot11MeshRetryTimeout) || |
| 3841 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3842 | cur_params.dot11MeshConfirmTimeout) || |
| 3843 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3844 | cur_params.dot11MeshHoldingTimeout) || |
| 3845 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3846 | cur_params.dot11MeshMaxPeerLinks) || |
| 3847 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3848 | cur_params.dot11MeshMaxRetries) || |
| 3849 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 3850 | cur_params.dot11MeshTTL) || |
| 3851 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3852 | cur_params.element_ttl) || |
| 3853 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3854 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3855 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3856 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3857 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3858 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 3859 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3860 | cur_params.path_refresh_time) || |
| 3861 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3862 | cur_params.min_discovery_timeout) || |
| 3863 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3864 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 3865 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3866 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 3867 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3868 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 3869 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3870 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 3871 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3872 | cur_params.dot11MeshHWMPRootMode) || |
| 3873 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3874 | cur_params.dot11MeshHWMPRannInterval) || |
| 3875 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3876 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 3877 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 3878 | cur_params.dot11MeshForwarding) || |
| 3879 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3880 | cur_params.rssi_threshold) || |
| 3881 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3882 | cur_params.ht_opmode) || |
| 3883 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3884 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 3885 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3886 | cur_params.dot11MeshHWMProotInterval) || |
| 3887 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3888 | cur_params.dot11MeshHWMPconfirmationInterval)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3889 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3890 | nla_nest_end(msg, pinfoattr); |
| 3891 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3892 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3893 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3894 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3895 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3896 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3897 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3898 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3899 | } |
| 3900 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3901 | 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] | 3902 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3903 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3904 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3905 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3906 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3907 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3908 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3909 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3910 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3911 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3912 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3913 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3914 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3915 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3916 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3917 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3918 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3919 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3920 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3921 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3922 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 3923 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3924 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 3925 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3926 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3927 | }; |
| 3928 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3929 | static const struct nla_policy |
| 3930 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3931 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3932 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3933 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3934 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3935 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3936 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3937 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3938 | }; |
| 3939 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3940 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3941 | struct mesh_config *cfg, |
| 3942 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3943 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3944 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3945 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3946 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3947 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3948 | do {\ |
| 3949 | if (table[attr_num]) {\ |
| 3950 | cfg->param = nla_fn(table[attr_num]); \ |
| 3951 | mask |= (1 << (attr_num - 1)); \ |
| 3952 | } \ |
| 3953 | } while (0);\ |
| 3954 | |
| 3955 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3956 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3957 | return -EINVAL; |
| 3958 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3959 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3960 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3961 | return -EINVAL; |
| 3962 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3963 | /* This makes sure that there aren't more than 32 mesh config |
| 3964 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3965 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3966 | |
| 3967 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3968 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3969 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3970 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3971 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3972 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3973 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3974 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3975 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3976 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3977 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3978 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3979 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3980 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3981 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 3982 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3983 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3984 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3985 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3986 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 3987 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3988 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3989 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3990 | nla_get_u8); |
| 3991 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask, |
| 3992 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3993 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3994 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3995 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3996 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3997 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3998 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3999 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4000 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4001 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4002 | nla_get_u16); |
| 4003 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask, |
| 4004 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4005 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4006 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4007 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4008 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4009 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4010 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4011 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4012 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4013 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
| 4014 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4015 | nla_get_u16); |
| 4016 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 4017 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 4018 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 4019 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4020 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4021 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4022 | dot11MeshGateAnnouncementProtocol, mask, |
| 4023 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4024 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4025 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4026 | mask, NL80211_MESHCONF_FORWARDING, |
| 4027 | nla_get_u8); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 4028 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4029 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4030 | nla_get_u32); |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4031 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4032 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4033 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4034 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
| 4035 | mask, |
| 4036 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4037 | nla_get_u32); |
| 4038 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, |
| 4039 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4040 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4041 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 4042 | dot11MeshHWMPconfirmationInterval, mask, |
| 4043 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4044 | nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4045 | if (mask_out) |
| 4046 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4047 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4048 | return 0; |
| 4049 | |
| 4050 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4051 | } |
| 4052 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4053 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4054 | struct mesh_setup *setup) |
| 4055 | { |
| 4056 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4057 | |
| 4058 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4059 | return -EINVAL; |
| 4060 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4061 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4062 | nl80211_mesh_setup_params_policy)) |
| 4063 | return -EINVAL; |
| 4064 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4065 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4066 | setup->sync_method = |
| 4067 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4068 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4069 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4070 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4071 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4072 | setup->path_sel_proto = |
| 4073 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4074 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4075 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4076 | |
| 4077 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4078 | setup->path_metric = |
| 4079 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4080 | IEEE80211_PATH_METRIC_VENDOR : |
| 4081 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4082 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4083 | |
| 4084 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4085 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4086 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4087 | if (!is_valid_ie_attr(ieattr)) |
| 4088 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4089 | setup->ie = nla_data(ieattr); |
| 4090 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4091 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4092 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4093 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4094 | |
| 4095 | return 0; |
| 4096 | } |
| 4097 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4098 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4099 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4100 | { |
| 4101 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4102 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4103 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4104 | struct mesh_config cfg; |
| 4105 | u32 mask; |
| 4106 | int err; |
| 4107 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4108 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4109 | return -EOPNOTSUPP; |
| 4110 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4111 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4112 | return -EOPNOTSUPP; |
| 4113 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4114 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4115 | if (err) |
| 4116 | return err; |
| 4117 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4118 | wdev_lock(wdev); |
| 4119 | if (!wdev->mesh_id_len) |
| 4120 | err = -ENOLINK; |
| 4121 | |
| 4122 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4123 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4124 | |
| 4125 | wdev_unlock(wdev); |
| 4126 | |
| 4127 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4128 | } |
| 4129 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4130 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4131 | { |
| 4132 | struct sk_buff *msg; |
| 4133 | void *hdr = NULL; |
| 4134 | struct nlattr *nl_reg_rules; |
| 4135 | unsigned int i; |
| 4136 | int err = -EINVAL; |
| 4137 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4138 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4139 | |
| 4140 | if (!cfg80211_regdomain) |
| 4141 | goto out; |
| 4142 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4143 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4144 | if (!msg) { |
| 4145 | err = -ENOBUFS; |
| 4146 | goto out; |
| 4147 | } |
| 4148 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4149 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4150 | NL80211_CMD_GET_REG); |
| 4151 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4152 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4153 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4154 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 4155 | cfg80211_regdomain->alpha2) || |
| 4156 | (cfg80211_regdomain->dfs_region && |
| 4157 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, |
| 4158 | cfg80211_regdomain->dfs_region))) |
| 4159 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4160 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4161 | if (reg_last_request_cell_base() && |
| 4162 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4163 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4164 | goto nla_put_failure; |
| 4165 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4166 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4167 | if (!nl_reg_rules) |
| 4168 | goto nla_put_failure; |
| 4169 | |
| 4170 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 4171 | struct nlattr *nl_reg_rule; |
| 4172 | const struct ieee80211_reg_rule *reg_rule; |
| 4173 | const struct ieee80211_freq_range *freq_range; |
| 4174 | const struct ieee80211_power_rule *power_rule; |
| 4175 | |
| 4176 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 4177 | freq_range = ®_rule->freq_range; |
| 4178 | power_rule = ®_rule->power_rule; |
| 4179 | |
| 4180 | nl_reg_rule = nla_nest_start(msg, i); |
| 4181 | if (!nl_reg_rule) |
| 4182 | goto nla_put_failure; |
| 4183 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4184 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4185 | reg_rule->flags) || |
| 4186 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4187 | freq_range->start_freq_khz) || |
| 4188 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4189 | freq_range->end_freq_khz) || |
| 4190 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4191 | freq_range->max_bandwidth_khz) || |
| 4192 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4193 | power_rule->max_antenna_gain) || |
| 4194 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4195 | power_rule->max_eirp)) |
| 4196 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4197 | |
| 4198 | nla_nest_end(msg, nl_reg_rule); |
| 4199 | } |
| 4200 | |
| 4201 | nla_nest_end(msg, nl_reg_rules); |
| 4202 | |
| 4203 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4204 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4205 | goto out; |
| 4206 | |
| 4207 | nla_put_failure: |
| 4208 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4209 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4210 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4211 | err = -EMSGSIZE; |
| 4212 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4213 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4214 | return err; |
| 4215 | } |
| 4216 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4217 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4218 | { |
| 4219 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4220 | struct nlattr *nl_reg_rule; |
| 4221 | char *alpha2 = NULL; |
| 4222 | int rem_reg_rules = 0, r = 0; |
| 4223 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4224 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4225 | struct ieee80211_regdomain *rd = NULL; |
| 4226 | |
| 4227 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4228 | return -EINVAL; |
| 4229 | |
| 4230 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4231 | return -EINVAL; |
| 4232 | |
| 4233 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4234 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4235 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4236 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4237 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4238 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4239 | rem_reg_rules) { |
| 4240 | num_rules++; |
| 4241 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4242 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4243 | } |
| 4244 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4245 | mutex_lock(&cfg80211_mutex); |
| 4246 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4247 | if (!reg_is_valid_request(alpha2)) { |
| 4248 | r = -EINVAL; |
| 4249 | goto bad_reg; |
| 4250 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4251 | |
| 4252 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 4253 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 4254 | |
| 4255 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4256 | if (!rd) { |
| 4257 | r = -ENOMEM; |
| 4258 | goto bad_reg; |
| 4259 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4260 | |
| 4261 | rd->n_reg_rules = num_rules; |
| 4262 | rd->alpha2[0] = alpha2[0]; |
| 4263 | rd->alpha2[1] = alpha2[1]; |
| 4264 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4265 | /* |
| 4266 | * Disable DFS master mode if the DFS region was |
| 4267 | * not supported or known on this kernel. |
| 4268 | */ |
| 4269 | if (reg_supported_dfs_region(dfs_region)) |
| 4270 | rd->dfs_region = dfs_region; |
| 4271 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4272 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4273 | rem_reg_rules) { |
| 4274 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 4275 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4276 | reg_rule_policy); |
| 4277 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4278 | if (r) |
| 4279 | goto bad_reg; |
| 4280 | |
| 4281 | rule_idx++; |
| 4282 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4283 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4284 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4285 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4286 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4287 | } |
| 4288 | |
| 4289 | BUG_ON(rule_idx != num_rules); |
| 4290 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4291 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4292 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4293 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4294 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4295 | return r; |
| 4296 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4297 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4298 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4299 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4300 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4301 | } |
| 4302 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4303 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4304 | { |
| 4305 | struct nlattr *attr1, *attr2; |
| 4306 | int n_channels = 0, tmp1, tmp2; |
| 4307 | |
| 4308 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4309 | n_channels++; |
| 4310 | /* |
| 4311 | * Some hardware has a limited channel list for |
| 4312 | * scanning, and it is pretty much nonsensical |
| 4313 | * to scan for a channel twice, so disallow that |
| 4314 | * and don't require drivers to check that the |
| 4315 | * channel list they get isn't longer than what |
| 4316 | * they can scan, as long as they can scan all |
| 4317 | * the channels they registered at once. |
| 4318 | */ |
| 4319 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4320 | if (attr1 != attr2 && |
| 4321 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4322 | return 0; |
| 4323 | } |
| 4324 | |
| 4325 | return n_channels; |
| 4326 | } |
| 4327 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4328 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4329 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4330 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4331 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4332 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4333 | struct nlattr *attr; |
| 4334 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4335 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4336 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4337 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4338 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4339 | return -EINVAL; |
| 4340 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4341 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4342 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4343 | if (!rdev->ops->scan) |
| 4344 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4345 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4346 | if (rdev->scan_req) |
| 4347 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4348 | |
| 4349 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4350 | n_channels = validate_scan_freqs( |
| 4351 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4352 | if (!n_channels) |
| 4353 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4354 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4355 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4356 | n_channels = 0; |
| 4357 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4358 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4359 | if (wiphy->bands[band]) |
| 4360 | n_channels += wiphy->bands[band]->n_channels; |
| 4361 | } |
| 4362 | |
| 4363 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4364 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4365 | n_ssids++; |
| 4366 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4367 | if (n_ssids > wiphy->max_scan_ssids) |
| 4368 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4369 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4370 | if (info->attrs[NL80211_ATTR_IE]) |
| 4371 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4372 | else |
| 4373 | ie_len = 0; |
| 4374 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4375 | if (ie_len > wiphy->max_scan_ie_len) |
| 4376 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4377 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4378 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4379 | + sizeof(*request->ssids) * n_ssids |
| 4380 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4381 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4382 | if (!request) |
| 4383 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4384 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4385 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4386 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4387 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4388 | if (ie_len) { |
| 4389 | if (request->ssids) |
| 4390 | request->ie = (void *)(request->ssids + n_ssids); |
| 4391 | else |
| 4392 | request->ie = (void *)(request->channels + n_channels); |
| 4393 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4394 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4395 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4396 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4397 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4398 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4399 | struct ieee80211_channel *chan; |
| 4400 | |
| 4401 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4402 | |
| 4403 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4404 | err = -EINVAL; |
| 4405 | goto out_free; |
| 4406 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4407 | |
| 4408 | /* ignore disabled channels */ |
| 4409 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4410 | continue; |
| 4411 | |
| 4412 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4413 | i++; |
| 4414 | } |
| 4415 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4416 | enum ieee80211_band band; |
| 4417 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4418 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4419 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4420 | int j; |
| 4421 | if (!wiphy->bands[band]) |
| 4422 | continue; |
| 4423 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4424 | struct ieee80211_channel *chan; |
| 4425 | |
| 4426 | chan = &wiphy->bands[band]->channels[j]; |
| 4427 | |
| 4428 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4429 | continue; |
| 4430 | |
| 4431 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4432 | i++; |
| 4433 | } |
| 4434 | } |
| 4435 | } |
| 4436 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4437 | if (!i) { |
| 4438 | err = -EINVAL; |
| 4439 | goto out_free; |
| 4440 | } |
| 4441 | |
| 4442 | request->n_channels = i; |
| 4443 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4444 | i = 0; |
| 4445 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4446 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4447 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4448 | err = -EINVAL; |
| 4449 | goto out_free; |
| 4450 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4451 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4452 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4453 | i++; |
| 4454 | } |
| 4455 | } |
| 4456 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4457 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4458 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4459 | memcpy((void *)request->ie, |
| 4460 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4461 | request->ie_len); |
| 4462 | } |
| 4463 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4464 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4465 | if (wiphy->bands[i]) |
| 4466 | request->rates[i] = |
| 4467 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4468 | |
| 4469 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4470 | nla_for_each_nested(attr, |
| 4471 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4472 | tmp) { |
| 4473 | enum ieee80211_band band = nla_type(attr); |
| 4474 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4475 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4476 | err = -EINVAL; |
| 4477 | goto out_free; |
| 4478 | } |
| 4479 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4480 | nla_data(attr), |
| 4481 | nla_len(attr), |
| 4482 | &request->rates[band]); |
| 4483 | if (err) |
| 4484 | goto out_free; |
| 4485 | } |
| 4486 | } |
| 4487 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4488 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4489 | request->flags = nla_get_u32( |
| 4490 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4491 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4492 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4493 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4494 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4495 | err = -EOPNOTSUPP; |
| 4496 | goto out_free; |
| 4497 | } |
| 4498 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4499 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4500 | request->no_cck = |
| 4501 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4502 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4503 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4504 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4505 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4506 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4507 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4508 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4509 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4510 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4511 | nl80211_send_scan_start(rdev, wdev); |
| 4512 | if (wdev->netdev) |
| 4513 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4514 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4515 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4516 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4517 | kfree(request); |
| 4518 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4519 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4520 | return err; |
| 4521 | } |
| 4522 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4523 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4524 | struct genl_info *info) |
| 4525 | { |
| 4526 | struct cfg80211_sched_scan_request *request; |
| 4527 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4528 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4529 | struct nlattr *attr; |
| 4530 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4531 | 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] | 4532 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4533 | enum ieee80211_band band; |
| 4534 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4535 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4536 | |
| 4537 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4538 | !rdev->ops->sched_scan_start) |
| 4539 | return -EOPNOTSUPP; |
| 4540 | |
| 4541 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4542 | return -EINVAL; |
| 4543 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4544 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4545 | return -EINVAL; |
| 4546 | |
| 4547 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4548 | if (interval == 0) |
| 4549 | return -EINVAL; |
| 4550 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4551 | wiphy = &rdev->wiphy; |
| 4552 | |
| 4553 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4554 | n_channels = validate_scan_freqs( |
| 4555 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4556 | if (!n_channels) |
| 4557 | return -EINVAL; |
| 4558 | } else { |
| 4559 | n_channels = 0; |
| 4560 | |
| 4561 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4562 | if (wiphy->bands[band]) |
| 4563 | n_channels += wiphy->bands[band]->n_channels; |
| 4564 | } |
| 4565 | |
| 4566 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4567 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4568 | tmp) |
| 4569 | n_ssids++; |
| 4570 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4571 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4572 | return -EINVAL; |
| 4573 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4574 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4575 | nla_for_each_nested(attr, |
| 4576 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4577 | tmp) |
| 4578 | n_match_sets++; |
| 4579 | |
| 4580 | if (n_match_sets > wiphy->max_match_sets) |
| 4581 | return -EINVAL; |
| 4582 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4583 | if (info->attrs[NL80211_ATTR_IE]) |
| 4584 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4585 | else |
| 4586 | ie_len = 0; |
| 4587 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4588 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4589 | return -EINVAL; |
| 4590 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4591 | mutex_lock(&rdev->sched_scan_mtx); |
| 4592 | |
| 4593 | if (rdev->sched_scan_req) { |
| 4594 | err = -EINPROGRESS; |
| 4595 | goto out; |
| 4596 | } |
| 4597 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4598 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4599 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4600 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4601 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4602 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4603 | if (!request) { |
| 4604 | err = -ENOMEM; |
| 4605 | goto out; |
| 4606 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4607 | |
| 4608 | if (n_ssids) |
| 4609 | request->ssids = (void *)&request->channels[n_channels]; |
| 4610 | request->n_ssids = n_ssids; |
| 4611 | if (ie_len) { |
| 4612 | if (request->ssids) |
| 4613 | request->ie = (void *)(request->ssids + n_ssids); |
| 4614 | else |
| 4615 | request->ie = (void *)(request->channels + n_channels); |
| 4616 | } |
| 4617 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4618 | if (n_match_sets) { |
| 4619 | if (request->ie) |
| 4620 | request->match_sets = (void *)(request->ie + ie_len); |
| 4621 | else if (request->ssids) |
| 4622 | request->match_sets = |
| 4623 | (void *)(request->ssids + n_ssids); |
| 4624 | else |
| 4625 | request->match_sets = |
| 4626 | (void *)(request->channels + n_channels); |
| 4627 | } |
| 4628 | request->n_match_sets = n_match_sets; |
| 4629 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4630 | i = 0; |
| 4631 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4632 | /* user specified, bail out if channel not found */ |
| 4633 | nla_for_each_nested(attr, |
| 4634 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4635 | tmp) { |
| 4636 | struct ieee80211_channel *chan; |
| 4637 | |
| 4638 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4639 | |
| 4640 | if (!chan) { |
| 4641 | err = -EINVAL; |
| 4642 | goto out_free; |
| 4643 | } |
| 4644 | |
| 4645 | /* ignore disabled channels */ |
| 4646 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4647 | continue; |
| 4648 | |
| 4649 | request->channels[i] = chan; |
| 4650 | i++; |
| 4651 | } |
| 4652 | } else { |
| 4653 | /* all channels */ |
| 4654 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4655 | int j; |
| 4656 | if (!wiphy->bands[band]) |
| 4657 | continue; |
| 4658 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4659 | struct ieee80211_channel *chan; |
| 4660 | |
| 4661 | chan = &wiphy->bands[band]->channels[j]; |
| 4662 | |
| 4663 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4664 | continue; |
| 4665 | |
| 4666 | request->channels[i] = chan; |
| 4667 | i++; |
| 4668 | } |
| 4669 | } |
| 4670 | } |
| 4671 | |
| 4672 | if (!i) { |
| 4673 | err = -EINVAL; |
| 4674 | goto out_free; |
| 4675 | } |
| 4676 | |
| 4677 | request->n_channels = i; |
| 4678 | |
| 4679 | i = 0; |
| 4680 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4681 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4682 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4683 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4684 | err = -EINVAL; |
| 4685 | goto out_free; |
| 4686 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4687 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4688 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4689 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4690 | i++; |
| 4691 | } |
| 4692 | } |
| 4693 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4694 | i = 0; |
| 4695 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4696 | nla_for_each_nested(attr, |
| 4697 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4698 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4699 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4700 | |
| 4701 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4702 | nla_data(attr), nla_len(attr), |
| 4703 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 4704 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4705 | if (ssid) { |
| 4706 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4707 | err = -EINVAL; |
| 4708 | goto out_free; |
| 4709 | } |
| 4710 | memcpy(request->match_sets[i].ssid.ssid, |
| 4711 | nla_data(ssid), nla_len(ssid)); |
| 4712 | request->match_sets[i].ssid.ssid_len = |
| 4713 | nla_len(ssid); |
| 4714 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4715 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 4716 | if (rssi) |
| 4717 | request->rssi_thold = nla_get_u32(rssi); |
| 4718 | else |
| 4719 | request->rssi_thold = |
| 4720 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4721 | i++; |
| 4722 | } |
| 4723 | } |
| 4724 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4725 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4726 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4727 | memcpy((void *)request->ie, |
| 4728 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4729 | request->ie_len); |
| 4730 | } |
| 4731 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4732 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4733 | request->flags = nla_get_u32( |
| 4734 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4735 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4736 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4737 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4738 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4739 | err = -EOPNOTSUPP; |
| 4740 | goto out_free; |
| 4741 | } |
| 4742 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4743 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4744 | request->dev = dev; |
| 4745 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4746 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4747 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4748 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4749 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4750 | if (!err) { |
| 4751 | rdev->sched_scan_req = request; |
| 4752 | nl80211_send_sched_scan(rdev, dev, |
| 4753 | NL80211_CMD_START_SCHED_SCAN); |
| 4754 | goto out; |
| 4755 | } |
| 4756 | |
| 4757 | out_free: |
| 4758 | kfree(request); |
| 4759 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4760 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4761 | return err; |
| 4762 | } |
| 4763 | |
| 4764 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4765 | struct genl_info *info) |
| 4766 | { |
| 4767 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4768 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4769 | |
| 4770 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4771 | !rdev->ops->sched_scan_stop) |
| 4772 | return -EOPNOTSUPP; |
| 4773 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4774 | mutex_lock(&rdev->sched_scan_mtx); |
| 4775 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4776 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4777 | |
| 4778 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4779 | } |
| 4780 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4781 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4782 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4783 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4784 | struct wireless_dev *wdev, |
| 4785 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4786 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4787 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4788 | void *hdr; |
| 4789 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4790 | |
| 4791 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4792 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4793 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4794 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4795 | if (!hdr) |
| 4796 | return -1; |
| 4797 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4798 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4799 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4800 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 4801 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 4802 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4803 | |
| 4804 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4805 | if (!bss) |
| 4806 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4807 | if ((!is_zero_ether_addr(res->bssid) && |
| 4808 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) || |
| 4809 | (res->information_elements && res->len_information_elements && |
| 4810 | nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4811 | res->len_information_elements, |
| 4812 | res->information_elements)) || |
| 4813 | (res->beacon_ies && res->len_beacon_ies && |
| 4814 | res->beacon_ies != res->information_elements && |
| 4815 | nla_put(msg, NL80211_BSS_BEACON_IES, |
| 4816 | res->len_beacon_ies, res->beacon_ies))) |
| 4817 | goto nla_put_failure; |
| 4818 | if (res->tsf && |
| 4819 | nla_put_u64(msg, NL80211_BSS_TSF, res->tsf)) |
| 4820 | goto nla_put_failure; |
| 4821 | if (res->beacon_interval && |
| 4822 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 4823 | goto nla_put_failure; |
| 4824 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 4825 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 4826 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4827 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 4828 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4829 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4830 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4831 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4832 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 4833 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4834 | break; |
| 4835 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4836 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 4837 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4838 | break; |
| 4839 | default: |
| 4840 | break; |
| 4841 | } |
| 4842 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4843 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4844 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4845 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4846 | if (intbss == wdev->current_bss && |
| 4847 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4848 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 4849 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4850 | break; |
| 4851 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4852 | if (intbss == wdev->current_bss && |
| 4853 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4854 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 4855 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4856 | break; |
| 4857 | default: |
| 4858 | break; |
| 4859 | } |
| 4860 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4861 | nla_nest_end(msg, bss); |
| 4862 | |
| 4863 | return genlmsg_end(msg, hdr); |
| 4864 | |
| 4865 | nla_put_failure: |
| 4866 | genlmsg_cancel(msg, hdr); |
| 4867 | return -EMSGSIZE; |
| 4868 | } |
| 4869 | |
| 4870 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4871 | struct netlink_callback *cb) |
| 4872 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4873 | struct cfg80211_registered_device *rdev; |
| 4874 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4875 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4876 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4877 | int start = cb->args[1], idx = 0; |
| 4878 | int err; |
| 4879 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4880 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4881 | if (err) |
| 4882 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4883 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4884 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4885 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4886 | wdev_lock(wdev); |
| 4887 | spin_lock_bh(&rdev->bss_lock); |
| 4888 | cfg80211_bss_expire(rdev); |
| 4889 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4890 | cb->seq = rdev->bss_generation; |
| 4891 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4892 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4893 | if (++idx <= start) |
| 4894 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4895 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4896 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4897 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4898 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4899 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4900 | } |
| 4901 | } |
| 4902 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4903 | spin_unlock_bh(&rdev->bss_lock); |
| 4904 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4905 | |
| 4906 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4907 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4908 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4909 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4910 | } |
| 4911 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4912 | 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] | 4913 | int flags, struct net_device *dev, |
| 4914 | struct survey_info *survey) |
| 4915 | { |
| 4916 | void *hdr; |
| 4917 | struct nlattr *infoattr; |
| 4918 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4919 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4920 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4921 | if (!hdr) |
| 4922 | return -ENOMEM; |
| 4923 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4924 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 4925 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4926 | |
| 4927 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4928 | if (!infoattr) |
| 4929 | goto nla_put_failure; |
| 4930 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4931 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4932 | survey->channel->center_freq)) |
| 4933 | goto nla_put_failure; |
| 4934 | |
| 4935 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 4936 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 4937 | goto nla_put_failure; |
| 4938 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 4939 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 4940 | goto nla_put_failure; |
| 4941 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 4942 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4943 | survey->channel_time)) |
| 4944 | goto nla_put_failure; |
| 4945 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 4946 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4947 | survey->channel_time_busy)) |
| 4948 | goto nla_put_failure; |
| 4949 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 4950 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4951 | survey->channel_time_ext_busy)) |
| 4952 | goto nla_put_failure; |
| 4953 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 4954 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4955 | survey->channel_time_rx)) |
| 4956 | goto nla_put_failure; |
| 4957 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 4958 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4959 | survey->channel_time_tx)) |
| 4960 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4961 | |
| 4962 | nla_nest_end(msg, infoattr); |
| 4963 | |
| 4964 | return genlmsg_end(msg, hdr); |
| 4965 | |
| 4966 | nla_put_failure: |
| 4967 | genlmsg_cancel(msg, hdr); |
| 4968 | return -EMSGSIZE; |
| 4969 | } |
| 4970 | |
| 4971 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4972 | struct netlink_callback *cb) |
| 4973 | { |
| 4974 | struct survey_info survey; |
| 4975 | struct cfg80211_registered_device *dev; |
| 4976 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4977 | int survey_idx = cb->args[1]; |
| 4978 | int res; |
| 4979 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4980 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4981 | if (res) |
| 4982 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4983 | |
| 4984 | if (!dev->ops->dump_survey) { |
| 4985 | res = -EOPNOTSUPP; |
| 4986 | goto out_err; |
| 4987 | } |
| 4988 | |
| 4989 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4990 | struct ieee80211_channel *chan; |
| 4991 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4992 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4993 | if (res == -ENOENT) |
| 4994 | break; |
| 4995 | if (res) |
| 4996 | goto out_err; |
| 4997 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4998 | /* Survey without a channel doesn't make sense */ |
| 4999 | if (!survey.channel) { |
| 5000 | res = -EINVAL; |
| 5001 | goto out; |
| 5002 | } |
| 5003 | |
| 5004 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5005 | survey.channel->center_freq); |
| 5006 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5007 | survey_idx++; |
| 5008 | continue; |
| 5009 | } |
| 5010 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5011 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5012 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5013 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5014 | netdev, |
| 5015 | &survey) < 0) |
| 5016 | goto out; |
| 5017 | survey_idx++; |
| 5018 | } |
| 5019 | |
| 5020 | out: |
| 5021 | cb->args[1] = survey_idx; |
| 5022 | res = skb->len; |
| 5023 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5024 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5025 | return res; |
| 5026 | } |
| 5027 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5028 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5029 | { |
| 5030 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5031 | NL80211_WPA_VERSION_2)); |
| 5032 | } |
| 5033 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5034 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5035 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5037 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5038 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5039 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5040 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5041 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5042 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5043 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5044 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5045 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5046 | return -EINVAL; |
| 5047 | |
| 5048 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5049 | return -EINVAL; |
| 5050 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5051 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5052 | return -EINVAL; |
| 5053 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5054 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5055 | return -EINVAL; |
| 5056 | |
| 5057 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5058 | return -EINVAL; |
| 5059 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5060 | err = nl80211_parse_key(info, &key); |
| 5061 | if (err) |
| 5062 | return err; |
| 5063 | |
| 5064 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5065 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5066 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5067 | if (!key.p.key || !key.p.key_len) |
| 5068 | return -EINVAL; |
| 5069 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5070 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5071 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5072 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5073 | return -EINVAL; |
| 5074 | if (key.idx > 4) |
| 5075 | return -EINVAL; |
| 5076 | } else { |
| 5077 | key.p.key_len = 0; |
| 5078 | key.p.key = NULL; |
| 5079 | } |
| 5080 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5081 | if (key.idx >= 0) { |
| 5082 | int i; |
| 5083 | bool ok = false; |
| 5084 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5085 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5086 | ok = true; |
| 5087 | break; |
| 5088 | } |
| 5089 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5090 | if (!ok) |
| 5091 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5092 | } |
| 5093 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5094 | if (!rdev->ops->auth) |
| 5095 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5096 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5097 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5098 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5099 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5100 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5101 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5102 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5103 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5104 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5105 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5106 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5107 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5108 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5109 | |
| 5110 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5111 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5112 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5113 | } |
| 5114 | |
| 5115 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5116 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5117 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5118 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5119 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5120 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5121 | return -EINVAL; |
| 5122 | |
| 5123 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5124 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5125 | return -EINVAL; |
| 5126 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5127 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5128 | /* need to include at least Auth Transaction and Status Code */ |
| 5129 | if (sae_data_len < 4) |
| 5130 | return -EINVAL; |
| 5131 | } |
| 5132 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5133 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5134 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5135 | /* |
| 5136 | * Since we no longer track auth state, ignore |
| 5137 | * requests to only change local state. |
| 5138 | */ |
| 5139 | if (local_state_change) |
| 5140 | return 0; |
| 5141 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5142 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5143 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5144 | key.p.key, key.p.key_len, key.idx, |
| 5145 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5146 | } |
| 5147 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5148 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5149 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5150 | struct cfg80211_crypto_settings *settings, |
| 5151 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5152 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5153 | memset(settings, 0, sizeof(*settings)); |
| 5154 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5155 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5156 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5157 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5158 | u16 proto; |
| 5159 | proto = nla_get_u16( |
| 5160 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5161 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5162 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5163 | proto != ETH_P_PAE) |
| 5164 | return -EINVAL; |
| 5165 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5166 | settings->control_port_no_encrypt = true; |
| 5167 | } else |
| 5168 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5169 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5170 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5171 | void *data; |
| 5172 | int len, i; |
| 5173 | |
| 5174 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5175 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5176 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5177 | |
| 5178 | if (len % sizeof(u32)) |
| 5179 | return -EINVAL; |
| 5180 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5181 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5182 | return -EINVAL; |
| 5183 | |
| 5184 | memcpy(settings->ciphers_pairwise, data, len); |
| 5185 | |
| 5186 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5187 | if (!cfg80211_supported_cipher_suite( |
| 5188 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5189 | settings->ciphers_pairwise[i])) |
| 5190 | return -EINVAL; |
| 5191 | } |
| 5192 | |
| 5193 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5194 | settings->cipher_group = |
| 5195 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5196 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5197 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5198 | return -EINVAL; |
| 5199 | } |
| 5200 | |
| 5201 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5202 | settings->wpa_versions = |
| 5203 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5204 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5205 | return -EINVAL; |
| 5206 | } |
| 5207 | |
| 5208 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5209 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5210 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5211 | |
| 5212 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5213 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5214 | settings->n_akm_suites = len / sizeof(u32); |
| 5215 | |
| 5216 | if (len % sizeof(u32)) |
| 5217 | return -EINVAL; |
| 5218 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5219 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5220 | return -EINVAL; |
| 5221 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5222 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5223 | } |
| 5224 | |
| 5225 | return 0; |
| 5226 | } |
| 5227 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5228 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5229 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5231 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5232 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5233 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5234 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5235 | int err, ssid_len, ie_len = 0; |
| 5236 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5237 | u32 flags = 0; |
| 5238 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5239 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5240 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5241 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5242 | return -EINVAL; |
| 5243 | |
| 5244 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5245 | !info->attrs[NL80211_ATTR_SSID] || |
| 5246 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5247 | return -EINVAL; |
| 5248 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5249 | if (!rdev->ops->assoc) |
| 5250 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5251 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5252 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5253 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5254 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5255 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5256 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5257 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5258 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5259 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5260 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5261 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5262 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5263 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5264 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5265 | |
| 5266 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5267 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5268 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5269 | } |
| 5270 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5271 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5272 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5273 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5274 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5275 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5276 | else if (mfp != NL80211_MFP_NO) |
| 5277 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5278 | } |
| 5279 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5280 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5281 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5282 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5283 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5284 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5285 | |
| 5286 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5287 | ht_capa_mask = |
| 5288 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5289 | |
| 5290 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5291 | if (!ht_capa_mask) |
| 5292 | return -EINVAL; |
| 5293 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5294 | } |
| 5295 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5296 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5297 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5298 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5299 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5300 | &crypto, flags, ht_capa, |
| 5301 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5302 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5303 | return err; |
| 5304 | } |
| 5305 | |
| 5306 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5307 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5308 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5309 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5310 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5311 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5312 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5313 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5314 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5315 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5316 | return -EINVAL; |
| 5317 | |
| 5318 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5319 | return -EINVAL; |
| 5320 | |
| 5321 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5322 | return -EINVAL; |
| 5323 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5324 | if (!rdev->ops->deauth) |
| 5325 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5326 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5327 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5328 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5329 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5330 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5331 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5332 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5333 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5334 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5335 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5336 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5337 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5338 | |
| 5339 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5340 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5341 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5342 | } |
| 5343 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5344 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5345 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5346 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5347 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5351 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5352 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5353 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5354 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5355 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5356 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5357 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5358 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5359 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5360 | return -EINVAL; |
| 5361 | |
| 5362 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5363 | return -EINVAL; |
| 5364 | |
| 5365 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5366 | return -EINVAL; |
| 5367 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5368 | if (!rdev->ops->disassoc) |
| 5369 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5370 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5371 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5372 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5373 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5374 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5375 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5376 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5377 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5378 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5379 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5380 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5381 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5382 | |
| 5383 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5384 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5385 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5386 | } |
| 5387 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5388 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5389 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5390 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5391 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5392 | } |
| 5393 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5394 | static bool |
| 5395 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5396 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5397 | int rateval) |
| 5398 | { |
| 5399 | struct wiphy *wiphy = &rdev->wiphy; |
| 5400 | bool found = false; |
| 5401 | int band, i; |
| 5402 | |
| 5403 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5404 | struct ieee80211_supported_band *sband; |
| 5405 | |
| 5406 | sband = wiphy->bands[band]; |
| 5407 | if (!sband) |
| 5408 | continue; |
| 5409 | |
| 5410 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5411 | if (sband->bitrates[i].bitrate == rateval) { |
| 5412 | mcast_rate[band] = i + 1; |
| 5413 | found = true; |
| 5414 | break; |
| 5415 | } |
| 5416 | } |
| 5417 | } |
| 5418 | |
| 5419 | return found; |
| 5420 | } |
| 5421 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5422 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5423 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5424 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5425 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5426 | struct cfg80211_ibss_params ibss; |
| 5427 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5428 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5429 | int err; |
| 5430 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5431 | memset(&ibss, 0, sizeof(ibss)); |
| 5432 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5433 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5434 | return -EINVAL; |
| 5435 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5436 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5437 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5438 | return -EINVAL; |
| 5439 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5440 | ibss.beacon_interval = 100; |
| 5441 | |
| 5442 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5443 | ibss.beacon_interval = |
| 5444 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5445 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5446 | return -EINVAL; |
| 5447 | } |
| 5448 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5449 | if (!rdev->ops->join_ibss) |
| 5450 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5451 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5452 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5453 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5454 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5455 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5456 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5457 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5458 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5459 | |
| 5460 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5461 | return -EINVAL; |
| 5462 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5463 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5464 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5465 | |
| 5466 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5467 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5468 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5469 | } |
| 5470 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5471 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 5472 | if (err) |
| 5473 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5474 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5475 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5476 | return -EINVAL; |
| 5477 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5478 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5479 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5480 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5481 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5482 | u8 *rates = |
| 5483 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5484 | int n_rates = |
| 5485 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5486 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5487 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5488 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5489 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5490 | &ibss.basic_rates); |
| 5491 | if (err) |
| 5492 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5493 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5494 | |
| 5495 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5496 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5497 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5498 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5499 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5500 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5501 | bool no_ht = false; |
| 5502 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5503 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5504 | info->attrs[NL80211_ATTR_KEYS], |
| 5505 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5506 | if (IS_ERR(connkeys)) |
| 5507 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5508 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame^] | 5509 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 5510 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5511 | kfree(connkeys); |
| 5512 | return -EINVAL; |
| 5513 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5514 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5515 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5516 | ibss.control_port = |
| 5517 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5518 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5519 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5520 | if (err) |
| 5521 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5522 | return err; |
| 5523 | } |
| 5524 | |
| 5525 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5526 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5527 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5528 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5529 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5530 | if (!rdev->ops->leave_ibss) |
| 5531 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5532 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5533 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5534 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5535 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5536 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5537 | } |
| 5538 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 5539 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 5540 | { |
| 5541 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5542 | struct net_device *dev = info->user_ptr[1]; |
| 5543 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 5544 | u32 nla_rate; |
| 5545 | int err; |
| 5546 | |
| 5547 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5548 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5549 | return -EOPNOTSUPP; |
| 5550 | |
| 5551 | if (!rdev->ops->set_mcast_rate) |
| 5552 | return -EOPNOTSUPP; |
| 5553 | |
| 5554 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 5555 | |
| 5556 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 5557 | return -EINVAL; |
| 5558 | |
| 5559 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 5560 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 5561 | return -EINVAL; |
| 5562 | |
| 5563 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 5564 | |
| 5565 | return err; |
| 5566 | } |
| 5567 | |
| 5568 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5569 | #ifdef CONFIG_NL80211_TESTMODE |
| 5570 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5571 | .name = "testmode", |
| 5572 | }; |
| 5573 | |
| 5574 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5575 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5576 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5577 | int err; |
| 5578 | |
| 5579 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5580 | return -EINVAL; |
| 5581 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5582 | err = -EOPNOTSUPP; |
| 5583 | if (rdev->ops->testmode_cmd) { |
| 5584 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5585 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5586 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5587 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5588 | rdev->testmode_info = NULL; |
| 5589 | } |
| 5590 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5591 | return err; |
| 5592 | } |
| 5593 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5594 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5595 | struct netlink_callback *cb) |
| 5596 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5597 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5598 | int err; |
| 5599 | long phy_idx; |
| 5600 | void *data = NULL; |
| 5601 | int data_len = 0; |
| 5602 | |
| 5603 | if (cb->args[0]) { |
| 5604 | /* |
| 5605 | * 0 is a valid index, but not valid for args[0], |
| 5606 | * so we need to offset by 1. |
| 5607 | */ |
| 5608 | phy_idx = cb->args[0] - 1; |
| 5609 | } else { |
| 5610 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5611 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5612 | nl80211_policy); |
| 5613 | if (err) |
| 5614 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5615 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5616 | mutex_lock(&cfg80211_mutex); |
| 5617 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 5618 | nl80211_fam.attrbuf); |
| 5619 | if (IS_ERR(rdev)) { |
| 5620 | mutex_unlock(&cfg80211_mutex); |
| 5621 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5622 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5623 | phy_idx = rdev->wiphy_idx; |
| 5624 | rdev = NULL; |
| 5625 | mutex_unlock(&cfg80211_mutex); |
| 5626 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5627 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 5628 | cb->args[1] = |
| 5629 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 5630 | } |
| 5631 | |
| 5632 | if (cb->args[1]) { |
| 5633 | data = nla_data((void *)cb->args[1]); |
| 5634 | data_len = nla_len((void *)cb->args[1]); |
| 5635 | } |
| 5636 | |
| 5637 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5638 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 5639 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5640 | mutex_unlock(&cfg80211_mutex); |
| 5641 | return -ENOENT; |
| 5642 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5643 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5644 | mutex_unlock(&cfg80211_mutex); |
| 5645 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5646 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5647 | err = -EOPNOTSUPP; |
| 5648 | goto out_err; |
| 5649 | } |
| 5650 | |
| 5651 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5652 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5653 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5654 | NL80211_CMD_TESTMODE); |
| 5655 | struct nlattr *tmdata; |
| 5656 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5657 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5658 | genlmsg_cancel(skb, hdr); |
| 5659 | break; |
| 5660 | } |
| 5661 | |
| 5662 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5663 | if (!tmdata) { |
| 5664 | genlmsg_cancel(skb, hdr); |
| 5665 | break; |
| 5666 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5667 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5668 | nla_nest_end(skb, tmdata); |
| 5669 | |
| 5670 | if (err == -ENOBUFS || err == -ENOENT) { |
| 5671 | genlmsg_cancel(skb, hdr); |
| 5672 | break; |
| 5673 | } else if (err) { |
| 5674 | genlmsg_cancel(skb, hdr); |
| 5675 | goto out_err; |
| 5676 | } |
| 5677 | |
| 5678 | genlmsg_end(skb, hdr); |
| 5679 | } |
| 5680 | |
| 5681 | err = skb->len; |
| 5682 | /* see above */ |
| 5683 | cb->args[0] = phy_idx + 1; |
| 5684 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5685 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5686 | return err; |
| 5687 | } |
| 5688 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5689 | static struct sk_buff * |
| 5690 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5691 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5692 | { |
| 5693 | struct sk_buff *skb; |
| 5694 | void *hdr; |
| 5695 | struct nlattr *data; |
| 5696 | |
| 5697 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5698 | if (!skb) |
| 5699 | return NULL; |
| 5700 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5701 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5702 | if (!hdr) { |
| 5703 | kfree_skb(skb); |
| 5704 | return NULL; |
| 5705 | } |
| 5706 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5707 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 5708 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5709 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5710 | |
| 5711 | ((void **)skb->cb)[0] = rdev; |
| 5712 | ((void **)skb->cb)[1] = hdr; |
| 5713 | ((void **)skb->cb)[2] = data; |
| 5714 | |
| 5715 | return skb; |
| 5716 | |
| 5717 | nla_put_failure: |
| 5718 | kfree_skb(skb); |
| 5719 | return NULL; |
| 5720 | } |
| 5721 | |
| 5722 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5723 | int approxlen) |
| 5724 | { |
| 5725 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5726 | |
| 5727 | if (WARN_ON(!rdev->testmode_info)) |
| 5728 | return NULL; |
| 5729 | |
| 5730 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5731 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5732 | rdev->testmode_info->snd_seq, |
| 5733 | GFP_KERNEL); |
| 5734 | } |
| 5735 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5736 | |
| 5737 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5738 | { |
| 5739 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5740 | void *hdr = ((void **)skb->cb)[1]; |
| 5741 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5742 | |
| 5743 | if (WARN_ON(!rdev->testmode_info)) { |
| 5744 | kfree_skb(skb); |
| 5745 | return -EINVAL; |
| 5746 | } |
| 5747 | |
| 5748 | nla_nest_end(skb, data); |
| 5749 | genlmsg_end(skb, hdr); |
| 5750 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5751 | } |
| 5752 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5753 | |
| 5754 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5755 | int approxlen, gfp_t gfp) |
| 5756 | { |
| 5757 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5758 | |
| 5759 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5760 | } |
| 5761 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5762 | |
| 5763 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5764 | { |
| 5765 | void *hdr = ((void **)skb->cb)[1]; |
| 5766 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5767 | |
| 5768 | nla_nest_end(skb, data); |
| 5769 | genlmsg_end(skb, hdr); |
| 5770 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5771 | } |
| 5772 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5773 | #endif |
| 5774 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5775 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5776 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5777 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5778 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5779 | struct cfg80211_connect_params connect; |
| 5780 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5781 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5782 | int err; |
| 5783 | |
| 5784 | memset(&connect, 0, sizeof(connect)); |
| 5785 | |
| 5786 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5787 | return -EINVAL; |
| 5788 | |
| 5789 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5790 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5791 | return -EINVAL; |
| 5792 | |
| 5793 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5794 | connect.auth_type = |
| 5795 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5796 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 5797 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5798 | return -EINVAL; |
| 5799 | } else |
| 5800 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5801 | |
| 5802 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5803 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5804 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5805 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5806 | if (err) |
| 5807 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5808 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5809 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5810 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5811 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5812 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5813 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5814 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 5815 | connect.bg_scan_period = -1; |
| 5816 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 5817 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 5818 | connect.bg_scan_period = |
| 5819 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 5820 | } |
| 5821 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5822 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5823 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5824 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5825 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5826 | |
| 5827 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5828 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5829 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5830 | } |
| 5831 | |
| 5832 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5833 | connect.channel = |
| 5834 | ieee80211_get_channel(wiphy, |
| 5835 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5836 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5837 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5838 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5839 | } |
| 5840 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5841 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5842 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5843 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5844 | if (IS_ERR(connkeys)) |
| 5845 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5846 | } |
| 5847 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5848 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5849 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5850 | |
| 5851 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5852 | memcpy(&connect.ht_capa_mask, |
| 5853 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5854 | sizeof(connect.ht_capa_mask)); |
| 5855 | |
| 5856 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5857 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 5858 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5859 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5860 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5861 | memcpy(&connect.ht_capa, |
| 5862 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5863 | sizeof(connect.ht_capa)); |
| 5864 | } |
| 5865 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5866 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5867 | if (err) |
| 5868 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5869 | return err; |
| 5870 | } |
| 5871 | |
| 5872 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5873 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5874 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5875 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5876 | u16 reason; |
| 5877 | |
| 5878 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5879 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5880 | else |
| 5881 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5882 | |
| 5883 | if (reason == 0) |
| 5884 | return -EINVAL; |
| 5885 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5886 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5887 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5888 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5889 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5890 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5891 | } |
| 5892 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5893 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5894 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5895 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5896 | struct net *net; |
| 5897 | int err; |
| 5898 | u32 pid; |
| 5899 | |
| 5900 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5901 | return -EINVAL; |
| 5902 | |
| 5903 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5904 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5905 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5906 | if (IS_ERR(net)) |
| 5907 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5908 | |
| 5909 | err = 0; |
| 5910 | |
| 5911 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5912 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5913 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5914 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5915 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5916 | return err; |
| 5917 | } |
| 5918 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5919 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5920 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5921 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5922 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5923 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5924 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5925 | struct cfg80211_pmksa pmksa; |
| 5926 | |
| 5927 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5928 | |
| 5929 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5930 | return -EINVAL; |
| 5931 | |
| 5932 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5933 | return -EINVAL; |
| 5934 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5935 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5936 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5937 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5938 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5939 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5940 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5941 | |
| 5942 | switch (info->genlhdr->cmd) { |
| 5943 | case NL80211_CMD_SET_PMKSA: |
| 5944 | rdev_ops = rdev->ops->set_pmksa; |
| 5945 | break; |
| 5946 | case NL80211_CMD_DEL_PMKSA: |
| 5947 | rdev_ops = rdev->ops->del_pmksa; |
| 5948 | break; |
| 5949 | default: |
| 5950 | WARN_ON(1); |
| 5951 | break; |
| 5952 | } |
| 5953 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5954 | if (!rdev_ops) |
| 5955 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5956 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5957 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5958 | } |
| 5959 | |
| 5960 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5961 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5962 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5963 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5964 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5965 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5966 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5967 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5968 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5969 | if (!rdev->ops->flush_pmksa) |
| 5970 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5971 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5972 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5973 | } |
| 5974 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5975 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5976 | { |
| 5977 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5978 | struct net_device *dev = info->user_ptr[1]; |
| 5979 | u8 action_code, dialog_token; |
| 5980 | u16 status_code; |
| 5981 | u8 *peer; |
| 5982 | |
| 5983 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5984 | !rdev->ops->tdls_mgmt) |
| 5985 | return -EOPNOTSUPP; |
| 5986 | |
| 5987 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5988 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5989 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5990 | !info->attrs[NL80211_ATTR_IE] || |
| 5991 | !info->attrs[NL80211_ATTR_MAC]) |
| 5992 | return -EINVAL; |
| 5993 | |
| 5994 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5995 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5996 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5997 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5998 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5999 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6000 | dialog_token, status_code, |
| 6001 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6002 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6003 | } |
| 6004 | |
| 6005 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6006 | { |
| 6007 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6008 | struct net_device *dev = info->user_ptr[1]; |
| 6009 | enum nl80211_tdls_operation operation; |
| 6010 | u8 *peer; |
| 6011 | |
| 6012 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6013 | !rdev->ops->tdls_oper) |
| 6014 | return -EOPNOTSUPP; |
| 6015 | |
| 6016 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6017 | !info->attrs[NL80211_ATTR_MAC]) |
| 6018 | return -EINVAL; |
| 6019 | |
| 6020 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6021 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6022 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6023 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6024 | } |
| 6025 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6026 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6027 | struct genl_info *info) |
| 6028 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6029 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6030 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6031 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6032 | struct sk_buff *msg; |
| 6033 | void *hdr; |
| 6034 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6035 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6036 | int err; |
| 6037 | |
| 6038 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6039 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6040 | return -EINVAL; |
| 6041 | |
| 6042 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6043 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6044 | if (!rdev->ops->remain_on_channel || |
| 6045 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6046 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6047 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6048 | /* |
| 6049 | * We should be on that channel for at least a minimum amount of |
| 6050 | * time (10ms) but no longer than the driver supports. |
| 6051 | */ |
| 6052 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6053 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6054 | return -EINVAL; |
| 6055 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6056 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6057 | if (err) |
| 6058 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6059 | |
| 6060 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6061 | if (!msg) |
| 6062 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6063 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6064 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6065 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6066 | |
| 6067 | if (IS_ERR(hdr)) { |
| 6068 | err = PTR_ERR(hdr); |
| 6069 | goto free_msg; |
| 6070 | } |
| 6071 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6072 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6073 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6074 | |
| 6075 | if (err) |
| 6076 | goto free_msg; |
| 6077 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6078 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6079 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6080 | |
| 6081 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6082 | |
| 6083 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6084 | |
| 6085 | nla_put_failure: |
| 6086 | err = -ENOBUFS; |
| 6087 | free_msg: |
| 6088 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6089 | return err; |
| 6090 | } |
| 6091 | |
| 6092 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6093 | struct genl_info *info) |
| 6094 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6095 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6096 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6097 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6098 | |
| 6099 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6100 | return -EINVAL; |
| 6101 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6102 | if (!rdev->ops->cancel_remain_on_channel) |
| 6103 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6104 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6105 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6106 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6107 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6108 | } |
| 6109 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6110 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6111 | u8 *rates, u8 rates_len) |
| 6112 | { |
| 6113 | u8 i; |
| 6114 | u32 mask = 0; |
| 6115 | |
| 6116 | for (i = 0; i < rates_len; i++) { |
| 6117 | int rate = (rates[i] & 0x7f) * 5; |
| 6118 | int ridx; |
| 6119 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6120 | struct ieee80211_rate *srate = |
| 6121 | &sband->bitrates[ridx]; |
| 6122 | if (rate == srate->bitrate) { |
| 6123 | mask |= 1 << ridx; |
| 6124 | break; |
| 6125 | } |
| 6126 | } |
| 6127 | if (ridx == sband->n_bitrates) |
| 6128 | return 0; /* rate not found */ |
| 6129 | } |
| 6130 | |
| 6131 | return mask; |
| 6132 | } |
| 6133 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6134 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6135 | u8 *rates, u8 rates_len, |
| 6136 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6137 | { |
| 6138 | u8 i; |
| 6139 | |
| 6140 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6141 | |
| 6142 | for (i = 0; i < rates_len; i++) { |
| 6143 | int ridx, rbit; |
| 6144 | |
| 6145 | ridx = rates[i] / 8; |
| 6146 | rbit = BIT(rates[i] % 8); |
| 6147 | |
| 6148 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6149 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6150 | return false; |
| 6151 | |
| 6152 | /* check availability */ |
| 6153 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6154 | mcs[ridx] |= rbit; |
| 6155 | else |
| 6156 | return false; |
| 6157 | } |
| 6158 | |
| 6159 | return true; |
| 6160 | } |
| 6161 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6162 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6163 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6164 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6165 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6166 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6167 | }; |
| 6168 | |
| 6169 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6170 | struct genl_info *info) |
| 6171 | { |
| 6172 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6173 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6174 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6175 | int rem, i; |
| 6176 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6177 | struct nlattr *tx_rates; |
| 6178 | struct ieee80211_supported_band *sband; |
| 6179 | |
| 6180 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6181 | return -EINVAL; |
| 6182 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6183 | if (!rdev->ops->set_bitrate_mask) |
| 6184 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6185 | |
| 6186 | memset(&mask, 0, sizeof(mask)); |
| 6187 | /* Default to all rates enabled */ |
| 6188 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6189 | sband = rdev->wiphy.bands[i]; |
| 6190 | mask.control[i].legacy = |
| 6191 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6192 | if (sband) |
| 6193 | memcpy(mask.control[i].mcs, |
| 6194 | sband->ht_cap.mcs.rx_mask, |
| 6195 | sizeof(mask.control[i].mcs)); |
| 6196 | else |
| 6197 | memset(mask.control[i].mcs, 0, |
| 6198 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | /* |
| 6202 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6203 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6204 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6205 | 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] | 6206 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6207 | { |
| 6208 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6209 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6210 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6211 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6212 | if (sband == NULL) |
| 6213 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6214 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6215 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6216 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6217 | mask.control[band].legacy = rateset_to_mask( |
| 6218 | sband, |
| 6219 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6220 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6221 | if ((mask.control[band].legacy == 0) && |
| 6222 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6223 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6224 | } |
| 6225 | if (tb[NL80211_TXRATE_MCS]) { |
| 6226 | if (!ht_rateset_to_mask( |
| 6227 | sband, |
| 6228 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6229 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6230 | mask.control[band].mcs)) |
| 6231 | return -EINVAL; |
| 6232 | } |
| 6233 | |
| 6234 | if (mask.control[band].legacy == 0) { |
| 6235 | /* don't allow empty legacy rates if HT |
| 6236 | * is not even supported. */ |
| 6237 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6238 | return -EINVAL; |
| 6239 | |
| 6240 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6241 | if (mask.control[band].mcs[i]) |
| 6242 | break; |
| 6243 | |
| 6244 | /* legacy and mcs rates may not be both empty */ |
| 6245 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6246 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6247 | } |
| 6248 | } |
| 6249 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6250 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6251 | } |
| 6252 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6253 | 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] | 6254 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6255 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6256 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6257 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6258 | |
| 6259 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6260 | return -EINVAL; |
| 6261 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6262 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6263 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6264 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6265 | switch (wdev->iftype) { |
| 6266 | case NL80211_IFTYPE_STATION: |
| 6267 | case NL80211_IFTYPE_ADHOC: |
| 6268 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6269 | case NL80211_IFTYPE_AP: |
| 6270 | case NL80211_IFTYPE_AP_VLAN: |
| 6271 | case NL80211_IFTYPE_MESH_POINT: |
| 6272 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6273 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6274 | break; |
| 6275 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6276 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6277 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6278 | |
| 6279 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6280 | if (!rdev->ops->mgmt_tx) |
| 6281 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6282 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6283 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6284 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6285 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6286 | } |
| 6287 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6288 | 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] | 6289 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6290 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6291 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6292 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6293 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6294 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6295 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6296 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6297 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6298 | bool offchan, no_cck, dont_wait_for_ack; |
| 6299 | |
| 6300 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6301 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6302 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6303 | return -EINVAL; |
| 6304 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6305 | if (!rdev->ops->mgmt_tx) |
| 6306 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6307 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6308 | switch (wdev->iftype) { |
| 6309 | case NL80211_IFTYPE_STATION: |
| 6310 | case NL80211_IFTYPE_ADHOC: |
| 6311 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6312 | case NL80211_IFTYPE_AP: |
| 6313 | case NL80211_IFTYPE_AP_VLAN: |
| 6314 | case NL80211_IFTYPE_MESH_POINT: |
| 6315 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6316 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6317 | break; |
| 6318 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6319 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6320 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6321 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6322 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6323 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6324 | return -EINVAL; |
| 6325 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6326 | |
| 6327 | /* |
| 6328 | * We should wait on the channel for at least a minimum amount |
| 6329 | * of time (10ms) but no longer than the driver supports. |
| 6330 | */ |
| 6331 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6332 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6333 | return -EINVAL; |
| 6334 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6335 | } |
| 6336 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6337 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6338 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6339 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6340 | return -EINVAL; |
| 6341 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6342 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6343 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6344 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6345 | if (err) |
| 6346 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6347 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6348 | if (!dont_wait_for_ack) { |
| 6349 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6350 | if (!msg) |
| 6351 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6352 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6353 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6354 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6355 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6356 | if (IS_ERR(hdr)) { |
| 6357 | err = PTR_ERR(hdr); |
| 6358 | goto free_msg; |
| 6359 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6360 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6361 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6362 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6363 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6364 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6365 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6366 | if (err) |
| 6367 | goto free_msg; |
| 6368 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6369 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6370 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6371 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6372 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6373 | genlmsg_end(msg, hdr); |
| 6374 | return genlmsg_reply(msg, info); |
| 6375 | } |
| 6376 | |
| 6377 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6378 | |
| 6379 | nla_put_failure: |
| 6380 | err = -ENOBUFS; |
| 6381 | free_msg: |
| 6382 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6383 | return err; |
| 6384 | } |
| 6385 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6386 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6387 | { |
| 6388 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6389 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6390 | u64 cookie; |
| 6391 | |
| 6392 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6393 | return -EINVAL; |
| 6394 | |
| 6395 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6396 | return -EOPNOTSUPP; |
| 6397 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6398 | switch (wdev->iftype) { |
| 6399 | case NL80211_IFTYPE_STATION: |
| 6400 | case NL80211_IFTYPE_ADHOC: |
| 6401 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6402 | case NL80211_IFTYPE_AP: |
| 6403 | case NL80211_IFTYPE_AP_VLAN: |
| 6404 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6405 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6406 | break; |
| 6407 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6408 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6409 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6410 | |
| 6411 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6412 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6413 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6414 | } |
| 6415 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6416 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6417 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6418 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6419 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6420 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6421 | u8 ps_state; |
| 6422 | bool state; |
| 6423 | int err; |
| 6424 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6425 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6426 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6427 | |
| 6428 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6429 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6430 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6431 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6432 | |
| 6433 | wdev = dev->ieee80211_ptr; |
| 6434 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6435 | if (!rdev->ops->set_power_mgmt) |
| 6436 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6437 | |
| 6438 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6439 | |
| 6440 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6441 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6442 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6443 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6444 | if (!err) |
| 6445 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6446 | return err; |
| 6447 | } |
| 6448 | |
| 6449 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6450 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6451 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6452 | enum nl80211_ps_state ps_state; |
| 6453 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6454 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6455 | struct sk_buff *msg; |
| 6456 | void *hdr; |
| 6457 | int err; |
| 6458 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6459 | wdev = dev->ieee80211_ptr; |
| 6460 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6461 | if (!rdev->ops->set_power_mgmt) |
| 6462 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6463 | |
| 6464 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6465 | if (!msg) |
| 6466 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6467 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6468 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6469 | NL80211_CMD_GET_POWER_SAVE); |
| 6470 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6471 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6472 | goto free_msg; |
| 6473 | } |
| 6474 | |
| 6475 | if (wdev->ps) |
| 6476 | ps_state = NL80211_PS_ENABLED; |
| 6477 | else |
| 6478 | ps_state = NL80211_PS_DISABLED; |
| 6479 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6480 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6481 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6482 | |
| 6483 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6484 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6485 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6486 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6487 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6488 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6489 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6490 | return err; |
| 6491 | } |
| 6492 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6493 | static struct nla_policy |
| 6494 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6495 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6496 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6497 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6498 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 6499 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 6500 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6501 | }; |
| 6502 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6503 | static int nl80211_set_cqm_txe(struct genl_info *info, |
| 6504 | u32 rate, u32 pkts, u32 intvl) |
| 6505 | { |
| 6506 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6507 | struct wireless_dev *wdev; |
| 6508 | struct net_device *dev = info->user_ptr[1]; |
| 6509 | |
| 6510 | if ((rate < 0 || rate > 100) || |
| 6511 | (intvl < 0 || intvl > NL80211_CQM_TXE_MAX_INTVL)) |
| 6512 | return -EINVAL; |
| 6513 | |
| 6514 | wdev = dev->ieee80211_ptr; |
| 6515 | |
| 6516 | if (!rdev->ops->set_cqm_txe_config) |
| 6517 | return -EOPNOTSUPP; |
| 6518 | |
| 6519 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 6520 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6521 | return -EOPNOTSUPP; |
| 6522 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6523 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6524 | } |
| 6525 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6526 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6527 | s32 threshold, u32 hysteresis) |
| 6528 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6529 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6530 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6531 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6532 | |
| 6533 | if (threshold > 0) |
| 6534 | return -EINVAL; |
| 6535 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6536 | wdev = dev->ieee80211_ptr; |
| 6537 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6538 | if (!rdev->ops->set_cqm_rssi_config) |
| 6539 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6540 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6541 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6542 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6543 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6544 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6545 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6546 | } |
| 6547 | |
| 6548 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6549 | { |
| 6550 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6551 | struct nlattr *cqm; |
| 6552 | int err; |
| 6553 | |
| 6554 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6555 | if (!cqm) { |
| 6556 | err = -EINVAL; |
| 6557 | goto out; |
| 6558 | } |
| 6559 | |
| 6560 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6561 | nl80211_attr_cqm_policy); |
| 6562 | if (err) |
| 6563 | goto out; |
| 6564 | |
| 6565 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6566 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6567 | s32 threshold; |
| 6568 | u32 hysteresis; |
| 6569 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6570 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6571 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6572 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 6573 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 6574 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 6575 | u32 rate, pkts, intvl; |
| 6576 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 6577 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 6578 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 6579 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6580 | } else |
| 6581 | err = -EINVAL; |
| 6582 | |
| 6583 | out: |
| 6584 | return err; |
| 6585 | } |
| 6586 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6587 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6588 | { |
| 6589 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6590 | struct net_device *dev = info->user_ptr[1]; |
| 6591 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6592 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6593 | int err; |
| 6594 | |
| 6595 | /* start with default */ |
| 6596 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6597 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6598 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6599 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6600 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6601 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6602 | if (err) |
| 6603 | return err; |
| 6604 | } |
| 6605 | |
| 6606 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6607 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 6608 | return -EINVAL; |
| 6609 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6610 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6611 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6612 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 6613 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6614 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 6615 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6616 | return -EINVAL; |
| 6617 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6618 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 6619 | /* parse additional setup parameters if given */ |
| 6620 | err = nl80211_parse_mesh_setup(info, &setup); |
| 6621 | if (err) |
| 6622 | return err; |
| 6623 | } |
| 6624 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6625 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6626 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 6627 | if (err) |
| 6628 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6629 | } else { |
| 6630 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6631 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6632 | } |
| 6633 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6634 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6635 | } |
| 6636 | |
| 6637 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6638 | { |
| 6639 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6640 | struct net_device *dev = info->user_ptr[1]; |
| 6641 | |
| 6642 | return cfg80211_leave_mesh(rdev, dev); |
| 6643 | } |
| 6644 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6645 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6646 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6647 | { |
| 6648 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6649 | struct sk_buff *msg; |
| 6650 | void *hdr; |
| 6651 | |
| 6652 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6653 | return -EOPNOTSUPP; |
| 6654 | |
| 6655 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6656 | if (!msg) |
| 6657 | return -ENOMEM; |
| 6658 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6659 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6660 | NL80211_CMD_GET_WOWLAN); |
| 6661 | if (!hdr) |
| 6662 | goto nla_put_failure; |
| 6663 | |
| 6664 | if (rdev->wowlan) { |
| 6665 | struct nlattr *nl_wowlan; |
| 6666 | |
| 6667 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 6668 | if (!nl_wowlan) |
| 6669 | goto nla_put_failure; |
| 6670 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6671 | if ((rdev->wowlan->any && |
| 6672 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 6673 | (rdev->wowlan->disconnect && |
| 6674 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 6675 | (rdev->wowlan->magic_pkt && |
| 6676 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 6677 | (rdev->wowlan->gtk_rekey_failure && |
| 6678 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 6679 | (rdev->wowlan->eap_identity_req && |
| 6680 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 6681 | (rdev->wowlan->four_way_handshake && |
| 6682 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 6683 | (rdev->wowlan->rfkill_release && |
| 6684 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 6685 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6686 | if (rdev->wowlan->n_patterns) { |
| 6687 | struct nlattr *nl_pats, *nl_pat; |
| 6688 | int i, pat_len; |
| 6689 | |
| 6690 | nl_pats = nla_nest_start(msg, |
| 6691 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 6692 | if (!nl_pats) |
| 6693 | goto nla_put_failure; |
| 6694 | |
| 6695 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 6696 | nl_pat = nla_nest_start(msg, i + 1); |
| 6697 | if (!nl_pat) |
| 6698 | goto nla_put_failure; |
| 6699 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6700 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 6701 | DIV_ROUND_UP(pat_len, 8), |
| 6702 | rdev->wowlan->patterns[i].mask) || |
| 6703 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 6704 | pat_len, |
| 6705 | rdev->wowlan->patterns[i].pattern)) |
| 6706 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6707 | nla_nest_end(msg, nl_pat); |
| 6708 | } |
| 6709 | nla_nest_end(msg, nl_pats); |
| 6710 | } |
| 6711 | |
| 6712 | nla_nest_end(msg, nl_wowlan); |
| 6713 | } |
| 6714 | |
| 6715 | genlmsg_end(msg, hdr); |
| 6716 | return genlmsg_reply(msg, info); |
| 6717 | |
| 6718 | nla_put_failure: |
| 6719 | nlmsg_free(msg); |
| 6720 | return -ENOBUFS; |
| 6721 | } |
| 6722 | |
| 6723 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6724 | { |
| 6725 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6726 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6727 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6728 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6729 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 6730 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6731 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6732 | |
| 6733 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6734 | return -EOPNOTSUPP; |
| 6735 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6736 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 6737 | cfg80211_rdev_free_wowlan(rdev); |
| 6738 | rdev->wowlan = NULL; |
| 6739 | goto set_wakeup; |
| 6740 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6741 | |
| 6742 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 6743 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6744 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6745 | nl80211_wowlan_policy); |
| 6746 | if (err) |
| 6747 | return err; |
| 6748 | |
| 6749 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 6750 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 6751 | return -EINVAL; |
| 6752 | new_triggers.any = true; |
| 6753 | } |
| 6754 | |
| 6755 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 6756 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 6757 | return -EINVAL; |
| 6758 | new_triggers.disconnect = true; |
| 6759 | } |
| 6760 | |
| 6761 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 6762 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 6763 | return -EINVAL; |
| 6764 | new_triggers.magic_pkt = true; |
| 6765 | } |
| 6766 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 6767 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 6768 | return -EINVAL; |
| 6769 | |
| 6770 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 6771 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 6772 | return -EINVAL; |
| 6773 | new_triggers.gtk_rekey_failure = true; |
| 6774 | } |
| 6775 | |
| 6776 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 6777 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 6778 | return -EINVAL; |
| 6779 | new_triggers.eap_identity_req = true; |
| 6780 | } |
| 6781 | |
| 6782 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 6783 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 6784 | return -EINVAL; |
| 6785 | new_triggers.four_way_handshake = true; |
| 6786 | } |
| 6787 | |
| 6788 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 6789 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 6790 | return -EINVAL; |
| 6791 | new_triggers.rfkill_release = true; |
| 6792 | } |
| 6793 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6794 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 6795 | struct nlattr *pat; |
| 6796 | int n_patterns = 0; |
| 6797 | int rem, pat_len, mask_len; |
| 6798 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6799 | |
| 6800 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6801 | rem) |
| 6802 | n_patterns++; |
| 6803 | if (n_patterns > wowlan->n_patterns) |
| 6804 | return -EINVAL; |
| 6805 | |
| 6806 | new_triggers.patterns = kcalloc(n_patterns, |
| 6807 | sizeof(new_triggers.patterns[0]), |
| 6808 | GFP_KERNEL); |
| 6809 | if (!new_triggers.patterns) |
| 6810 | return -ENOMEM; |
| 6811 | |
| 6812 | new_triggers.n_patterns = n_patterns; |
| 6813 | i = 0; |
| 6814 | |
| 6815 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6816 | rem) { |
| 6817 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6818 | nla_data(pat), nla_len(pat), NULL); |
| 6819 | err = -EINVAL; |
| 6820 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6821 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6822 | goto error; |
| 6823 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6824 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6825 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6826 | mask_len) |
| 6827 | goto error; |
| 6828 | if (pat_len > wowlan->pattern_max_len || |
| 6829 | pat_len < wowlan->pattern_min_len) |
| 6830 | goto error; |
| 6831 | |
| 6832 | new_triggers.patterns[i].mask = |
| 6833 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6834 | if (!new_triggers.patterns[i].mask) { |
| 6835 | err = -ENOMEM; |
| 6836 | goto error; |
| 6837 | } |
| 6838 | new_triggers.patterns[i].pattern = |
| 6839 | new_triggers.patterns[i].mask + mask_len; |
| 6840 | memcpy(new_triggers.patterns[i].mask, |
| 6841 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6842 | mask_len); |
| 6843 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6844 | memcpy(new_triggers.patterns[i].pattern, |
| 6845 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6846 | pat_len); |
| 6847 | i++; |
| 6848 | } |
| 6849 | } |
| 6850 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6851 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 6852 | if (!ntrig) { |
| 6853 | err = -ENOMEM; |
| 6854 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6855 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6856 | cfg80211_rdev_free_wowlan(rdev); |
| 6857 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6858 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6859 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6860 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6861 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6862 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6863 | return 0; |
| 6864 | error: |
| 6865 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6866 | kfree(new_triggers.patterns[i].mask); |
| 6867 | kfree(new_triggers.patterns); |
| 6868 | return err; |
| 6869 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6870 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6871 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6872 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6873 | { |
| 6874 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6875 | struct net_device *dev = info->user_ptr[1]; |
| 6876 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6877 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6878 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6879 | int err; |
| 6880 | |
| 6881 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6882 | return -EINVAL; |
| 6883 | |
| 6884 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6885 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6886 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6887 | nl80211_rekey_policy); |
| 6888 | if (err) |
| 6889 | return err; |
| 6890 | |
| 6891 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6892 | return -ERANGE; |
| 6893 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6894 | return -ERANGE; |
| 6895 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6896 | return -ERANGE; |
| 6897 | |
| 6898 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6899 | NL80211_KEK_LEN); |
| 6900 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6901 | NL80211_KCK_LEN); |
| 6902 | memcpy(rekey_data.replay_ctr, |
| 6903 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6904 | NL80211_REPLAY_CTR_LEN); |
| 6905 | |
| 6906 | wdev_lock(wdev); |
| 6907 | if (!wdev->current_bss) { |
| 6908 | err = -ENOTCONN; |
| 6909 | goto out; |
| 6910 | } |
| 6911 | |
| 6912 | if (!rdev->ops->set_rekey_data) { |
| 6913 | err = -EOPNOTSUPP; |
| 6914 | goto out; |
| 6915 | } |
| 6916 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6917 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6918 | out: |
| 6919 | wdev_unlock(wdev); |
| 6920 | return err; |
| 6921 | } |
| 6922 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6923 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6924 | struct genl_info *info) |
| 6925 | { |
| 6926 | struct net_device *dev = info->user_ptr[1]; |
| 6927 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6928 | |
| 6929 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6930 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6931 | return -EINVAL; |
| 6932 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6933 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6934 | return -EBUSY; |
| 6935 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6936 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6937 | return 0; |
| 6938 | } |
| 6939 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6940 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6941 | struct genl_info *info) |
| 6942 | { |
| 6943 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6944 | struct net_device *dev = info->user_ptr[1]; |
| 6945 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6946 | struct sk_buff *msg; |
| 6947 | void *hdr; |
| 6948 | const u8 *addr; |
| 6949 | u64 cookie; |
| 6950 | int err; |
| 6951 | |
| 6952 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6953 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6954 | return -EOPNOTSUPP; |
| 6955 | |
| 6956 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6957 | return -EINVAL; |
| 6958 | |
| 6959 | if (!rdev->ops->probe_client) |
| 6960 | return -EOPNOTSUPP; |
| 6961 | |
| 6962 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6963 | if (!msg) |
| 6964 | return -ENOMEM; |
| 6965 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6966 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6967 | NL80211_CMD_PROBE_CLIENT); |
| 6968 | |
| 6969 | if (IS_ERR(hdr)) { |
| 6970 | err = PTR_ERR(hdr); |
| 6971 | goto free_msg; |
| 6972 | } |
| 6973 | |
| 6974 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6975 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6976 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6977 | if (err) |
| 6978 | goto free_msg; |
| 6979 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6980 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6981 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6982 | |
| 6983 | genlmsg_end(msg, hdr); |
| 6984 | |
| 6985 | return genlmsg_reply(msg, info); |
| 6986 | |
| 6987 | nla_put_failure: |
| 6988 | err = -ENOBUFS; |
| 6989 | free_msg: |
| 6990 | nlmsg_free(msg); |
| 6991 | return err; |
| 6992 | } |
| 6993 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6994 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 6995 | { |
| 6996 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 6997 | struct cfg80211_beacon_registration *reg, *nreg; |
| 6998 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6999 | |
| 7000 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 7001 | return -EOPNOTSUPP; |
| 7002 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7003 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 7004 | if (!nreg) |
| 7005 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7006 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7007 | /* First, check if already registered. */ |
| 7008 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 7009 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 7010 | if (reg->nlportid == info->snd_portid) { |
| 7011 | rv = -EALREADY; |
| 7012 | goto out_err; |
| 7013 | } |
| 7014 | } |
| 7015 | /* Add it to the list */ |
| 7016 | nreg->nlportid = info->snd_portid; |
| 7017 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 7018 | |
| 7019 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7020 | |
| 7021 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7022 | out_err: |
| 7023 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 7024 | kfree(nreg); |
| 7025 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7026 | } |
| 7027 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7028 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7029 | { |
| 7030 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7031 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7032 | int err; |
| 7033 | |
| 7034 | if (!rdev->ops->start_p2p_device) |
| 7035 | return -EOPNOTSUPP; |
| 7036 | |
| 7037 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7038 | return -EOPNOTSUPP; |
| 7039 | |
| 7040 | if (wdev->p2p_started) |
| 7041 | return 0; |
| 7042 | |
| 7043 | mutex_lock(&rdev->devlist_mtx); |
| 7044 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 7045 | mutex_unlock(&rdev->devlist_mtx); |
| 7046 | if (err) |
| 7047 | return err; |
| 7048 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7049 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7050 | if (err) |
| 7051 | return err; |
| 7052 | |
| 7053 | wdev->p2p_started = true; |
| 7054 | mutex_lock(&rdev->devlist_mtx); |
| 7055 | rdev->opencount++; |
| 7056 | mutex_unlock(&rdev->devlist_mtx); |
| 7057 | |
| 7058 | return 0; |
| 7059 | } |
| 7060 | |
| 7061 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7062 | { |
| 7063 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7064 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7065 | |
| 7066 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7067 | return -EOPNOTSUPP; |
| 7068 | |
| 7069 | if (!rdev->ops->stop_p2p_device) |
| 7070 | return -EOPNOTSUPP; |
| 7071 | |
| 7072 | if (!wdev->p2p_started) |
| 7073 | return 0; |
| 7074 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7075 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7076 | wdev->p2p_started = false; |
| 7077 | |
| 7078 | mutex_lock(&rdev->devlist_mtx); |
| 7079 | rdev->opencount--; |
| 7080 | mutex_unlock(&rdev->devlist_mtx); |
| 7081 | |
| 7082 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 7083 | rdev->scan_req->aborted = true; |
| 7084 | ___cfg80211_scan_done(rdev, true); |
| 7085 | } |
| 7086 | |
| 7087 | return 0; |
| 7088 | } |
| 7089 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7090 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 7091 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 7092 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7093 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 7094 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 7095 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7096 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7097 | /* 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] | 7098 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 7099 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7100 | |
| 7101 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7102 | struct genl_info *info) |
| 7103 | { |
| 7104 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7105 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7106 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7107 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 7108 | |
| 7109 | if (rtnl) |
| 7110 | rtnl_lock(); |
| 7111 | |
| 7112 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 7113 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7114 | if (IS_ERR(rdev)) { |
| 7115 | if (rtnl) |
| 7116 | rtnl_unlock(); |
| 7117 | return PTR_ERR(rdev); |
| 7118 | } |
| 7119 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7120 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7121 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7122 | mutex_lock(&cfg80211_mutex); |
| 7123 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7124 | info->attrs); |
| 7125 | if (IS_ERR(wdev)) { |
| 7126 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7127 | if (rtnl) |
| 7128 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7129 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7130 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7131 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7132 | dev = wdev->netdev; |
| 7133 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7134 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7135 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7136 | if (!dev) { |
| 7137 | mutex_unlock(&cfg80211_mutex); |
| 7138 | if (rtnl) |
| 7139 | rtnl_unlock(); |
| 7140 | return -EINVAL; |
| 7141 | } |
| 7142 | |
| 7143 | info->user_ptr[1] = dev; |
| 7144 | } else { |
| 7145 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7146 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7147 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7148 | if (dev) { |
| 7149 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7150 | !netif_running(dev)) { |
| 7151 | mutex_unlock(&cfg80211_mutex); |
| 7152 | if (rtnl) |
| 7153 | rtnl_unlock(); |
| 7154 | return -ENETDOWN; |
| 7155 | } |
| 7156 | |
| 7157 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7158 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7159 | if (!wdev->p2p_started) { |
| 7160 | mutex_unlock(&cfg80211_mutex); |
| 7161 | if (rtnl) |
| 7162 | rtnl_unlock(); |
| 7163 | return -ENETDOWN; |
| 7164 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7165 | } |
| 7166 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7167 | cfg80211_lock_rdev(rdev); |
| 7168 | |
| 7169 | mutex_unlock(&cfg80211_mutex); |
| 7170 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7171 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7172 | } |
| 7173 | |
| 7174 | return 0; |
| 7175 | } |
| 7176 | |
| 7177 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7178 | struct genl_info *info) |
| 7179 | { |
| 7180 | if (info->user_ptr[0]) |
| 7181 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7182 | if (info->user_ptr[1]) { |
| 7183 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7184 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7185 | |
| 7186 | if (wdev->netdev) |
| 7187 | dev_put(wdev->netdev); |
| 7188 | } else { |
| 7189 | dev_put(info->user_ptr[1]); |
| 7190 | } |
| 7191 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7192 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7193 | rtnl_unlock(); |
| 7194 | } |
| 7195 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7196 | static struct genl_ops nl80211_ops[] = { |
| 7197 | { |
| 7198 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7199 | .doit = nl80211_get_wiphy, |
| 7200 | .dumpit = nl80211_dump_wiphy, |
| 7201 | .policy = nl80211_policy, |
| 7202 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7203 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7204 | }, |
| 7205 | { |
| 7206 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7207 | .doit = nl80211_set_wiphy, |
| 7208 | .policy = nl80211_policy, |
| 7209 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7210 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7211 | }, |
| 7212 | { |
| 7213 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7214 | .doit = nl80211_get_interface, |
| 7215 | .dumpit = nl80211_dump_interface, |
| 7216 | .policy = nl80211_policy, |
| 7217 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7218 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7219 | }, |
| 7220 | { |
| 7221 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7222 | .doit = nl80211_set_interface, |
| 7223 | .policy = nl80211_policy, |
| 7224 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7225 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7226 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7227 | }, |
| 7228 | { |
| 7229 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7230 | .doit = nl80211_new_interface, |
| 7231 | .policy = nl80211_policy, |
| 7232 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7233 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7234 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7235 | }, |
| 7236 | { |
| 7237 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7238 | .doit = nl80211_del_interface, |
| 7239 | .policy = nl80211_policy, |
| 7240 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7241 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7242 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7243 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7244 | { |
| 7245 | .cmd = NL80211_CMD_GET_KEY, |
| 7246 | .doit = nl80211_get_key, |
| 7247 | .policy = nl80211_policy, |
| 7248 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7249 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7250 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7251 | }, |
| 7252 | { |
| 7253 | .cmd = NL80211_CMD_SET_KEY, |
| 7254 | .doit = nl80211_set_key, |
| 7255 | .policy = nl80211_policy, |
| 7256 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7257 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7258 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7259 | }, |
| 7260 | { |
| 7261 | .cmd = NL80211_CMD_NEW_KEY, |
| 7262 | .doit = nl80211_new_key, |
| 7263 | .policy = nl80211_policy, |
| 7264 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7265 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7266 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7267 | }, |
| 7268 | { |
| 7269 | .cmd = NL80211_CMD_DEL_KEY, |
| 7270 | .doit = nl80211_del_key, |
| 7271 | .policy = nl80211_policy, |
| 7272 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7273 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7274 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7275 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7276 | { |
| 7277 | .cmd = NL80211_CMD_SET_BEACON, |
| 7278 | .policy = nl80211_policy, |
| 7279 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7280 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7281 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7282 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7283 | }, |
| 7284 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7285 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7286 | .policy = nl80211_policy, |
| 7287 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7288 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7289 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7290 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7291 | }, |
| 7292 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7293 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7294 | .policy = nl80211_policy, |
| 7295 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7296 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7297 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7298 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7299 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7300 | { |
| 7301 | .cmd = NL80211_CMD_GET_STATION, |
| 7302 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7303 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7304 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7305 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7306 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7307 | }, |
| 7308 | { |
| 7309 | .cmd = NL80211_CMD_SET_STATION, |
| 7310 | .doit = nl80211_set_station, |
| 7311 | .policy = nl80211_policy, |
| 7312 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7313 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7314 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7315 | }, |
| 7316 | { |
| 7317 | .cmd = NL80211_CMD_NEW_STATION, |
| 7318 | .doit = nl80211_new_station, |
| 7319 | .policy = nl80211_policy, |
| 7320 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7321 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7322 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7323 | }, |
| 7324 | { |
| 7325 | .cmd = NL80211_CMD_DEL_STATION, |
| 7326 | .doit = nl80211_del_station, |
| 7327 | .policy = nl80211_policy, |
| 7328 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7329 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7330 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7331 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7332 | { |
| 7333 | .cmd = NL80211_CMD_GET_MPATH, |
| 7334 | .doit = nl80211_get_mpath, |
| 7335 | .dumpit = nl80211_dump_mpath, |
| 7336 | .policy = nl80211_policy, |
| 7337 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7338 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7339 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7340 | }, |
| 7341 | { |
| 7342 | .cmd = NL80211_CMD_SET_MPATH, |
| 7343 | .doit = nl80211_set_mpath, |
| 7344 | .policy = nl80211_policy, |
| 7345 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7346 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7347 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7348 | }, |
| 7349 | { |
| 7350 | .cmd = NL80211_CMD_NEW_MPATH, |
| 7351 | .doit = nl80211_new_mpath, |
| 7352 | .policy = nl80211_policy, |
| 7353 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7354 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7355 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7356 | }, |
| 7357 | { |
| 7358 | .cmd = NL80211_CMD_DEL_MPATH, |
| 7359 | .doit = nl80211_del_mpath, |
| 7360 | .policy = nl80211_policy, |
| 7361 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7362 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7363 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7364 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7365 | { |
| 7366 | .cmd = NL80211_CMD_SET_BSS, |
| 7367 | .doit = nl80211_set_bss, |
| 7368 | .policy = nl80211_policy, |
| 7369 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7370 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7371 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7372 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7373 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7374 | .cmd = NL80211_CMD_GET_REG, |
| 7375 | .doit = nl80211_get_reg, |
| 7376 | .policy = nl80211_policy, |
| 7377 | /* can be retrieved by unprivileged users */ |
| 7378 | }, |
| 7379 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7380 | .cmd = NL80211_CMD_SET_REG, |
| 7381 | .doit = nl80211_set_reg, |
| 7382 | .policy = nl80211_policy, |
| 7383 | .flags = GENL_ADMIN_PERM, |
| 7384 | }, |
| 7385 | { |
| 7386 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 7387 | .doit = nl80211_req_set_reg, |
| 7388 | .policy = nl80211_policy, |
| 7389 | .flags = GENL_ADMIN_PERM, |
| 7390 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7391 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7392 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 7393 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7394 | .policy = nl80211_policy, |
| 7395 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7396 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7397 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7398 | }, |
| 7399 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7400 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 7401 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7402 | .policy = nl80211_policy, |
| 7403 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7404 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7405 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7406 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 7407 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7408 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 7409 | .doit = nl80211_trigger_scan, |
| 7410 | .policy = nl80211_policy, |
| 7411 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7412 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7413 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7414 | }, |
| 7415 | { |
| 7416 | .cmd = NL80211_CMD_GET_SCAN, |
| 7417 | .policy = nl80211_policy, |
| 7418 | .dumpit = nl80211_dump_scan, |
| 7419 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7420 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7421 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 7422 | .doit = nl80211_start_sched_scan, |
| 7423 | .policy = nl80211_policy, |
| 7424 | .flags = GENL_ADMIN_PERM, |
| 7425 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7426 | NL80211_FLAG_NEED_RTNL, |
| 7427 | }, |
| 7428 | { |
| 7429 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 7430 | .doit = nl80211_stop_sched_scan, |
| 7431 | .policy = nl80211_policy, |
| 7432 | .flags = GENL_ADMIN_PERM, |
| 7433 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7434 | NL80211_FLAG_NEED_RTNL, |
| 7435 | }, |
| 7436 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7437 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 7438 | .doit = nl80211_authenticate, |
| 7439 | .policy = nl80211_policy, |
| 7440 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7441 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7442 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7443 | }, |
| 7444 | { |
| 7445 | .cmd = NL80211_CMD_ASSOCIATE, |
| 7446 | .doit = nl80211_associate, |
| 7447 | .policy = nl80211_policy, |
| 7448 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7449 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7450 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7451 | }, |
| 7452 | { |
| 7453 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 7454 | .doit = nl80211_deauthenticate, |
| 7455 | .policy = nl80211_policy, |
| 7456 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7457 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7458 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7459 | }, |
| 7460 | { |
| 7461 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 7462 | .doit = nl80211_disassociate, |
| 7463 | .policy = nl80211_policy, |
| 7464 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7465 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7466 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7467 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7468 | { |
| 7469 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 7470 | .doit = nl80211_join_ibss, |
| 7471 | .policy = nl80211_policy, |
| 7472 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7473 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7474 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7475 | }, |
| 7476 | { |
| 7477 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 7478 | .doit = nl80211_leave_ibss, |
| 7479 | .policy = nl80211_policy, |
| 7480 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7481 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7482 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7483 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7484 | #ifdef CONFIG_NL80211_TESTMODE |
| 7485 | { |
| 7486 | .cmd = NL80211_CMD_TESTMODE, |
| 7487 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7488 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7489 | .policy = nl80211_policy, |
| 7490 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7491 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7492 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7493 | }, |
| 7494 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7495 | { |
| 7496 | .cmd = NL80211_CMD_CONNECT, |
| 7497 | .doit = nl80211_connect, |
| 7498 | .policy = nl80211_policy, |
| 7499 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7500 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7501 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7502 | }, |
| 7503 | { |
| 7504 | .cmd = NL80211_CMD_DISCONNECT, |
| 7505 | .doit = nl80211_disconnect, |
| 7506 | .policy = nl80211_policy, |
| 7507 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7508 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7509 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7510 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7511 | { |
| 7512 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 7513 | .doit = nl80211_wiphy_netns, |
| 7514 | .policy = nl80211_policy, |
| 7515 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7516 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7517 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7518 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7519 | { |
| 7520 | .cmd = NL80211_CMD_GET_SURVEY, |
| 7521 | .policy = nl80211_policy, |
| 7522 | .dumpit = nl80211_dump_survey, |
| 7523 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7524 | { |
| 7525 | .cmd = NL80211_CMD_SET_PMKSA, |
| 7526 | .doit = nl80211_setdel_pmksa, |
| 7527 | .policy = nl80211_policy, |
| 7528 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7529 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7530 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7531 | }, |
| 7532 | { |
| 7533 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 7534 | .doit = nl80211_setdel_pmksa, |
| 7535 | .policy = nl80211_policy, |
| 7536 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7537 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7538 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7539 | }, |
| 7540 | { |
| 7541 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 7542 | .doit = nl80211_flush_pmksa, |
| 7543 | .policy = nl80211_policy, |
| 7544 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7545 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7546 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7547 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7548 | { |
| 7549 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7550 | .doit = nl80211_remain_on_channel, |
| 7551 | .policy = nl80211_policy, |
| 7552 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7553 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7554 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7555 | }, |
| 7556 | { |
| 7557 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7558 | .doit = nl80211_cancel_remain_on_channel, |
| 7559 | .policy = nl80211_policy, |
| 7560 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7561 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7562 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7563 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7564 | { |
| 7565 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 7566 | .doit = nl80211_set_tx_bitrate_mask, |
| 7567 | .policy = nl80211_policy, |
| 7568 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7569 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7570 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7571 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7572 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7573 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 7574 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7575 | .policy = nl80211_policy, |
| 7576 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7577 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7578 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7579 | }, |
| 7580 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7581 | .cmd = NL80211_CMD_FRAME, |
| 7582 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7583 | .policy = nl80211_policy, |
| 7584 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7585 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7586 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7587 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7588 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7589 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 7590 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 7591 | .policy = nl80211_policy, |
| 7592 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7593 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7594 | NL80211_FLAG_NEED_RTNL, |
| 7595 | }, |
| 7596 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7597 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 7598 | .doit = nl80211_set_power_save, |
| 7599 | .policy = nl80211_policy, |
| 7600 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7601 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7602 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7603 | }, |
| 7604 | { |
| 7605 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 7606 | .doit = nl80211_get_power_save, |
| 7607 | .policy = nl80211_policy, |
| 7608 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7609 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7610 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7611 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7612 | { |
| 7613 | .cmd = NL80211_CMD_SET_CQM, |
| 7614 | .doit = nl80211_set_cqm, |
| 7615 | .policy = nl80211_policy, |
| 7616 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7617 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7618 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7619 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7620 | { |
| 7621 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 7622 | .doit = nl80211_set_channel, |
| 7623 | .policy = nl80211_policy, |
| 7624 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7625 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7626 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7627 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7628 | { |
| 7629 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 7630 | .doit = nl80211_set_wds_peer, |
| 7631 | .policy = nl80211_policy, |
| 7632 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 7633 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7634 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7635 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7636 | { |
| 7637 | .cmd = NL80211_CMD_JOIN_MESH, |
| 7638 | .doit = nl80211_join_mesh, |
| 7639 | .policy = nl80211_policy, |
| 7640 | .flags = GENL_ADMIN_PERM, |
| 7641 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7642 | NL80211_FLAG_NEED_RTNL, |
| 7643 | }, |
| 7644 | { |
| 7645 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 7646 | .doit = nl80211_leave_mesh, |
| 7647 | .policy = nl80211_policy, |
| 7648 | .flags = GENL_ADMIN_PERM, |
| 7649 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7650 | NL80211_FLAG_NEED_RTNL, |
| 7651 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7652 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7653 | { |
| 7654 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 7655 | .doit = nl80211_get_wowlan, |
| 7656 | .policy = nl80211_policy, |
| 7657 | /* can be retrieved by unprivileged users */ |
| 7658 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7659 | NL80211_FLAG_NEED_RTNL, |
| 7660 | }, |
| 7661 | { |
| 7662 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 7663 | .doit = nl80211_set_wowlan, |
| 7664 | .policy = nl80211_policy, |
| 7665 | .flags = GENL_ADMIN_PERM, |
| 7666 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7667 | NL80211_FLAG_NEED_RTNL, |
| 7668 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7669 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7670 | { |
| 7671 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 7672 | .doit = nl80211_set_rekey_data, |
| 7673 | .policy = nl80211_policy, |
| 7674 | .flags = GENL_ADMIN_PERM, |
| 7675 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7676 | NL80211_FLAG_NEED_RTNL, |
| 7677 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7678 | { |
| 7679 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 7680 | .doit = nl80211_tdls_mgmt, |
| 7681 | .policy = nl80211_policy, |
| 7682 | .flags = GENL_ADMIN_PERM, |
| 7683 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7684 | NL80211_FLAG_NEED_RTNL, |
| 7685 | }, |
| 7686 | { |
| 7687 | .cmd = NL80211_CMD_TDLS_OPER, |
| 7688 | .doit = nl80211_tdls_oper, |
| 7689 | .policy = nl80211_policy, |
| 7690 | .flags = GENL_ADMIN_PERM, |
| 7691 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7692 | NL80211_FLAG_NEED_RTNL, |
| 7693 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7694 | { |
| 7695 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 7696 | .doit = nl80211_register_unexpected_frame, |
| 7697 | .policy = nl80211_policy, |
| 7698 | .flags = GENL_ADMIN_PERM, |
| 7699 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7700 | NL80211_FLAG_NEED_RTNL, |
| 7701 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7702 | { |
| 7703 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 7704 | .doit = nl80211_probe_client, |
| 7705 | .policy = nl80211_policy, |
| 7706 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7707 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7708 | NL80211_FLAG_NEED_RTNL, |
| 7709 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7710 | { |
| 7711 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 7712 | .doit = nl80211_register_beacons, |
| 7713 | .policy = nl80211_policy, |
| 7714 | .flags = GENL_ADMIN_PERM, |
| 7715 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7716 | NL80211_FLAG_NEED_RTNL, |
| 7717 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 7718 | { |
| 7719 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 7720 | .doit = nl80211_set_noack_map, |
| 7721 | .policy = nl80211_policy, |
| 7722 | .flags = GENL_ADMIN_PERM, |
| 7723 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7724 | NL80211_FLAG_NEED_RTNL, |
| 7725 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7726 | { |
| 7727 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 7728 | .doit = nl80211_start_p2p_device, |
| 7729 | .policy = nl80211_policy, |
| 7730 | .flags = GENL_ADMIN_PERM, |
| 7731 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 7732 | NL80211_FLAG_NEED_RTNL, |
| 7733 | }, |
| 7734 | { |
| 7735 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 7736 | .doit = nl80211_stop_p2p_device, |
| 7737 | .policy = nl80211_policy, |
| 7738 | .flags = GENL_ADMIN_PERM, |
| 7739 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 7740 | NL80211_FLAG_NEED_RTNL, |
| 7741 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7742 | { |
| 7743 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 7744 | .doit = nl80211_set_mcast_rate, |
| 7745 | .policy = nl80211_policy, |
| 7746 | .flags = GENL_ADMIN_PERM, |
| 7747 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7748 | NL80211_FLAG_NEED_RTNL, |
| 7749 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7750 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7751 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7752 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 7753 | .name = "mlme", |
| 7754 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7755 | |
| 7756 | /* multicast groups */ |
| 7757 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 7758 | .name = "config", |
| 7759 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7760 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 7761 | .name = "scan", |
| 7762 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7763 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 7764 | .name = "regulatory", |
| 7765 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7766 | |
| 7767 | /* notification functions */ |
| 7768 | |
| 7769 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 7770 | { |
| 7771 | struct sk_buff *msg; |
| 7772 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7773 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7774 | if (!msg) |
| 7775 | return; |
| 7776 | |
| 7777 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 7778 | nlmsg_free(msg); |
| 7779 | return; |
| 7780 | } |
| 7781 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7782 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7783 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7784 | } |
| 7785 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7786 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 7787 | struct cfg80211_registered_device *rdev) |
| 7788 | { |
| 7789 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 7790 | struct nlattr *nest; |
| 7791 | int i; |
| 7792 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7793 | ASSERT_RDEV_LOCK(rdev); |
| 7794 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7795 | if (WARN_ON(!req)) |
| 7796 | return 0; |
| 7797 | |
| 7798 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 7799 | if (!nest) |
| 7800 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7801 | for (i = 0; i < req->n_ssids; i++) { |
| 7802 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 7803 | goto nla_put_failure; |
| 7804 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7805 | nla_nest_end(msg, nest); |
| 7806 | |
| 7807 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 7808 | if (!nest) |
| 7809 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7810 | for (i = 0; i < req->n_channels; i++) { |
| 7811 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 7812 | goto nla_put_failure; |
| 7813 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7814 | nla_nest_end(msg, nest); |
| 7815 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7816 | if (req->ie && |
| 7817 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 7818 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7819 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7820 | if (req->flags) |
| 7821 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 7822 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7823 | return 0; |
| 7824 | nla_put_failure: |
| 7825 | return -ENOBUFS; |
| 7826 | } |
| 7827 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7828 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 7829 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7830 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7831 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7832 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7833 | { |
| 7834 | void *hdr; |
| 7835 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7836 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7837 | if (!hdr) |
| 7838 | return -1; |
| 7839 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7840 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7841 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 7842 | wdev->netdev->ifindex)) || |
| 7843 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7844 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7845 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7846 | /* ignore errors and send incomplete event anyway */ |
| 7847 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7848 | |
| 7849 | return genlmsg_end(msg, hdr); |
| 7850 | |
| 7851 | nla_put_failure: |
| 7852 | genlmsg_cancel(msg, hdr); |
| 7853 | return -EMSGSIZE; |
| 7854 | } |
| 7855 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7856 | static int |
| 7857 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 7858 | struct cfg80211_registered_device *rdev, |
| 7859 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7860 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7861 | { |
| 7862 | void *hdr; |
| 7863 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7864 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7865 | if (!hdr) |
| 7866 | return -1; |
| 7867 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7868 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7869 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7870 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7871 | |
| 7872 | return genlmsg_end(msg, hdr); |
| 7873 | |
| 7874 | nla_put_failure: |
| 7875 | genlmsg_cancel(msg, hdr); |
| 7876 | return -EMSGSIZE; |
| 7877 | } |
| 7878 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7879 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7880 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7881 | { |
| 7882 | struct sk_buff *msg; |
| 7883 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 7884 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7885 | if (!msg) |
| 7886 | return; |
| 7887 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7888 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7889 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 7890 | nlmsg_free(msg); |
| 7891 | return; |
| 7892 | } |
| 7893 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7894 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7895 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7896 | } |
| 7897 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7898 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7899 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7900 | { |
| 7901 | struct sk_buff *msg; |
| 7902 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7903 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7904 | if (!msg) |
| 7905 | return; |
| 7906 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7907 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7908 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7909 | nlmsg_free(msg); |
| 7910 | return; |
| 7911 | } |
| 7912 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7913 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7914 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7915 | } |
| 7916 | |
| 7917 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7918 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7919 | { |
| 7920 | struct sk_buff *msg; |
| 7921 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7922 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7923 | if (!msg) |
| 7924 | return; |
| 7925 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7926 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7927 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7928 | nlmsg_free(msg); |
| 7929 | return; |
| 7930 | } |
| 7931 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7932 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7933 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7934 | } |
| 7935 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7936 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 7937 | struct net_device *netdev) |
| 7938 | { |
| 7939 | struct sk_buff *msg; |
| 7940 | |
| 7941 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7942 | if (!msg) |
| 7943 | return; |
| 7944 | |
| 7945 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7946 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 7947 | nlmsg_free(msg); |
| 7948 | return; |
| 7949 | } |
| 7950 | |
| 7951 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7952 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7953 | } |
| 7954 | |
| 7955 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 7956 | struct net_device *netdev, u32 cmd) |
| 7957 | { |
| 7958 | struct sk_buff *msg; |
| 7959 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 7960 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7961 | if (!msg) |
| 7962 | return; |
| 7963 | |
| 7964 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 7965 | nlmsg_free(msg); |
| 7966 | return; |
| 7967 | } |
| 7968 | |
| 7969 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7970 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7971 | } |
| 7972 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7973 | /* |
| 7974 | * This can happen on global regulatory changes or device specific settings |
| 7975 | * based on custom world regulatory domains. |
| 7976 | */ |
| 7977 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 7978 | { |
| 7979 | struct sk_buff *msg; |
| 7980 | void *hdr; |
| 7981 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7982 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7983 | if (!msg) |
| 7984 | return; |
| 7985 | |
| 7986 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 7987 | if (!hdr) { |
| 7988 | nlmsg_free(msg); |
| 7989 | return; |
| 7990 | } |
| 7991 | |
| 7992 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7993 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 7994 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7995 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7996 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 7997 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7998 | NL80211_REGDOM_TYPE_WORLD)) |
| 7999 | goto nla_put_failure; |
| 8000 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 8001 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8002 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 8003 | goto nla_put_failure; |
| 8004 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 8005 | request->intersect) { |
| 8006 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8007 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 8008 | goto nla_put_failure; |
| 8009 | } else { |
| 8010 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8011 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 8012 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 8013 | request->alpha2)) |
| 8014 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8015 | } |
| 8016 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8017 | if (wiphy_idx_valid(request->wiphy_idx) && |
| 8018 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 8019 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8020 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8021 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8022 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8023 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8024 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8025 | GFP_ATOMIC); |
| 8026 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8027 | |
| 8028 | return; |
| 8029 | |
| 8030 | nla_put_failure: |
| 8031 | genlmsg_cancel(msg, hdr); |
| 8032 | nlmsg_free(msg); |
| 8033 | } |
| 8034 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8035 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 8036 | struct net_device *netdev, |
| 8037 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8038 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8039 | { |
| 8040 | struct sk_buff *msg; |
| 8041 | void *hdr; |
| 8042 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8043 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8044 | if (!msg) |
| 8045 | return; |
| 8046 | |
| 8047 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8048 | if (!hdr) { |
| 8049 | nlmsg_free(msg); |
| 8050 | return; |
| 8051 | } |
| 8052 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8053 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8054 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8055 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8056 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8057 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8058 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8059 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8060 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8061 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8062 | return; |
| 8063 | |
| 8064 | nla_put_failure: |
| 8065 | genlmsg_cancel(msg, hdr); |
| 8066 | nlmsg_free(msg); |
| 8067 | } |
| 8068 | |
| 8069 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8070 | struct net_device *netdev, const u8 *buf, |
| 8071 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8072 | { |
| 8073 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8074 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8075 | } |
| 8076 | |
| 8077 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 8078 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8079 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8080 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8081 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8082 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8083 | } |
| 8084 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8085 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8086 | struct net_device *netdev, const u8 *buf, |
| 8087 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8088 | { |
| 8089 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8090 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8091 | } |
| 8092 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8093 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 8094 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8095 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8096 | { |
| 8097 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8098 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8099 | } |
| 8100 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 8101 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 8102 | struct net_device *netdev, const u8 *buf, |
| 8103 | size_t len, gfp_t gfp) |
| 8104 | { |
| 8105 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8106 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 8107 | } |
| 8108 | |
| 8109 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 8110 | struct net_device *netdev, const u8 *buf, |
| 8111 | size_t len, gfp_t gfp) |
| 8112 | { |
| 8113 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8114 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 8115 | } |
| 8116 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 8117 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 8118 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8119 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8120 | { |
| 8121 | struct sk_buff *msg; |
| 8122 | void *hdr; |
| 8123 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8124 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8125 | if (!msg) |
| 8126 | return; |
| 8127 | |
| 8128 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8129 | if (!hdr) { |
| 8130 | nlmsg_free(msg); |
| 8131 | return; |
| 8132 | } |
| 8133 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8134 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8135 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8136 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8137 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8138 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8139 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8140 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8141 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8142 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8143 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8144 | return; |
| 8145 | |
| 8146 | nla_put_failure: |
| 8147 | genlmsg_cancel(msg, hdr); |
| 8148 | nlmsg_free(msg); |
| 8149 | } |
| 8150 | |
| 8151 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8152 | struct net_device *netdev, const u8 *addr, |
| 8153 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8154 | { |
| 8155 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8156 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8157 | } |
| 8158 | |
| 8159 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8160 | struct net_device *netdev, const u8 *addr, |
| 8161 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8162 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8163 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8164 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8165 | } |
| 8166 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8167 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8168 | struct net_device *netdev, const u8 *bssid, |
| 8169 | const u8 *req_ie, size_t req_ie_len, |
| 8170 | const u8 *resp_ie, size_t resp_ie_len, |
| 8171 | u16 status, gfp_t gfp) |
| 8172 | { |
| 8173 | struct sk_buff *msg; |
| 8174 | void *hdr; |
| 8175 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8176 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8177 | if (!msg) |
| 8178 | return; |
| 8179 | |
| 8180 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8181 | if (!hdr) { |
| 8182 | nlmsg_free(msg); |
| 8183 | return; |
| 8184 | } |
| 8185 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8186 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8187 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8188 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8189 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8190 | (req_ie && |
| 8191 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8192 | (resp_ie && |
| 8193 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8194 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8195 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8196 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8197 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8198 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8199 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8200 | return; |
| 8201 | |
| 8202 | nla_put_failure: |
| 8203 | genlmsg_cancel(msg, hdr); |
| 8204 | nlmsg_free(msg); |
| 8205 | |
| 8206 | } |
| 8207 | |
| 8208 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8209 | struct net_device *netdev, const u8 *bssid, |
| 8210 | const u8 *req_ie, size_t req_ie_len, |
| 8211 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8212 | { |
| 8213 | struct sk_buff *msg; |
| 8214 | void *hdr; |
| 8215 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8216 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8217 | if (!msg) |
| 8218 | return; |
| 8219 | |
| 8220 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8221 | if (!hdr) { |
| 8222 | nlmsg_free(msg); |
| 8223 | return; |
| 8224 | } |
| 8225 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8226 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8227 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8228 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8229 | (req_ie && |
| 8230 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8231 | (resp_ie && |
| 8232 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8233 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8234 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8235 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8236 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8237 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8238 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8239 | return; |
| 8240 | |
| 8241 | nla_put_failure: |
| 8242 | genlmsg_cancel(msg, hdr); |
| 8243 | nlmsg_free(msg); |
| 8244 | |
| 8245 | } |
| 8246 | |
| 8247 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 8248 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8249 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8250 | { |
| 8251 | struct sk_buff *msg; |
| 8252 | void *hdr; |
| 8253 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8254 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8255 | if (!msg) |
| 8256 | return; |
| 8257 | |
| 8258 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 8259 | if (!hdr) { |
| 8260 | nlmsg_free(msg); |
| 8261 | return; |
| 8262 | } |
| 8263 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8264 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8265 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8266 | (from_ap && reason && |
| 8267 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 8268 | (from_ap && |
| 8269 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 8270 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 8271 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8272 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8273 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8274 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8275 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8276 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8277 | return; |
| 8278 | |
| 8279 | nla_put_failure: |
| 8280 | genlmsg_cancel(msg, hdr); |
| 8281 | nlmsg_free(msg); |
| 8282 | |
| 8283 | } |
| 8284 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8285 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 8286 | struct net_device *netdev, const u8 *bssid, |
| 8287 | gfp_t gfp) |
| 8288 | { |
| 8289 | struct sk_buff *msg; |
| 8290 | void *hdr; |
| 8291 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8292 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8293 | if (!msg) |
| 8294 | return; |
| 8295 | |
| 8296 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 8297 | if (!hdr) { |
| 8298 | nlmsg_free(msg); |
| 8299 | return; |
| 8300 | } |
| 8301 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8302 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8303 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8304 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8305 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8306 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8307 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8308 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8309 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8310 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8311 | return; |
| 8312 | |
| 8313 | nla_put_failure: |
| 8314 | genlmsg_cancel(msg, hdr); |
| 8315 | nlmsg_free(msg); |
| 8316 | } |
| 8317 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8318 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 8319 | struct net_device *netdev, |
| 8320 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 8321 | gfp_t gfp) |
| 8322 | { |
| 8323 | struct sk_buff *msg; |
| 8324 | void *hdr; |
| 8325 | |
| 8326 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8327 | if (!msg) |
| 8328 | return; |
| 8329 | |
| 8330 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 8331 | if (!hdr) { |
| 8332 | nlmsg_free(msg); |
| 8333 | return; |
| 8334 | } |
| 8335 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8336 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8337 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8338 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 8339 | (ie_len && ie && |
| 8340 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 8341 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8342 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8343 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8344 | |
| 8345 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8346 | nl80211_mlme_mcgrp.id, gfp); |
| 8347 | return; |
| 8348 | |
| 8349 | nla_put_failure: |
| 8350 | genlmsg_cancel(msg, hdr); |
| 8351 | nlmsg_free(msg); |
| 8352 | } |
| 8353 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8354 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 8355 | struct net_device *netdev, const u8 *addr, |
| 8356 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8357 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8358 | { |
| 8359 | struct sk_buff *msg; |
| 8360 | void *hdr; |
| 8361 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8362 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8363 | if (!msg) |
| 8364 | return; |
| 8365 | |
| 8366 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 8367 | if (!hdr) { |
| 8368 | nlmsg_free(msg); |
| 8369 | return; |
| 8370 | } |
| 8371 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8372 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8373 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8374 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 8375 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 8376 | (key_id != -1 && |
| 8377 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 8378 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 8379 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8380 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8381 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8382 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8383 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8384 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8385 | return; |
| 8386 | |
| 8387 | nla_put_failure: |
| 8388 | genlmsg_cancel(msg, hdr); |
| 8389 | nlmsg_free(msg); |
| 8390 | } |
| 8391 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8392 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 8393 | struct ieee80211_channel *channel_before, |
| 8394 | struct ieee80211_channel *channel_after) |
| 8395 | { |
| 8396 | struct sk_buff *msg; |
| 8397 | void *hdr; |
| 8398 | struct nlattr *nl_freq; |
| 8399 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8400 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8401 | if (!msg) |
| 8402 | return; |
| 8403 | |
| 8404 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 8405 | if (!hdr) { |
| 8406 | nlmsg_free(msg); |
| 8407 | return; |
| 8408 | } |
| 8409 | |
| 8410 | /* |
| 8411 | * Since we are applying the beacon hint to a wiphy we know its |
| 8412 | * wiphy_idx is valid |
| 8413 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8414 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 8415 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8416 | |
| 8417 | /* Before */ |
| 8418 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 8419 | if (!nl_freq) |
| 8420 | goto nla_put_failure; |
| 8421 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 8422 | goto nla_put_failure; |
| 8423 | nla_nest_end(msg, nl_freq); |
| 8424 | |
| 8425 | /* After */ |
| 8426 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 8427 | if (!nl_freq) |
| 8428 | goto nla_put_failure; |
| 8429 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 8430 | goto nla_put_failure; |
| 8431 | nla_nest_end(msg, nl_freq); |
| 8432 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8433 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8434 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8435 | rcu_read_lock(); |
| 8436 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 8437 | GFP_ATOMIC); |
| 8438 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8439 | |
| 8440 | return; |
| 8441 | |
| 8442 | nla_put_failure: |
| 8443 | genlmsg_cancel(msg, hdr); |
| 8444 | nlmsg_free(msg); |
| 8445 | } |
| 8446 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8447 | static void nl80211_send_remain_on_chan_event( |
| 8448 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8449 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8450 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8451 | unsigned int duration, gfp_t gfp) |
| 8452 | { |
| 8453 | struct sk_buff *msg; |
| 8454 | void *hdr; |
| 8455 | |
| 8456 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8457 | if (!msg) |
| 8458 | return; |
| 8459 | |
| 8460 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8461 | if (!hdr) { |
| 8462 | nlmsg_free(msg); |
| 8463 | return; |
| 8464 | } |
| 8465 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8466 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8467 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8468 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 8469 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8470 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8471 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 8472 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8473 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8474 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8475 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8476 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 8477 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 8478 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8479 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8480 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8481 | |
| 8482 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8483 | nl80211_mlme_mcgrp.id, gfp); |
| 8484 | return; |
| 8485 | |
| 8486 | nla_put_failure: |
| 8487 | genlmsg_cancel(msg, hdr); |
| 8488 | nlmsg_free(msg); |
| 8489 | } |
| 8490 | |
| 8491 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8492 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8493 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8494 | unsigned int duration, gfp_t gfp) |
| 8495 | { |
| 8496 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8497 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8498 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8499 | } |
| 8500 | |
| 8501 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8502 | struct cfg80211_registered_device *rdev, |
| 8503 | struct wireless_dev *wdev, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8504 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8505 | { |
| 8506 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8507 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8508 | } |
| 8509 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8510 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 8511 | struct net_device *dev, const u8 *mac_addr, |
| 8512 | struct station_info *sinfo, gfp_t gfp) |
| 8513 | { |
| 8514 | struct sk_buff *msg; |
| 8515 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8516 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8517 | if (!msg) |
| 8518 | return; |
| 8519 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 8520 | if (nl80211_send_station(msg, 0, 0, 0, |
| 8521 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8522 | nlmsg_free(msg); |
| 8523 | return; |
| 8524 | } |
| 8525 | |
| 8526 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8527 | nl80211_mlme_mcgrp.id, gfp); |
| 8528 | } |
| 8529 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8530 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 8531 | struct net_device *dev, const u8 *mac_addr, |
| 8532 | gfp_t gfp) |
| 8533 | { |
| 8534 | struct sk_buff *msg; |
| 8535 | void *hdr; |
| 8536 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8537 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8538 | if (!msg) |
| 8539 | return; |
| 8540 | |
| 8541 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 8542 | if (!hdr) { |
| 8543 | nlmsg_free(msg); |
| 8544 | return; |
| 8545 | } |
| 8546 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8547 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8548 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 8549 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8550 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8551 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8552 | |
| 8553 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8554 | nl80211_mlme_mcgrp.id, gfp); |
| 8555 | return; |
| 8556 | |
| 8557 | nla_put_failure: |
| 8558 | genlmsg_cancel(msg, hdr); |
| 8559 | nlmsg_free(msg); |
| 8560 | } |
| 8561 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 8562 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 8563 | struct net_device *dev, const u8 *mac_addr, |
| 8564 | enum nl80211_connect_failed_reason reason, |
| 8565 | gfp_t gfp) |
| 8566 | { |
| 8567 | struct sk_buff *msg; |
| 8568 | void *hdr; |
| 8569 | |
| 8570 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8571 | if (!msg) |
| 8572 | return; |
| 8573 | |
| 8574 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 8575 | if (!hdr) { |
| 8576 | nlmsg_free(msg); |
| 8577 | return; |
| 8578 | } |
| 8579 | |
| 8580 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8581 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 8582 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 8583 | goto nla_put_failure; |
| 8584 | |
| 8585 | genlmsg_end(msg, hdr); |
| 8586 | |
| 8587 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8588 | nl80211_mlme_mcgrp.id, gfp); |
| 8589 | return; |
| 8590 | |
| 8591 | nla_put_failure: |
| 8592 | genlmsg_cancel(msg, hdr); |
| 8593 | nlmsg_free(msg); |
| 8594 | } |
| 8595 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8596 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 8597 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8598 | { |
| 8599 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8600 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8601 | struct sk_buff *msg; |
| 8602 | void *hdr; |
| 8603 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8604 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8605 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8606 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8607 | return false; |
| 8608 | |
| 8609 | msg = nlmsg_new(100, gfp); |
| 8610 | if (!msg) |
| 8611 | return true; |
| 8612 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8613 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8614 | if (!hdr) { |
| 8615 | nlmsg_free(msg); |
| 8616 | return true; |
| 8617 | } |
| 8618 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8619 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8620 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8621 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8622 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8623 | |
| 8624 | err = genlmsg_end(msg, hdr); |
| 8625 | if (err < 0) { |
| 8626 | nlmsg_free(msg); |
| 8627 | return true; |
| 8628 | } |
| 8629 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8630 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8631 | return true; |
| 8632 | |
| 8633 | nla_put_failure: |
| 8634 | genlmsg_cancel(msg, hdr); |
| 8635 | nlmsg_free(msg); |
| 8636 | return true; |
| 8637 | } |
| 8638 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8639 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 8640 | { |
| 8641 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 8642 | addr, gfp); |
| 8643 | } |
| 8644 | |
| 8645 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 8646 | const u8 *addr, gfp_t gfp) |
| 8647 | { |
| 8648 | return __nl80211_unexpected_frame(dev, |
| 8649 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 8650 | addr, gfp); |
| 8651 | } |
| 8652 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8653 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8654 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8655 | int freq, int sig_dbm, |
| 8656 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8657 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8658 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8659 | struct sk_buff *msg; |
| 8660 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8661 | |
| 8662 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8663 | if (!msg) |
| 8664 | return -ENOMEM; |
| 8665 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8666 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8667 | if (!hdr) { |
| 8668 | nlmsg_free(msg); |
| 8669 | return -ENOMEM; |
| 8670 | } |
| 8671 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8672 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8673 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8674 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8675 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8676 | (sig_dbm && |
| 8677 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8678 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8679 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8680 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8681 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8682 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8683 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8684 | |
| 8685 | nla_put_failure: |
| 8686 | genlmsg_cancel(msg, hdr); |
| 8687 | nlmsg_free(msg); |
| 8688 | return -ENOBUFS; |
| 8689 | } |
| 8690 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8691 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8692 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8693 | const u8 *buf, size_t len, bool ack, |
| 8694 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8695 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8696 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8697 | struct sk_buff *msg; |
| 8698 | void *hdr; |
| 8699 | |
| 8700 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8701 | if (!msg) |
| 8702 | return; |
| 8703 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8704 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8705 | if (!hdr) { |
| 8706 | nlmsg_free(msg); |
| 8707 | return; |
| 8708 | } |
| 8709 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8710 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8711 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8712 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8713 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 8714 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8715 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8716 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8717 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8718 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8719 | |
| 8720 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 8721 | return; |
| 8722 | |
| 8723 | nla_put_failure: |
| 8724 | genlmsg_cancel(msg, hdr); |
| 8725 | nlmsg_free(msg); |
| 8726 | } |
| 8727 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8728 | void |
| 8729 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 8730 | struct net_device *netdev, |
| 8731 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 8732 | gfp_t gfp) |
| 8733 | { |
| 8734 | struct sk_buff *msg; |
| 8735 | struct nlattr *pinfoattr; |
| 8736 | void *hdr; |
| 8737 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8738 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8739 | if (!msg) |
| 8740 | return; |
| 8741 | |
| 8742 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8743 | if (!hdr) { |
| 8744 | nlmsg_free(msg); |
| 8745 | return; |
| 8746 | } |
| 8747 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8748 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8749 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8750 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8751 | |
| 8752 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8753 | if (!pinfoattr) |
| 8754 | goto nla_put_failure; |
| 8755 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8756 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 8757 | rssi_event)) |
| 8758 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8759 | |
| 8760 | nla_nest_end(msg, pinfoattr); |
| 8761 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8762 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8763 | |
| 8764 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8765 | nl80211_mlme_mcgrp.id, gfp); |
| 8766 | return; |
| 8767 | |
| 8768 | nla_put_failure: |
| 8769 | genlmsg_cancel(msg, hdr); |
| 8770 | nlmsg_free(msg); |
| 8771 | } |
| 8772 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8773 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 8774 | struct net_device *netdev, const u8 *bssid, |
| 8775 | const u8 *replay_ctr, gfp_t gfp) |
| 8776 | { |
| 8777 | struct sk_buff *msg; |
| 8778 | struct nlattr *rekey_attr; |
| 8779 | void *hdr; |
| 8780 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8781 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8782 | if (!msg) |
| 8783 | return; |
| 8784 | |
| 8785 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 8786 | if (!hdr) { |
| 8787 | nlmsg_free(msg); |
| 8788 | return; |
| 8789 | } |
| 8790 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8791 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8792 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8793 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8794 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8795 | |
| 8796 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 8797 | if (!rekey_attr) |
| 8798 | goto nla_put_failure; |
| 8799 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8800 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 8801 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 8802 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8803 | |
| 8804 | nla_nest_end(msg, rekey_attr); |
| 8805 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8806 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8807 | |
| 8808 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8809 | nl80211_mlme_mcgrp.id, gfp); |
| 8810 | return; |
| 8811 | |
| 8812 | nla_put_failure: |
| 8813 | genlmsg_cancel(msg, hdr); |
| 8814 | nlmsg_free(msg); |
| 8815 | } |
| 8816 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8817 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 8818 | struct net_device *netdev, int index, |
| 8819 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 8820 | { |
| 8821 | struct sk_buff *msg; |
| 8822 | struct nlattr *attr; |
| 8823 | void *hdr; |
| 8824 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8825 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8826 | if (!msg) |
| 8827 | return; |
| 8828 | |
| 8829 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 8830 | if (!hdr) { |
| 8831 | nlmsg_free(msg); |
| 8832 | return; |
| 8833 | } |
| 8834 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8835 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8836 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8837 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8838 | |
| 8839 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 8840 | if (!attr) |
| 8841 | goto nla_put_failure; |
| 8842 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8843 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 8844 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 8845 | (preauth && |
| 8846 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 8847 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8848 | |
| 8849 | nla_nest_end(msg, attr); |
| 8850 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8851 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8852 | |
| 8853 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8854 | nl80211_mlme_mcgrp.id, gfp); |
| 8855 | return; |
| 8856 | |
| 8857 | nla_put_failure: |
| 8858 | genlmsg_cancel(msg, hdr); |
| 8859 | nlmsg_free(msg); |
| 8860 | } |
| 8861 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8862 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8863 | struct net_device *netdev, |
| 8864 | struct cfg80211_chan_def *chandef, gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 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); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8870 | if (!msg) |
| 8871 | return; |
| 8872 | |
| 8873 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 8874 | if (!hdr) { |
| 8875 | nlmsg_free(msg); |
| 8876 | return; |
| 8877 | } |
| 8878 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8879 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8880 | goto nla_put_failure; |
| 8881 | |
| 8882 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 8883 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8884 | |
| 8885 | genlmsg_end(msg, hdr); |
| 8886 | |
| 8887 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8888 | nl80211_mlme_mcgrp.id, gfp); |
| 8889 | return; |
| 8890 | |
| 8891 | nla_put_failure: |
| 8892 | genlmsg_cancel(msg, hdr); |
| 8893 | nlmsg_free(msg); |
| 8894 | } |
| 8895 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8896 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8897 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 8898 | struct net_device *netdev, const u8 *peer, |
| 8899 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 8900 | { |
| 8901 | struct sk_buff *msg; |
| 8902 | struct nlattr *pinfoattr; |
| 8903 | void *hdr; |
| 8904 | |
| 8905 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8906 | if (!msg) |
| 8907 | return; |
| 8908 | |
| 8909 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8910 | if (!hdr) { |
| 8911 | nlmsg_free(msg); |
| 8912 | return; |
| 8913 | } |
| 8914 | |
| 8915 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8916 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8917 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8918 | goto nla_put_failure; |
| 8919 | |
| 8920 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8921 | if (!pinfoattr) |
| 8922 | goto nla_put_failure; |
| 8923 | |
| 8924 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 8925 | goto nla_put_failure; |
| 8926 | |
| 8927 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 8928 | goto nla_put_failure; |
| 8929 | |
| 8930 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 8931 | goto nla_put_failure; |
| 8932 | |
| 8933 | nla_nest_end(msg, pinfoattr); |
| 8934 | |
| 8935 | genlmsg_end(msg, hdr); |
| 8936 | |
| 8937 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8938 | nl80211_mlme_mcgrp.id, gfp); |
| 8939 | return; |
| 8940 | |
| 8941 | nla_put_failure: |
| 8942 | genlmsg_cancel(msg, hdr); |
| 8943 | nlmsg_free(msg); |
| 8944 | } |
| 8945 | |
| 8946 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8947 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 8948 | struct net_device *netdev, const u8 *peer, |
| 8949 | u32 num_packets, gfp_t gfp) |
| 8950 | { |
| 8951 | struct sk_buff *msg; |
| 8952 | struct nlattr *pinfoattr; |
| 8953 | void *hdr; |
| 8954 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8955 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8956 | if (!msg) |
| 8957 | return; |
| 8958 | |
| 8959 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8960 | if (!hdr) { |
| 8961 | nlmsg_free(msg); |
| 8962 | return; |
| 8963 | } |
| 8964 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8965 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8966 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8967 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8968 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8969 | |
| 8970 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8971 | if (!pinfoattr) |
| 8972 | goto nla_put_failure; |
| 8973 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8974 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 8975 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8976 | |
| 8977 | nla_nest_end(msg, pinfoattr); |
| 8978 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8979 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8980 | |
| 8981 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8982 | nl80211_mlme_mcgrp.id, gfp); |
| 8983 | return; |
| 8984 | |
| 8985 | nla_put_failure: |
| 8986 | genlmsg_cancel(msg, hdr); |
| 8987 | nlmsg_free(msg); |
| 8988 | } |
| 8989 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8990 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 8991 | u64 cookie, bool acked, gfp_t gfp) |
| 8992 | { |
| 8993 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8994 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8995 | struct sk_buff *msg; |
| 8996 | void *hdr; |
| 8997 | int err; |
| 8998 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 8999 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 9000 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9001 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9002 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9003 | if (!msg) |
| 9004 | return; |
| 9005 | |
| 9006 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 9007 | if (!hdr) { |
| 9008 | nlmsg_free(msg); |
| 9009 | return; |
| 9010 | } |
| 9011 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9012 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9013 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9014 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9015 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9016 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9017 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9018 | |
| 9019 | err = genlmsg_end(msg, hdr); |
| 9020 | if (err < 0) { |
| 9021 | nlmsg_free(msg); |
| 9022 | return; |
| 9023 | } |
| 9024 | |
| 9025 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9026 | nl80211_mlme_mcgrp.id, gfp); |
| 9027 | return; |
| 9028 | |
| 9029 | nla_put_failure: |
| 9030 | genlmsg_cancel(msg, hdr); |
| 9031 | nlmsg_free(msg); |
| 9032 | } |
| 9033 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 9034 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9035 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 9036 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9037 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9038 | { |
| 9039 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9040 | struct sk_buff *msg; |
| 9041 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9042 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9043 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9044 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 9045 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9046 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9047 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9048 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 9049 | if (!msg) { |
| 9050 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9051 | return; |
| 9052 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9053 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9054 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 9055 | if (!hdr) |
| 9056 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9057 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9058 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9059 | (freq && |
| 9060 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9061 | (sig_dbm && |
| 9062 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9063 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 9064 | goto nla_put_failure; |
| 9065 | |
| 9066 | genlmsg_end(msg, hdr); |
| 9067 | |
| 9068 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9069 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9070 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9071 | return; |
| 9072 | |
| 9073 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9074 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9075 | if (hdr) |
| 9076 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9077 | nlmsg_free(msg); |
| 9078 | } |
| 9079 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 9080 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 9081 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 9082 | enum nl80211_tdls_operation oper, |
| 9083 | u16 reason_code, gfp_t gfp) |
| 9084 | { |
| 9085 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9086 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9087 | struct sk_buff *msg; |
| 9088 | void *hdr; |
| 9089 | int err; |
| 9090 | |
| 9091 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 9092 | reason_code); |
| 9093 | |
| 9094 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9095 | if (!msg) |
| 9096 | return; |
| 9097 | |
| 9098 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 9099 | if (!hdr) { |
| 9100 | nlmsg_free(msg); |
| 9101 | return; |
| 9102 | } |
| 9103 | |
| 9104 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9105 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9106 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 9107 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 9108 | (reason_code > 0 && |
| 9109 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 9110 | goto nla_put_failure; |
| 9111 | |
| 9112 | err = genlmsg_end(msg, hdr); |
| 9113 | if (err < 0) { |
| 9114 | nlmsg_free(msg); |
| 9115 | return; |
| 9116 | } |
| 9117 | |
| 9118 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9119 | nl80211_mlme_mcgrp.id, gfp); |
| 9120 | return; |
| 9121 | |
| 9122 | nla_put_failure: |
| 9123 | genlmsg_cancel(msg, hdr); |
| 9124 | nlmsg_free(msg); |
| 9125 | } |
| 9126 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 9127 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9128 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 9129 | unsigned long state, |
| 9130 | void *_notify) |
| 9131 | { |
| 9132 | struct netlink_notify *notify = _notify; |
| 9133 | struct cfg80211_registered_device *rdev; |
| 9134 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9135 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9136 | |
| 9137 | if (state != NETLINK_URELEASE) |
| 9138 | return NOTIFY_DONE; |
| 9139 | |
| 9140 | rcu_read_lock(); |
| 9141 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9142 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9143 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9144 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9145 | |
| 9146 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9147 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 9148 | list) { |
| 9149 | if (reg->nlportid == notify->portid) { |
| 9150 | list_del(®->list); |
| 9151 | kfree(reg); |
| 9152 | break; |
| 9153 | } |
| 9154 | } |
| 9155 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9156 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9157 | |
| 9158 | rcu_read_unlock(); |
| 9159 | |
| 9160 | return NOTIFY_DONE; |
| 9161 | } |
| 9162 | |
| 9163 | static struct notifier_block nl80211_netlink_notifier = { |
| 9164 | .notifier_call = nl80211_netlink_notify, |
| 9165 | }; |
| 9166 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9167 | /* initialisation/exit functions */ |
| 9168 | |
| 9169 | int nl80211_init(void) |
| 9170 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9171 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9172 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9173 | err = genl_register_family_with_ops(&nl80211_fam, |
| 9174 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9175 | if (err) |
| 9176 | return err; |
| 9177 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9178 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 9179 | if (err) |
| 9180 | goto err_out; |
| 9181 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9182 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 9183 | if (err) |
| 9184 | goto err_out; |
| 9185 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9186 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 9187 | if (err) |
| 9188 | goto err_out; |
| 9189 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9190 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 9191 | if (err) |
| 9192 | goto err_out; |
| 9193 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9194 | #ifdef CONFIG_NL80211_TESTMODE |
| 9195 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 9196 | if (err) |
| 9197 | goto err_out; |
| 9198 | #endif |
| 9199 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9200 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 9201 | if (err) |
| 9202 | goto err_out; |
| 9203 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9204 | return 0; |
| 9205 | err_out: |
| 9206 | genl_unregister_family(&nl80211_fam); |
| 9207 | return err; |
| 9208 | } |
| 9209 | |
| 9210 | void nl80211_exit(void) |
| 9211 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9212 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9213 | genl_unregister_family(&nl80211_fam); |
| 9214 | } |