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 | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 282 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 283 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 284 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 285 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 286 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 287 | |
| 288 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 289 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 290 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 291 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 292 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 293 | |
| 294 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 295 | .len = IEEE80211_MAX_SSID_LEN }, |
| 296 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 297 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 298 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 299 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_STA_FLAGS2] = { |
| 302 | .len = sizeof(struct nl80211_sta_flag_update), |
| 303 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 304 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 306 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 308 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 309 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 311 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 313 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 314 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 315 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 318 | .len = IEEE80211_MAX_DATA_LEN }, |
| 319 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 320 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 322 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 323 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 324 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 325 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 327 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 328 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 329 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 330 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 331 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 333 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 335 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 336 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 337 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 339 | .len = IEEE80211_MAX_DATA_LEN }, |
| 340 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 341 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 342 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 343 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 344 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 345 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 346 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 347 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 348 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 349 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 350 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 351 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 352 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 353 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 354 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 355 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 356 | .len = NL80211_HT_CAPABILITY_LEN |
| 357 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 358 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 359 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 360 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 361 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 362 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 363 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 364 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 365 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 366 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 367 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 368 | }; |
| 369 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 370 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 371 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 372 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 373 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 374 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 375 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 376 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 377 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 378 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 379 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 380 | }; |
| 381 | |
| 382 | /* policy for the key default flags */ |
| 383 | static const struct nla_policy |
| 384 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 385 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 386 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 387 | }; |
| 388 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 389 | /* policy for WoWLAN attributes */ |
| 390 | static const struct nla_policy |
| 391 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 392 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 393 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 394 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 395 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 396 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 397 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 398 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 399 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 400 | }; |
| 401 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 402 | /* policy for GTK rekey offload attributes */ |
| 403 | static const struct nla_policy |
| 404 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 405 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 406 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 407 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 408 | }; |
| 409 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 410 | static const struct nla_policy |
| 411 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 412 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 413 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 414 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 415 | }; |
| 416 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 417 | /* ifidx get helper */ |
| 418 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 419 | { |
| 420 | int res; |
| 421 | |
| 422 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 423 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 424 | nl80211_policy); |
| 425 | if (res) |
| 426 | return res; |
| 427 | |
| 428 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 429 | return -EINVAL; |
| 430 | |
| 431 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 432 | if (!res) |
| 433 | return -EINVAL; |
| 434 | return res; |
| 435 | } |
| 436 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 437 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 438 | struct netlink_callback *cb, |
| 439 | struct cfg80211_registered_device **rdev, |
| 440 | struct net_device **dev) |
| 441 | { |
| 442 | int ifidx = cb->args[0]; |
| 443 | int err; |
| 444 | |
| 445 | if (!ifidx) |
| 446 | ifidx = nl80211_get_ifidx(cb); |
| 447 | if (ifidx < 0) |
| 448 | return ifidx; |
| 449 | |
| 450 | cb->args[0] = ifidx; |
| 451 | |
| 452 | rtnl_lock(); |
| 453 | |
| 454 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 455 | if (!*dev) { |
| 456 | err = -ENODEV; |
| 457 | goto out_rtnl; |
| 458 | } |
| 459 | |
| 460 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 461 | if (IS_ERR(*rdev)) { |
| 462 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 463 | goto out_rtnl; |
| 464 | } |
| 465 | |
| 466 | return 0; |
| 467 | out_rtnl: |
| 468 | rtnl_unlock(); |
| 469 | return err; |
| 470 | } |
| 471 | |
| 472 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 473 | { |
| 474 | cfg80211_unlock_rdev(rdev); |
| 475 | rtnl_unlock(); |
| 476 | } |
| 477 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 478 | /* IE validation */ |
| 479 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 480 | { |
| 481 | const u8 *pos; |
| 482 | int len; |
| 483 | |
| 484 | if (!attr) |
| 485 | return true; |
| 486 | |
| 487 | pos = nla_data(attr); |
| 488 | len = nla_len(attr); |
| 489 | |
| 490 | while (len) { |
| 491 | u8 elemlen; |
| 492 | |
| 493 | if (len < 2) |
| 494 | return false; |
| 495 | len -= 2; |
| 496 | |
| 497 | elemlen = pos[1]; |
| 498 | if (elemlen > len) |
| 499 | return false; |
| 500 | |
| 501 | len -= elemlen; |
| 502 | pos += 2 + elemlen; |
| 503 | } |
| 504 | |
| 505 | return true; |
| 506 | } |
| 507 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 508 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 509 | 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] | 510 | int flags, u8 cmd) |
| 511 | { |
| 512 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 513 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 514 | } |
| 515 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 516 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 517 | struct ieee80211_channel *chan) |
| 518 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 519 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 520 | chan->center_freq)) |
| 521 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 522 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 523 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 524 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 525 | goto nla_put_failure; |
| 526 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 527 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 528 | goto nla_put_failure; |
| 529 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 530 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 531 | goto nla_put_failure; |
| 532 | if ((chan->flags & IEEE80211_CHAN_RADAR) && |
| 533 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 534 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 535 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 536 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 537 | DBM_TO_MBM(chan->max_power))) |
| 538 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 539 | |
| 540 | return 0; |
| 541 | |
| 542 | nla_put_failure: |
| 543 | return -ENOBUFS; |
| 544 | } |
| 545 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 546 | /* netlink command implementations */ |
| 547 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 548 | struct key_parse { |
| 549 | struct key_params p; |
| 550 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 551 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 552 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 553 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 554 | }; |
| 555 | |
| 556 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 557 | { |
| 558 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 559 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 560 | nl80211_key_policy); |
| 561 | if (err) |
| 562 | return err; |
| 563 | |
| 564 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 565 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 566 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 567 | if (k->def) { |
| 568 | k->def_uni = true; |
| 569 | k->def_multi = true; |
| 570 | } |
| 571 | if (k->defmgmt) |
| 572 | k->def_multi = true; |
| 573 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 574 | if (tb[NL80211_KEY_IDX]) |
| 575 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 576 | |
| 577 | if (tb[NL80211_KEY_DATA]) { |
| 578 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 579 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 580 | } |
| 581 | |
| 582 | if (tb[NL80211_KEY_SEQ]) { |
| 583 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 584 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 585 | } |
| 586 | |
| 587 | if (tb[NL80211_KEY_CIPHER]) |
| 588 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 589 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 590 | if (tb[NL80211_KEY_TYPE]) { |
| 591 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 592 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 593 | return -EINVAL; |
| 594 | } |
| 595 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 596 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 597 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 598 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 599 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 600 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 601 | if (err) |
| 602 | return err; |
| 603 | |
| 604 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 605 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 606 | } |
| 607 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 612 | { |
| 613 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 614 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 615 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 616 | } |
| 617 | |
| 618 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 619 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 620 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 621 | } |
| 622 | |
| 623 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 624 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 625 | |
| 626 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 627 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 628 | |
| 629 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 630 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 631 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 632 | if (k->def) { |
| 633 | k->def_uni = true; |
| 634 | k->def_multi = true; |
| 635 | } |
| 636 | if (k->defmgmt) |
| 637 | k->def_multi = true; |
| 638 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 639 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 640 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 641 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 642 | return -EINVAL; |
| 643 | } |
| 644 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 645 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 646 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 647 | int err = nla_parse_nested( |
| 648 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 649 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 650 | nl80211_key_default_policy); |
| 651 | if (err) |
| 652 | return err; |
| 653 | |
| 654 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 655 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 656 | } |
| 657 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 658 | return 0; |
| 659 | } |
| 660 | |
| 661 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 662 | { |
| 663 | int err; |
| 664 | |
| 665 | memset(k, 0, sizeof(*k)); |
| 666 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 667 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 668 | |
| 669 | if (info->attrs[NL80211_ATTR_KEY]) |
| 670 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 671 | else |
| 672 | err = nl80211_parse_key_old(info, k); |
| 673 | |
| 674 | if (err) |
| 675 | return err; |
| 676 | |
| 677 | if (k->def && k->defmgmt) |
| 678 | return -EINVAL; |
| 679 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 680 | if (k->defmgmt) { |
| 681 | if (k->def_uni || !k->def_multi) |
| 682 | return -EINVAL; |
| 683 | } |
| 684 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 685 | if (k->idx != -1) { |
| 686 | if (k->defmgmt) { |
| 687 | if (k->idx < 4 || k->idx > 5) |
| 688 | return -EINVAL; |
| 689 | } else if (k->def) { |
| 690 | if (k->idx < 0 || k->idx > 3) |
| 691 | return -EINVAL; |
| 692 | } else { |
| 693 | if (k->idx < 0 || k->idx > 5) |
| 694 | return -EINVAL; |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | return 0; |
| 699 | } |
| 700 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 701 | static struct cfg80211_cached_keys * |
| 702 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 703 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 704 | { |
| 705 | struct key_parse parse; |
| 706 | struct nlattr *key; |
| 707 | struct cfg80211_cached_keys *result; |
| 708 | int rem, err, def = 0; |
| 709 | |
| 710 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 711 | if (!result) |
| 712 | return ERR_PTR(-ENOMEM); |
| 713 | |
| 714 | result->def = -1; |
| 715 | result->defmgmt = -1; |
| 716 | |
| 717 | nla_for_each_nested(key, keys, rem) { |
| 718 | memset(&parse, 0, sizeof(parse)); |
| 719 | parse.idx = -1; |
| 720 | |
| 721 | err = nl80211_parse_key_new(key, &parse); |
| 722 | if (err) |
| 723 | goto error; |
| 724 | err = -EINVAL; |
| 725 | if (!parse.p.key) |
| 726 | goto error; |
| 727 | if (parse.idx < 0 || parse.idx > 4) |
| 728 | goto error; |
| 729 | if (parse.def) { |
| 730 | if (def) |
| 731 | goto error; |
| 732 | def = 1; |
| 733 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 734 | if (!parse.def_uni || !parse.def_multi) |
| 735 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 736 | } else if (parse.defmgmt) |
| 737 | goto error; |
| 738 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 739 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 740 | if (err) |
| 741 | goto error; |
| 742 | result->params[parse.idx].cipher = parse.p.cipher; |
| 743 | result->params[parse.idx].key_len = parse.p.key_len; |
| 744 | result->params[parse.idx].key = result->data[parse.idx]; |
| 745 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 746 | |
| 747 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 748 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 749 | if (no_ht) |
| 750 | *no_ht = true; |
| 751 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | return result; |
| 755 | error: |
| 756 | kfree(result); |
| 757 | return ERR_PTR(err); |
| 758 | } |
| 759 | |
| 760 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 761 | { |
| 762 | ASSERT_WDEV_LOCK(wdev); |
| 763 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 764 | switch (wdev->iftype) { |
| 765 | case NL80211_IFTYPE_AP: |
| 766 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 767 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 768 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 769 | break; |
| 770 | case NL80211_IFTYPE_ADHOC: |
| 771 | if (!wdev->current_bss) |
| 772 | return -ENOLINK; |
| 773 | break; |
| 774 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 775 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 776 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 777 | return -ENOLINK; |
| 778 | break; |
| 779 | default: |
| 780 | return -EINVAL; |
| 781 | } |
| 782 | |
| 783 | return 0; |
| 784 | } |
| 785 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 786 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 787 | { |
| 788 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 789 | int i; |
| 790 | |
| 791 | if (!nl_modes) |
| 792 | goto nla_put_failure; |
| 793 | |
| 794 | i = 0; |
| 795 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 796 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 797 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 798 | ifmodes >>= 1; |
| 799 | i++; |
| 800 | } |
| 801 | |
| 802 | nla_nest_end(msg, nl_modes); |
| 803 | return 0; |
| 804 | |
| 805 | nla_put_failure: |
| 806 | return -ENOBUFS; |
| 807 | } |
| 808 | |
| 809 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 810 | struct sk_buff *msg) |
| 811 | { |
| 812 | struct nlattr *nl_combis; |
| 813 | int i, j; |
| 814 | |
| 815 | nl_combis = nla_nest_start(msg, |
| 816 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 817 | if (!nl_combis) |
| 818 | goto nla_put_failure; |
| 819 | |
| 820 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 821 | const struct ieee80211_iface_combination *c; |
| 822 | struct nlattr *nl_combi, *nl_limits; |
| 823 | |
| 824 | c = &wiphy->iface_combinations[i]; |
| 825 | |
| 826 | nl_combi = nla_nest_start(msg, i + 1); |
| 827 | if (!nl_combi) |
| 828 | goto nla_put_failure; |
| 829 | |
| 830 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 831 | if (!nl_limits) |
| 832 | goto nla_put_failure; |
| 833 | |
| 834 | for (j = 0; j < c->n_limits; j++) { |
| 835 | struct nlattr *nl_limit; |
| 836 | |
| 837 | nl_limit = nla_nest_start(msg, j + 1); |
| 838 | if (!nl_limit) |
| 839 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 840 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 841 | c->limits[j].max)) |
| 842 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 843 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 844 | c->limits[j].types)) |
| 845 | goto nla_put_failure; |
| 846 | nla_nest_end(msg, nl_limit); |
| 847 | } |
| 848 | |
| 849 | nla_nest_end(msg, nl_limits); |
| 850 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 851 | if (c->beacon_int_infra_match && |
| 852 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 853 | goto nla_put_failure; |
| 854 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 855 | c->num_different_channels) || |
| 856 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 857 | c->max_interfaces)) |
| 858 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 859 | |
| 860 | nla_nest_end(msg, nl_combi); |
| 861 | } |
| 862 | |
| 863 | nla_nest_end(msg, nl_combis); |
| 864 | |
| 865 | return 0; |
| 866 | nla_put_failure: |
| 867 | return -ENOBUFS; |
| 868 | } |
| 869 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 870 | 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] | 871 | struct cfg80211_registered_device *dev) |
| 872 | { |
| 873 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 874 | struct nlattr *nl_bands, *nl_band; |
| 875 | struct nlattr *nl_freqs, *nl_freq; |
| 876 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 877 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 878 | enum ieee80211_band band; |
| 879 | struct ieee80211_channel *chan; |
| 880 | struct ieee80211_rate *rate; |
| 881 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 882 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 883 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 884 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 885 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 886 | if (!hdr) |
| 887 | return -1; |
| 888 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 889 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
| 890 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || |
| 891 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 892 | cfg80211_rdev_list_generation) || |
| 893 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 894 | dev->wiphy.retry_short) || |
| 895 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 896 | dev->wiphy.retry_long) || |
| 897 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 898 | dev->wiphy.frag_threshold) || |
| 899 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 900 | dev->wiphy.rts_threshold) || |
| 901 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 902 | dev->wiphy.coverage_class) || |
| 903 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 904 | dev->wiphy.max_scan_ssids) || |
| 905 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 906 | dev->wiphy.max_sched_scan_ssids) || |
| 907 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 908 | dev->wiphy.max_scan_ie_len) || |
| 909 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 910 | dev->wiphy.max_sched_scan_ie_len) || |
| 911 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 912 | dev->wiphy.max_match_sets)) |
| 913 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 914 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 915 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 916 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 917 | goto nla_put_failure; |
| 918 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 919 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 920 | goto nla_put_failure; |
| 921 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 922 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 923 | goto nla_put_failure; |
| 924 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 925 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 926 | goto nla_put_failure; |
| 927 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 928 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 929 | goto nla_put_failure; |
| 930 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 931 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 932 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 933 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 934 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 935 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 936 | dev->wiphy.cipher_suites)) |
| 937 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 938 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 939 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 940 | dev->wiphy.max_num_pmkids)) |
| 941 | goto nla_put_failure; |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 942 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 943 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 944 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 945 | goto nla_put_failure; |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 946 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 947 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 948 | dev->wiphy.available_antennas_tx) || |
| 949 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 950 | dev->wiphy.available_antennas_rx)) |
| 951 | goto nla_put_failure; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 952 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 953 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 954 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 955 | dev->wiphy.probe_resp_offload)) |
| 956 | goto nla_put_failure; |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 957 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 958 | if ((dev->wiphy.available_antennas_tx || |
| 959 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 960 | u32 tx_ant = 0, rx_ant = 0; |
| 961 | int res; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 962 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 963 | if (!res) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 964 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 965 | tx_ant) || |
| 966 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 967 | rx_ant)) |
| 968 | goto nla_put_failure; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 969 | } |
| 970 | } |
| 971 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 972 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 973 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 974 | goto nla_put_failure; |
| 975 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 976 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 977 | if (!nl_bands) |
| 978 | goto nla_put_failure; |
| 979 | |
| 980 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 981 | if (!dev->wiphy.bands[band]) |
| 982 | continue; |
| 983 | |
| 984 | nl_band = nla_nest_start(msg, band); |
| 985 | if (!nl_band) |
| 986 | goto nla_put_failure; |
| 987 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 988 | /* add HT info */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 989 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
| 990 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 991 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 992 | &dev->wiphy.bands[band]->ht_cap.mcs) || |
| 993 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 994 | dev->wiphy.bands[band]->ht_cap.cap) || |
| 995 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 996 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || |
| 997 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 998 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) |
| 999 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1000 | |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1001 | /* add VHT info */ |
| 1002 | if (dev->wiphy.bands[band]->vht_cap.vht_supported && |
| 1003 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1004 | sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs), |
| 1005 | &dev->wiphy.bands[band]->vht_cap.vht_mcs) || |
| 1006 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1007 | dev->wiphy.bands[band]->vht_cap.cap))) |
| 1008 | goto nla_put_failure; |
| 1009 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1010 | /* add frequencies */ |
| 1011 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 1012 | if (!nl_freqs) |
| 1013 | goto nla_put_failure; |
| 1014 | |
| 1015 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 1016 | nl_freq = nla_nest_start(msg, i); |
| 1017 | if (!nl_freq) |
| 1018 | goto nla_put_failure; |
| 1019 | |
| 1020 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1021 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1022 | if (nl80211_msg_put_channel(msg, chan)) |
| 1023 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1024 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1025 | nla_nest_end(msg, nl_freq); |
| 1026 | } |
| 1027 | |
| 1028 | nla_nest_end(msg, nl_freqs); |
| 1029 | |
| 1030 | /* add bitrates */ |
| 1031 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1032 | if (!nl_rates) |
| 1033 | goto nla_put_failure; |
| 1034 | |
| 1035 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 1036 | nl_rate = nla_nest_start(msg, i); |
| 1037 | if (!nl_rate) |
| 1038 | goto nla_put_failure; |
| 1039 | |
| 1040 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1041 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1042 | rate->bitrate)) |
| 1043 | goto nla_put_failure; |
| 1044 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1045 | nla_put_flag(msg, |
| 1046 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1047 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1048 | |
| 1049 | nla_nest_end(msg, nl_rate); |
| 1050 | } |
| 1051 | |
| 1052 | nla_nest_end(msg, nl_rates); |
| 1053 | |
| 1054 | nla_nest_end(msg, nl_band); |
| 1055 | } |
| 1056 | nla_nest_end(msg, nl_bands); |
| 1057 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1058 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1059 | if (!nl_cmds) |
| 1060 | goto nla_put_failure; |
| 1061 | |
| 1062 | i = 0; |
| 1063 | #define CMD(op, n) \ |
| 1064 | do { \ |
| 1065 | if (dev->ops->op) { \ |
| 1066 | i++; \ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1067 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1068 | goto nla_put_failure; \ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1069 | } \ |
| 1070 | } while (0) |
| 1071 | |
| 1072 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1073 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1074 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1075 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1076 | CMD(add_station, NEW_STATION); |
| 1077 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 1078 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1079 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1080 | CMD(auth, AUTHENTICATE); |
| 1081 | CMD(assoc, ASSOCIATE); |
| 1082 | CMD(deauth, DEAUTHENTICATE); |
| 1083 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1084 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1085 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1086 | CMD(set_pmksa, SET_PMKSA); |
| 1087 | CMD(del_pmksa, DEL_PMKSA); |
| 1088 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1089 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1090 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 1091 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1092 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1093 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 1094 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1095 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1096 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1097 | goto nla_put_failure; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1098 | } |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1099 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1100 | dev->ops->join_mesh) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1101 | i++; |
| 1102 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1103 | goto nla_put_failure; |
| 1104 | } |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1105 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 1106 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1107 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1108 | CMD(tdls_oper, TDLS_OPER); |
| 1109 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 1110 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1111 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 1112 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1113 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1114 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1115 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1116 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1117 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1118 | } |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1119 | CMD(start_p2p_device, START_P2P_DEVICE); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 1120 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1121 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1122 | #ifdef CONFIG_NL80211_TESTMODE |
| 1123 | CMD(testmode_cmd, TESTMODE); |
| 1124 | #endif |
| 1125 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1126 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1127 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1128 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1129 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1130 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1131 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1132 | } |
| 1133 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1134 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1135 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1136 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1137 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1138 | } |
| 1139 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1140 | nla_nest_end(msg, nl_cmds); |
| 1141 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1142 | if (dev->ops->remain_on_channel && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1143 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1144 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1145 | dev->wiphy.max_remain_on_channel_duration)) |
| 1146 | goto nla_put_failure; |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 1147 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1148 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1149 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1150 | goto nla_put_failure; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1151 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1152 | if (mgmt_stypes) { |
| 1153 | u16 stypes; |
| 1154 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1155 | enum nl80211_iftype ift; |
| 1156 | |
| 1157 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1158 | if (!nl_ifs) |
| 1159 | goto nla_put_failure; |
| 1160 | |
| 1161 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1162 | nl_ftypes = nla_nest_start(msg, ift); |
| 1163 | if (!nl_ftypes) |
| 1164 | goto nla_put_failure; |
| 1165 | i = 0; |
| 1166 | stypes = mgmt_stypes[ift].tx; |
| 1167 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1168 | if ((stypes & 1) && |
| 1169 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1170 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1171 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1172 | stypes >>= 1; |
| 1173 | i++; |
| 1174 | } |
| 1175 | nla_nest_end(msg, nl_ftypes); |
| 1176 | } |
| 1177 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1178 | nla_nest_end(msg, nl_ifs); |
| 1179 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1180 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1181 | if (!nl_ifs) |
| 1182 | goto nla_put_failure; |
| 1183 | |
| 1184 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1185 | nl_ftypes = nla_nest_start(msg, ift); |
| 1186 | if (!nl_ftypes) |
| 1187 | goto nla_put_failure; |
| 1188 | i = 0; |
| 1189 | stypes = mgmt_stypes[ift].rx; |
| 1190 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1191 | if ((stypes & 1) && |
| 1192 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1193 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1194 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1195 | stypes >>= 1; |
| 1196 | i++; |
| 1197 | } |
| 1198 | nla_nest_end(msg, nl_ftypes); |
| 1199 | } |
| 1200 | nla_nest_end(msg, nl_ifs); |
| 1201 | } |
| 1202 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1203 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1204 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 1205 | struct nlattr *nl_wowlan; |
| 1206 | |
| 1207 | nl_wowlan = nla_nest_start(msg, |
| 1208 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1209 | if (!nl_wowlan) |
| 1210 | goto nla_put_failure; |
| 1211 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1212 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 1213 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1214 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1215 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1216 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1217 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1218 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1219 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1220 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1221 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1222 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1223 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1224 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1225 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1226 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1227 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1228 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1229 | if (dev->wiphy.wowlan.n_patterns) { |
| 1230 | struct nl80211_wowlan_pattern_support pat = { |
| 1231 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1232 | .min_pattern_len = |
| 1233 | dev->wiphy.wowlan.pattern_min_len, |
| 1234 | .max_pattern_len = |
| 1235 | dev->wiphy.wowlan.pattern_max_len, |
| 1236 | }; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1237 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1238 | sizeof(pat), &pat)) |
| 1239 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | nla_nest_end(msg, nl_wowlan); |
| 1243 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1244 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1245 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1246 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1247 | dev->wiphy.software_iftypes)) |
| 1248 | goto nla_put_failure; |
| 1249 | |
| 1250 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1251 | goto nla_put_failure; |
| 1252 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1253 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1254 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1255 | dev->wiphy.ap_sme_capa)) |
| 1256 | goto nla_put_failure; |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1257 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1258 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
| 1259 | dev->wiphy.features)) |
| 1260 | goto nla_put_failure; |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1261 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1262 | if (dev->wiphy.ht_capa_mod_mask && |
| 1263 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1264 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1265 | dev->wiphy.ht_capa_mod_mask)) |
| 1266 | goto nla_put_failure; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1267 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1268 | return genlmsg_end(msg, hdr); |
| 1269 | |
| 1270 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1271 | genlmsg_cancel(msg, hdr); |
| 1272 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1276 | { |
| 1277 | int idx = 0; |
| 1278 | int start = cb->args[0]; |
| 1279 | struct cfg80211_registered_device *dev; |
| 1280 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1281 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1282 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1283 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1284 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1285 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1286 | continue; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1287 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1288 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1289 | dev) < 0) { |
| 1290 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1291 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1292 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1293 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1294 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1295 | |
| 1296 | cb->args[0] = idx; |
| 1297 | |
| 1298 | return skb->len; |
| 1299 | } |
| 1300 | |
| 1301 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1302 | { |
| 1303 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1304 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1305 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1306 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1307 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1308 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1309 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1310 | 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] | 1311 | nlmsg_free(msg); |
| 1312 | return -ENOBUFS; |
| 1313 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1314 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1315 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1316 | } |
| 1317 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1318 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1319 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1320 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1321 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1322 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1323 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1324 | }; |
| 1325 | |
| 1326 | static int parse_txq_params(struct nlattr *tb[], |
| 1327 | struct ieee80211_txq_params *txq_params) |
| 1328 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1329 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1330 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1331 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1332 | return -EINVAL; |
| 1333 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1334 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1335 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1336 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1337 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1338 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1339 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1340 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1341 | return -EINVAL; |
| 1342 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1343 | return 0; |
| 1344 | } |
| 1345 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1346 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1347 | { |
| 1348 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1349 | * You can only set the channel explicitly for WDS interfaces, |
| 1350 | * all others have their channel managed via their respective |
| 1351 | * "establish a connection" command (connect, join, ...) |
| 1352 | * |
| 1353 | * For AP/GO and mesh mode, the channel can be set with the |
| 1354 | * channel userspace API, but is only stored and passed to the |
| 1355 | * low-level driver when the AP starts or the mesh is joined. |
| 1356 | * This is for backward compatibility, userspace can also give |
| 1357 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1358 | * |
| 1359 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1360 | * whatever else is going on, so they have their own special |
| 1361 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1362 | */ |
| 1363 | return !wdev || |
| 1364 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1365 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1366 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1367 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1368 | } |
| 1369 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1370 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1371 | struct genl_info *info, |
| 1372 | struct cfg80211_chan_def *chandef) |
| 1373 | { |
| 1374 | struct ieee80211_sta_ht_cap *ht_cap; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1375 | struct ieee80211_sta_vht_cap *vht_cap; |
| 1376 | u32 control_freq, width; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1377 | |
| 1378 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1379 | return -EINVAL; |
| 1380 | |
| 1381 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1382 | |
| 1383 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1384 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1385 | chandef->center_freq1 = control_freq; |
| 1386 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1387 | |
| 1388 | /* Primary channel not allowed */ |
| 1389 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1390 | return -EINVAL; |
| 1391 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1392 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1393 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1394 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1395 | chantype = nla_get_u32( |
| 1396 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1397 | |
| 1398 | switch (chantype) { |
| 1399 | case NL80211_CHAN_NO_HT: |
| 1400 | case NL80211_CHAN_HT20: |
| 1401 | case NL80211_CHAN_HT40PLUS: |
| 1402 | case NL80211_CHAN_HT40MINUS: |
| 1403 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1404 | chantype); |
| 1405 | break; |
| 1406 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1407 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1408 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1409 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1410 | chandef->width = |
| 1411 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1412 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1413 | chandef->center_freq1 = |
| 1414 | nla_get_u32( |
| 1415 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1416 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1417 | chandef->center_freq2 = |
| 1418 | nla_get_u32( |
| 1419 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1420 | } |
| 1421 | |
| 1422 | ht_cap = &rdev->wiphy.bands[chandef->chan->band]->ht_cap; |
| 1423 | vht_cap = &rdev->wiphy.bands[chandef->chan->band]->vht_cap; |
| 1424 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1425 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1426 | return -EINVAL; |
| 1427 | |
| 1428 | switch (chandef->width) { |
| 1429 | case NL80211_CHAN_WIDTH_20: |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1430 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1431 | width = 20; |
| 1432 | break; |
| 1433 | case NL80211_CHAN_WIDTH_40: |
| 1434 | width = 40; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1435 | break; |
| 1436 | case NL80211_CHAN_WIDTH_80: |
| 1437 | width = 80; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1438 | break; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1439 | case NL80211_CHAN_WIDTH_80P80: |
| 1440 | width = 80; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1441 | break; |
| 1442 | case NL80211_CHAN_WIDTH_160: |
| 1443 | width = 160; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1444 | break; |
| 1445 | default: |
| 1446 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1447 | } |
| 1448 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1449 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1450 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1451 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1452 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1453 | return 0; |
| 1454 | } |
| 1455 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1456 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1457 | struct wireless_dev *wdev, |
| 1458 | struct genl_info *info) |
| 1459 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1460 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1461 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1462 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1463 | |
| 1464 | if (wdev) |
| 1465 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1466 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1467 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1468 | return -EOPNOTSUPP; |
| 1469 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1470 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1471 | if (result) |
| 1472 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1473 | |
| 1474 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1475 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1476 | case NL80211_IFTYPE_AP: |
| 1477 | case NL80211_IFTYPE_P2P_GO: |
| 1478 | if (wdev->beacon_interval) { |
| 1479 | result = -EBUSY; |
| 1480 | break; |
| 1481 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1482 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1483 | result = -EINVAL; |
| 1484 | break; |
| 1485 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1486 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1487 | result = 0; |
| 1488 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1489 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1490 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1491 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1492 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1493 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1494 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1495 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1496 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1497 | } |
| 1498 | mutex_unlock(&rdev->devlist_mtx); |
| 1499 | |
| 1500 | return result; |
| 1501 | } |
| 1502 | |
| 1503 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1504 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1505 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1506 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1507 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1508 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1509 | } |
| 1510 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1511 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1512 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1513 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1514 | struct net_device *dev = info->user_ptr[1]; |
| 1515 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1516 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1517 | |
| 1518 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1519 | return -EINVAL; |
| 1520 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1521 | if (netif_running(dev)) |
| 1522 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1523 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1524 | if (!rdev->ops->set_wds_peer) |
| 1525 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1526 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1527 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1528 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1529 | |
| 1530 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1531 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1535 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1536 | { |
| 1537 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1538 | struct net_device *netdev = NULL; |
| 1539 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1540 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1541 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1542 | u32 changed; |
| 1543 | u8 retry_short = 0, retry_long = 0; |
| 1544 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1545 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1546 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1547 | /* |
| 1548 | * Try to find the wiphy and netdev. Normally this |
| 1549 | * function shouldn't need the netdev, but this is |
| 1550 | * done for backward compatibility -- previously |
| 1551 | * setting the channel was done per wiphy, but now |
| 1552 | * it is per netdev. Previous userland like hostapd |
| 1553 | * also passed a netdev to set_wiphy, so that it is |
| 1554 | * possible to let that go to the right netdev! |
| 1555 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1556 | mutex_lock(&cfg80211_mutex); |
| 1557 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1558 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1559 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1560 | |
| 1561 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1562 | if (netdev && netdev->ieee80211_ptr) { |
| 1563 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1564 | mutex_lock(&rdev->mtx); |
| 1565 | } else |
| 1566 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1567 | } |
| 1568 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1569 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1570 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1571 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1572 | if (IS_ERR(rdev)) { |
| 1573 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1574 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1575 | } |
| 1576 | wdev = NULL; |
| 1577 | netdev = NULL; |
| 1578 | result = 0; |
| 1579 | |
| 1580 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1581 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1582 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1583 | |
| 1584 | /* |
| 1585 | * end workaround code, by now the rdev is available |
| 1586 | * and locked, and wdev may or may not be NULL. |
| 1587 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1588 | |
| 1589 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1590 | result = cfg80211_dev_rename( |
| 1591 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1592 | |
| 1593 | mutex_unlock(&cfg80211_mutex); |
| 1594 | |
| 1595 | if (result) |
| 1596 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1597 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1598 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1599 | struct ieee80211_txq_params txq_params; |
| 1600 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1601 | |
| 1602 | if (!rdev->ops->set_txq_params) { |
| 1603 | result = -EOPNOTSUPP; |
| 1604 | goto bad_res; |
| 1605 | } |
| 1606 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1607 | if (!netdev) { |
| 1608 | result = -EINVAL; |
| 1609 | goto bad_res; |
| 1610 | } |
| 1611 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1612 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1613 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1614 | result = -EINVAL; |
| 1615 | goto bad_res; |
| 1616 | } |
| 1617 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1618 | if (!netif_running(netdev)) { |
| 1619 | result = -ENETDOWN; |
| 1620 | goto bad_res; |
| 1621 | } |
| 1622 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1623 | nla_for_each_nested(nl_txq_params, |
| 1624 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1625 | rem_txq_params) { |
| 1626 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1627 | nla_data(nl_txq_params), |
| 1628 | nla_len(nl_txq_params), |
| 1629 | txq_params_policy); |
| 1630 | result = parse_txq_params(tb, &txq_params); |
| 1631 | if (result) |
| 1632 | goto bad_res; |
| 1633 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1634 | result = rdev_set_txq_params(rdev, netdev, |
| 1635 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1636 | if (result) |
| 1637 | goto bad_res; |
| 1638 | } |
| 1639 | } |
| 1640 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1641 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1642 | result = __nl80211_set_channel(rdev, |
| 1643 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1644 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1645 | if (result) |
| 1646 | goto bad_res; |
| 1647 | } |
| 1648 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1649 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1650 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1651 | enum nl80211_tx_power_setting type; |
| 1652 | int idx, mbm = 0; |
| 1653 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1654 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1655 | txp_wdev = NULL; |
| 1656 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1657 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1658 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1659 | goto bad_res; |
| 1660 | } |
| 1661 | |
| 1662 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1663 | type = nla_get_u32(info->attrs[idx]); |
| 1664 | |
| 1665 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1666 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1667 | result = -EINVAL; |
| 1668 | goto bad_res; |
| 1669 | } |
| 1670 | |
| 1671 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1672 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1673 | mbm = nla_get_u32(info->attrs[idx]); |
| 1674 | } |
| 1675 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1676 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1677 | if (result) |
| 1678 | goto bad_res; |
| 1679 | } |
| 1680 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1681 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1682 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1683 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1684 | if ((!rdev->wiphy.available_antennas_tx && |
| 1685 | !rdev->wiphy.available_antennas_rx) || |
| 1686 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1687 | result = -EOPNOTSUPP; |
| 1688 | goto bad_res; |
| 1689 | } |
| 1690 | |
| 1691 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1692 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1693 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1694 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1695 | * available antenna masks, except for the "all" mask */ |
| 1696 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1697 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1698 | result = -EINVAL; |
| 1699 | goto bad_res; |
| 1700 | } |
| 1701 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1702 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1703 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1704 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1705 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1706 | if (result) |
| 1707 | goto bad_res; |
| 1708 | } |
| 1709 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1710 | changed = 0; |
| 1711 | |
| 1712 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1713 | retry_short = nla_get_u8( |
| 1714 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1715 | if (retry_short == 0) { |
| 1716 | result = -EINVAL; |
| 1717 | goto bad_res; |
| 1718 | } |
| 1719 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1720 | } |
| 1721 | |
| 1722 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1723 | retry_long = nla_get_u8( |
| 1724 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1725 | if (retry_long == 0) { |
| 1726 | result = -EINVAL; |
| 1727 | goto bad_res; |
| 1728 | } |
| 1729 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1730 | } |
| 1731 | |
| 1732 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1733 | frag_threshold = nla_get_u32( |
| 1734 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1735 | if (frag_threshold < 256) { |
| 1736 | result = -EINVAL; |
| 1737 | goto bad_res; |
| 1738 | } |
| 1739 | if (frag_threshold != (u32) -1) { |
| 1740 | /* |
| 1741 | * Fragments (apart from the last one) are required to |
| 1742 | * have even length. Make the fragmentation code |
| 1743 | * simpler by stripping LSB should someone try to use |
| 1744 | * odd threshold value. |
| 1745 | */ |
| 1746 | frag_threshold &= ~0x1; |
| 1747 | } |
| 1748 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1749 | } |
| 1750 | |
| 1751 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1752 | rts_threshold = nla_get_u32( |
| 1753 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1754 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1755 | } |
| 1756 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1757 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1758 | coverage_class = nla_get_u8( |
| 1759 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1760 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1761 | } |
| 1762 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1763 | if (changed) { |
| 1764 | u8 old_retry_short, old_retry_long; |
| 1765 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1766 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1767 | |
| 1768 | if (!rdev->ops->set_wiphy_params) { |
| 1769 | result = -EOPNOTSUPP; |
| 1770 | goto bad_res; |
| 1771 | } |
| 1772 | |
| 1773 | old_retry_short = rdev->wiphy.retry_short; |
| 1774 | old_retry_long = rdev->wiphy.retry_long; |
| 1775 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1776 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1777 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1778 | |
| 1779 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1780 | rdev->wiphy.retry_short = retry_short; |
| 1781 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1782 | rdev->wiphy.retry_long = retry_long; |
| 1783 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1784 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1785 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1786 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1787 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1788 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1789 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1790 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1791 | if (result) { |
| 1792 | rdev->wiphy.retry_short = old_retry_short; |
| 1793 | rdev->wiphy.retry_long = old_retry_long; |
| 1794 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1795 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1796 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1797 | } |
| 1798 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1799 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1800 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1801 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1802 | if (netdev) |
| 1803 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1804 | return result; |
| 1805 | } |
| 1806 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1807 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1808 | { |
| 1809 | return (u64)wdev->identifier | |
| 1810 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1811 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1812 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1813 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 1814 | struct cfg80211_chan_def *chandef) |
| 1815 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1816 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1817 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1818 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1819 | chandef->chan->center_freq)) |
| 1820 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1821 | switch (chandef->width) { |
| 1822 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1823 | case NL80211_CHAN_WIDTH_20: |
| 1824 | case NL80211_CHAN_WIDTH_40: |
| 1825 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1826 | cfg80211_get_chandef_type(chandef))) |
| 1827 | return -ENOBUFS; |
| 1828 | break; |
| 1829 | default: |
| 1830 | break; |
| 1831 | } |
| 1832 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 1833 | return -ENOBUFS; |
| 1834 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 1835 | return -ENOBUFS; |
| 1836 | if (chandef->center_freq2 && |
| 1837 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1838 | return -ENOBUFS; |
| 1839 | return 0; |
| 1840 | } |
| 1841 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1842 | 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] | 1843 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1844 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1845 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1846 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1847 | void *hdr; |
| 1848 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1849 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1850 | if (!hdr) |
| 1851 | return -1; |
| 1852 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1853 | if (dev && |
| 1854 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1855 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1856 | goto nla_put_failure; |
| 1857 | |
| 1858 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1859 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1860 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1861 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1862 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1863 | rdev->devlist_generation ^ |
| 1864 | (cfg80211_rdev_list_generation << 2))) |
| 1865 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1866 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1867 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1868 | int ret; |
| 1869 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1870 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1871 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 1872 | if (ret == 0) { |
| 1873 | if (nl80211_send_chandef(msg, &chandef)) |
| 1874 | goto nla_put_failure; |
| 1875 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1876 | } |
| 1877 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 1878 | if (wdev->ssid_len) { |
| 1879 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 1880 | goto nla_put_failure; |
| 1881 | } |
| 1882 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1883 | return genlmsg_end(msg, hdr); |
| 1884 | |
| 1885 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1886 | genlmsg_cancel(msg, hdr); |
| 1887 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1891 | { |
| 1892 | int wp_idx = 0; |
| 1893 | int if_idx = 0; |
| 1894 | int wp_start = cb->args[0]; |
| 1895 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1896 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1897 | struct wireless_dev *wdev; |
| 1898 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1899 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1900 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1901 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1902 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1903 | if (wp_idx < wp_start) { |
| 1904 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1905 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1906 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1907 | if_idx = 0; |
| 1908 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1909 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1910 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1911 | if (if_idx < if_start) { |
| 1912 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1913 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1914 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1915 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1916 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1917 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1918 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1919 | goto out; |
| 1920 | } |
| 1921 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1922 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1923 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1924 | |
| 1925 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1926 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1927 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1928 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1929 | |
| 1930 | cb->args[0] = wp_idx; |
| 1931 | cb->args[1] = if_idx; |
| 1932 | |
| 1933 | return skb->len; |
| 1934 | } |
| 1935 | |
| 1936 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1937 | { |
| 1938 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1939 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1940 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1941 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1942 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1943 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1944 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1945 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1946 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1947 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1948 | nlmsg_free(msg); |
| 1949 | return -ENOBUFS; |
| 1950 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1951 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1952 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1953 | } |
| 1954 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1955 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1956 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1957 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1958 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1959 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1960 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1961 | }; |
| 1962 | |
| 1963 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1964 | { |
| 1965 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1966 | int flag; |
| 1967 | |
| 1968 | *mntrflags = 0; |
| 1969 | |
| 1970 | if (!nla) |
| 1971 | return -EINVAL; |
| 1972 | |
| 1973 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1974 | nla, mntr_flags_policy)) |
| 1975 | return -EINVAL; |
| 1976 | |
| 1977 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1978 | if (flags[flag]) |
| 1979 | *mntrflags |= (1<<flag); |
| 1980 | |
| 1981 | return 0; |
| 1982 | } |
| 1983 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1984 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1985 | struct net_device *netdev, u8 use_4addr, |
| 1986 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1987 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1988 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1989 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1990 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1991 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1992 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1993 | |
| 1994 | switch (iftype) { |
| 1995 | case NL80211_IFTYPE_AP_VLAN: |
| 1996 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1997 | return 0; |
| 1998 | break; |
| 1999 | case NL80211_IFTYPE_STATION: |
| 2000 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2001 | return 0; |
| 2002 | break; |
| 2003 | default: |
| 2004 | break; |
| 2005 | } |
| 2006 | |
| 2007 | return -EOPNOTSUPP; |
| 2008 | } |
| 2009 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2010 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2011 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2012 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2013 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2014 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2015 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2016 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2017 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2018 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2019 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2020 | memset(¶ms, 0, sizeof(params)); |
| 2021 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2022 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2023 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2024 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2025 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2026 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2027 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2028 | if (ntype > NL80211_IFTYPE_MAX) |
| 2029 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2030 | } |
| 2031 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2032 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2033 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2034 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2035 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2036 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2037 | if (netif_running(dev)) |
| 2038 | return -EBUSY; |
| 2039 | |
| 2040 | wdev_lock(wdev); |
| 2041 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2042 | IEEE80211_MAX_MESH_ID_LEN); |
| 2043 | wdev->mesh_id_up_len = |
| 2044 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2045 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2046 | wdev->mesh_id_up_len); |
| 2047 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2048 | } |
| 2049 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2050 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2051 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2052 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2053 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2054 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2055 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2056 | } else { |
| 2057 | params.use_4addr = -1; |
| 2058 | } |
| 2059 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2060 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2061 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2062 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2063 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2064 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2065 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2066 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2067 | |
| 2068 | flags = &_flags; |
| 2069 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2070 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2071 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2072 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2073 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2074 | else |
| 2075 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2076 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2077 | if (!err && params.use_4addr != -1) |
| 2078 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2079 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2080 | return err; |
| 2081 | } |
| 2082 | |
| 2083 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2084 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2085 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2086 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2087 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2088 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2089 | int err; |
| 2090 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2091 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2092 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2093 | memset(¶ms, 0, sizeof(params)); |
| 2094 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2095 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2096 | return -EINVAL; |
| 2097 | |
| 2098 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2099 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2100 | if (type > NL80211_IFTYPE_MAX) |
| 2101 | return -EINVAL; |
| 2102 | } |
| 2103 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2104 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2105 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2106 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2107 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2108 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2109 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2110 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2111 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2112 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2113 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2114 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2115 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2116 | if (!msg) |
| 2117 | return -ENOMEM; |
| 2118 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2119 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2120 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2121 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2122 | wdev = rdev_add_virtual_intf(rdev, |
| 2123 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2124 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2125 | if (IS_ERR(wdev)) { |
| 2126 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2127 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2128 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2129 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2130 | switch (type) { |
| 2131 | case NL80211_IFTYPE_MESH_POINT: |
| 2132 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2133 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2134 | wdev_lock(wdev); |
| 2135 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2136 | IEEE80211_MAX_MESH_ID_LEN); |
| 2137 | wdev->mesh_id_up_len = |
| 2138 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2139 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2140 | wdev->mesh_id_up_len); |
| 2141 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2142 | break; |
| 2143 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2144 | /* |
| 2145 | * P2P Device doesn't have a netdev, so doesn't go |
| 2146 | * through the netdev notifier and must be added here |
| 2147 | */ |
| 2148 | mutex_init(&wdev->mtx); |
| 2149 | INIT_LIST_HEAD(&wdev->event_list); |
| 2150 | spin_lock_init(&wdev->event_lock); |
| 2151 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2152 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2153 | |
| 2154 | mutex_lock(&rdev->devlist_mtx); |
| 2155 | wdev->identifier = ++rdev->wdev_id; |
| 2156 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2157 | rdev->devlist_generation++; |
| 2158 | mutex_unlock(&rdev->devlist_mtx); |
| 2159 | break; |
| 2160 | default: |
| 2161 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2162 | } |
| 2163 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2164 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2165 | rdev, wdev) < 0) { |
| 2166 | nlmsg_free(msg); |
| 2167 | return -ENOBUFS; |
| 2168 | } |
| 2169 | |
| 2170 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2174 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2175 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2176 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2177 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2178 | if (!rdev->ops->del_virtual_intf) |
| 2179 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2180 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2181 | /* |
| 2182 | * If we remove a wireless device without a netdev then clear |
| 2183 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2184 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2185 | * since the wdev has been freed, unlike with a netdev where |
| 2186 | * we need the dev_put() for the netdev to really be freed. |
| 2187 | */ |
| 2188 | if (!wdev->netdev) |
| 2189 | info->user_ptr[1] = NULL; |
| 2190 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2191 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2192 | } |
| 2193 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2194 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2195 | { |
| 2196 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2197 | struct net_device *dev = info->user_ptr[1]; |
| 2198 | u16 noack_map; |
| 2199 | |
| 2200 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2201 | return -EINVAL; |
| 2202 | |
| 2203 | if (!rdev->ops->set_noack_map) |
| 2204 | return -EOPNOTSUPP; |
| 2205 | |
| 2206 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2207 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2208 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2209 | } |
| 2210 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2211 | struct get_key_cookie { |
| 2212 | struct sk_buff *msg; |
| 2213 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2214 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2215 | }; |
| 2216 | |
| 2217 | static void get_key_callback(void *c, struct key_params *params) |
| 2218 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2219 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2220 | struct get_key_cookie *cookie = c; |
| 2221 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2222 | if ((params->key && |
| 2223 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2224 | params->key_len, params->key)) || |
| 2225 | (params->seq && |
| 2226 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2227 | params->seq_len, params->seq)) || |
| 2228 | (params->cipher && |
| 2229 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2230 | params->cipher))) |
| 2231 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2232 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2233 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2234 | if (!key) |
| 2235 | goto nla_put_failure; |
| 2236 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2237 | if ((params->key && |
| 2238 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2239 | params->key_len, params->key)) || |
| 2240 | (params->seq && |
| 2241 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2242 | params->seq_len, params->seq)) || |
| 2243 | (params->cipher && |
| 2244 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2245 | params->cipher))) |
| 2246 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2247 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2248 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2249 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2250 | |
| 2251 | nla_nest_end(cookie->msg, key); |
| 2252 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2253 | return; |
| 2254 | nla_put_failure: |
| 2255 | cookie->error = 1; |
| 2256 | } |
| 2257 | |
| 2258 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2259 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2260 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2261 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2262 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2263 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2264 | const u8 *mac_addr = NULL; |
| 2265 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2266 | struct get_key_cookie cookie = { |
| 2267 | .error = 0, |
| 2268 | }; |
| 2269 | void *hdr; |
| 2270 | struct sk_buff *msg; |
| 2271 | |
| 2272 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2273 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2274 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2275 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2276 | return -EINVAL; |
| 2277 | |
| 2278 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2279 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2280 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2281 | pairwise = !!mac_addr; |
| 2282 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2283 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2284 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2285 | return -EINVAL; |
| 2286 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2287 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2288 | return -EINVAL; |
| 2289 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2290 | } |
| 2291 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2292 | if (!rdev->ops->get_key) |
| 2293 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2294 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2295 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2296 | if (!msg) |
| 2297 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2298 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2299 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2300 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2301 | if (IS_ERR(hdr)) |
| 2302 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2303 | |
| 2304 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2305 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2306 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2307 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2308 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2309 | goto nla_put_failure; |
| 2310 | if (mac_addr && |
| 2311 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2312 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2313 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2314 | if (pairwise && mac_addr && |
| 2315 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2316 | return -ENOENT; |
| 2317 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2318 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2319 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2320 | |
| 2321 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2322 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2323 | |
| 2324 | if (cookie.error) |
| 2325 | goto nla_put_failure; |
| 2326 | |
| 2327 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2328 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2329 | |
| 2330 | nla_put_failure: |
| 2331 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2332 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2333 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2334 | return err; |
| 2335 | } |
| 2336 | |
| 2337 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2338 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2339 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2340 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2341 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2342 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2343 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2344 | err = nl80211_parse_key(info, &key); |
| 2345 | if (err) |
| 2346 | return err; |
| 2347 | |
| 2348 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2349 | return -EINVAL; |
| 2350 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2351 | /* only support setting default key */ |
| 2352 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2353 | return -EINVAL; |
| 2354 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2355 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2356 | |
| 2357 | if (key.def) { |
| 2358 | if (!rdev->ops->set_default_key) { |
| 2359 | err = -EOPNOTSUPP; |
| 2360 | goto out; |
| 2361 | } |
| 2362 | |
| 2363 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2364 | if (err) |
| 2365 | goto out; |
| 2366 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2367 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2368 | key.def_uni, key.def_multi); |
| 2369 | |
| 2370 | if (err) |
| 2371 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2372 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2373 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2374 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2375 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2376 | } else { |
| 2377 | if (key.def_uni || !key.def_multi) { |
| 2378 | err = -EINVAL; |
| 2379 | goto out; |
| 2380 | } |
| 2381 | |
| 2382 | if (!rdev->ops->set_default_mgmt_key) { |
| 2383 | err = -EOPNOTSUPP; |
| 2384 | goto out; |
| 2385 | } |
| 2386 | |
| 2387 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2388 | if (err) |
| 2389 | goto out; |
| 2390 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2391 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2392 | if (err) |
| 2393 | goto out; |
| 2394 | |
| 2395 | #ifdef CONFIG_CFG80211_WEXT |
| 2396 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2397 | #endif |
| 2398 | } |
| 2399 | |
| 2400 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2401 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2402 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2403 | return err; |
| 2404 | } |
| 2405 | |
| 2406 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2407 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2408 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2409 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2410 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2411 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2412 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2413 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2414 | err = nl80211_parse_key(info, &key); |
| 2415 | if (err) |
| 2416 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2417 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2418 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2419 | return -EINVAL; |
| 2420 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2421 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2422 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2423 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2424 | if (key.type == -1) { |
| 2425 | if (mac_addr) |
| 2426 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2427 | else |
| 2428 | key.type = NL80211_KEYTYPE_GROUP; |
| 2429 | } |
| 2430 | |
| 2431 | /* for now */ |
| 2432 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2433 | key.type != NL80211_KEYTYPE_GROUP) |
| 2434 | return -EINVAL; |
| 2435 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2436 | if (!rdev->ops->add_key) |
| 2437 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2438 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2439 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2440 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2441 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2442 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2443 | |
| 2444 | wdev_lock(dev->ieee80211_ptr); |
| 2445 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2446 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2447 | err = rdev_add_key(rdev, dev, key.idx, |
| 2448 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2449 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2450 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2451 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2452 | return err; |
| 2453 | } |
| 2454 | |
| 2455 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2456 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2457 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2458 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2459 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2460 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2461 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2462 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2463 | err = nl80211_parse_key(info, &key); |
| 2464 | if (err) |
| 2465 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2466 | |
| 2467 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2468 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2469 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2470 | if (key.type == -1) { |
| 2471 | if (mac_addr) |
| 2472 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2473 | else |
| 2474 | key.type = NL80211_KEYTYPE_GROUP; |
| 2475 | } |
| 2476 | |
| 2477 | /* for now */ |
| 2478 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2479 | key.type != NL80211_KEYTYPE_GROUP) |
| 2480 | return -EINVAL; |
| 2481 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2482 | if (!rdev->ops->del_key) |
| 2483 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2484 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2485 | wdev_lock(dev->ieee80211_ptr); |
| 2486 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2487 | |
| 2488 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2489 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2490 | err = -ENOENT; |
| 2491 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2492 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2493 | err = rdev_del_key(rdev, dev, key.idx, |
| 2494 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2495 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2496 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2497 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2498 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2499 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2500 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2501 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2502 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2503 | } |
| 2504 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2505 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2506 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2507 | return err; |
| 2508 | } |
| 2509 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2510 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2511 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2512 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2513 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2514 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2515 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2516 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2517 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2518 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2519 | return -EINVAL; |
| 2520 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2521 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2522 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2523 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2524 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2525 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2526 | if (!bcn->head_len) |
| 2527 | return -EINVAL; |
| 2528 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2529 | } |
| 2530 | |
| 2531 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2532 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2533 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2534 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2535 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2536 | } |
| 2537 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2538 | if (!haveinfo) |
| 2539 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2540 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2541 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2542 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2543 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2547 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2548 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2549 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2550 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2551 | } |
| 2552 | |
| 2553 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2554 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2555 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2556 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2557 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2558 | } |
| 2559 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2560 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2561 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2562 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2563 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2564 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2565 | } |
| 2566 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2567 | return 0; |
| 2568 | } |
| 2569 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2570 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2571 | struct cfg80211_ap_settings *params) |
| 2572 | { |
| 2573 | struct wireless_dev *wdev; |
| 2574 | bool ret = false; |
| 2575 | |
| 2576 | mutex_lock(&rdev->devlist_mtx); |
| 2577 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2578 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2579 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2580 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2581 | continue; |
| 2582 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2583 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2584 | continue; |
| 2585 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2586 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2587 | ret = true; |
| 2588 | break; |
| 2589 | } |
| 2590 | |
| 2591 | mutex_unlock(&rdev->devlist_mtx); |
| 2592 | |
| 2593 | return ret; |
| 2594 | } |
| 2595 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2596 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2597 | enum nl80211_auth_type auth_type, |
| 2598 | enum nl80211_commands cmd) |
| 2599 | { |
| 2600 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2601 | return false; |
| 2602 | |
| 2603 | switch (cmd) { |
| 2604 | case NL80211_CMD_AUTHENTICATE: |
| 2605 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2606 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2607 | return false; |
| 2608 | return true; |
| 2609 | case NL80211_CMD_CONNECT: |
| 2610 | case NL80211_CMD_START_AP: |
| 2611 | /* SAE not supported yet */ |
| 2612 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2613 | return false; |
| 2614 | return true; |
| 2615 | default: |
| 2616 | return false; |
| 2617 | } |
| 2618 | } |
| 2619 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2620 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2621 | { |
| 2622 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2623 | struct net_device *dev = info->user_ptr[1]; |
| 2624 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2625 | struct cfg80211_ap_settings params; |
| 2626 | int err; |
| 2627 | |
| 2628 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2629 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2630 | return -EOPNOTSUPP; |
| 2631 | |
| 2632 | if (!rdev->ops->start_ap) |
| 2633 | return -EOPNOTSUPP; |
| 2634 | |
| 2635 | if (wdev->beacon_interval) |
| 2636 | return -EALREADY; |
| 2637 | |
| 2638 | memset(¶ms, 0, sizeof(params)); |
| 2639 | |
| 2640 | /* these are required for START_AP */ |
| 2641 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2642 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2643 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2644 | return -EINVAL; |
| 2645 | |
| 2646 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2647 | if (err) |
| 2648 | return err; |
| 2649 | |
| 2650 | params.beacon_interval = |
| 2651 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2652 | params.dtim_period = |
| 2653 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2654 | |
| 2655 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2656 | if (err) |
| 2657 | return err; |
| 2658 | |
| 2659 | /* |
| 2660 | * In theory, some of these attributes should be required here |
| 2661 | * but since they were not used when the command was originally |
| 2662 | * added, keep them optional for old user space programs to let |
| 2663 | * them continue to work with drivers that do not need the |
| 2664 | * additional information -- drivers must check! |
| 2665 | */ |
| 2666 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2667 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2668 | params.ssid_len = |
| 2669 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2670 | if (params.ssid_len == 0 || |
| 2671 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2672 | return -EINVAL; |
| 2673 | } |
| 2674 | |
| 2675 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2676 | params.hidden_ssid = nla_get_u32( |
| 2677 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2678 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2679 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2680 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2681 | return -EINVAL; |
| 2682 | } |
| 2683 | |
| 2684 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2685 | |
| 2686 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2687 | params.auth_type = nla_get_u32( |
| 2688 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2689 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 2690 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2691 | return -EINVAL; |
| 2692 | } else |
| 2693 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2694 | |
| 2695 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2696 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2697 | if (err) |
| 2698 | return err; |
| 2699 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2700 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2701 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2702 | return -EOPNOTSUPP; |
| 2703 | params.inactivity_timeout = nla_get_u16( |
| 2704 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2705 | } |
| 2706 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 2707 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 2708 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2709 | return -EINVAL; |
| 2710 | params.p2p_ctwindow = |
| 2711 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 2712 | if (params.p2p_ctwindow > 127) |
| 2713 | return -EINVAL; |
| 2714 | if (params.p2p_ctwindow != 0 && |
| 2715 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 2716 | return -EINVAL; |
| 2717 | } |
| 2718 | |
| 2719 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 2720 | u8 tmp; |
| 2721 | |
| 2722 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2723 | return -EINVAL; |
| 2724 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 2725 | if (tmp > 1) |
| 2726 | return -EINVAL; |
| 2727 | params.p2p_opp_ps = tmp; |
| 2728 | if (params.p2p_opp_ps != 0 && |
| 2729 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 2730 | return -EINVAL; |
| 2731 | } |
| 2732 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2733 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2734 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 2735 | if (err) |
| 2736 | return err; |
| 2737 | } else if (wdev->preset_chandef.chan) { |
| 2738 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2739 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2740 | return -EINVAL; |
| 2741 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2742 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2743 | return -EINVAL; |
| 2744 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2745 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2746 | err = cfg80211_can_use_chan(rdev, wdev, params.chandef.chan, |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2747 | CHAN_MODE_SHARED); |
| 2748 | mutex_unlock(&rdev->devlist_mtx); |
| 2749 | |
| 2750 | if (err) |
| 2751 | return err; |
| 2752 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2753 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2754 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2755 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2756 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2757 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 2758 | wdev->ssid_len = params.ssid_len; |
| 2759 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2760 | } |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2761 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2762 | } |
| 2763 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2764 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2765 | { |
| 2766 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2767 | struct net_device *dev = info->user_ptr[1]; |
| 2768 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2769 | struct cfg80211_beacon_data params; |
| 2770 | int err; |
| 2771 | |
| 2772 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2773 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2774 | return -EOPNOTSUPP; |
| 2775 | |
| 2776 | if (!rdev->ops->change_beacon) |
| 2777 | return -EOPNOTSUPP; |
| 2778 | |
| 2779 | if (!wdev->beacon_interval) |
| 2780 | return -EINVAL; |
| 2781 | |
| 2782 | err = nl80211_parse_beacon(info, ¶ms); |
| 2783 | if (err) |
| 2784 | return err; |
| 2785 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2786 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | 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] | 2790 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2791 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2792 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2793 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2794 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2795 | } |
| 2796 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2797 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2798 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2799 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2800 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2801 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2802 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2803 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2804 | }; |
| 2805 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2806 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2807 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2808 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2809 | { |
| 2810 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2811 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2812 | int flag; |
| 2813 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2814 | /* |
| 2815 | * Try parsing the new attribute first so userspace |
| 2816 | * can specify both for older kernels. |
| 2817 | */ |
| 2818 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2819 | if (nla) { |
| 2820 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2821 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2822 | sta_flags = nla_data(nla); |
| 2823 | params->sta_flags_mask = sta_flags->mask; |
| 2824 | params->sta_flags_set = sta_flags->set; |
| 2825 | if ((params->sta_flags_mask | |
| 2826 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2827 | return -EINVAL; |
| 2828 | return 0; |
| 2829 | } |
| 2830 | |
| 2831 | /* if present, parse the old attribute */ |
| 2832 | |
| 2833 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2834 | if (!nla) |
| 2835 | return 0; |
| 2836 | |
| 2837 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2838 | nla, sta_flags_policy)) |
| 2839 | return -EINVAL; |
| 2840 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2841 | /* |
| 2842 | * Only allow certain flags for interface types so that |
| 2843 | * other attributes are silently ignored. Remember that |
| 2844 | * this is backward compatibility code with old userspace |
| 2845 | * and shouldn't be hit in other cases anyway. |
| 2846 | */ |
| 2847 | switch (iftype) { |
| 2848 | case NL80211_IFTYPE_AP: |
| 2849 | case NL80211_IFTYPE_AP_VLAN: |
| 2850 | case NL80211_IFTYPE_P2P_GO: |
| 2851 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2852 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2853 | BIT(NL80211_STA_FLAG_WME) | |
| 2854 | BIT(NL80211_STA_FLAG_MFP); |
| 2855 | break; |
| 2856 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2857 | case NL80211_IFTYPE_STATION: |
| 2858 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2859 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2860 | break; |
| 2861 | case NL80211_IFTYPE_MESH_POINT: |
| 2862 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2863 | BIT(NL80211_STA_FLAG_MFP) | |
| 2864 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2865 | default: |
| 2866 | return -EINVAL; |
| 2867 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2868 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2869 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 2870 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2871 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2872 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2873 | /* no longer support new API additions in old API */ |
| 2874 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 2875 | return -EINVAL; |
| 2876 | } |
| 2877 | } |
| 2878 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2879 | return 0; |
| 2880 | } |
| 2881 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2882 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2883 | int attr) |
| 2884 | { |
| 2885 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2886 | u32 bitrate; |
| 2887 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2888 | |
| 2889 | rate = nla_nest_start(msg, attr); |
| 2890 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 2891 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2892 | |
| 2893 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2894 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2895 | /* report 16-bit bitrate only if we can */ |
| 2896 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 2897 | if (bitrate > 0 && |
| 2898 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 2899 | return false; |
| 2900 | if (bitrate_compat > 0 && |
| 2901 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 2902 | return false; |
| 2903 | |
| 2904 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 2905 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 2906 | return false; |
| 2907 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 2908 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 2909 | return false; |
| 2910 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 2911 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 2912 | return false; |
| 2913 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 2914 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 2915 | return false; |
| 2916 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 2917 | return false; |
| 2918 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 2919 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 2920 | return false; |
| 2921 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 2922 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 2923 | return false; |
| 2924 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 2925 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 2926 | return false; |
| 2927 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 2928 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 2929 | return false; |
| 2930 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 2931 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 2932 | return false; |
| 2933 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2934 | |
| 2935 | nla_nest_end(msg, rate); |
| 2936 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2937 | } |
| 2938 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2939 | 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] | 2940 | int flags, |
| 2941 | struct cfg80211_registered_device *rdev, |
| 2942 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2943 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2944 | { |
| 2945 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2946 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2947 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2948 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2949 | if (!hdr) |
| 2950 | return -1; |
| 2951 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2952 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2953 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 2954 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 2955 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2956 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2957 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2958 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2959 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2960 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 2961 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2962 | sinfo->connected_time)) |
| 2963 | goto nla_put_failure; |
| 2964 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 2965 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2966 | sinfo->inactive_time)) |
| 2967 | goto nla_put_failure; |
| 2968 | if ((sinfo->filled & STATION_INFO_RX_BYTES) && |
| 2969 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2970 | sinfo->rx_bytes)) |
| 2971 | goto nla_put_failure; |
| 2972 | if ((sinfo->filled & STATION_INFO_TX_BYTES) && |
| 2973 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2974 | sinfo->tx_bytes)) |
| 2975 | goto nla_put_failure; |
| 2976 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 2977 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 2978 | goto nla_put_failure; |
| 2979 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 2980 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 2981 | goto nla_put_failure; |
| 2982 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 2983 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2984 | sinfo->plink_state)) |
| 2985 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2986 | switch (rdev->wiphy.signal_type) { |
| 2987 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2988 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 2989 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 2990 | sinfo->signal)) |
| 2991 | goto nla_put_failure; |
| 2992 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 2993 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2994 | sinfo->signal_avg)) |
| 2995 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2996 | break; |
| 2997 | default: |
| 2998 | break; |
| 2999 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3000 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3001 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3002 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3003 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3004 | } |
| 3005 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3006 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3007 | NL80211_STA_INFO_RX_BITRATE)) |
| 3008 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3009 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3010 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3011 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3012 | sinfo->rx_packets)) |
| 3013 | goto nla_put_failure; |
| 3014 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3015 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3016 | sinfo->tx_packets)) |
| 3017 | goto nla_put_failure; |
| 3018 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3019 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3020 | sinfo->tx_retries)) |
| 3021 | goto nla_put_failure; |
| 3022 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3023 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3024 | sinfo->tx_failed)) |
| 3025 | goto nla_put_failure; |
| 3026 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3027 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3028 | sinfo->beacon_loss_count)) |
| 3029 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3030 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3031 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3032 | if (!bss_param) |
| 3033 | goto nla_put_failure; |
| 3034 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3035 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3036 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3037 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3038 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3039 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3040 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3041 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3042 | sinfo->bss_param.dtim_period) || |
| 3043 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3044 | sinfo->bss_param.beacon_interval)) |
| 3045 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3046 | |
| 3047 | nla_nest_end(msg, bss_param); |
| 3048 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3049 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3050 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3051 | sizeof(struct nl80211_sta_flag_update), |
| 3052 | &sinfo->sta_flags)) |
| 3053 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3054 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3055 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3056 | sinfo->t_offset)) |
| 3057 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3058 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3059 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3060 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3061 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3062 | sinfo->assoc_req_ies)) |
| 3063 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3064 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3065 | return genlmsg_end(msg, hdr); |
| 3066 | |
| 3067 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3068 | genlmsg_cancel(msg, hdr); |
| 3069 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3070 | } |
| 3071 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3072 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3073 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3074 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3075 | struct station_info sinfo; |
| 3076 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3077 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3078 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3079 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3080 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3081 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3082 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3083 | if (err) |
| 3084 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3085 | |
| 3086 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3087 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3088 | goto out_err; |
| 3089 | } |
| 3090 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3091 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3092 | memset(&sinfo, 0, sizeof(sinfo)); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3093 | err = rdev_dump_station(dev, netdev, sta_idx, |
| 3094 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3095 | if (err == -ENOENT) |
| 3096 | break; |
| 3097 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3098 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3099 | |
| 3100 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3101 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3102 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3103 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3104 | &sinfo) < 0) |
| 3105 | goto out; |
| 3106 | |
| 3107 | sta_idx++; |
| 3108 | } |
| 3109 | |
| 3110 | |
| 3111 | out: |
| 3112 | cb->args[1] = sta_idx; |
| 3113 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3114 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3115 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3116 | |
| 3117 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3118 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3119 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3120 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3121 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3122 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3123 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3124 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3125 | struct sk_buff *msg; |
| 3126 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3127 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3128 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3129 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3130 | |
| 3131 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3132 | return -EINVAL; |
| 3133 | |
| 3134 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3135 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3136 | if (!rdev->ops->get_station) |
| 3137 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3138 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3139 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3140 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3141 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3142 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3143 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3144 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3145 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3146 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3147 | 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] | 3148 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3149 | nlmsg_free(msg); |
| 3150 | return -ENOBUFS; |
| 3151 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3152 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3153 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3157 | * 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] | 3158 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3159 | static struct net_device *get_vlan(struct genl_info *info, |
| 3160 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3161 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3162 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3163 | struct net_device *v; |
| 3164 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3165 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3166 | if (!vlanattr) |
| 3167 | return NULL; |
| 3168 | |
| 3169 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3170 | if (!v) |
| 3171 | return ERR_PTR(-ENODEV); |
| 3172 | |
| 3173 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3174 | ret = -EINVAL; |
| 3175 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3176 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3177 | |
| 3178 | if (!netif_running(v)) { |
| 3179 | ret = -ENETDOWN; |
| 3180 | goto error; |
| 3181 | } |
| 3182 | |
| 3183 | return v; |
| 3184 | error: |
| 3185 | dev_put(v); |
| 3186 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3190 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3191 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3192 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3193 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3194 | struct station_parameters params; |
| 3195 | u8 *mac_addr = NULL; |
| 3196 | |
| 3197 | memset(¶ms, 0, sizeof(params)); |
| 3198 | |
| 3199 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 3200 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3201 | |
| 3202 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3203 | return -EINVAL; |
| 3204 | |
| 3205 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3206 | return -EINVAL; |
| 3207 | |
| 3208 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3209 | |
| 3210 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3211 | params.supported_rates = |
| 3212 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3213 | params.supported_rates_len = |
| 3214 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3215 | } |
| 3216 | |
| 3217 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3218 | params.listen_interval = |
| 3219 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 3220 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3221 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3222 | params.ht_capa = |
| 3223 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3224 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3225 | if (!rdev->ops->change_station) |
| 3226 | return -EOPNOTSUPP; |
| 3227 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3228 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3229 | return -EINVAL; |
| 3230 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3231 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3232 | params.plink_action = |
| 3233 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3234 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3235 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3236 | params.plink_state = |
| 3237 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3238 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3239 | switch (dev->ieee80211_ptr->iftype) { |
| 3240 | case NL80211_IFTYPE_AP: |
| 3241 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3242 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3243 | /* disallow mesh-specific things */ |
| 3244 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3245 | return -EINVAL; |
| 3246 | |
| 3247 | /* TDLS can't be set, ... */ |
| 3248 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3249 | return -EINVAL; |
| 3250 | /* |
| 3251 | * ... but don't bother the driver with it. This works around |
| 3252 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3253 | * TLDS_PEER flag in the mask even for AP mode. |
| 3254 | */ |
| 3255 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3256 | |
| 3257 | /* accept only the listed bits */ |
| 3258 | if (params.sta_flags_mask & |
| 3259 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3260 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3261 | BIT(NL80211_STA_FLAG_WME) | |
| 3262 | BIT(NL80211_STA_FLAG_MFP))) |
| 3263 | return -EINVAL; |
| 3264 | |
| 3265 | /* must be last in here for error handling */ |
| 3266 | params.vlan = get_vlan(info, rdev); |
| 3267 | if (IS_ERR(params.vlan)) |
| 3268 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3269 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3270 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3271 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3272 | /* |
| 3273 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3274 | * but silently ignore attempts to change it since we |
| 3275 | * don't have state here to verify that it doesn't try |
| 3276 | * to change the flag. |
| 3277 | */ |
| 3278 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3279 | /* fall through */ |
| 3280 | case NL80211_IFTYPE_ADHOC: |
| 3281 | /* disallow things sta doesn't support */ |
| 3282 | if (params.plink_action) |
| 3283 | return -EINVAL; |
| 3284 | if (params.ht_capa) |
| 3285 | return -EINVAL; |
| 3286 | if (params.listen_interval >= 0) |
| 3287 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3288 | /* reject any changes other than AUTHORIZED */ |
| 3289 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3290 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3291 | break; |
| 3292 | case NL80211_IFTYPE_MESH_POINT: |
| 3293 | /* disallow things mesh doesn't support */ |
| 3294 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3295 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3296 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3297 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3298 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3299 | return -EINVAL; |
| 3300 | /* |
| 3301 | * No special handling for TDLS here -- the userspace |
| 3302 | * mesh code doesn't have this bug. |
| 3303 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3304 | if (params.sta_flags_mask & |
| 3305 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3306 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3307 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3308 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3309 | break; |
| 3310 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3311 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3312 | } |
| 3313 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3314 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3315 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3316 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3317 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3318 | if (params.vlan) |
| 3319 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3320 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3321 | return err; |
| 3322 | } |
| 3323 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3324 | static struct nla_policy |
| 3325 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3326 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3327 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3328 | }; |
| 3329 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3330 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3331 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3332 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3333 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3334 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3335 | struct station_parameters params; |
| 3336 | u8 *mac_addr = NULL; |
| 3337 | |
| 3338 | memset(¶ms, 0, sizeof(params)); |
| 3339 | |
| 3340 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3341 | return -EINVAL; |
| 3342 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3343 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3344 | return -EINVAL; |
| 3345 | |
| 3346 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3347 | return -EINVAL; |
| 3348 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3349 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3350 | return -EINVAL; |
| 3351 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3352 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3353 | params.supported_rates = |
| 3354 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3355 | params.supported_rates_len = |
| 3356 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3357 | params.listen_interval = |
| 3358 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3359 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3360 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3361 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3362 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3363 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3364 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3365 | params.ht_capa = |
| 3366 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3367 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3368 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3369 | params.vht_capa = |
| 3370 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3371 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3372 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3373 | params.plink_action = |
| 3374 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3375 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3376 | if (!rdev->ops->add_station) |
| 3377 | return -EOPNOTSUPP; |
| 3378 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3379 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3380 | return -EINVAL; |
| 3381 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3382 | switch (dev->ieee80211_ptr->iftype) { |
| 3383 | case NL80211_IFTYPE_AP: |
| 3384 | case NL80211_IFTYPE_AP_VLAN: |
| 3385 | case NL80211_IFTYPE_P2P_GO: |
| 3386 | /* parse WME attributes if sta is WME capable */ |
| 3387 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3388 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3389 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3390 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3391 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3392 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3393 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3394 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3395 | nl80211_sta_wme_policy); |
| 3396 | if (err) |
| 3397 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3398 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3399 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3400 | params.uapsd_queues = |
| 3401 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3402 | if (params.uapsd_queues & |
| 3403 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3404 | return -EINVAL; |
| 3405 | |
| 3406 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3407 | params.max_sp = |
| 3408 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3409 | |
| 3410 | if (params.max_sp & |
| 3411 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3412 | return -EINVAL; |
| 3413 | |
| 3414 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3415 | } |
| 3416 | /* TDLS peers cannot be added */ |
| 3417 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3418 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3419 | /* but don't bother the driver with it */ |
| 3420 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3421 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3422 | /* must be last in here for error handling */ |
| 3423 | params.vlan = get_vlan(info, rdev); |
| 3424 | if (IS_ERR(params.vlan)) |
| 3425 | return PTR_ERR(params.vlan); |
| 3426 | break; |
| 3427 | case NL80211_IFTYPE_MESH_POINT: |
| 3428 | /* TDLS peers cannot be added */ |
| 3429 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3430 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3431 | break; |
| 3432 | case NL80211_IFTYPE_STATION: |
| 3433 | /* Only TDLS peers can be added */ |
| 3434 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3435 | return -EINVAL; |
| 3436 | /* Can only add if TDLS ... */ |
| 3437 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3438 | return -EOPNOTSUPP; |
| 3439 | /* ... with external setup is supported */ |
| 3440 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3441 | return -EOPNOTSUPP; |
| 3442 | break; |
| 3443 | default: |
| 3444 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3445 | } |
| 3446 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3447 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3448 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3449 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3450 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3451 | if (params.vlan) |
| 3452 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3453 | return err; |
| 3454 | } |
| 3455 | |
| 3456 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3457 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3458 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3459 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3460 | u8 *mac_addr = NULL; |
| 3461 | |
| 3462 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3463 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3464 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3465 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3466 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3467 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3468 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3469 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3470 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3471 | if (!rdev->ops->del_station) |
| 3472 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3473 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3474 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3475 | } |
| 3476 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3477 | 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] | 3478 | int flags, struct net_device *dev, |
| 3479 | u8 *dst, u8 *next_hop, |
| 3480 | struct mpath_info *pinfo) |
| 3481 | { |
| 3482 | void *hdr; |
| 3483 | struct nlattr *pinfoattr; |
| 3484 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3485 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3486 | if (!hdr) |
| 3487 | return -1; |
| 3488 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3489 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3490 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3491 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3492 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3493 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3494 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3495 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3496 | if (!pinfoattr) |
| 3497 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3498 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3499 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3500 | pinfo->frame_qlen)) |
| 3501 | goto nla_put_failure; |
| 3502 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3503 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3504 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3505 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3506 | pinfo->metric)) || |
| 3507 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3508 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3509 | pinfo->exptime)) || |
| 3510 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3511 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3512 | pinfo->flags)) || |
| 3513 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3514 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3515 | pinfo->discovery_timeout)) || |
| 3516 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3517 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3518 | pinfo->discovery_retries))) |
| 3519 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3520 | |
| 3521 | nla_nest_end(msg, pinfoattr); |
| 3522 | |
| 3523 | return genlmsg_end(msg, hdr); |
| 3524 | |
| 3525 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3526 | genlmsg_cancel(msg, hdr); |
| 3527 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3528 | } |
| 3529 | |
| 3530 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3531 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3532 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3533 | struct mpath_info pinfo; |
| 3534 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3535 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3536 | u8 dst[ETH_ALEN]; |
| 3537 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3538 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3539 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3540 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3541 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3542 | if (err) |
| 3543 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3544 | |
| 3545 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3546 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3547 | goto out_err; |
| 3548 | } |
| 3549 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3550 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3551 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3552 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3553 | } |
| 3554 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3555 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3556 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 3557 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3558 | if (err == -ENOENT) |
| 3559 | break; |
| 3560 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3561 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3562 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3563 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3564 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3565 | netdev, dst, next_hop, |
| 3566 | &pinfo) < 0) |
| 3567 | goto out; |
| 3568 | |
| 3569 | path_idx++; |
| 3570 | } |
| 3571 | |
| 3572 | |
| 3573 | out: |
| 3574 | cb->args[1] = path_idx; |
| 3575 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3576 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3577 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3578 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3579 | } |
| 3580 | |
| 3581 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3582 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3583 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3584 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3585 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3586 | struct mpath_info pinfo; |
| 3587 | struct sk_buff *msg; |
| 3588 | u8 *dst = NULL; |
| 3589 | u8 next_hop[ETH_ALEN]; |
| 3590 | |
| 3591 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3592 | |
| 3593 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3594 | return -EINVAL; |
| 3595 | |
| 3596 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3597 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3598 | if (!rdev->ops->get_mpath) |
| 3599 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3600 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3601 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3602 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3603 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3604 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3605 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3606 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3607 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3608 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3609 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3610 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3611 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3612 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3613 | dev, dst, next_hop, &pinfo) < 0) { |
| 3614 | nlmsg_free(msg); |
| 3615 | return -ENOBUFS; |
| 3616 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3617 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3618 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3622 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3623 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3624 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3625 | u8 *dst = NULL; |
| 3626 | u8 *next_hop = NULL; |
| 3627 | |
| 3628 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3629 | return -EINVAL; |
| 3630 | |
| 3631 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3632 | return -EINVAL; |
| 3633 | |
| 3634 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3635 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3636 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3637 | if (!rdev->ops->change_mpath) |
| 3638 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3639 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3640 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3641 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3642 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3643 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3644 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3645 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3646 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3647 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3648 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3649 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3650 | u8 *dst = NULL; |
| 3651 | u8 *next_hop = NULL; |
| 3652 | |
| 3653 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3654 | return -EINVAL; |
| 3655 | |
| 3656 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3657 | return -EINVAL; |
| 3658 | |
| 3659 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3660 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3661 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3662 | if (!rdev->ops->add_mpath) |
| 3663 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3664 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3665 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3666 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3667 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3668 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3672 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3673 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3674 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3675 | u8 *dst = NULL; |
| 3676 | |
| 3677 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3678 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3679 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3680 | if (!rdev->ops->del_mpath) |
| 3681 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3682 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3683 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3684 | } |
| 3685 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3686 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3687 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3689 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3690 | struct bss_parameters params; |
| 3691 | |
| 3692 | memset(¶ms, 0, sizeof(params)); |
| 3693 | /* default to not changing parameters */ |
| 3694 | params.use_cts_prot = -1; |
| 3695 | params.use_short_preamble = -1; |
| 3696 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3697 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3698 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3699 | params.p2p_ctwindow = -1; |
| 3700 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3701 | |
| 3702 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3703 | params.use_cts_prot = |
| 3704 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3705 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3706 | params.use_short_preamble = |
| 3707 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3708 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3709 | params.use_short_slot_time = |
| 3710 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3711 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3712 | params.basic_rates = |
| 3713 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3714 | params.basic_rates_len = |
| 3715 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3716 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3717 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3718 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3719 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3720 | params.ht_opmode = |
| 3721 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3722 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3723 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3724 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3725 | return -EINVAL; |
| 3726 | params.p2p_ctwindow = |
| 3727 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3728 | if (params.p2p_ctwindow < 0) |
| 3729 | return -EINVAL; |
| 3730 | if (params.p2p_ctwindow != 0 && |
| 3731 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3732 | return -EINVAL; |
| 3733 | } |
| 3734 | |
| 3735 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3736 | u8 tmp; |
| 3737 | |
| 3738 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3739 | return -EINVAL; |
| 3740 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3741 | if (tmp > 1) |
| 3742 | return -EINVAL; |
| 3743 | params.p2p_opp_ps = tmp; |
| 3744 | if (params.p2p_opp_ps && |
| 3745 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3746 | return -EINVAL; |
| 3747 | } |
| 3748 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3749 | if (!rdev->ops->change_bss) |
| 3750 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3751 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3752 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3753 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3754 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3755 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3756 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3757 | } |
| 3758 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3759 | 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] | 3760 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3761 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3762 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3763 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3764 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3765 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3766 | }; |
| 3767 | |
| 3768 | static int parse_reg_rule(struct nlattr *tb[], |
| 3769 | struct ieee80211_reg_rule *reg_rule) |
| 3770 | { |
| 3771 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3772 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3773 | |
| 3774 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3775 | return -EINVAL; |
| 3776 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3777 | return -EINVAL; |
| 3778 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3779 | return -EINVAL; |
| 3780 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3781 | return -EINVAL; |
| 3782 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3783 | return -EINVAL; |
| 3784 | |
| 3785 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3786 | |
| 3787 | freq_range->start_freq_khz = |
| 3788 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3789 | freq_range->end_freq_khz = |
| 3790 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3791 | freq_range->max_bandwidth_khz = |
| 3792 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3793 | |
| 3794 | power_rule->max_eirp = |
| 3795 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3796 | |
| 3797 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3798 | power_rule->max_antenna_gain = |
| 3799 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3800 | |
| 3801 | return 0; |
| 3802 | } |
| 3803 | |
| 3804 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3805 | { |
| 3806 | int r; |
| 3807 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3808 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3809 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3810 | /* |
| 3811 | * You should only get this when cfg80211 hasn't yet initialized |
| 3812 | * completely when built-in to the kernel right between the time |
| 3813 | * window between nl80211_init() and regulatory_init(), if that is |
| 3814 | * even possible. |
| 3815 | */ |
| 3816 | mutex_lock(&cfg80211_mutex); |
| 3817 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3818 | mutex_unlock(&cfg80211_mutex); |
| 3819 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3820 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3821 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3822 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3823 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3824 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3825 | |
| 3826 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3827 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3828 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 3829 | user_reg_hint_type = |
| 3830 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 3831 | else |
| 3832 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 3833 | |
| 3834 | switch (user_reg_hint_type) { |
| 3835 | case NL80211_USER_REG_HINT_USER: |
| 3836 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 3837 | break; |
| 3838 | default: |
| 3839 | return -EINVAL; |
| 3840 | } |
| 3841 | |
| 3842 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3843 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3844 | return r; |
| 3845 | } |
| 3846 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3847 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3848 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3849 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3851 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3852 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3853 | struct mesh_config cur_params; |
| 3854 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3855 | void *hdr; |
| 3856 | struct nlattr *pinfoattr; |
| 3857 | struct sk_buff *msg; |
| 3858 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3859 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3860 | return -EOPNOTSUPP; |
| 3861 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3862 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3863 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3864 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3865 | wdev_lock(wdev); |
| 3866 | /* If not connected, get default parameters */ |
| 3867 | if (!wdev->mesh_id_len) |
| 3868 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3869 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3870 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3871 | wdev_unlock(wdev); |
| 3872 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3873 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3874 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3875 | |
| 3876 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3877 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3878 | if (!msg) |
| 3879 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3880 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3881 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3882 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3883 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3884 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3885 | if (!pinfoattr) |
| 3886 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3887 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3888 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3889 | cur_params.dot11MeshRetryTimeout) || |
| 3890 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3891 | cur_params.dot11MeshConfirmTimeout) || |
| 3892 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3893 | cur_params.dot11MeshHoldingTimeout) || |
| 3894 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3895 | cur_params.dot11MeshMaxPeerLinks) || |
| 3896 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3897 | cur_params.dot11MeshMaxRetries) || |
| 3898 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 3899 | cur_params.dot11MeshTTL) || |
| 3900 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3901 | cur_params.element_ttl) || |
| 3902 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3903 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3904 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3905 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3906 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3907 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 3908 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3909 | cur_params.path_refresh_time) || |
| 3910 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3911 | cur_params.min_discovery_timeout) || |
| 3912 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3913 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 3914 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3915 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 3916 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3917 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 3918 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3919 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 3920 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3921 | cur_params.dot11MeshHWMPRootMode) || |
| 3922 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3923 | cur_params.dot11MeshHWMPRannInterval) || |
| 3924 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3925 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 3926 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 3927 | cur_params.dot11MeshForwarding) || |
| 3928 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3929 | cur_params.rssi_threshold) || |
| 3930 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3931 | cur_params.ht_opmode) || |
| 3932 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3933 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 3934 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3935 | cur_params.dot11MeshHWMProotInterval) || |
| 3936 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3937 | cur_params.dot11MeshHWMPconfirmationInterval)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3938 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3939 | nla_nest_end(msg, pinfoattr); |
| 3940 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3941 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3942 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3943 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3944 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3945 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3946 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3947 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3948 | } |
| 3949 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3950 | 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] | 3951 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3952 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3953 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3954 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3955 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3956 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3957 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3958 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3959 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3960 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3961 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3962 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3963 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3964 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3965 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3966 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3967 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3968 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3969 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3970 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3971 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 3972 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3973 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 3974 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3975 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3976 | }; |
| 3977 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3978 | static const struct nla_policy |
| 3979 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3980 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3981 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3982 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3983 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3984 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3985 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3986 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3987 | }; |
| 3988 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3989 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3990 | struct mesh_config *cfg, |
| 3991 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3992 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3993 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3994 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3995 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3996 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3997 | do {\ |
| 3998 | if (table[attr_num]) {\ |
| 3999 | cfg->param = nla_fn(table[attr_num]); \ |
| 4000 | mask |= (1 << (attr_num - 1)); \ |
| 4001 | } \ |
| 4002 | } while (0);\ |
| 4003 | |
| 4004 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4005 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4006 | return -EINVAL; |
| 4007 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4008 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4009 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4010 | return -EINVAL; |
| 4011 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4012 | /* This makes sure that there aren't more than 32 mesh config |
| 4013 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4014 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4015 | |
| 4016 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4017 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4018 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4019 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4020 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4021 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4022 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4023 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4024 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4025 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4026 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4027 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4028 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4029 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4030 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4031 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4032 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4033 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4034 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4035 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4036 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4037 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4038 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4039 | nla_get_u8); |
| 4040 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask, |
| 4041 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4042 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4043 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4044 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4045 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4046 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4047 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4048 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4049 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4050 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4051 | nla_get_u16); |
| 4052 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask, |
| 4053 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4054 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4055 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4056 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4057 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4058 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4059 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4060 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4061 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4062 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
| 4063 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4064 | nla_get_u16); |
| 4065 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 4066 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 4067 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 4068 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4069 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4070 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4071 | dot11MeshGateAnnouncementProtocol, mask, |
| 4072 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4073 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4074 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4075 | mask, NL80211_MESHCONF_FORWARDING, |
| 4076 | nla_get_u8); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 4077 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4078 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4079 | nla_get_u32); |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4080 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4081 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4082 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4083 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
| 4084 | mask, |
| 4085 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4086 | nla_get_u32); |
| 4087 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, |
| 4088 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4089 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4090 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 4091 | dot11MeshHWMPconfirmationInterval, mask, |
| 4092 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4093 | nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4094 | if (mask_out) |
| 4095 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4096 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4097 | return 0; |
| 4098 | |
| 4099 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4100 | } |
| 4101 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4102 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4103 | struct mesh_setup *setup) |
| 4104 | { |
| 4105 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4106 | |
| 4107 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4108 | return -EINVAL; |
| 4109 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4110 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4111 | nl80211_mesh_setup_params_policy)) |
| 4112 | return -EINVAL; |
| 4113 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4114 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4115 | setup->sync_method = |
| 4116 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4117 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4118 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4119 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4120 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4121 | setup->path_sel_proto = |
| 4122 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4123 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4124 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4125 | |
| 4126 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4127 | setup->path_metric = |
| 4128 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4129 | IEEE80211_PATH_METRIC_VENDOR : |
| 4130 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4131 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4132 | |
| 4133 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4134 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4135 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4136 | if (!is_valid_ie_attr(ieattr)) |
| 4137 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4138 | setup->ie = nla_data(ieattr); |
| 4139 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4140 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4141 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4142 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4143 | |
| 4144 | return 0; |
| 4145 | } |
| 4146 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4147 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4148 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4149 | { |
| 4150 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4151 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4152 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4153 | struct mesh_config cfg; |
| 4154 | u32 mask; |
| 4155 | int err; |
| 4156 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4157 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4158 | return -EOPNOTSUPP; |
| 4159 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4160 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4161 | return -EOPNOTSUPP; |
| 4162 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4163 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4164 | if (err) |
| 4165 | return err; |
| 4166 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4167 | wdev_lock(wdev); |
| 4168 | if (!wdev->mesh_id_len) |
| 4169 | err = -ENOLINK; |
| 4170 | |
| 4171 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4172 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4173 | |
| 4174 | wdev_unlock(wdev); |
| 4175 | |
| 4176 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4177 | } |
| 4178 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4179 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4180 | { |
| 4181 | struct sk_buff *msg; |
| 4182 | void *hdr = NULL; |
| 4183 | struct nlattr *nl_reg_rules; |
| 4184 | unsigned int i; |
| 4185 | int err = -EINVAL; |
| 4186 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4187 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4188 | |
| 4189 | if (!cfg80211_regdomain) |
| 4190 | goto out; |
| 4191 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4192 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4193 | if (!msg) { |
| 4194 | err = -ENOBUFS; |
| 4195 | goto out; |
| 4196 | } |
| 4197 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4198 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4199 | NL80211_CMD_GET_REG); |
| 4200 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4201 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4202 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4203 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 4204 | cfg80211_regdomain->alpha2) || |
| 4205 | (cfg80211_regdomain->dfs_region && |
| 4206 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, |
| 4207 | cfg80211_regdomain->dfs_region))) |
| 4208 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4209 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4210 | if (reg_last_request_cell_base() && |
| 4211 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4212 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4213 | goto nla_put_failure; |
| 4214 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4215 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4216 | if (!nl_reg_rules) |
| 4217 | goto nla_put_failure; |
| 4218 | |
| 4219 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 4220 | struct nlattr *nl_reg_rule; |
| 4221 | const struct ieee80211_reg_rule *reg_rule; |
| 4222 | const struct ieee80211_freq_range *freq_range; |
| 4223 | const struct ieee80211_power_rule *power_rule; |
| 4224 | |
| 4225 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 4226 | freq_range = ®_rule->freq_range; |
| 4227 | power_rule = ®_rule->power_rule; |
| 4228 | |
| 4229 | nl_reg_rule = nla_nest_start(msg, i); |
| 4230 | if (!nl_reg_rule) |
| 4231 | goto nla_put_failure; |
| 4232 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4233 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4234 | reg_rule->flags) || |
| 4235 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4236 | freq_range->start_freq_khz) || |
| 4237 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4238 | freq_range->end_freq_khz) || |
| 4239 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4240 | freq_range->max_bandwidth_khz) || |
| 4241 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4242 | power_rule->max_antenna_gain) || |
| 4243 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4244 | power_rule->max_eirp)) |
| 4245 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4246 | |
| 4247 | nla_nest_end(msg, nl_reg_rule); |
| 4248 | } |
| 4249 | |
| 4250 | nla_nest_end(msg, nl_reg_rules); |
| 4251 | |
| 4252 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4253 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4254 | goto out; |
| 4255 | |
| 4256 | nla_put_failure: |
| 4257 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4258 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4259 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4260 | err = -EMSGSIZE; |
| 4261 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4262 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4263 | return err; |
| 4264 | } |
| 4265 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4266 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4267 | { |
| 4268 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4269 | struct nlattr *nl_reg_rule; |
| 4270 | char *alpha2 = NULL; |
| 4271 | int rem_reg_rules = 0, r = 0; |
| 4272 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4273 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4274 | struct ieee80211_regdomain *rd = NULL; |
| 4275 | |
| 4276 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4277 | return -EINVAL; |
| 4278 | |
| 4279 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4280 | return -EINVAL; |
| 4281 | |
| 4282 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4283 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4284 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4285 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4286 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4287 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4288 | rem_reg_rules) { |
| 4289 | num_rules++; |
| 4290 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4291 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4292 | } |
| 4293 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4294 | mutex_lock(&cfg80211_mutex); |
| 4295 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4296 | if (!reg_is_valid_request(alpha2)) { |
| 4297 | r = -EINVAL; |
| 4298 | goto bad_reg; |
| 4299 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4300 | |
| 4301 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 4302 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 4303 | |
| 4304 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4305 | if (!rd) { |
| 4306 | r = -ENOMEM; |
| 4307 | goto bad_reg; |
| 4308 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4309 | |
| 4310 | rd->n_reg_rules = num_rules; |
| 4311 | rd->alpha2[0] = alpha2[0]; |
| 4312 | rd->alpha2[1] = alpha2[1]; |
| 4313 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4314 | /* |
| 4315 | * Disable DFS master mode if the DFS region was |
| 4316 | * not supported or known on this kernel. |
| 4317 | */ |
| 4318 | if (reg_supported_dfs_region(dfs_region)) |
| 4319 | rd->dfs_region = dfs_region; |
| 4320 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4321 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4322 | rem_reg_rules) { |
| 4323 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 4324 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4325 | reg_rule_policy); |
| 4326 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4327 | if (r) |
| 4328 | goto bad_reg; |
| 4329 | |
| 4330 | rule_idx++; |
| 4331 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4332 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4333 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4334 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4335 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | BUG_ON(rule_idx != num_rules); |
| 4339 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4340 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4341 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4342 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4343 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4344 | return r; |
| 4345 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4346 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4347 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4348 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4349 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4350 | } |
| 4351 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4352 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4353 | { |
| 4354 | struct nlattr *attr1, *attr2; |
| 4355 | int n_channels = 0, tmp1, tmp2; |
| 4356 | |
| 4357 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4358 | n_channels++; |
| 4359 | /* |
| 4360 | * Some hardware has a limited channel list for |
| 4361 | * scanning, and it is pretty much nonsensical |
| 4362 | * to scan for a channel twice, so disallow that |
| 4363 | * and don't require drivers to check that the |
| 4364 | * channel list they get isn't longer than what |
| 4365 | * they can scan, as long as they can scan all |
| 4366 | * the channels they registered at once. |
| 4367 | */ |
| 4368 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4369 | if (attr1 != attr2 && |
| 4370 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4371 | return 0; |
| 4372 | } |
| 4373 | |
| 4374 | return n_channels; |
| 4375 | } |
| 4376 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4377 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4378 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4379 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4380 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4381 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4382 | struct nlattr *attr; |
| 4383 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4384 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4385 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4386 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4387 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4388 | return -EINVAL; |
| 4389 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4390 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4391 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4392 | if (!rdev->ops->scan) |
| 4393 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4394 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4395 | if (rdev->scan_req) |
| 4396 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4397 | |
| 4398 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4399 | n_channels = validate_scan_freqs( |
| 4400 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4401 | if (!n_channels) |
| 4402 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4403 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4404 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4405 | n_channels = 0; |
| 4406 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4407 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4408 | if (wiphy->bands[band]) |
| 4409 | n_channels += wiphy->bands[band]->n_channels; |
| 4410 | } |
| 4411 | |
| 4412 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4413 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4414 | n_ssids++; |
| 4415 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4416 | if (n_ssids > wiphy->max_scan_ssids) |
| 4417 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4418 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4419 | if (info->attrs[NL80211_ATTR_IE]) |
| 4420 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4421 | else |
| 4422 | ie_len = 0; |
| 4423 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4424 | if (ie_len > wiphy->max_scan_ie_len) |
| 4425 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4426 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4427 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4428 | + sizeof(*request->ssids) * n_ssids |
| 4429 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4430 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4431 | if (!request) |
| 4432 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4433 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4434 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4435 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4436 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4437 | if (ie_len) { |
| 4438 | if (request->ssids) |
| 4439 | request->ie = (void *)(request->ssids + n_ssids); |
| 4440 | else |
| 4441 | request->ie = (void *)(request->channels + n_channels); |
| 4442 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4443 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4444 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4445 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4446 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4447 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4448 | struct ieee80211_channel *chan; |
| 4449 | |
| 4450 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4451 | |
| 4452 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4453 | err = -EINVAL; |
| 4454 | goto out_free; |
| 4455 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4456 | |
| 4457 | /* ignore disabled channels */ |
| 4458 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4459 | continue; |
| 4460 | |
| 4461 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4462 | i++; |
| 4463 | } |
| 4464 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4465 | enum ieee80211_band band; |
| 4466 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4467 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4468 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4469 | int j; |
| 4470 | if (!wiphy->bands[band]) |
| 4471 | continue; |
| 4472 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4473 | struct ieee80211_channel *chan; |
| 4474 | |
| 4475 | chan = &wiphy->bands[band]->channels[j]; |
| 4476 | |
| 4477 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4478 | continue; |
| 4479 | |
| 4480 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4481 | i++; |
| 4482 | } |
| 4483 | } |
| 4484 | } |
| 4485 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4486 | if (!i) { |
| 4487 | err = -EINVAL; |
| 4488 | goto out_free; |
| 4489 | } |
| 4490 | |
| 4491 | request->n_channels = i; |
| 4492 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4493 | i = 0; |
| 4494 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4495 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4496 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4497 | err = -EINVAL; |
| 4498 | goto out_free; |
| 4499 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4500 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4501 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4502 | i++; |
| 4503 | } |
| 4504 | } |
| 4505 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4506 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4507 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4508 | memcpy((void *)request->ie, |
| 4509 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4510 | request->ie_len); |
| 4511 | } |
| 4512 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4513 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4514 | if (wiphy->bands[i]) |
| 4515 | request->rates[i] = |
| 4516 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4517 | |
| 4518 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4519 | nla_for_each_nested(attr, |
| 4520 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4521 | tmp) { |
| 4522 | enum ieee80211_band band = nla_type(attr); |
| 4523 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4524 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4525 | err = -EINVAL; |
| 4526 | goto out_free; |
| 4527 | } |
| 4528 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4529 | nla_data(attr), |
| 4530 | nla_len(attr), |
| 4531 | &request->rates[band]); |
| 4532 | if (err) |
| 4533 | goto out_free; |
| 4534 | } |
| 4535 | } |
| 4536 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4537 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4538 | request->flags = nla_get_u32( |
| 4539 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4540 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4541 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4542 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4543 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4544 | err = -EOPNOTSUPP; |
| 4545 | goto out_free; |
| 4546 | } |
| 4547 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4548 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4549 | request->no_cck = |
| 4550 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4551 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4552 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4553 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4554 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4555 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4556 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4557 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4558 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4559 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4560 | nl80211_send_scan_start(rdev, wdev); |
| 4561 | if (wdev->netdev) |
| 4562 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4563 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4564 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4565 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4566 | kfree(request); |
| 4567 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4568 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4569 | return err; |
| 4570 | } |
| 4571 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4572 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4573 | struct genl_info *info) |
| 4574 | { |
| 4575 | struct cfg80211_sched_scan_request *request; |
| 4576 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4577 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4578 | struct nlattr *attr; |
| 4579 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4580 | 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] | 4581 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4582 | enum ieee80211_band band; |
| 4583 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4584 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4585 | |
| 4586 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4587 | !rdev->ops->sched_scan_start) |
| 4588 | return -EOPNOTSUPP; |
| 4589 | |
| 4590 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4591 | return -EINVAL; |
| 4592 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4593 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4594 | return -EINVAL; |
| 4595 | |
| 4596 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4597 | if (interval == 0) |
| 4598 | return -EINVAL; |
| 4599 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4600 | wiphy = &rdev->wiphy; |
| 4601 | |
| 4602 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4603 | n_channels = validate_scan_freqs( |
| 4604 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4605 | if (!n_channels) |
| 4606 | return -EINVAL; |
| 4607 | } else { |
| 4608 | n_channels = 0; |
| 4609 | |
| 4610 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4611 | if (wiphy->bands[band]) |
| 4612 | n_channels += wiphy->bands[band]->n_channels; |
| 4613 | } |
| 4614 | |
| 4615 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4616 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4617 | tmp) |
| 4618 | n_ssids++; |
| 4619 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4620 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4621 | return -EINVAL; |
| 4622 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4623 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4624 | nla_for_each_nested(attr, |
| 4625 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4626 | tmp) |
| 4627 | n_match_sets++; |
| 4628 | |
| 4629 | if (n_match_sets > wiphy->max_match_sets) |
| 4630 | return -EINVAL; |
| 4631 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4632 | if (info->attrs[NL80211_ATTR_IE]) |
| 4633 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4634 | else |
| 4635 | ie_len = 0; |
| 4636 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4637 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4638 | return -EINVAL; |
| 4639 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4640 | mutex_lock(&rdev->sched_scan_mtx); |
| 4641 | |
| 4642 | if (rdev->sched_scan_req) { |
| 4643 | err = -EINPROGRESS; |
| 4644 | goto out; |
| 4645 | } |
| 4646 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4647 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4648 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4649 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4650 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4651 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4652 | if (!request) { |
| 4653 | err = -ENOMEM; |
| 4654 | goto out; |
| 4655 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4656 | |
| 4657 | if (n_ssids) |
| 4658 | request->ssids = (void *)&request->channels[n_channels]; |
| 4659 | request->n_ssids = n_ssids; |
| 4660 | if (ie_len) { |
| 4661 | if (request->ssids) |
| 4662 | request->ie = (void *)(request->ssids + n_ssids); |
| 4663 | else |
| 4664 | request->ie = (void *)(request->channels + n_channels); |
| 4665 | } |
| 4666 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4667 | if (n_match_sets) { |
| 4668 | if (request->ie) |
| 4669 | request->match_sets = (void *)(request->ie + ie_len); |
| 4670 | else if (request->ssids) |
| 4671 | request->match_sets = |
| 4672 | (void *)(request->ssids + n_ssids); |
| 4673 | else |
| 4674 | request->match_sets = |
| 4675 | (void *)(request->channels + n_channels); |
| 4676 | } |
| 4677 | request->n_match_sets = n_match_sets; |
| 4678 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4679 | i = 0; |
| 4680 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4681 | /* user specified, bail out if channel not found */ |
| 4682 | nla_for_each_nested(attr, |
| 4683 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4684 | tmp) { |
| 4685 | struct ieee80211_channel *chan; |
| 4686 | |
| 4687 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4688 | |
| 4689 | if (!chan) { |
| 4690 | err = -EINVAL; |
| 4691 | goto out_free; |
| 4692 | } |
| 4693 | |
| 4694 | /* ignore disabled channels */ |
| 4695 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4696 | continue; |
| 4697 | |
| 4698 | request->channels[i] = chan; |
| 4699 | i++; |
| 4700 | } |
| 4701 | } else { |
| 4702 | /* all channels */ |
| 4703 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4704 | int j; |
| 4705 | if (!wiphy->bands[band]) |
| 4706 | continue; |
| 4707 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4708 | struct ieee80211_channel *chan; |
| 4709 | |
| 4710 | chan = &wiphy->bands[band]->channels[j]; |
| 4711 | |
| 4712 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4713 | continue; |
| 4714 | |
| 4715 | request->channels[i] = chan; |
| 4716 | i++; |
| 4717 | } |
| 4718 | } |
| 4719 | } |
| 4720 | |
| 4721 | if (!i) { |
| 4722 | err = -EINVAL; |
| 4723 | goto out_free; |
| 4724 | } |
| 4725 | |
| 4726 | request->n_channels = i; |
| 4727 | |
| 4728 | i = 0; |
| 4729 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4730 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4731 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4732 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4733 | err = -EINVAL; |
| 4734 | goto out_free; |
| 4735 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4736 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4737 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4738 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4739 | i++; |
| 4740 | } |
| 4741 | } |
| 4742 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4743 | i = 0; |
| 4744 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4745 | nla_for_each_nested(attr, |
| 4746 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4747 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4748 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4749 | |
| 4750 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4751 | nla_data(attr), nla_len(attr), |
| 4752 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 4753 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4754 | if (ssid) { |
| 4755 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4756 | err = -EINVAL; |
| 4757 | goto out_free; |
| 4758 | } |
| 4759 | memcpy(request->match_sets[i].ssid.ssid, |
| 4760 | nla_data(ssid), nla_len(ssid)); |
| 4761 | request->match_sets[i].ssid.ssid_len = |
| 4762 | nla_len(ssid); |
| 4763 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4764 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 4765 | if (rssi) |
| 4766 | request->rssi_thold = nla_get_u32(rssi); |
| 4767 | else |
| 4768 | request->rssi_thold = |
| 4769 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4770 | i++; |
| 4771 | } |
| 4772 | } |
| 4773 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4774 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4775 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4776 | memcpy((void *)request->ie, |
| 4777 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4778 | request->ie_len); |
| 4779 | } |
| 4780 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4781 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4782 | request->flags = nla_get_u32( |
| 4783 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4784 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4785 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4786 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4787 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4788 | err = -EOPNOTSUPP; |
| 4789 | goto out_free; |
| 4790 | } |
| 4791 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4792 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4793 | request->dev = dev; |
| 4794 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4795 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4796 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4797 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4798 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4799 | if (!err) { |
| 4800 | rdev->sched_scan_req = request; |
| 4801 | nl80211_send_sched_scan(rdev, dev, |
| 4802 | NL80211_CMD_START_SCHED_SCAN); |
| 4803 | goto out; |
| 4804 | } |
| 4805 | |
| 4806 | out_free: |
| 4807 | kfree(request); |
| 4808 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4809 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4810 | return err; |
| 4811 | } |
| 4812 | |
| 4813 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4814 | struct genl_info *info) |
| 4815 | { |
| 4816 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4817 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4818 | |
| 4819 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4820 | !rdev->ops->sched_scan_stop) |
| 4821 | return -EOPNOTSUPP; |
| 4822 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4823 | mutex_lock(&rdev->sched_scan_mtx); |
| 4824 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4825 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4826 | |
| 4827 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4828 | } |
| 4829 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4830 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4831 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4832 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4833 | struct wireless_dev *wdev, |
| 4834 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4835 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4836 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4837 | void *hdr; |
| 4838 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4839 | |
| 4840 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4841 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4842 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4843 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4844 | if (!hdr) |
| 4845 | return -1; |
| 4846 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4847 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4848 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4849 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 4850 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 4851 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4852 | |
| 4853 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4854 | if (!bss) |
| 4855 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4856 | if ((!is_zero_ether_addr(res->bssid) && |
| 4857 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) || |
| 4858 | (res->information_elements && res->len_information_elements && |
| 4859 | nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4860 | res->len_information_elements, |
| 4861 | res->information_elements)) || |
| 4862 | (res->beacon_ies && res->len_beacon_ies && |
| 4863 | res->beacon_ies != res->information_elements && |
| 4864 | nla_put(msg, NL80211_BSS_BEACON_IES, |
| 4865 | res->len_beacon_ies, res->beacon_ies))) |
| 4866 | goto nla_put_failure; |
| 4867 | if (res->tsf && |
| 4868 | nla_put_u64(msg, NL80211_BSS_TSF, res->tsf)) |
| 4869 | goto nla_put_failure; |
| 4870 | if (res->beacon_interval && |
| 4871 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 4872 | goto nla_put_failure; |
| 4873 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 4874 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 4875 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4876 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 4877 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4878 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4879 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4880 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4881 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 4882 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4883 | break; |
| 4884 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4885 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 4886 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4887 | break; |
| 4888 | default: |
| 4889 | break; |
| 4890 | } |
| 4891 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4892 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4893 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4894 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4895 | if (intbss == wdev->current_bss && |
| 4896 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4897 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 4898 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4899 | break; |
| 4900 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4901 | if (intbss == wdev->current_bss && |
| 4902 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4903 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 4904 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4905 | break; |
| 4906 | default: |
| 4907 | break; |
| 4908 | } |
| 4909 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4910 | nla_nest_end(msg, bss); |
| 4911 | |
| 4912 | return genlmsg_end(msg, hdr); |
| 4913 | |
| 4914 | nla_put_failure: |
| 4915 | genlmsg_cancel(msg, hdr); |
| 4916 | return -EMSGSIZE; |
| 4917 | } |
| 4918 | |
| 4919 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4920 | struct netlink_callback *cb) |
| 4921 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4922 | struct cfg80211_registered_device *rdev; |
| 4923 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4924 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4925 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4926 | int start = cb->args[1], idx = 0; |
| 4927 | int err; |
| 4928 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4929 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4930 | if (err) |
| 4931 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4932 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4933 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4934 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4935 | wdev_lock(wdev); |
| 4936 | spin_lock_bh(&rdev->bss_lock); |
| 4937 | cfg80211_bss_expire(rdev); |
| 4938 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4939 | cb->seq = rdev->bss_generation; |
| 4940 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4941 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4942 | if (++idx <= start) |
| 4943 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4944 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4945 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4946 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4947 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4948 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4949 | } |
| 4950 | } |
| 4951 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4952 | spin_unlock_bh(&rdev->bss_lock); |
| 4953 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4954 | |
| 4955 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4956 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4957 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4958 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4959 | } |
| 4960 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4961 | 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] | 4962 | int flags, struct net_device *dev, |
| 4963 | struct survey_info *survey) |
| 4964 | { |
| 4965 | void *hdr; |
| 4966 | struct nlattr *infoattr; |
| 4967 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4968 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4969 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4970 | if (!hdr) |
| 4971 | return -ENOMEM; |
| 4972 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4973 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 4974 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4975 | |
| 4976 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4977 | if (!infoattr) |
| 4978 | goto nla_put_failure; |
| 4979 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4980 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4981 | survey->channel->center_freq)) |
| 4982 | goto nla_put_failure; |
| 4983 | |
| 4984 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 4985 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 4986 | goto nla_put_failure; |
| 4987 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 4988 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 4989 | goto nla_put_failure; |
| 4990 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 4991 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4992 | survey->channel_time)) |
| 4993 | goto nla_put_failure; |
| 4994 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 4995 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4996 | survey->channel_time_busy)) |
| 4997 | goto nla_put_failure; |
| 4998 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 4999 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5000 | survey->channel_time_ext_busy)) |
| 5001 | goto nla_put_failure; |
| 5002 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5003 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5004 | survey->channel_time_rx)) |
| 5005 | goto nla_put_failure; |
| 5006 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5007 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5008 | survey->channel_time_tx)) |
| 5009 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5010 | |
| 5011 | nla_nest_end(msg, infoattr); |
| 5012 | |
| 5013 | return genlmsg_end(msg, hdr); |
| 5014 | |
| 5015 | nla_put_failure: |
| 5016 | genlmsg_cancel(msg, hdr); |
| 5017 | return -EMSGSIZE; |
| 5018 | } |
| 5019 | |
| 5020 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5021 | struct netlink_callback *cb) |
| 5022 | { |
| 5023 | struct survey_info survey; |
| 5024 | struct cfg80211_registered_device *dev; |
| 5025 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5026 | int survey_idx = cb->args[1]; |
| 5027 | int res; |
| 5028 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5029 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 5030 | if (res) |
| 5031 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5032 | |
| 5033 | if (!dev->ops->dump_survey) { |
| 5034 | res = -EOPNOTSUPP; |
| 5035 | goto out_err; |
| 5036 | } |
| 5037 | |
| 5038 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5039 | struct ieee80211_channel *chan; |
| 5040 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5041 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5042 | if (res == -ENOENT) |
| 5043 | break; |
| 5044 | if (res) |
| 5045 | goto out_err; |
| 5046 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5047 | /* Survey without a channel doesn't make sense */ |
| 5048 | if (!survey.channel) { |
| 5049 | res = -EINVAL; |
| 5050 | goto out; |
| 5051 | } |
| 5052 | |
| 5053 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5054 | survey.channel->center_freq); |
| 5055 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5056 | survey_idx++; |
| 5057 | continue; |
| 5058 | } |
| 5059 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5060 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5061 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5062 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5063 | netdev, |
| 5064 | &survey) < 0) |
| 5065 | goto out; |
| 5066 | survey_idx++; |
| 5067 | } |
| 5068 | |
| 5069 | out: |
| 5070 | cb->args[1] = survey_idx; |
| 5071 | res = skb->len; |
| 5072 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5073 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5074 | return res; |
| 5075 | } |
| 5076 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5077 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5078 | { |
| 5079 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5080 | NL80211_WPA_VERSION_2)); |
| 5081 | } |
| 5082 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5083 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5084 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5085 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5086 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5087 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5088 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5089 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5090 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5091 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5092 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5093 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5094 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5095 | return -EINVAL; |
| 5096 | |
| 5097 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5098 | return -EINVAL; |
| 5099 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5100 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5101 | return -EINVAL; |
| 5102 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5103 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5104 | return -EINVAL; |
| 5105 | |
| 5106 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5107 | return -EINVAL; |
| 5108 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5109 | err = nl80211_parse_key(info, &key); |
| 5110 | if (err) |
| 5111 | return err; |
| 5112 | |
| 5113 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5114 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5115 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5116 | if (!key.p.key || !key.p.key_len) |
| 5117 | return -EINVAL; |
| 5118 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5119 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5120 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5121 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5122 | return -EINVAL; |
| 5123 | if (key.idx > 4) |
| 5124 | return -EINVAL; |
| 5125 | } else { |
| 5126 | key.p.key_len = 0; |
| 5127 | key.p.key = NULL; |
| 5128 | } |
| 5129 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5130 | if (key.idx >= 0) { |
| 5131 | int i; |
| 5132 | bool ok = false; |
| 5133 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5134 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5135 | ok = true; |
| 5136 | break; |
| 5137 | } |
| 5138 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5139 | if (!ok) |
| 5140 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5141 | } |
| 5142 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5143 | if (!rdev->ops->auth) |
| 5144 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5145 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5146 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5147 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5148 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5149 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5150 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5151 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5152 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5153 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5154 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5155 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5156 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5157 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5158 | |
| 5159 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5160 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5161 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5162 | } |
| 5163 | |
| 5164 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5165 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5166 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5167 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5168 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5169 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5170 | return -EINVAL; |
| 5171 | |
| 5172 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5173 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5174 | return -EINVAL; |
| 5175 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5176 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5177 | /* need to include at least Auth Transaction and Status Code */ |
| 5178 | if (sae_data_len < 4) |
| 5179 | return -EINVAL; |
| 5180 | } |
| 5181 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5182 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5183 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5184 | /* |
| 5185 | * Since we no longer track auth state, ignore |
| 5186 | * requests to only change local state. |
| 5187 | */ |
| 5188 | if (local_state_change) |
| 5189 | return 0; |
| 5190 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5191 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5192 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5193 | key.p.key, key.p.key_len, key.idx, |
| 5194 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5195 | } |
| 5196 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5197 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5198 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5199 | struct cfg80211_crypto_settings *settings, |
| 5200 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5201 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5202 | memset(settings, 0, sizeof(*settings)); |
| 5203 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5204 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5205 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5206 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5207 | u16 proto; |
| 5208 | proto = nla_get_u16( |
| 5209 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5210 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5211 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5212 | proto != ETH_P_PAE) |
| 5213 | return -EINVAL; |
| 5214 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5215 | settings->control_port_no_encrypt = true; |
| 5216 | } else |
| 5217 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5218 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5219 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5220 | void *data; |
| 5221 | int len, i; |
| 5222 | |
| 5223 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5224 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5225 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5226 | |
| 5227 | if (len % sizeof(u32)) |
| 5228 | return -EINVAL; |
| 5229 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5230 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5231 | return -EINVAL; |
| 5232 | |
| 5233 | memcpy(settings->ciphers_pairwise, data, len); |
| 5234 | |
| 5235 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5236 | if (!cfg80211_supported_cipher_suite( |
| 5237 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5238 | settings->ciphers_pairwise[i])) |
| 5239 | return -EINVAL; |
| 5240 | } |
| 5241 | |
| 5242 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5243 | settings->cipher_group = |
| 5244 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5245 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5246 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5247 | return -EINVAL; |
| 5248 | } |
| 5249 | |
| 5250 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5251 | settings->wpa_versions = |
| 5252 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5253 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5254 | return -EINVAL; |
| 5255 | } |
| 5256 | |
| 5257 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5258 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5259 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5260 | |
| 5261 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5262 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5263 | settings->n_akm_suites = len / sizeof(u32); |
| 5264 | |
| 5265 | if (len % sizeof(u32)) |
| 5266 | return -EINVAL; |
| 5267 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5268 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5269 | return -EINVAL; |
| 5270 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5271 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5272 | } |
| 5273 | |
| 5274 | return 0; |
| 5275 | } |
| 5276 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5277 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5278 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5280 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5281 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5282 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5283 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5284 | int err, ssid_len, ie_len = 0; |
| 5285 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5286 | u32 flags = 0; |
| 5287 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5288 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5289 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5290 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5291 | return -EINVAL; |
| 5292 | |
| 5293 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5294 | !info->attrs[NL80211_ATTR_SSID] || |
| 5295 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5296 | return -EINVAL; |
| 5297 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5298 | if (!rdev->ops->assoc) |
| 5299 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5300 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5301 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5302 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5303 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5304 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5305 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5306 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5307 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5308 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5309 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5310 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5311 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5312 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5313 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5314 | |
| 5315 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5316 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5317 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5318 | } |
| 5319 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5320 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5321 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5322 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5323 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5324 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5325 | else if (mfp != NL80211_MFP_NO) |
| 5326 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5327 | } |
| 5328 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5329 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5330 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5331 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5332 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5333 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5334 | |
| 5335 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5336 | ht_capa_mask = |
| 5337 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5338 | |
| 5339 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5340 | if (!ht_capa_mask) |
| 5341 | return -EINVAL; |
| 5342 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5343 | } |
| 5344 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5345 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5346 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5347 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5348 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5349 | &crypto, flags, ht_capa, |
| 5350 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5351 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5352 | return err; |
| 5353 | } |
| 5354 | |
| 5355 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5356 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5357 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5358 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5359 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5360 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5361 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5362 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5363 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5364 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5365 | return -EINVAL; |
| 5366 | |
| 5367 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5368 | return -EINVAL; |
| 5369 | |
| 5370 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5371 | return -EINVAL; |
| 5372 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5373 | if (!rdev->ops->deauth) |
| 5374 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5375 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5376 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5377 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5378 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5379 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5380 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5381 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5382 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5383 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5384 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5385 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5386 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5387 | |
| 5388 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5389 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5390 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5391 | } |
| 5392 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5393 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5394 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5395 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5396 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5397 | } |
| 5398 | |
| 5399 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5400 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5401 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5402 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5403 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5404 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5405 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5406 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5407 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5408 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5409 | return -EINVAL; |
| 5410 | |
| 5411 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5412 | return -EINVAL; |
| 5413 | |
| 5414 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5415 | return -EINVAL; |
| 5416 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5417 | if (!rdev->ops->disassoc) |
| 5418 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5419 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5420 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5421 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5422 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5423 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5424 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5425 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5426 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5427 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5428 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5429 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5430 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5431 | |
| 5432 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5433 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5434 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5435 | } |
| 5436 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5437 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5438 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5439 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5440 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5441 | } |
| 5442 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5443 | static bool |
| 5444 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5445 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5446 | int rateval) |
| 5447 | { |
| 5448 | struct wiphy *wiphy = &rdev->wiphy; |
| 5449 | bool found = false; |
| 5450 | int band, i; |
| 5451 | |
| 5452 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5453 | struct ieee80211_supported_band *sband; |
| 5454 | |
| 5455 | sband = wiphy->bands[band]; |
| 5456 | if (!sband) |
| 5457 | continue; |
| 5458 | |
| 5459 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5460 | if (sband->bitrates[i].bitrate == rateval) { |
| 5461 | mcast_rate[band] = i + 1; |
| 5462 | found = true; |
| 5463 | break; |
| 5464 | } |
| 5465 | } |
| 5466 | } |
| 5467 | |
| 5468 | return found; |
| 5469 | } |
| 5470 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5471 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5472 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5473 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5474 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5475 | struct cfg80211_ibss_params ibss; |
| 5476 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5477 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5478 | int err; |
| 5479 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5480 | memset(&ibss, 0, sizeof(ibss)); |
| 5481 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5482 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5483 | return -EINVAL; |
| 5484 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5485 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5486 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5487 | return -EINVAL; |
| 5488 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5489 | ibss.beacon_interval = 100; |
| 5490 | |
| 5491 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5492 | ibss.beacon_interval = |
| 5493 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5494 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5495 | return -EINVAL; |
| 5496 | } |
| 5497 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5498 | if (!rdev->ops->join_ibss) |
| 5499 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5500 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5501 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5502 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5503 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5504 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5505 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5506 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5507 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5508 | |
| 5509 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5510 | return -EINVAL; |
| 5511 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5512 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5513 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5514 | |
| 5515 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5516 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5517 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5518 | } |
| 5519 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5520 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 5521 | if (err) |
| 5522 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5523 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5524 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5525 | return -EINVAL; |
| 5526 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5527 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 5528 | return -EINVAL; |
| 5529 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 5530 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 5531 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5532 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5533 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5534 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5535 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5536 | u8 *rates = |
| 5537 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5538 | int n_rates = |
| 5539 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5540 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5541 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5542 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5543 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5544 | &ibss.basic_rates); |
| 5545 | if (err) |
| 5546 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5547 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5548 | |
| 5549 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5550 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5551 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5552 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5553 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5554 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5555 | bool no_ht = false; |
| 5556 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5557 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5558 | info->attrs[NL80211_ATTR_KEYS], |
| 5559 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5560 | if (IS_ERR(connkeys)) |
| 5561 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5562 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 5563 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 5564 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5565 | kfree(connkeys); |
| 5566 | return -EINVAL; |
| 5567 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5568 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5569 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5570 | ibss.control_port = |
| 5571 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5572 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5573 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5574 | if (err) |
| 5575 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5576 | return err; |
| 5577 | } |
| 5578 | |
| 5579 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5580 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5581 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5582 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5583 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5584 | if (!rdev->ops->leave_ibss) |
| 5585 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5586 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5587 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5588 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5589 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5590 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5591 | } |
| 5592 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 5593 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 5594 | { |
| 5595 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5596 | struct net_device *dev = info->user_ptr[1]; |
| 5597 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 5598 | u32 nla_rate; |
| 5599 | int err; |
| 5600 | |
| 5601 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5602 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5603 | return -EOPNOTSUPP; |
| 5604 | |
| 5605 | if (!rdev->ops->set_mcast_rate) |
| 5606 | return -EOPNOTSUPP; |
| 5607 | |
| 5608 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 5609 | |
| 5610 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 5611 | return -EINVAL; |
| 5612 | |
| 5613 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 5614 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 5615 | return -EINVAL; |
| 5616 | |
| 5617 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 5618 | |
| 5619 | return err; |
| 5620 | } |
| 5621 | |
| 5622 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5623 | #ifdef CONFIG_NL80211_TESTMODE |
| 5624 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5625 | .name = "testmode", |
| 5626 | }; |
| 5627 | |
| 5628 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5629 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5630 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5631 | int err; |
| 5632 | |
| 5633 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5634 | return -EINVAL; |
| 5635 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5636 | err = -EOPNOTSUPP; |
| 5637 | if (rdev->ops->testmode_cmd) { |
| 5638 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5639 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5640 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5641 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5642 | rdev->testmode_info = NULL; |
| 5643 | } |
| 5644 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5645 | return err; |
| 5646 | } |
| 5647 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5648 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5649 | struct netlink_callback *cb) |
| 5650 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5651 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5652 | int err; |
| 5653 | long phy_idx; |
| 5654 | void *data = NULL; |
| 5655 | int data_len = 0; |
| 5656 | |
| 5657 | if (cb->args[0]) { |
| 5658 | /* |
| 5659 | * 0 is a valid index, but not valid for args[0], |
| 5660 | * so we need to offset by 1. |
| 5661 | */ |
| 5662 | phy_idx = cb->args[0] - 1; |
| 5663 | } else { |
| 5664 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5665 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5666 | nl80211_policy); |
| 5667 | if (err) |
| 5668 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5669 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5670 | mutex_lock(&cfg80211_mutex); |
| 5671 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 5672 | nl80211_fam.attrbuf); |
| 5673 | if (IS_ERR(rdev)) { |
| 5674 | mutex_unlock(&cfg80211_mutex); |
| 5675 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5676 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5677 | phy_idx = rdev->wiphy_idx; |
| 5678 | rdev = NULL; |
| 5679 | mutex_unlock(&cfg80211_mutex); |
| 5680 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5681 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 5682 | cb->args[1] = |
| 5683 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 5684 | } |
| 5685 | |
| 5686 | if (cb->args[1]) { |
| 5687 | data = nla_data((void *)cb->args[1]); |
| 5688 | data_len = nla_len((void *)cb->args[1]); |
| 5689 | } |
| 5690 | |
| 5691 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5692 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 5693 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5694 | mutex_unlock(&cfg80211_mutex); |
| 5695 | return -ENOENT; |
| 5696 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5697 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5698 | mutex_unlock(&cfg80211_mutex); |
| 5699 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5700 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5701 | err = -EOPNOTSUPP; |
| 5702 | goto out_err; |
| 5703 | } |
| 5704 | |
| 5705 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5706 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5707 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5708 | NL80211_CMD_TESTMODE); |
| 5709 | struct nlattr *tmdata; |
| 5710 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5711 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5712 | genlmsg_cancel(skb, hdr); |
| 5713 | break; |
| 5714 | } |
| 5715 | |
| 5716 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5717 | if (!tmdata) { |
| 5718 | genlmsg_cancel(skb, hdr); |
| 5719 | break; |
| 5720 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5721 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5722 | nla_nest_end(skb, tmdata); |
| 5723 | |
| 5724 | if (err == -ENOBUFS || err == -ENOENT) { |
| 5725 | genlmsg_cancel(skb, hdr); |
| 5726 | break; |
| 5727 | } else if (err) { |
| 5728 | genlmsg_cancel(skb, hdr); |
| 5729 | goto out_err; |
| 5730 | } |
| 5731 | |
| 5732 | genlmsg_end(skb, hdr); |
| 5733 | } |
| 5734 | |
| 5735 | err = skb->len; |
| 5736 | /* see above */ |
| 5737 | cb->args[0] = phy_idx + 1; |
| 5738 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5739 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5740 | return err; |
| 5741 | } |
| 5742 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5743 | static struct sk_buff * |
| 5744 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5745 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5746 | { |
| 5747 | struct sk_buff *skb; |
| 5748 | void *hdr; |
| 5749 | struct nlattr *data; |
| 5750 | |
| 5751 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5752 | if (!skb) |
| 5753 | return NULL; |
| 5754 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5755 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5756 | if (!hdr) { |
| 5757 | kfree_skb(skb); |
| 5758 | return NULL; |
| 5759 | } |
| 5760 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5761 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 5762 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5763 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5764 | |
| 5765 | ((void **)skb->cb)[0] = rdev; |
| 5766 | ((void **)skb->cb)[1] = hdr; |
| 5767 | ((void **)skb->cb)[2] = data; |
| 5768 | |
| 5769 | return skb; |
| 5770 | |
| 5771 | nla_put_failure: |
| 5772 | kfree_skb(skb); |
| 5773 | return NULL; |
| 5774 | } |
| 5775 | |
| 5776 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5777 | int approxlen) |
| 5778 | { |
| 5779 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5780 | |
| 5781 | if (WARN_ON(!rdev->testmode_info)) |
| 5782 | return NULL; |
| 5783 | |
| 5784 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5785 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5786 | rdev->testmode_info->snd_seq, |
| 5787 | GFP_KERNEL); |
| 5788 | } |
| 5789 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5790 | |
| 5791 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5792 | { |
| 5793 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5794 | void *hdr = ((void **)skb->cb)[1]; |
| 5795 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5796 | |
| 5797 | if (WARN_ON(!rdev->testmode_info)) { |
| 5798 | kfree_skb(skb); |
| 5799 | return -EINVAL; |
| 5800 | } |
| 5801 | |
| 5802 | nla_nest_end(skb, data); |
| 5803 | genlmsg_end(skb, hdr); |
| 5804 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5805 | } |
| 5806 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5807 | |
| 5808 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5809 | int approxlen, gfp_t gfp) |
| 5810 | { |
| 5811 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5812 | |
| 5813 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5814 | } |
| 5815 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5816 | |
| 5817 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5818 | { |
| 5819 | void *hdr = ((void **)skb->cb)[1]; |
| 5820 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5821 | |
| 5822 | nla_nest_end(skb, data); |
| 5823 | genlmsg_end(skb, hdr); |
| 5824 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5825 | } |
| 5826 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5827 | #endif |
| 5828 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5829 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5830 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5831 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5832 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5833 | struct cfg80211_connect_params connect; |
| 5834 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5835 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5836 | int err; |
| 5837 | |
| 5838 | memset(&connect, 0, sizeof(connect)); |
| 5839 | |
| 5840 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5841 | return -EINVAL; |
| 5842 | |
| 5843 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5844 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5845 | return -EINVAL; |
| 5846 | |
| 5847 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5848 | connect.auth_type = |
| 5849 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5850 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 5851 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5852 | return -EINVAL; |
| 5853 | } else |
| 5854 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5855 | |
| 5856 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5857 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5858 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5859 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5860 | if (err) |
| 5861 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5862 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5863 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5864 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5865 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5866 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5867 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5868 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 5869 | connect.bg_scan_period = -1; |
| 5870 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 5871 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 5872 | connect.bg_scan_period = |
| 5873 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 5874 | } |
| 5875 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5876 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5877 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5878 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5879 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5880 | |
| 5881 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5882 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5883 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5884 | } |
| 5885 | |
| 5886 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5887 | connect.channel = |
| 5888 | ieee80211_get_channel(wiphy, |
| 5889 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5890 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5891 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5892 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5893 | } |
| 5894 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5895 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5896 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5897 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5898 | if (IS_ERR(connkeys)) |
| 5899 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5900 | } |
| 5901 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5902 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5903 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5904 | |
| 5905 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5906 | memcpy(&connect.ht_capa_mask, |
| 5907 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5908 | sizeof(connect.ht_capa_mask)); |
| 5909 | |
| 5910 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5911 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 5912 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5913 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5914 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5915 | memcpy(&connect.ht_capa, |
| 5916 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5917 | sizeof(connect.ht_capa)); |
| 5918 | } |
| 5919 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5920 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5921 | if (err) |
| 5922 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5923 | return err; |
| 5924 | } |
| 5925 | |
| 5926 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5927 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5928 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5929 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5930 | u16 reason; |
| 5931 | |
| 5932 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5933 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5934 | else |
| 5935 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5936 | |
| 5937 | if (reason == 0) |
| 5938 | return -EINVAL; |
| 5939 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5940 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5941 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5942 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5943 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5944 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5945 | } |
| 5946 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5947 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5948 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5949 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5950 | struct net *net; |
| 5951 | int err; |
| 5952 | u32 pid; |
| 5953 | |
| 5954 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5955 | return -EINVAL; |
| 5956 | |
| 5957 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5958 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5959 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5960 | if (IS_ERR(net)) |
| 5961 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5962 | |
| 5963 | err = 0; |
| 5964 | |
| 5965 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5966 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5967 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5968 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5969 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5970 | return err; |
| 5971 | } |
| 5972 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5973 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5974 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5975 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5976 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5977 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5978 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5979 | struct cfg80211_pmksa pmksa; |
| 5980 | |
| 5981 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5982 | |
| 5983 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5984 | return -EINVAL; |
| 5985 | |
| 5986 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5987 | return -EINVAL; |
| 5988 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5989 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5990 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5991 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5992 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5993 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5994 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5995 | |
| 5996 | switch (info->genlhdr->cmd) { |
| 5997 | case NL80211_CMD_SET_PMKSA: |
| 5998 | rdev_ops = rdev->ops->set_pmksa; |
| 5999 | break; |
| 6000 | case NL80211_CMD_DEL_PMKSA: |
| 6001 | rdev_ops = rdev->ops->del_pmksa; |
| 6002 | break; |
| 6003 | default: |
| 6004 | WARN_ON(1); |
| 6005 | break; |
| 6006 | } |
| 6007 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6008 | if (!rdev_ops) |
| 6009 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6010 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6011 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6012 | } |
| 6013 | |
| 6014 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6015 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6016 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6017 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6018 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6019 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6020 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6021 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6022 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6023 | if (!rdev->ops->flush_pmksa) |
| 6024 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6025 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6026 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6027 | } |
| 6028 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6029 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6030 | { |
| 6031 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6032 | struct net_device *dev = info->user_ptr[1]; |
| 6033 | u8 action_code, dialog_token; |
| 6034 | u16 status_code; |
| 6035 | u8 *peer; |
| 6036 | |
| 6037 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6038 | !rdev->ops->tdls_mgmt) |
| 6039 | return -EOPNOTSUPP; |
| 6040 | |
| 6041 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6042 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6043 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6044 | !info->attrs[NL80211_ATTR_IE] || |
| 6045 | !info->attrs[NL80211_ATTR_MAC]) |
| 6046 | return -EINVAL; |
| 6047 | |
| 6048 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6049 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6050 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6051 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6052 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6053 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6054 | dialog_token, status_code, |
| 6055 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6056 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6057 | } |
| 6058 | |
| 6059 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6060 | { |
| 6061 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6062 | struct net_device *dev = info->user_ptr[1]; |
| 6063 | enum nl80211_tdls_operation operation; |
| 6064 | u8 *peer; |
| 6065 | |
| 6066 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6067 | !rdev->ops->tdls_oper) |
| 6068 | return -EOPNOTSUPP; |
| 6069 | |
| 6070 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6071 | !info->attrs[NL80211_ATTR_MAC]) |
| 6072 | return -EINVAL; |
| 6073 | |
| 6074 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6075 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6076 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6077 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6078 | } |
| 6079 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6080 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6081 | struct genl_info *info) |
| 6082 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6083 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6084 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6085 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6086 | struct sk_buff *msg; |
| 6087 | void *hdr; |
| 6088 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6089 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6090 | int err; |
| 6091 | |
| 6092 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6093 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6094 | return -EINVAL; |
| 6095 | |
| 6096 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6097 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6098 | if (!rdev->ops->remain_on_channel || |
| 6099 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6100 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6101 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6102 | /* |
| 6103 | * We should be on that channel for at least a minimum amount of |
| 6104 | * time (10ms) but no longer than the driver supports. |
| 6105 | */ |
| 6106 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6107 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6108 | return -EINVAL; |
| 6109 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6110 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6111 | if (err) |
| 6112 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6113 | |
| 6114 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6115 | if (!msg) |
| 6116 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6117 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6118 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6119 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6120 | |
| 6121 | if (IS_ERR(hdr)) { |
| 6122 | err = PTR_ERR(hdr); |
| 6123 | goto free_msg; |
| 6124 | } |
| 6125 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6126 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6127 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6128 | |
| 6129 | if (err) |
| 6130 | goto free_msg; |
| 6131 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6132 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6133 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6134 | |
| 6135 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6136 | |
| 6137 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6138 | |
| 6139 | nla_put_failure: |
| 6140 | err = -ENOBUFS; |
| 6141 | free_msg: |
| 6142 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6143 | return err; |
| 6144 | } |
| 6145 | |
| 6146 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6147 | struct genl_info *info) |
| 6148 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6149 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6150 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6151 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6152 | |
| 6153 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6154 | return -EINVAL; |
| 6155 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6156 | if (!rdev->ops->cancel_remain_on_channel) |
| 6157 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6158 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6159 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6160 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6161 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6162 | } |
| 6163 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6164 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6165 | u8 *rates, u8 rates_len) |
| 6166 | { |
| 6167 | u8 i; |
| 6168 | u32 mask = 0; |
| 6169 | |
| 6170 | for (i = 0; i < rates_len; i++) { |
| 6171 | int rate = (rates[i] & 0x7f) * 5; |
| 6172 | int ridx; |
| 6173 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6174 | struct ieee80211_rate *srate = |
| 6175 | &sband->bitrates[ridx]; |
| 6176 | if (rate == srate->bitrate) { |
| 6177 | mask |= 1 << ridx; |
| 6178 | break; |
| 6179 | } |
| 6180 | } |
| 6181 | if (ridx == sband->n_bitrates) |
| 6182 | return 0; /* rate not found */ |
| 6183 | } |
| 6184 | |
| 6185 | return mask; |
| 6186 | } |
| 6187 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6188 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6189 | u8 *rates, u8 rates_len, |
| 6190 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6191 | { |
| 6192 | u8 i; |
| 6193 | |
| 6194 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6195 | |
| 6196 | for (i = 0; i < rates_len; i++) { |
| 6197 | int ridx, rbit; |
| 6198 | |
| 6199 | ridx = rates[i] / 8; |
| 6200 | rbit = BIT(rates[i] % 8); |
| 6201 | |
| 6202 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6203 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6204 | return false; |
| 6205 | |
| 6206 | /* check availability */ |
| 6207 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6208 | mcs[ridx] |= rbit; |
| 6209 | else |
| 6210 | return false; |
| 6211 | } |
| 6212 | |
| 6213 | return true; |
| 6214 | } |
| 6215 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6216 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6217 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6218 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6219 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6220 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6221 | }; |
| 6222 | |
| 6223 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6224 | struct genl_info *info) |
| 6225 | { |
| 6226 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6227 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6228 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6229 | int rem, i; |
| 6230 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6231 | struct nlattr *tx_rates; |
| 6232 | struct ieee80211_supported_band *sband; |
| 6233 | |
| 6234 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6235 | return -EINVAL; |
| 6236 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6237 | if (!rdev->ops->set_bitrate_mask) |
| 6238 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6239 | |
| 6240 | memset(&mask, 0, sizeof(mask)); |
| 6241 | /* Default to all rates enabled */ |
| 6242 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6243 | sband = rdev->wiphy.bands[i]; |
| 6244 | mask.control[i].legacy = |
| 6245 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6246 | if (sband) |
| 6247 | memcpy(mask.control[i].mcs, |
| 6248 | sband->ht_cap.mcs.rx_mask, |
| 6249 | sizeof(mask.control[i].mcs)); |
| 6250 | else |
| 6251 | memset(mask.control[i].mcs, 0, |
| 6252 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6253 | } |
| 6254 | |
| 6255 | /* |
| 6256 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6257 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6258 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6259 | 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] | 6260 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6261 | { |
| 6262 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6263 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6264 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6265 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6266 | if (sband == NULL) |
| 6267 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6268 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6269 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6270 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6271 | mask.control[band].legacy = rateset_to_mask( |
| 6272 | sband, |
| 6273 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6274 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6275 | if ((mask.control[band].legacy == 0) && |
| 6276 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6277 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6278 | } |
| 6279 | if (tb[NL80211_TXRATE_MCS]) { |
| 6280 | if (!ht_rateset_to_mask( |
| 6281 | sband, |
| 6282 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6283 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6284 | mask.control[band].mcs)) |
| 6285 | return -EINVAL; |
| 6286 | } |
| 6287 | |
| 6288 | if (mask.control[band].legacy == 0) { |
| 6289 | /* don't allow empty legacy rates if HT |
| 6290 | * is not even supported. */ |
| 6291 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6292 | return -EINVAL; |
| 6293 | |
| 6294 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6295 | if (mask.control[band].mcs[i]) |
| 6296 | break; |
| 6297 | |
| 6298 | /* legacy and mcs rates may not be both empty */ |
| 6299 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6300 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6301 | } |
| 6302 | } |
| 6303 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6304 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6305 | } |
| 6306 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6307 | 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] | 6308 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6309 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6310 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6311 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6312 | |
| 6313 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6314 | return -EINVAL; |
| 6315 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6316 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6317 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6318 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6319 | switch (wdev->iftype) { |
| 6320 | case NL80211_IFTYPE_STATION: |
| 6321 | case NL80211_IFTYPE_ADHOC: |
| 6322 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6323 | case NL80211_IFTYPE_AP: |
| 6324 | case NL80211_IFTYPE_AP_VLAN: |
| 6325 | case NL80211_IFTYPE_MESH_POINT: |
| 6326 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6327 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6328 | break; |
| 6329 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6330 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6331 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6332 | |
| 6333 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6334 | if (!rdev->ops->mgmt_tx) |
| 6335 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6336 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6337 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6338 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6339 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6340 | } |
| 6341 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6342 | 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] | 6343 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6344 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6345 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6346 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6347 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6348 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6349 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6350 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6351 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6352 | bool offchan, no_cck, dont_wait_for_ack; |
| 6353 | |
| 6354 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6355 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6356 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6357 | return -EINVAL; |
| 6358 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6359 | if (!rdev->ops->mgmt_tx) |
| 6360 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6361 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6362 | switch (wdev->iftype) { |
| 6363 | case NL80211_IFTYPE_STATION: |
| 6364 | case NL80211_IFTYPE_ADHOC: |
| 6365 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6366 | case NL80211_IFTYPE_AP: |
| 6367 | case NL80211_IFTYPE_AP_VLAN: |
| 6368 | case NL80211_IFTYPE_MESH_POINT: |
| 6369 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6370 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6371 | break; |
| 6372 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6373 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6374 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6375 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6376 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6377 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6378 | return -EINVAL; |
| 6379 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6380 | |
| 6381 | /* |
| 6382 | * We should wait on the channel for at least a minimum amount |
| 6383 | * of time (10ms) but no longer than the driver supports. |
| 6384 | */ |
| 6385 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6386 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6387 | return -EINVAL; |
| 6388 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6389 | } |
| 6390 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6391 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6392 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6393 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6394 | return -EINVAL; |
| 6395 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6396 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6397 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6398 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6399 | if (err) |
| 6400 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6401 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6402 | if (!dont_wait_for_ack) { |
| 6403 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6404 | if (!msg) |
| 6405 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6406 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6407 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6408 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6409 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6410 | if (IS_ERR(hdr)) { |
| 6411 | err = PTR_ERR(hdr); |
| 6412 | goto free_msg; |
| 6413 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6414 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6415 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6416 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6417 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6418 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6419 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6420 | if (err) |
| 6421 | goto free_msg; |
| 6422 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6423 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6424 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6425 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6426 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6427 | genlmsg_end(msg, hdr); |
| 6428 | return genlmsg_reply(msg, info); |
| 6429 | } |
| 6430 | |
| 6431 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6432 | |
| 6433 | nla_put_failure: |
| 6434 | err = -ENOBUFS; |
| 6435 | free_msg: |
| 6436 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6437 | return err; |
| 6438 | } |
| 6439 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6440 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6441 | { |
| 6442 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6443 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6444 | u64 cookie; |
| 6445 | |
| 6446 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6447 | return -EINVAL; |
| 6448 | |
| 6449 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6450 | return -EOPNOTSUPP; |
| 6451 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6452 | switch (wdev->iftype) { |
| 6453 | case NL80211_IFTYPE_STATION: |
| 6454 | case NL80211_IFTYPE_ADHOC: |
| 6455 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6456 | case NL80211_IFTYPE_AP: |
| 6457 | case NL80211_IFTYPE_AP_VLAN: |
| 6458 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6459 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6460 | break; |
| 6461 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6462 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6463 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6464 | |
| 6465 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6466 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6467 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6468 | } |
| 6469 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6470 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6471 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6472 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6473 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6474 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6475 | u8 ps_state; |
| 6476 | bool state; |
| 6477 | int err; |
| 6478 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6479 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6480 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6481 | |
| 6482 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6483 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6484 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6485 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6486 | |
| 6487 | wdev = dev->ieee80211_ptr; |
| 6488 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6489 | if (!rdev->ops->set_power_mgmt) |
| 6490 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6491 | |
| 6492 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6493 | |
| 6494 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6495 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6496 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6497 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6498 | if (!err) |
| 6499 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6500 | return err; |
| 6501 | } |
| 6502 | |
| 6503 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6504 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6505 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6506 | enum nl80211_ps_state ps_state; |
| 6507 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6508 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6509 | struct sk_buff *msg; |
| 6510 | void *hdr; |
| 6511 | int err; |
| 6512 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6513 | wdev = dev->ieee80211_ptr; |
| 6514 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6515 | if (!rdev->ops->set_power_mgmt) |
| 6516 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6517 | |
| 6518 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6519 | if (!msg) |
| 6520 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6521 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6522 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6523 | NL80211_CMD_GET_POWER_SAVE); |
| 6524 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6525 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6526 | goto free_msg; |
| 6527 | } |
| 6528 | |
| 6529 | if (wdev->ps) |
| 6530 | ps_state = NL80211_PS_ENABLED; |
| 6531 | else |
| 6532 | ps_state = NL80211_PS_DISABLED; |
| 6533 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6534 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6535 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6536 | |
| 6537 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6538 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6539 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6540 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6541 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6542 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6543 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6544 | return err; |
| 6545 | } |
| 6546 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6547 | static struct nla_policy |
| 6548 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6549 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6550 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6551 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6552 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 6553 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 6554 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6555 | }; |
| 6556 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6557 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame^] | 6558 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6559 | { |
| 6560 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6561 | struct wireless_dev *wdev; |
| 6562 | struct net_device *dev = info->user_ptr[1]; |
| 6563 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame^] | 6564 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6565 | return -EINVAL; |
| 6566 | |
| 6567 | wdev = dev->ieee80211_ptr; |
| 6568 | |
| 6569 | if (!rdev->ops->set_cqm_txe_config) |
| 6570 | return -EOPNOTSUPP; |
| 6571 | |
| 6572 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 6573 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6574 | return -EOPNOTSUPP; |
| 6575 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6576 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6577 | } |
| 6578 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6579 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6580 | s32 threshold, u32 hysteresis) |
| 6581 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6582 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6583 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6584 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6585 | |
| 6586 | if (threshold > 0) |
| 6587 | return -EINVAL; |
| 6588 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6589 | wdev = dev->ieee80211_ptr; |
| 6590 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6591 | if (!rdev->ops->set_cqm_rssi_config) |
| 6592 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6593 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6594 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6595 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6596 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6597 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6598 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6599 | } |
| 6600 | |
| 6601 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6602 | { |
| 6603 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6604 | struct nlattr *cqm; |
| 6605 | int err; |
| 6606 | |
| 6607 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6608 | if (!cqm) { |
| 6609 | err = -EINVAL; |
| 6610 | goto out; |
| 6611 | } |
| 6612 | |
| 6613 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6614 | nl80211_attr_cqm_policy); |
| 6615 | if (err) |
| 6616 | goto out; |
| 6617 | |
| 6618 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6619 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6620 | s32 threshold; |
| 6621 | u32 hysteresis; |
| 6622 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6623 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6624 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6625 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 6626 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 6627 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 6628 | u32 rate, pkts, intvl; |
| 6629 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 6630 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 6631 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 6632 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6633 | } else |
| 6634 | err = -EINVAL; |
| 6635 | |
| 6636 | out: |
| 6637 | return err; |
| 6638 | } |
| 6639 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6640 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6641 | { |
| 6642 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6643 | struct net_device *dev = info->user_ptr[1]; |
| 6644 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6645 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6646 | int err; |
| 6647 | |
| 6648 | /* start with default */ |
| 6649 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6650 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6651 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6652 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6653 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6654 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6655 | if (err) |
| 6656 | return err; |
| 6657 | } |
| 6658 | |
| 6659 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6660 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 6661 | return -EINVAL; |
| 6662 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6663 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6664 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6665 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 6666 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6667 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 6668 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6669 | return -EINVAL; |
| 6670 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6671 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 6672 | /* parse additional setup parameters if given */ |
| 6673 | err = nl80211_parse_mesh_setup(info, &setup); |
| 6674 | if (err) |
| 6675 | return err; |
| 6676 | } |
| 6677 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6678 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6679 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 6680 | if (err) |
| 6681 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6682 | } else { |
| 6683 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6684 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6685 | } |
| 6686 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6687 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6688 | } |
| 6689 | |
| 6690 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6691 | { |
| 6692 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6693 | struct net_device *dev = info->user_ptr[1]; |
| 6694 | |
| 6695 | return cfg80211_leave_mesh(rdev, dev); |
| 6696 | } |
| 6697 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6698 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6699 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6700 | { |
| 6701 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6702 | struct sk_buff *msg; |
| 6703 | void *hdr; |
| 6704 | |
| 6705 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6706 | return -EOPNOTSUPP; |
| 6707 | |
| 6708 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6709 | if (!msg) |
| 6710 | return -ENOMEM; |
| 6711 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6712 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6713 | NL80211_CMD_GET_WOWLAN); |
| 6714 | if (!hdr) |
| 6715 | goto nla_put_failure; |
| 6716 | |
| 6717 | if (rdev->wowlan) { |
| 6718 | struct nlattr *nl_wowlan; |
| 6719 | |
| 6720 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 6721 | if (!nl_wowlan) |
| 6722 | goto nla_put_failure; |
| 6723 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6724 | if ((rdev->wowlan->any && |
| 6725 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 6726 | (rdev->wowlan->disconnect && |
| 6727 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 6728 | (rdev->wowlan->magic_pkt && |
| 6729 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 6730 | (rdev->wowlan->gtk_rekey_failure && |
| 6731 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 6732 | (rdev->wowlan->eap_identity_req && |
| 6733 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 6734 | (rdev->wowlan->four_way_handshake && |
| 6735 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 6736 | (rdev->wowlan->rfkill_release && |
| 6737 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 6738 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6739 | if (rdev->wowlan->n_patterns) { |
| 6740 | struct nlattr *nl_pats, *nl_pat; |
| 6741 | int i, pat_len; |
| 6742 | |
| 6743 | nl_pats = nla_nest_start(msg, |
| 6744 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 6745 | if (!nl_pats) |
| 6746 | goto nla_put_failure; |
| 6747 | |
| 6748 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 6749 | nl_pat = nla_nest_start(msg, i + 1); |
| 6750 | if (!nl_pat) |
| 6751 | goto nla_put_failure; |
| 6752 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6753 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 6754 | DIV_ROUND_UP(pat_len, 8), |
| 6755 | rdev->wowlan->patterns[i].mask) || |
| 6756 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 6757 | pat_len, |
| 6758 | rdev->wowlan->patterns[i].pattern)) |
| 6759 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6760 | nla_nest_end(msg, nl_pat); |
| 6761 | } |
| 6762 | nla_nest_end(msg, nl_pats); |
| 6763 | } |
| 6764 | |
| 6765 | nla_nest_end(msg, nl_wowlan); |
| 6766 | } |
| 6767 | |
| 6768 | genlmsg_end(msg, hdr); |
| 6769 | return genlmsg_reply(msg, info); |
| 6770 | |
| 6771 | nla_put_failure: |
| 6772 | nlmsg_free(msg); |
| 6773 | return -ENOBUFS; |
| 6774 | } |
| 6775 | |
| 6776 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6777 | { |
| 6778 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6779 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6780 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6781 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6782 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 6783 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6784 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6785 | |
| 6786 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6787 | return -EOPNOTSUPP; |
| 6788 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6789 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 6790 | cfg80211_rdev_free_wowlan(rdev); |
| 6791 | rdev->wowlan = NULL; |
| 6792 | goto set_wakeup; |
| 6793 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6794 | |
| 6795 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 6796 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6797 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6798 | nl80211_wowlan_policy); |
| 6799 | if (err) |
| 6800 | return err; |
| 6801 | |
| 6802 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 6803 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 6804 | return -EINVAL; |
| 6805 | new_triggers.any = true; |
| 6806 | } |
| 6807 | |
| 6808 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 6809 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 6810 | return -EINVAL; |
| 6811 | new_triggers.disconnect = true; |
| 6812 | } |
| 6813 | |
| 6814 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 6815 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 6816 | return -EINVAL; |
| 6817 | new_triggers.magic_pkt = true; |
| 6818 | } |
| 6819 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 6820 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 6821 | return -EINVAL; |
| 6822 | |
| 6823 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 6824 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 6825 | return -EINVAL; |
| 6826 | new_triggers.gtk_rekey_failure = true; |
| 6827 | } |
| 6828 | |
| 6829 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 6830 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 6831 | return -EINVAL; |
| 6832 | new_triggers.eap_identity_req = true; |
| 6833 | } |
| 6834 | |
| 6835 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 6836 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 6837 | return -EINVAL; |
| 6838 | new_triggers.four_way_handshake = true; |
| 6839 | } |
| 6840 | |
| 6841 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 6842 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 6843 | return -EINVAL; |
| 6844 | new_triggers.rfkill_release = true; |
| 6845 | } |
| 6846 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6847 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 6848 | struct nlattr *pat; |
| 6849 | int n_patterns = 0; |
| 6850 | int rem, pat_len, mask_len; |
| 6851 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6852 | |
| 6853 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6854 | rem) |
| 6855 | n_patterns++; |
| 6856 | if (n_patterns > wowlan->n_patterns) |
| 6857 | return -EINVAL; |
| 6858 | |
| 6859 | new_triggers.patterns = kcalloc(n_patterns, |
| 6860 | sizeof(new_triggers.patterns[0]), |
| 6861 | GFP_KERNEL); |
| 6862 | if (!new_triggers.patterns) |
| 6863 | return -ENOMEM; |
| 6864 | |
| 6865 | new_triggers.n_patterns = n_patterns; |
| 6866 | i = 0; |
| 6867 | |
| 6868 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6869 | rem) { |
| 6870 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6871 | nla_data(pat), nla_len(pat), NULL); |
| 6872 | err = -EINVAL; |
| 6873 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6874 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6875 | goto error; |
| 6876 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6877 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6878 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6879 | mask_len) |
| 6880 | goto error; |
| 6881 | if (pat_len > wowlan->pattern_max_len || |
| 6882 | pat_len < wowlan->pattern_min_len) |
| 6883 | goto error; |
| 6884 | |
| 6885 | new_triggers.patterns[i].mask = |
| 6886 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6887 | if (!new_triggers.patterns[i].mask) { |
| 6888 | err = -ENOMEM; |
| 6889 | goto error; |
| 6890 | } |
| 6891 | new_triggers.patterns[i].pattern = |
| 6892 | new_triggers.patterns[i].mask + mask_len; |
| 6893 | memcpy(new_triggers.patterns[i].mask, |
| 6894 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6895 | mask_len); |
| 6896 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6897 | memcpy(new_triggers.patterns[i].pattern, |
| 6898 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6899 | pat_len); |
| 6900 | i++; |
| 6901 | } |
| 6902 | } |
| 6903 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6904 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 6905 | if (!ntrig) { |
| 6906 | err = -ENOMEM; |
| 6907 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6908 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6909 | cfg80211_rdev_free_wowlan(rdev); |
| 6910 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6911 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6912 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6913 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6914 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6915 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6916 | return 0; |
| 6917 | error: |
| 6918 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6919 | kfree(new_triggers.patterns[i].mask); |
| 6920 | kfree(new_triggers.patterns); |
| 6921 | return err; |
| 6922 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6923 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6924 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6925 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6926 | { |
| 6927 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6928 | struct net_device *dev = info->user_ptr[1]; |
| 6929 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6930 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6931 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6932 | int err; |
| 6933 | |
| 6934 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6935 | return -EINVAL; |
| 6936 | |
| 6937 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6938 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6939 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6940 | nl80211_rekey_policy); |
| 6941 | if (err) |
| 6942 | return err; |
| 6943 | |
| 6944 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6945 | return -ERANGE; |
| 6946 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6947 | return -ERANGE; |
| 6948 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6949 | return -ERANGE; |
| 6950 | |
| 6951 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6952 | NL80211_KEK_LEN); |
| 6953 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6954 | NL80211_KCK_LEN); |
| 6955 | memcpy(rekey_data.replay_ctr, |
| 6956 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6957 | NL80211_REPLAY_CTR_LEN); |
| 6958 | |
| 6959 | wdev_lock(wdev); |
| 6960 | if (!wdev->current_bss) { |
| 6961 | err = -ENOTCONN; |
| 6962 | goto out; |
| 6963 | } |
| 6964 | |
| 6965 | if (!rdev->ops->set_rekey_data) { |
| 6966 | err = -EOPNOTSUPP; |
| 6967 | goto out; |
| 6968 | } |
| 6969 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6970 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6971 | out: |
| 6972 | wdev_unlock(wdev); |
| 6973 | return err; |
| 6974 | } |
| 6975 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6976 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6977 | struct genl_info *info) |
| 6978 | { |
| 6979 | struct net_device *dev = info->user_ptr[1]; |
| 6980 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6981 | |
| 6982 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6983 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6984 | return -EINVAL; |
| 6985 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6986 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6987 | return -EBUSY; |
| 6988 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6989 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6990 | return 0; |
| 6991 | } |
| 6992 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6993 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6994 | struct genl_info *info) |
| 6995 | { |
| 6996 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6997 | struct net_device *dev = info->user_ptr[1]; |
| 6998 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6999 | struct sk_buff *msg; |
| 7000 | void *hdr; |
| 7001 | const u8 *addr; |
| 7002 | u64 cookie; |
| 7003 | int err; |
| 7004 | |
| 7005 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 7006 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 7007 | return -EOPNOTSUPP; |
| 7008 | |
| 7009 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7010 | return -EINVAL; |
| 7011 | |
| 7012 | if (!rdev->ops->probe_client) |
| 7013 | return -EOPNOTSUPP; |
| 7014 | |
| 7015 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7016 | if (!msg) |
| 7017 | return -ENOMEM; |
| 7018 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7019 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7020 | NL80211_CMD_PROBE_CLIENT); |
| 7021 | |
| 7022 | if (IS_ERR(hdr)) { |
| 7023 | err = PTR_ERR(hdr); |
| 7024 | goto free_msg; |
| 7025 | } |
| 7026 | |
| 7027 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7028 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7029 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7030 | if (err) |
| 7031 | goto free_msg; |
| 7032 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7033 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7034 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7035 | |
| 7036 | genlmsg_end(msg, hdr); |
| 7037 | |
| 7038 | return genlmsg_reply(msg, info); |
| 7039 | |
| 7040 | nla_put_failure: |
| 7041 | err = -ENOBUFS; |
| 7042 | free_msg: |
| 7043 | nlmsg_free(msg); |
| 7044 | return err; |
| 7045 | } |
| 7046 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7047 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 7048 | { |
| 7049 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7050 | struct cfg80211_beacon_registration *reg, *nreg; |
| 7051 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7052 | |
| 7053 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 7054 | return -EOPNOTSUPP; |
| 7055 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7056 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 7057 | if (!nreg) |
| 7058 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7059 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7060 | /* First, check if already registered. */ |
| 7061 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 7062 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 7063 | if (reg->nlportid == info->snd_portid) { |
| 7064 | rv = -EALREADY; |
| 7065 | goto out_err; |
| 7066 | } |
| 7067 | } |
| 7068 | /* Add it to the list */ |
| 7069 | nreg->nlportid = info->snd_portid; |
| 7070 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 7071 | |
| 7072 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7073 | |
| 7074 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7075 | out_err: |
| 7076 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 7077 | kfree(nreg); |
| 7078 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7079 | } |
| 7080 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7081 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7082 | { |
| 7083 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7084 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7085 | int err; |
| 7086 | |
| 7087 | if (!rdev->ops->start_p2p_device) |
| 7088 | return -EOPNOTSUPP; |
| 7089 | |
| 7090 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7091 | return -EOPNOTSUPP; |
| 7092 | |
| 7093 | if (wdev->p2p_started) |
| 7094 | return 0; |
| 7095 | |
| 7096 | mutex_lock(&rdev->devlist_mtx); |
| 7097 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 7098 | mutex_unlock(&rdev->devlist_mtx); |
| 7099 | if (err) |
| 7100 | return err; |
| 7101 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7102 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7103 | if (err) |
| 7104 | return err; |
| 7105 | |
| 7106 | wdev->p2p_started = true; |
| 7107 | mutex_lock(&rdev->devlist_mtx); |
| 7108 | rdev->opencount++; |
| 7109 | mutex_unlock(&rdev->devlist_mtx); |
| 7110 | |
| 7111 | return 0; |
| 7112 | } |
| 7113 | |
| 7114 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7115 | { |
| 7116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7117 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7118 | |
| 7119 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7120 | return -EOPNOTSUPP; |
| 7121 | |
| 7122 | if (!rdev->ops->stop_p2p_device) |
| 7123 | return -EOPNOTSUPP; |
| 7124 | |
| 7125 | if (!wdev->p2p_started) |
| 7126 | return 0; |
| 7127 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7128 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7129 | wdev->p2p_started = false; |
| 7130 | |
| 7131 | mutex_lock(&rdev->devlist_mtx); |
| 7132 | rdev->opencount--; |
| 7133 | mutex_unlock(&rdev->devlist_mtx); |
| 7134 | |
| 7135 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 7136 | rdev->scan_req->aborted = true; |
| 7137 | ___cfg80211_scan_done(rdev, true); |
| 7138 | } |
| 7139 | |
| 7140 | return 0; |
| 7141 | } |
| 7142 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7143 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 7144 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 7145 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7146 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 7147 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 7148 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7149 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7150 | /* 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] | 7151 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 7152 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7153 | |
| 7154 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7155 | struct genl_info *info) |
| 7156 | { |
| 7157 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7158 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7159 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7160 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 7161 | |
| 7162 | if (rtnl) |
| 7163 | rtnl_lock(); |
| 7164 | |
| 7165 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 7166 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7167 | if (IS_ERR(rdev)) { |
| 7168 | if (rtnl) |
| 7169 | rtnl_unlock(); |
| 7170 | return PTR_ERR(rdev); |
| 7171 | } |
| 7172 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7173 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7174 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7175 | mutex_lock(&cfg80211_mutex); |
| 7176 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7177 | info->attrs); |
| 7178 | if (IS_ERR(wdev)) { |
| 7179 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7180 | if (rtnl) |
| 7181 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7182 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7183 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7184 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7185 | dev = wdev->netdev; |
| 7186 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7187 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7188 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7189 | if (!dev) { |
| 7190 | mutex_unlock(&cfg80211_mutex); |
| 7191 | if (rtnl) |
| 7192 | rtnl_unlock(); |
| 7193 | return -EINVAL; |
| 7194 | } |
| 7195 | |
| 7196 | info->user_ptr[1] = dev; |
| 7197 | } else { |
| 7198 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7199 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7200 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7201 | if (dev) { |
| 7202 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7203 | !netif_running(dev)) { |
| 7204 | mutex_unlock(&cfg80211_mutex); |
| 7205 | if (rtnl) |
| 7206 | rtnl_unlock(); |
| 7207 | return -ENETDOWN; |
| 7208 | } |
| 7209 | |
| 7210 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7211 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7212 | if (!wdev->p2p_started) { |
| 7213 | mutex_unlock(&cfg80211_mutex); |
| 7214 | if (rtnl) |
| 7215 | rtnl_unlock(); |
| 7216 | return -ENETDOWN; |
| 7217 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7218 | } |
| 7219 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7220 | cfg80211_lock_rdev(rdev); |
| 7221 | |
| 7222 | mutex_unlock(&cfg80211_mutex); |
| 7223 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7224 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7225 | } |
| 7226 | |
| 7227 | return 0; |
| 7228 | } |
| 7229 | |
| 7230 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7231 | struct genl_info *info) |
| 7232 | { |
| 7233 | if (info->user_ptr[0]) |
| 7234 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7235 | if (info->user_ptr[1]) { |
| 7236 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7237 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7238 | |
| 7239 | if (wdev->netdev) |
| 7240 | dev_put(wdev->netdev); |
| 7241 | } else { |
| 7242 | dev_put(info->user_ptr[1]); |
| 7243 | } |
| 7244 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7245 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7246 | rtnl_unlock(); |
| 7247 | } |
| 7248 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7249 | static struct genl_ops nl80211_ops[] = { |
| 7250 | { |
| 7251 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7252 | .doit = nl80211_get_wiphy, |
| 7253 | .dumpit = nl80211_dump_wiphy, |
| 7254 | .policy = nl80211_policy, |
| 7255 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7256 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7257 | }, |
| 7258 | { |
| 7259 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7260 | .doit = nl80211_set_wiphy, |
| 7261 | .policy = nl80211_policy, |
| 7262 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7263 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7264 | }, |
| 7265 | { |
| 7266 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7267 | .doit = nl80211_get_interface, |
| 7268 | .dumpit = nl80211_dump_interface, |
| 7269 | .policy = nl80211_policy, |
| 7270 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7271 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7272 | }, |
| 7273 | { |
| 7274 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7275 | .doit = nl80211_set_interface, |
| 7276 | .policy = nl80211_policy, |
| 7277 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7278 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7279 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7280 | }, |
| 7281 | { |
| 7282 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7283 | .doit = nl80211_new_interface, |
| 7284 | .policy = nl80211_policy, |
| 7285 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7286 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7287 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7288 | }, |
| 7289 | { |
| 7290 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7291 | .doit = nl80211_del_interface, |
| 7292 | .policy = nl80211_policy, |
| 7293 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7294 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7295 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7296 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7297 | { |
| 7298 | .cmd = NL80211_CMD_GET_KEY, |
| 7299 | .doit = nl80211_get_key, |
| 7300 | .policy = nl80211_policy, |
| 7301 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7302 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7303 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7304 | }, |
| 7305 | { |
| 7306 | .cmd = NL80211_CMD_SET_KEY, |
| 7307 | .doit = nl80211_set_key, |
| 7308 | .policy = nl80211_policy, |
| 7309 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7310 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7311 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7312 | }, |
| 7313 | { |
| 7314 | .cmd = NL80211_CMD_NEW_KEY, |
| 7315 | .doit = nl80211_new_key, |
| 7316 | .policy = nl80211_policy, |
| 7317 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7318 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7319 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7320 | }, |
| 7321 | { |
| 7322 | .cmd = NL80211_CMD_DEL_KEY, |
| 7323 | .doit = nl80211_del_key, |
| 7324 | .policy = nl80211_policy, |
| 7325 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7326 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7327 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7328 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7329 | { |
| 7330 | .cmd = NL80211_CMD_SET_BEACON, |
| 7331 | .policy = nl80211_policy, |
| 7332 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7333 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7334 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7335 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7336 | }, |
| 7337 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7338 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7339 | .policy = nl80211_policy, |
| 7340 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7341 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7342 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7343 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7344 | }, |
| 7345 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7346 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7347 | .policy = nl80211_policy, |
| 7348 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7349 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7350 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7351 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7352 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7353 | { |
| 7354 | .cmd = NL80211_CMD_GET_STATION, |
| 7355 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7356 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7357 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7358 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7359 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7360 | }, |
| 7361 | { |
| 7362 | .cmd = NL80211_CMD_SET_STATION, |
| 7363 | .doit = nl80211_set_station, |
| 7364 | .policy = nl80211_policy, |
| 7365 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7366 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7367 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7368 | }, |
| 7369 | { |
| 7370 | .cmd = NL80211_CMD_NEW_STATION, |
| 7371 | .doit = nl80211_new_station, |
| 7372 | .policy = nl80211_policy, |
| 7373 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7374 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7375 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7376 | }, |
| 7377 | { |
| 7378 | .cmd = NL80211_CMD_DEL_STATION, |
| 7379 | .doit = nl80211_del_station, |
| 7380 | .policy = nl80211_policy, |
| 7381 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7382 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7383 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7384 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7385 | { |
| 7386 | .cmd = NL80211_CMD_GET_MPATH, |
| 7387 | .doit = nl80211_get_mpath, |
| 7388 | .dumpit = nl80211_dump_mpath, |
| 7389 | .policy = nl80211_policy, |
| 7390 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7391 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7392 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7393 | }, |
| 7394 | { |
| 7395 | .cmd = NL80211_CMD_SET_MPATH, |
| 7396 | .doit = nl80211_set_mpath, |
| 7397 | .policy = nl80211_policy, |
| 7398 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7399 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7400 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7401 | }, |
| 7402 | { |
| 7403 | .cmd = NL80211_CMD_NEW_MPATH, |
| 7404 | .doit = nl80211_new_mpath, |
| 7405 | .policy = nl80211_policy, |
| 7406 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7407 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7408 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7409 | }, |
| 7410 | { |
| 7411 | .cmd = NL80211_CMD_DEL_MPATH, |
| 7412 | .doit = nl80211_del_mpath, |
| 7413 | .policy = nl80211_policy, |
| 7414 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7415 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7416 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7417 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7418 | { |
| 7419 | .cmd = NL80211_CMD_SET_BSS, |
| 7420 | .doit = nl80211_set_bss, |
| 7421 | .policy = nl80211_policy, |
| 7422 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7423 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7424 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7425 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7426 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7427 | .cmd = NL80211_CMD_GET_REG, |
| 7428 | .doit = nl80211_get_reg, |
| 7429 | .policy = nl80211_policy, |
| 7430 | /* can be retrieved by unprivileged users */ |
| 7431 | }, |
| 7432 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7433 | .cmd = NL80211_CMD_SET_REG, |
| 7434 | .doit = nl80211_set_reg, |
| 7435 | .policy = nl80211_policy, |
| 7436 | .flags = GENL_ADMIN_PERM, |
| 7437 | }, |
| 7438 | { |
| 7439 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 7440 | .doit = nl80211_req_set_reg, |
| 7441 | .policy = nl80211_policy, |
| 7442 | .flags = GENL_ADMIN_PERM, |
| 7443 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7444 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7445 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 7446 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7447 | .policy = nl80211_policy, |
| 7448 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7451 | }, |
| 7452 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7453 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 7454 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7455 | .policy = nl80211_policy, |
| 7456 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [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, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7459 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 7460 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7461 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 7462 | .doit = nl80211_trigger_scan, |
| 7463 | .policy = nl80211_policy, |
| 7464 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7465 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7466 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7467 | }, |
| 7468 | { |
| 7469 | .cmd = NL80211_CMD_GET_SCAN, |
| 7470 | .policy = nl80211_policy, |
| 7471 | .dumpit = nl80211_dump_scan, |
| 7472 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7473 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7474 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 7475 | .doit = nl80211_start_sched_scan, |
| 7476 | .policy = nl80211_policy, |
| 7477 | .flags = GENL_ADMIN_PERM, |
| 7478 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7479 | NL80211_FLAG_NEED_RTNL, |
| 7480 | }, |
| 7481 | { |
| 7482 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 7483 | .doit = nl80211_stop_sched_scan, |
| 7484 | .policy = nl80211_policy, |
| 7485 | .flags = GENL_ADMIN_PERM, |
| 7486 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7487 | NL80211_FLAG_NEED_RTNL, |
| 7488 | }, |
| 7489 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7490 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 7491 | .doit = nl80211_authenticate, |
| 7492 | .policy = nl80211_policy, |
| 7493 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7494 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7495 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7496 | }, |
| 7497 | { |
| 7498 | .cmd = NL80211_CMD_ASSOCIATE, |
| 7499 | .doit = nl80211_associate, |
| 7500 | .policy = nl80211_policy, |
| 7501 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7502 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7503 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7504 | }, |
| 7505 | { |
| 7506 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 7507 | .doit = nl80211_deauthenticate, |
| 7508 | .policy = nl80211_policy, |
| 7509 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7510 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7511 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7512 | }, |
| 7513 | { |
| 7514 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 7515 | .doit = nl80211_disassociate, |
| 7516 | .policy = nl80211_policy, |
| 7517 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7518 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7519 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7520 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7521 | { |
| 7522 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 7523 | .doit = nl80211_join_ibss, |
| 7524 | .policy = nl80211_policy, |
| 7525 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7526 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7527 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7528 | }, |
| 7529 | { |
| 7530 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 7531 | .doit = nl80211_leave_ibss, |
| 7532 | .policy = nl80211_policy, |
| 7533 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7534 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7535 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7536 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7537 | #ifdef CONFIG_NL80211_TESTMODE |
| 7538 | { |
| 7539 | .cmd = NL80211_CMD_TESTMODE, |
| 7540 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7541 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7542 | .policy = nl80211_policy, |
| 7543 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7544 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7545 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7546 | }, |
| 7547 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7548 | { |
| 7549 | .cmd = NL80211_CMD_CONNECT, |
| 7550 | .doit = nl80211_connect, |
| 7551 | .policy = nl80211_policy, |
| 7552 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7553 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7554 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7555 | }, |
| 7556 | { |
| 7557 | .cmd = NL80211_CMD_DISCONNECT, |
| 7558 | .doit = nl80211_disconnect, |
| 7559 | .policy = nl80211_policy, |
| 7560 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7561 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7562 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7563 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7564 | { |
| 7565 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 7566 | .doit = nl80211_wiphy_netns, |
| 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_WIPHY | |
| 7570 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7571 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7572 | { |
| 7573 | .cmd = NL80211_CMD_GET_SURVEY, |
| 7574 | .policy = nl80211_policy, |
| 7575 | .dumpit = nl80211_dump_survey, |
| 7576 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7577 | { |
| 7578 | .cmd = NL80211_CMD_SET_PMKSA, |
| 7579 | .doit = nl80211_setdel_pmksa, |
| 7580 | .policy = nl80211_policy, |
| 7581 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7582 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7583 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7584 | }, |
| 7585 | { |
| 7586 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 7587 | .doit = nl80211_setdel_pmksa, |
| 7588 | .policy = nl80211_policy, |
| 7589 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7590 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7591 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7592 | }, |
| 7593 | { |
| 7594 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 7595 | .doit = nl80211_flush_pmksa, |
| 7596 | .policy = nl80211_policy, |
| 7597 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7598 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7599 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7600 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7601 | { |
| 7602 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7603 | .doit = nl80211_remain_on_channel, |
| 7604 | .policy = nl80211_policy, |
| 7605 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7606 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7607 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7608 | }, |
| 7609 | { |
| 7610 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7611 | .doit = nl80211_cancel_remain_on_channel, |
| 7612 | .policy = nl80211_policy, |
| 7613 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7614 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7615 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7616 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7617 | { |
| 7618 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 7619 | .doit = nl80211_set_tx_bitrate_mask, |
| 7620 | .policy = nl80211_policy, |
| 7621 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7622 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7623 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7624 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7625 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7626 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 7627 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7628 | .policy = nl80211_policy, |
| 7629 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7630 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7631 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7632 | }, |
| 7633 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7634 | .cmd = NL80211_CMD_FRAME, |
| 7635 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7636 | .policy = nl80211_policy, |
| 7637 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7638 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7639 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7640 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7641 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7642 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 7643 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 7644 | .policy = nl80211_policy, |
| 7645 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7646 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7647 | NL80211_FLAG_NEED_RTNL, |
| 7648 | }, |
| 7649 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7650 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 7651 | .doit = nl80211_set_power_save, |
| 7652 | .policy = nl80211_policy, |
| 7653 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7654 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7655 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7656 | }, |
| 7657 | { |
| 7658 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 7659 | .doit = nl80211_get_power_save, |
| 7660 | .policy = nl80211_policy, |
| 7661 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7662 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7663 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7664 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7665 | { |
| 7666 | .cmd = NL80211_CMD_SET_CQM, |
| 7667 | .doit = nl80211_set_cqm, |
| 7668 | .policy = nl80211_policy, |
| 7669 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7670 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7671 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7672 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7673 | { |
| 7674 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 7675 | .doit = nl80211_set_channel, |
| 7676 | .policy = nl80211_policy, |
| 7677 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7678 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7679 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7680 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7681 | { |
| 7682 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 7683 | .doit = nl80211_set_wds_peer, |
| 7684 | .policy = nl80211_policy, |
| 7685 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 7686 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7687 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7688 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7689 | { |
| 7690 | .cmd = NL80211_CMD_JOIN_MESH, |
| 7691 | .doit = nl80211_join_mesh, |
| 7692 | .policy = nl80211_policy, |
| 7693 | .flags = GENL_ADMIN_PERM, |
| 7694 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7695 | NL80211_FLAG_NEED_RTNL, |
| 7696 | }, |
| 7697 | { |
| 7698 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 7699 | .doit = nl80211_leave_mesh, |
| 7700 | .policy = nl80211_policy, |
| 7701 | .flags = GENL_ADMIN_PERM, |
| 7702 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7703 | NL80211_FLAG_NEED_RTNL, |
| 7704 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7705 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7706 | { |
| 7707 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 7708 | .doit = nl80211_get_wowlan, |
| 7709 | .policy = nl80211_policy, |
| 7710 | /* can be retrieved by unprivileged users */ |
| 7711 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7712 | NL80211_FLAG_NEED_RTNL, |
| 7713 | }, |
| 7714 | { |
| 7715 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 7716 | .doit = nl80211_set_wowlan, |
| 7717 | .policy = nl80211_policy, |
| 7718 | .flags = GENL_ADMIN_PERM, |
| 7719 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7720 | NL80211_FLAG_NEED_RTNL, |
| 7721 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7722 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7723 | { |
| 7724 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 7725 | .doit = nl80211_set_rekey_data, |
| 7726 | .policy = nl80211_policy, |
| 7727 | .flags = GENL_ADMIN_PERM, |
| 7728 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7729 | NL80211_FLAG_NEED_RTNL, |
| 7730 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7731 | { |
| 7732 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 7733 | .doit = nl80211_tdls_mgmt, |
| 7734 | .policy = nl80211_policy, |
| 7735 | .flags = GENL_ADMIN_PERM, |
| 7736 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7737 | NL80211_FLAG_NEED_RTNL, |
| 7738 | }, |
| 7739 | { |
| 7740 | .cmd = NL80211_CMD_TDLS_OPER, |
| 7741 | .doit = nl80211_tdls_oper, |
| 7742 | .policy = nl80211_policy, |
| 7743 | .flags = GENL_ADMIN_PERM, |
| 7744 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7745 | NL80211_FLAG_NEED_RTNL, |
| 7746 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7747 | { |
| 7748 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 7749 | .doit = nl80211_register_unexpected_frame, |
| 7750 | .policy = nl80211_policy, |
| 7751 | .flags = GENL_ADMIN_PERM, |
| 7752 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7753 | NL80211_FLAG_NEED_RTNL, |
| 7754 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7755 | { |
| 7756 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 7757 | .doit = nl80211_probe_client, |
| 7758 | .policy = nl80211_policy, |
| 7759 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7760 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7761 | NL80211_FLAG_NEED_RTNL, |
| 7762 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7763 | { |
| 7764 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 7765 | .doit = nl80211_register_beacons, |
| 7766 | .policy = nl80211_policy, |
| 7767 | .flags = GENL_ADMIN_PERM, |
| 7768 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7769 | NL80211_FLAG_NEED_RTNL, |
| 7770 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 7771 | { |
| 7772 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 7773 | .doit = nl80211_set_noack_map, |
| 7774 | .policy = nl80211_policy, |
| 7775 | .flags = GENL_ADMIN_PERM, |
| 7776 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7777 | NL80211_FLAG_NEED_RTNL, |
| 7778 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7779 | { |
| 7780 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 7781 | .doit = nl80211_start_p2p_device, |
| 7782 | .policy = nl80211_policy, |
| 7783 | .flags = GENL_ADMIN_PERM, |
| 7784 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 7785 | NL80211_FLAG_NEED_RTNL, |
| 7786 | }, |
| 7787 | { |
| 7788 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 7789 | .doit = nl80211_stop_p2p_device, |
| 7790 | .policy = nl80211_policy, |
| 7791 | .flags = GENL_ADMIN_PERM, |
| 7792 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 7793 | NL80211_FLAG_NEED_RTNL, |
| 7794 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7795 | { |
| 7796 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 7797 | .doit = nl80211_set_mcast_rate, |
| 7798 | .policy = nl80211_policy, |
| 7799 | .flags = GENL_ADMIN_PERM, |
| 7800 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7801 | NL80211_FLAG_NEED_RTNL, |
| 7802 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7803 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7804 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7805 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 7806 | .name = "mlme", |
| 7807 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7808 | |
| 7809 | /* multicast groups */ |
| 7810 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 7811 | .name = "config", |
| 7812 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7813 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 7814 | .name = "scan", |
| 7815 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7816 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 7817 | .name = "regulatory", |
| 7818 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7819 | |
| 7820 | /* notification functions */ |
| 7821 | |
| 7822 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 7823 | { |
| 7824 | struct sk_buff *msg; |
| 7825 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7826 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7827 | if (!msg) |
| 7828 | return; |
| 7829 | |
| 7830 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 7831 | nlmsg_free(msg); |
| 7832 | return; |
| 7833 | } |
| 7834 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7835 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7836 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7837 | } |
| 7838 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7839 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 7840 | struct cfg80211_registered_device *rdev) |
| 7841 | { |
| 7842 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 7843 | struct nlattr *nest; |
| 7844 | int i; |
| 7845 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7846 | ASSERT_RDEV_LOCK(rdev); |
| 7847 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7848 | if (WARN_ON(!req)) |
| 7849 | return 0; |
| 7850 | |
| 7851 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 7852 | if (!nest) |
| 7853 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7854 | for (i = 0; i < req->n_ssids; i++) { |
| 7855 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 7856 | goto nla_put_failure; |
| 7857 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7858 | nla_nest_end(msg, nest); |
| 7859 | |
| 7860 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 7861 | if (!nest) |
| 7862 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7863 | for (i = 0; i < req->n_channels; i++) { |
| 7864 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 7865 | goto nla_put_failure; |
| 7866 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7867 | nla_nest_end(msg, nest); |
| 7868 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7869 | if (req->ie && |
| 7870 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 7871 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7872 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7873 | if (req->flags) |
| 7874 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 7875 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7876 | return 0; |
| 7877 | nla_put_failure: |
| 7878 | return -ENOBUFS; |
| 7879 | } |
| 7880 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7881 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 7882 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7883 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7884 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7885 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7886 | { |
| 7887 | void *hdr; |
| 7888 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7889 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7890 | if (!hdr) |
| 7891 | return -1; |
| 7892 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7893 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7894 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 7895 | wdev->netdev->ifindex)) || |
| 7896 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7897 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7898 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7899 | /* ignore errors and send incomplete event anyway */ |
| 7900 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7901 | |
| 7902 | return genlmsg_end(msg, hdr); |
| 7903 | |
| 7904 | nla_put_failure: |
| 7905 | genlmsg_cancel(msg, hdr); |
| 7906 | return -EMSGSIZE; |
| 7907 | } |
| 7908 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7909 | static int |
| 7910 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 7911 | struct cfg80211_registered_device *rdev, |
| 7912 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7913 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7914 | { |
| 7915 | void *hdr; |
| 7916 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7917 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7918 | if (!hdr) |
| 7919 | return -1; |
| 7920 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7921 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7922 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7923 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7924 | |
| 7925 | return genlmsg_end(msg, hdr); |
| 7926 | |
| 7927 | nla_put_failure: |
| 7928 | genlmsg_cancel(msg, hdr); |
| 7929 | return -EMSGSIZE; |
| 7930 | } |
| 7931 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7932 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7933 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7934 | { |
| 7935 | struct sk_buff *msg; |
| 7936 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 7937 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7938 | if (!msg) |
| 7939 | return; |
| 7940 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7941 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7942 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 7943 | nlmsg_free(msg); |
| 7944 | return; |
| 7945 | } |
| 7946 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7947 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7948 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7949 | } |
| 7950 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7951 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7952 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7953 | { |
| 7954 | struct sk_buff *msg; |
| 7955 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7956 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7957 | if (!msg) |
| 7958 | return; |
| 7959 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7960 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7961 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7962 | nlmsg_free(msg); |
| 7963 | return; |
| 7964 | } |
| 7965 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7966 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7967 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7968 | } |
| 7969 | |
| 7970 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7971 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7972 | { |
| 7973 | struct sk_buff *msg; |
| 7974 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7975 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7976 | if (!msg) |
| 7977 | return; |
| 7978 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7979 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7980 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7981 | nlmsg_free(msg); |
| 7982 | return; |
| 7983 | } |
| 7984 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7985 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7986 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7987 | } |
| 7988 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7989 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 7990 | struct net_device *netdev) |
| 7991 | { |
| 7992 | struct sk_buff *msg; |
| 7993 | |
| 7994 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7995 | if (!msg) |
| 7996 | return; |
| 7997 | |
| 7998 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7999 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 8000 | nlmsg_free(msg); |
| 8001 | return; |
| 8002 | } |
| 8003 | |
| 8004 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8005 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8006 | } |
| 8007 | |
| 8008 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 8009 | struct net_device *netdev, u32 cmd) |
| 8010 | { |
| 8011 | struct sk_buff *msg; |
| 8012 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8013 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8014 | if (!msg) |
| 8015 | return; |
| 8016 | |
| 8017 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 8018 | nlmsg_free(msg); |
| 8019 | return; |
| 8020 | } |
| 8021 | |
| 8022 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8023 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 8024 | } |
| 8025 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8026 | /* |
| 8027 | * This can happen on global regulatory changes or device specific settings |
| 8028 | * based on custom world regulatory domains. |
| 8029 | */ |
| 8030 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 8031 | { |
| 8032 | struct sk_buff *msg; |
| 8033 | void *hdr; |
| 8034 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8035 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8036 | if (!msg) |
| 8037 | return; |
| 8038 | |
| 8039 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 8040 | if (!hdr) { |
| 8041 | nlmsg_free(msg); |
| 8042 | return; |
| 8043 | } |
| 8044 | |
| 8045 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8046 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 8047 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8048 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8049 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 8050 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8051 | NL80211_REGDOM_TYPE_WORLD)) |
| 8052 | goto nla_put_failure; |
| 8053 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 8054 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8055 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 8056 | goto nla_put_failure; |
| 8057 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 8058 | request->intersect) { |
| 8059 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8060 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 8061 | goto nla_put_failure; |
| 8062 | } else { |
| 8063 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8064 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 8065 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 8066 | request->alpha2)) |
| 8067 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8068 | } |
| 8069 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8070 | if (wiphy_idx_valid(request->wiphy_idx) && |
| 8071 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 8072 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8073 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8074 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8075 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8076 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8077 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8078 | GFP_ATOMIC); |
| 8079 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8080 | |
| 8081 | return; |
| 8082 | |
| 8083 | nla_put_failure: |
| 8084 | genlmsg_cancel(msg, hdr); |
| 8085 | nlmsg_free(msg); |
| 8086 | } |
| 8087 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8088 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 8089 | struct net_device *netdev, |
| 8090 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8091 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8092 | { |
| 8093 | struct sk_buff *msg; |
| 8094 | void *hdr; |
| 8095 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8096 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8097 | if (!msg) |
| 8098 | return; |
| 8099 | |
| 8100 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8101 | if (!hdr) { |
| 8102 | nlmsg_free(msg); |
| 8103 | return; |
| 8104 | } |
| 8105 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8106 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8107 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8108 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8109 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8110 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8111 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8112 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8113 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8114 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8115 | return; |
| 8116 | |
| 8117 | nla_put_failure: |
| 8118 | genlmsg_cancel(msg, hdr); |
| 8119 | nlmsg_free(msg); |
| 8120 | } |
| 8121 | |
| 8122 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8123 | struct net_device *netdev, const u8 *buf, |
| 8124 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8125 | { |
| 8126 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8127 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8128 | } |
| 8129 | |
| 8130 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 8131 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8132 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8133 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8134 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8135 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8136 | } |
| 8137 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8138 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8139 | struct net_device *netdev, const u8 *buf, |
| 8140 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8141 | { |
| 8142 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8143 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8144 | } |
| 8145 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8146 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 8147 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8148 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8149 | { |
| 8150 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8151 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8152 | } |
| 8153 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 8154 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 8155 | struct net_device *netdev, const u8 *buf, |
| 8156 | size_t len, gfp_t gfp) |
| 8157 | { |
| 8158 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8159 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 8160 | } |
| 8161 | |
| 8162 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 8163 | struct net_device *netdev, const u8 *buf, |
| 8164 | size_t len, gfp_t gfp) |
| 8165 | { |
| 8166 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8167 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 8168 | } |
| 8169 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 8170 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 8171 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8172 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8173 | { |
| 8174 | struct sk_buff *msg; |
| 8175 | void *hdr; |
| 8176 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8177 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8178 | if (!msg) |
| 8179 | return; |
| 8180 | |
| 8181 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8182 | if (!hdr) { |
| 8183 | nlmsg_free(msg); |
| 8184 | return; |
| 8185 | } |
| 8186 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8187 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8188 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8189 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8190 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8191 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8192 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8193 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8194 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8195 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8196 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8197 | return; |
| 8198 | |
| 8199 | nla_put_failure: |
| 8200 | genlmsg_cancel(msg, hdr); |
| 8201 | nlmsg_free(msg); |
| 8202 | } |
| 8203 | |
| 8204 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8205 | struct net_device *netdev, const u8 *addr, |
| 8206 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8207 | { |
| 8208 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8209 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8210 | } |
| 8211 | |
| 8212 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8213 | struct net_device *netdev, const u8 *addr, |
| 8214 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8215 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8216 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8217 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8218 | } |
| 8219 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8220 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8221 | struct net_device *netdev, const u8 *bssid, |
| 8222 | const u8 *req_ie, size_t req_ie_len, |
| 8223 | const u8 *resp_ie, size_t resp_ie_len, |
| 8224 | u16 status, gfp_t gfp) |
| 8225 | { |
| 8226 | struct sk_buff *msg; |
| 8227 | void *hdr; |
| 8228 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8229 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8230 | if (!msg) |
| 8231 | return; |
| 8232 | |
| 8233 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8234 | if (!hdr) { |
| 8235 | nlmsg_free(msg); |
| 8236 | return; |
| 8237 | } |
| 8238 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8239 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8240 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8241 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8242 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8243 | (req_ie && |
| 8244 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8245 | (resp_ie && |
| 8246 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8247 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8248 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8249 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8250 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8251 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8252 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8253 | return; |
| 8254 | |
| 8255 | nla_put_failure: |
| 8256 | genlmsg_cancel(msg, hdr); |
| 8257 | nlmsg_free(msg); |
| 8258 | |
| 8259 | } |
| 8260 | |
| 8261 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8262 | struct net_device *netdev, const u8 *bssid, |
| 8263 | const u8 *req_ie, size_t req_ie_len, |
| 8264 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8265 | { |
| 8266 | struct sk_buff *msg; |
| 8267 | void *hdr; |
| 8268 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8269 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8270 | if (!msg) |
| 8271 | return; |
| 8272 | |
| 8273 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8274 | if (!hdr) { |
| 8275 | nlmsg_free(msg); |
| 8276 | return; |
| 8277 | } |
| 8278 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8279 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8280 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8281 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8282 | (req_ie && |
| 8283 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8284 | (resp_ie && |
| 8285 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8286 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8287 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8288 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8289 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8290 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8291 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8292 | return; |
| 8293 | |
| 8294 | nla_put_failure: |
| 8295 | genlmsg_cancel(msg, hdr); |
| 8296 | nlmsg_free(msg); |
| 8297 | |
| 8298 | } |
| 8299 | |
| 8300 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 8301 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8302 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8303 | { |
| 8304 | struct sk_buff *msg; |
| 8305 | void *hdr; |
| 8306 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8307 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8308 | if (!msg) |
| 8309 | return; |
| 8310 | |
| 8311 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 8312 | if (!hdr) { |
| 8313 | nlmsg_free(msg); |
| 8314 | return; |
| 8315 | } |
| 8316 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8317 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8318 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8319 | (from_ap && reason && |
| 8320 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 8321 | (from_ap && |
| 8322 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 8323 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 8324 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8325 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8326 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8327 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8328 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8329 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8330 | return; |
| 8331 | |
| 8332 | nla_put_failure: |
| 8333 | genlmsg_cancel(msg, hdr); |
| 8334 | nlmsg_free(msg); |
| 8335 | |
| 8336 | } |
| 8337 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8338 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 8339 | struct net_device *netdev, const u8 *bssid, |
| 8340 | gfp_t gfp) |
| 8341 | { |
| 8342 | struct sk_buff *msg; |
| 8343 | void *hdr; |
| 8344 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8345 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8346 | if (!msg) |
| 8347 | return; |
| 8348 | |
| 8349 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 8350 | if (!hdr) { |
| 8351 | nlmsg_free(msg); |
| 8352 | return; |
| 8353 | } |
| 8354 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8355 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8356 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8357 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8358 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8359 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8360 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8361 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8362 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8363 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8364 | return; |
| 8365 | |
| 8366 | nla_put_failure: |
| 8367 | genlmsg_cancel(msg, hdr); |
| 8368 | nlmsg_free(msg); |
| 8369 | } |
| 8370 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8371 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 8372 | struct net_device *netdev, |
| 8373 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 8374 | gfp_t gfp) |
| 8375 | { |
| 8376 | struct sk_buff *msg; |
| 8377 | void *hdr; |
| 8378 | |
| 8379 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8380 | if (!msg) |
| 8381 | return; |
| 8382 | |
| 8383 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 8384 | if (!hdr) { |
| 8385 | nlmsg_free(msg); |
| 8386 | return; |
| 8387 | } |
| 8388 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8389 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8390 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8391 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 8392 | (ie_len && ie && |
| 8393 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 8394 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8395 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8396 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8397 | |
| 8398 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8399 | nl80211_mlme_mcgrp.id, gfp); |
| 8400 | return; |
| 8401 | |
| 8402 | nla_put_failure: |
| 8403 | genlmsg_cancel(msg, hdr); |
| 8404 | nlmsg_free(msg); |
| 8405 | } |
| 8406 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8407 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 8408 | struct net_device *netdev, const u8 *addr, |
| 8409 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8410 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8411 | { |
| 8412 | struct sk_buff *msg; |
| 8413 | void *hdr; |
| 8414 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8415 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8416 | if (!msg) |
| 8417 | return; |
| 8418 | |
| 8419 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 8420 | if (!hdr) { |
| 8421 | nlmsg_free(msg); |
| 8422 | return; |
| 8423 | } |
| 8424 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8425 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8426 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8427 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 8428 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 8429 | (key_id != -1 && |
| 8430 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 8431 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 8432 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8433 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8434 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8435 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8436 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8437 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8438 | return; |
| 8439 | |
| 8440 | nla_put_failure: |
| 8441 | genlmsg_cancel(msg, hdr); |
| 8442 | nlmsg_free(msg); |
| 8443 | } |
| 8444 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8445 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 8446 | struct ieee80211_channel *channel_before, |
| 8447 | struct ieee80211_channel *channel_after) |
| 8448 | { |
| 8449 | struct sk_buff *msg; |
| 8450 | void *hdr; |
| 8451 | struct nlattr *nl_freq; |
| 8452 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8453 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8454 | if (!msg) |
| 8455 | return; |
| 8456 | |
| 8457 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 8458 | if (!hdr) { |
| 8459 | nlmsg_free(msg); |
| 8460 | return; |
| 8461 | } |
| 8462 | |
| 8463 | /* |
| 8464 | * Since we are applying the beacon hint to a wiphy we know its |
| 8465 | * wiphy_idx is valid |
| 8466 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8467 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 8468 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8469 | |
| 8470 | /* Before */ |
| 8471 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 8472 | if (!nl_freq) |
| 8473 | goto nla_put_failure; |
| 8474 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 8475 | goto nla_put_failure; |
| 8476 | nla_nest_end(msg, nl_freq); |
| 8477 | |
| 8478 | /* After */ |
| 8479 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 8480 | if (!nl_freq) |
| 8481 | goto nla_put_failure; |
| 8482 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 8483 | goto nla_put_failure; |
| 8484 | nla_nest_end(msg, nl_freq); |
| 8485 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8486 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8487 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8488 | rcu_read_lock(); |
| 8489 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 8490 | GFP_ATOMIC); |
| 8491 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8492 | |
| 8493 | return; |
| 8494 | |
| 8495 | nla_put_failure: |
| 8496 | genlmsg_cancel(msg, hdr); |
| 8497 | nlmsg_free(msg); |
| 8498 | } |
| 8499 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8500 | static void nl80211_send_remain_on_chan_event( |
| 8501 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8502 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8503 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8504 | unsigned int duration, gfp_t gfp) |
| 8505 | { |
| 8506 | struct sk_buff *msg; |
| 8507 | void *hdr; |
| 8508 | |
| 8509 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8510 | if (!msg) |
| 8511 | return; |
| 8512 | |
| 8513 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8514 | if (!hdr) { |
| 8515 | nlmsg_free(msg); |
| 8516 | return; |
| 8517 | } |
| 8518 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8519 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8520 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8521 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 8522 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8523 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8524 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 8525 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8526 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8527 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8528 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8529 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 8530 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 8531 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8532 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8533 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8534 | |
| 8535 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8536 | nl80211_mlme_mcgrp.id, gfp); |
| 8537 | return; |
| 8538 | |
| 8539 | nla_put_failure: |
| 8540 | genlmsg_cancel(msg, hdr); |
| 8541 | nlmsg_free(msg); |
| 8542 | } |
| 8543 | |
| 8544 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8545 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8546 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8547 | unsigned int duration, gfp_t gfp) |
| 8548 | { |
| 8549 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8550 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8551 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8552 | } |
| 8553 | |
| 8554 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8555 | struct cfg80211_registered_device *rdev, |
| 8556 | struct wireless_dev *wdev, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8557 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8558 | { |
| 8559 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8560 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8561 | } |
| 8562 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8563 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 8564 | struct net_device *dev, const u8 *mac_addr, |
| 8565 | struct station_info *sinfo, gfp_t gfp) |
| 8566 | { |
| 8567 | struct sk_buff *msg; |
| 8568 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8569 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8570 | if (!msg) |
| 8571 | return; |
| 8572 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 8573 | if (nl80211_send_station(msg, 0, 0, 0, |
| 8574 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8575 | nlmsg_free(msg); |
| 8576 | return; |
| 8577 | } |
| 8578 | |
| 8579 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8580 | nl80211_mlme_mcgrp.id, gfp); |
| 8581 | } |
| 8582 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8583 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 8584 | struct net_device *dev, const u8 *mac_addr, |
| 8585 | gfp_t gfp) |
| 8586 | { |
| 8587 | struct sk_buff *msg; |
| 8588 | void *hdr; |
| 8589 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8590 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8591 | if (!msg) |
| 8592 | return; |
| 8593 | |
| 8594 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 8595 | if (!hdr) { |
| 8596 | nlmsg_free(msg); |
| 8597 | return; |
| 8598 | } |
| 8599 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8600 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8601 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 8602 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8603 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8604 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8605 | |
| 8606 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8607 | nl80211_mlme_mcgrp.id, gfp); |
| 8608 | return; |
| 8609 | |
| 8610 | nla_put_failure: |
| 8611 | genlmsg_cancel(msg, hdr); |
| 8612 | nlmsg_free(msg); |
| 8613 | } |
| 8614 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 8615 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 8616 | struct net_device *dev, const u8 *mac_addr, |
| 8617 | enum nl80211_connect_failed_reason reason, |
| 8618 | gfp_t gfp) |
| 8619 | { |
| 8620 | struct sk_buff *msg; |
| 8621 | void *hdr; |
| 8622 | |
| 8623 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8624 | if (!msg) |
| 8625 | return; |
| 8626 | |
| 8627 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 8628 | if (!hdr) { |
| 8629 | nlmsg_free(msg); |
| 8630 | return; |
| 8631 | } |
| 8632 | |
| 8633 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8634 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 8635 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 8636 | goto nla_put_failure; |
| 8637 | |
| 8638 | genlmsg_end(msg, hdr); |
| 8639 | |
| 8640 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8641 | nl80211_mlme_mcgrp.id, gfp); |
| 8642 | return; |
| 8643 | |
| 8644 | nla_put_failure: |
| 8645 | genlmsg_cancel(msg, hdr); |
| 8646 | nlmsg_free(msg); |
| 8647 | } |
| 8648 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8649 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 8650 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8651 | { |
| 8652 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8653 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8654 | struct sk_buff *msg; |
| 8655 | void *hdr; |
| 8656 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8657 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8658 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8659 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8660 | return false; |
| 8661 | |
| 8662 | msg = nlmsg_new(100, gfp); |
| 8663 | if (!msg) |
| 8664 | return true; |
| 8665 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8666 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8667 | if (!hdr) { |
| 8668 | nlmsg_free(msg); |
| 8669 | return true; |
| 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) || |
| 8673 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8674 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8675 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8676 | |
| 8677 | err = genlmsg_end(msg, hdr); |
| 8678 | if (err < 0) { |
| 8679 | nlmsg_free(msg); |
| 8680 | return true; |
| 8681 | } |
| 8682 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8683 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8684 | return true; |
| 8685 | |
| 8686 | nla_put_failure: |
| 8687 | genlmsg_cancel(msg, hdr); |
| 8688 | nlmsg_free(msg); |
| 8689 | return true; |
| 8690 | } |
| 8691 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8692 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 8693 | { |
| 8694 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 8695 | addr, gfp); |
| 8696 | } |
| 8697 | |
| 8698 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 8699 | const u8 *addr, gfp_t gfp) |
| 8700 | { |
| 8701 | return __nl80211_unexpected_frame(dev, |
| 8702 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 8703 | addr, gfp); |
| 8704 | } |
| 8705 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8706 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8707 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8708 | int freq, int sig_dbm, |
| 8709 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8710 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8711 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8712 | struct sk_buff *msg; |
| 8713 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8714 | |
| 8715 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8716 | if (!msg) |
| 8717 | return -ENOMEM; |
| 8718 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8719 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8720 | if (!hdr) { |
| 8721 | nlmsg_free(msg); |
| 8722 | return -ENOMEM; |
| 8723 | } |
| 8724 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8725 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8726 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8727 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8728 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8729 | (sig_dbm && |
| 8730 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8731 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8732 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8733 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8734 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8735 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8736 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8737 | |
| 8738 | nla_put_failure: |
| 8739 | genlmsg_cancel(msg, hdr); |
| 8740 | nlmsg_free(msg); |
| 8741 | return -ENOBUFS; |
| 8742 | } |
| 8743 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8744 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8745 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8746 | const u8 *buf, size_t len, bool ack, |
| 8747 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8748 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8749 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8750 | struct sk_buff *msg; |
| 8751 | void *hdr; |
| 8752 | |
| 8753 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8754 | if (!msg) |
| 8755 | return; |
| 8756 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8757 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8758 | if (!hdr) { |
| 8759 | nlmsg_free(msg); |
| 8760 | return; |
| 8761 | } |
| 8762 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8763 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8764 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8765 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8766 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 8767 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8768 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8769 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8770 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8771 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8772 | |
| 8773 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 8774 | return; |
| 8775 | |
| 8776 | nla_put_failure: |
| 8777 | genlmsg_cancel(msg, hdr); |
| 8778 | nlmsg_free(msg); |
| 8779 | } |
| 8780 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8781 | void |
| 8782 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 8783 | struct net_device *netdev, |
| 8784 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 8785 | gfp_t gfp) |
| 8786 | { |
| 8787 | struct sk_buff *msg; |
| 8788 | struct nlattr *pinfoattr; |
| 8789 | void *hdr; |
| 8790 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8791 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8792 | if (!msg) |
| 8793 | return; |
| 8794 | |
| 8795 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8796 | if (!hdr) { |
| 8797 | nlmsg_free(msg); |
| 8798 | return; |
| 8799 | } |
| 8800 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8801 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8802 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8803 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8804 | |
| 8805 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8806 | if (!pinfoattr) |
| 8807 | goto nla_put_failure; |
| 8808 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8809 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 8810 | rssi_event)) |
| 8811 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8812 | |
| 8813 | nla_nest_end(msg, pinfoattr); |
| 8814 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8815 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8816 | |
| 8817 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8818 | nl80211_mlme_mcgrp.id, gfp); |
| 8819 | return; |
| 8820 | |
| 8821 | nla_put_failure: |
| 8822 | genlmsg_cancel(msg, hdr); |
| 8823 | nlmsg_free(msg); |
| 8824 | } |
| 8825 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8826 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 8827 | struct net_device *netdev, const u8 *bssid, |
| 8828 | const u8 *replay_ctr, gfp_t gfp) |
| 8829 | { |
| 8830 | struct sk_buff *msg; |
| 8831 | struct nlattr *rekey_attr; |
| 8832 | void *hdr; |
| 8833 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8834 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8835 | if (!msg) |
| 8836 | return; |
| 8837 | |
| 8838 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 8839 | if (!hdr) { |
| 8840 | nlmsg_free(msg); |
| 8841 | return; |
| 8842 | } |
| 8843 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8844 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8845 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8846 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8847 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8848 | |
| 8849 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 8850 | if (!rekey_attr) |
| 8851 | goto nla_put_failure; |
| 8852 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8853 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 8854 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 8855 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8856 | |
| 8857 | nla_nest_end(msg, rekey_attr); |
| 8858 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8859 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8860 | |
| 8861 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8862 | nl80211_mlme_mcgrp.id, gfp); |
| 8863 | return; |
| 8864 | |
| 8865 | nla_put_failure: |
| 8866 | genlmsg_cancel(msg, hdr); |
| 8867 | nlmsg_free(msg); |
| 8868 | } |
| 8869 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8870 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 8871 | struct net_device *netdev, int index, |
| 8872 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 8873 | { |
| 8874 | struct sk_buff *msg; |
| 8875 | struct nlattr *attr; |
| 8876 | void *hdr; |
| 8877 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8878 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8879 | if (!msg) |
| 8880 | return; |
| 8881 | |
| 8882 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 8883 | if (!hdr) { |
| 8884 | nlmsg_free(msg); |
| 8885 | return; |
| 8886 | } |
| 8887 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8888 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8889 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8890 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8891 | |
| 8892 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 8893 | if (!attr) |
| 8894 | goto nla_put_failure; |
| 8895 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8896 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 8897 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 8898 | (preauth && |
| 8899 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 8900 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8901 | |
| 8902 | nla_nest_end(msg, attr); |
| 8903 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8904 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8905 | |
| 8906 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8907 | nl80211_mlme_mcgrp.id, gfp); |
| 8908 | return; |
| 8909 | |
| 8910 | nla_put_failure: |
| 8911 | genlmsg_cancel(msg, hdr); |
| 8912 | nlmsg_free(msg); |
| 8913 | } |
| 8914 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8915 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8916 | struct net_device *netdev, |
| 8917 | struct cfg80211_chan_def *chandef, gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8918 | { |
| 8919 | struct sk_buff *msg; |
| 8920 | void *hdr; |
| 8921 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8922 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8923 | if (!msg) |
| 8924 | return; |
| 8925 | |
| 8926 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 8927 | if (!hdr) { |
| 8928 | nlmsg_free(msg); |
| 8929 | return; |
| 8930 | } |
| 8931 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8932 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8933 | goto nla_put_failure; |
| 8934 | |
| 8935 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 8936 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8937 | |
| 8938 | genlmsg_end(msg, hdr); |
| 8939 | |
| 8940 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8941 | nl80211_mlme_mcgrp.id, gfp); |
| 8942 | return; |
| 8943 | |
| 8944 | nla_put_failure: |
| 8945 | genlmsg_cancel(msg, hdr); |
| 8946 | nlmsg_free(msg); |
| 8947 | } |
| 8948 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8949 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8950 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 8951 | struct net_device *netdev, const u8 *peer, |
| 8952 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 8953 | { |
| 8954 | struct sk_buff *msg; |
| 8955 | struct nlattr *pinfoattr; |
| 8956 | void *hdr; |
| 8957 | |
| 8958 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8959 | if (!msg) |
| 8960 | return; |
| 8961 | |
| 8962 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8963 | if (!hdr) { |
| 8964 | nlmsg_free(msg); |
| 8965 | return; |
| 8966 | } |
| 8967 | |
| 8968 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8969 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8970 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8971 | goto nla_put_failure; |
| 8972 | |
| 8973 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8974 | if (!pinfoattr) |
| 8975 | goto nla_put_failure; |
| 8976 | |
| 8977 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 8978 | goto nla_put_failure; |
| 8979 | |
| 8980 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 8981 | goto nla_put_failure; |
| 8982 | |
| 8983 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 8984 | goto nla_put_failure; |
| 8985 | |
| 8986 | nla_nest_end(msg, pinfoattr); |
| 8987 | |
| 8988 | genlmsg_end(msg, hdr); |
| 8989 | |
| 8990 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8991 | nl80211_mlme_mcgrp.id, gfp); |
| 8992 | return; |
| 8993 | |
| 8994 | nla_put_failure: |
| 8995 | genlmsg_cancel(msg, hdr); |
| 8996 | nlmsg_free(msg); |
| 8997 | } |
| 8998 | |
| 8999 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9000 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 9001 | struct net_device *netdev, const u8 *peer, |
| 9002 | u32 num_packets, gfp_t gfp) |
| 9003 | { |
| 9004 | struct sk_buff *msg; |
| 9005 | struct nlattr *pinfoattr; |
| 9006 | void *hdr; |
| 9007 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9008 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9009 | if (!msg) |
| 9010 | return; |
| 9011 | |
| 9012 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 9013 | if (!hdr) { |
| 9014 | nlmsg_free(msg); |
| 9015 | return; |
| 9016 | } |
| 9017 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9018 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9019 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9020 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 9021 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9022 | |
| 9023 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 9024 | if (!pinfoattr) |
| 9025 | goto nla_put_failure; |
| 9026 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9027 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 9028 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9029 | |
| 9030 | nla_nest_end(msg, pinfoattr); |
| 9031 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9032 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9033 | |
| 9034 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9035 | nl80211_mlme_mcgrp.id, gfp); |
| 9036 | return; |
| 9037 | |
| 9038 | nla_put_failure: |
| 9039 | genlmsg_cancel(msg, hdr); |
| 9040 | nlmsg_free(msg); |
| 9041 | } |
| 9042 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9043 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 9044 | u64 cookie, bool acked, gfp_t gfp) |
| 9045 | { |
| 9046 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9047 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9048 | struct sk_buff *msg; |
| 9049 | void *hdr; |
| 9050 | int err; |
| 9051 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9052 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 9053 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9054 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9055 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9056 | if (!msg) |
| 9057 | return; |
| 9058 | |
| 9059 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 9060 | if (!hdr) { |
| 9061 | nlmsg_free(msg); |
| 9062 | return; |
| 9063 | } |
| 9064 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9065 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9066 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9067 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9068 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9069 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9070 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9071 | |
| 9072 | err = genlmsg_end(msg, hdr); |
| 9073 | if (err < 0) { |
| 9074 | nlmsg_free(msg); |
| 9075 | return; |
| 9076 | } |
| 9077 | |
| 9078 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9079 | nl80211_mlme_mcgrp.id, gfp); |
| 9080 | return; |
| 9081 | |
| 9082 | nla_put_failure: |
| 9083 | genlmsg_cancel(msg, hdr); |
| 9084 | nlmsg_free(msg); |
| 9085 | } |
| 9086 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 9087 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9088 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 9089 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9090 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9091 | { |
| 9092 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9093 | struct sk_buff *msg; |
| 9094 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9095 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9096 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9097 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 9098 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9099 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9100 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9101 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 9102 | if (!msg) { |
| 9103 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9104 | return; |
| 9105 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9106 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9107 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 9108 | if (!hdr) |
| 9109 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9110 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9111 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9112 | (freq && |
| 9113 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9114 | (sig_dbm && |
| 9115 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9116 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 9117 | goto nla_put_failure; |
| 9118 | |
| 9119 | genlmsg_end(msg, hdr); |
| 9120 | |
| 9121 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9122 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9123 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9124 | return; |
| 9125 | |
| 9126 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9127 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9128 | if (hdr) |
| 9129 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9130 | nlmsg_free(msg); |
| 9131 | } |
| 9132 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 9133 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 9134 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 9135 | enum nl80211_tdls_operation oper, |
| 9136 | u16 reason_code, gfp_t gfp) |
| 9137 | { |
| 9138 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9139 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9140 | struct sk_buff *msg; |
| 9141 | void *hdr; |
| 9142 | int err; |
| 9143 | |
| 9144 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 9145 | reason_code); |
| 9146 | |
| 9147 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9148 | if (!msg) |
| 9149 | return; |
| 9150 | |
| 9151 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 9152 | if (!hdr) { |
| 9153 | nlmsg_free(msg); |
| 9154 | return; |
| 9155 | } |
| 9156 | |
| 9157 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9158 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9159 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 9160 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 9161 | (reason_code > 0 && |
| 9162 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 9163 | goto nla_put_failure; |
| 9164 | |
| 9165 | err = genlmsg_end(msg, hdr); |
| 9166 | if (err < 0) { |
| 9167 | nlmsg_free(msg); |
| 9168 | return; |
| 9169 | } |
| 9170 | |
| 9171 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9172 | nl80211_mlme_mcgrp.id, gfp); |
| 9173 | return; |
| 9174 | |
| 9175 | nla_put_failure: |
| 9176 | genlmsg_cancel(msg, hdr); |
| 9177 | nlmsg_free(msg); |
| 9178 | } |
| 9179 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 9180 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9181 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 9182 | unsigned long state, |
| 9183 | void *_notify) |
| 9184 | { |
| 9185 | struct netlink_notify *notify = _notify; |
| 9186 | struct cfg80211_registered_device *rdev; |
| 9187 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9188 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9189 | |
| 9190 | if (state != NETLINK_URELEASE) |
| 9191 | return NOTIFY_DONE; |
| 9192 | |
| 9193 | rcu_read_lock(); |
| 9194 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9195 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9196 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9197 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9198 | |
| 9199 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9200 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 9201 | list) { |
| 9202 | if (reg->nlportid == notify->portid) { |
| 9203 | list_del(®->list); |
| 9204 | kfree(reg); |
| 9205 | break; |
| 9206 | } |
| 9207 | } |
| 9208 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9209 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9210 | |
| 9211 | rcu_read_unlock(); |
| 9212 | |
| 9213 | return NOTIFY_DONE; |
| 9214 | } |
| 9215 | |
| 9216 | static struct notifier_block nl80211_netlink_notifier = { |
| 9217 | .notifier_call = nl80211_netlink_notify, |
| 9218 | }; |
| 9219 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9220 | /* initialisation/exit functions */ |
| 9221 | |
| 9222 | int nl80211_init(void) |
| 9223 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9224 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9225 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9226 | err = genl_register_family_with_ops(&nl80211_fam, |
| 9227 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9228 | if (err) |
| 9229 | return err; |
| 9230 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9231 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 9232 | if (err) |
| 9233 | goto err_out; |
| 9234 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9235 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 9236 | if (err) |
| 9237 | goto err_out; |
| 9238 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9239 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 9240 | if (err) |
| 9241 | goto err_out; |
| 9242 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9243 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 9244 | if (err) |
| 9245 | goto err_out; |
| 9246 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9247 | #ifdef CONFIG_NL80211_TESTMODE |
| 9248 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 9249 | if (err) |
| 9250 | goto err_out; |
| 9251 | #endif |
| 9252 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9253 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 9254 | if (err) |
| 9255 | goto err_out; |
| 9256 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9257 | return 0; |
| 9258 | err_out: |
| 9259 | genl_unregister_family(&nl80211_fam); |
| 9260 | return err; |
| 9261 | } |
| 9262 | |
| 9263 | void nl80211_exit(void) |
| 9264 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9265 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9266 | genl_unregister_family(&nl80211_fam); |
| 9267 | } |