Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | #include "core.h" |
| 23 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 24 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 25 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 26 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 27 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 28 | struct genl_info *info, |
| 29 | struct cfg80211_crypto_settings *settings, |
| 30 | int cipher_limit); |
| 31 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 32 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 33 | struct genl_info *info); |
| 34 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 35 | struct genl_info *info); |
| 36 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | /* the netlink family */ |
| 38 | static struct genl_family nl80211_fam = { |
| 39 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 40 | .name = "nl80211", /* have users key off the name instead */ |
| 41 | .hdrsize = 0, /* no private header */ |
| 42 | .version = 1, /* no particular meaning now */ |
| 43 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 44 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 45 | .pre_doit = nl80211_pre_doit, |
| 46 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 49 | /* returns ERR_PTR values */ |
| 50 | static struct wireless_dev * |
| 51 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 52 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 53 | struct cfg80211_registered_device *rdev; |
| 54 | struct wireless_dev *result = NULL; |
| 55 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 56 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 57 | u64 wdev_id; |
| 58 | int wiphy_idx = -1; |
| 59 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 60 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 61 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 62 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 63 | if (!have_ifidx && !have_wdev_id) |
| 64 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 65 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 66 | if (have_ifidx) |
| 67 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 68 | if (have_wdev_id) { |
| 69 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 70 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 73 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 74 | struct wireless_dev *wdev; |
| 75 | |
| 76 | if (wiphy_net(&rdev->wiphy) != netns) |
| 77 | continue; |
| 78 | |
| 79 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 80 | continue; |
| 81 | |
| 82 | mutex_lock(&rdev->devlist_mtx); |
| 83 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 84 | if (have_ifidx && wdev->netdev && |
| 85 | wdev->netdev->ifindex == ifidx) { |
| 86 | result = wdev; |
| 87 | break; |
| 88 | } |
| 89 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 90 | result = wdev; |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | mutex_unlock(&rdev->devlist_mtx); |
| 95 | |
| 96 | if (result) |
| 97 | break; |
| 98 | } |
| 99 | |
| 100 | if (result) |
| 101 | return result; |
| 102 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 103 | } |
| 104 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 105 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 106 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 107 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 108 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 109 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 110 | |
| 111 | assert_cfg80211_lock(); |
| 112 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 113 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 114 | !attrs[NL80211_ATTR_IFINDEX] && |
| 115 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 116 | return ERR_PTR(-EINVAL); |
| 117 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 118 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 119 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 120 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 121 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 122 | if (attrs[NL80211_ATTR_WDEV]) { |
| 123 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 124 | struct wireless_dev *wdev; |
| 125 | bool found = false; |
| 126 | |
| 127 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 128 | if (tmp) { |
| 129 | /* make sure wdev exists */ |
| 130 | mutex_lock(&tmp->devlist_mtx); |
| 131 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 132 | if (wdev->identifier != (u32)wdev_id) |
| 133 | continue; |
| 134 | found = true; |
| 135 | break; |
| 136 | } |
| 137 | mutex_unlock(&tmp->devlist_mtx); |
| 138 | |
| 139 | if (!found) |
| 140 | tmp = NULL; |
| 141 | |
| 142 | if (rdev && tmp != rdev) |
| 143 | return ERR_PTR(-EINVAL); |
| 144 | rdev = tmp; |
| 145 | } |
| 146 | } |
| 147 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 148 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 149 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 150 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 151 | if (netdev) { |
| 152 | if (netdev->ieee80211_ptr) |
| 153 | tmp = wiphy_to_dev( |
| 154 | netdev->ieee80211_ptr->wiphy); |
| 155 | else |
| 156 | tmp = NULL; |
| 157 | |
| 158 | dev_put(netdev); |
| 159 | |
| 160 | /* not wireless device -- return error */ |
| 161 | if (!tmp) |
| 162 | return ERR_PTR(-EINVAL); |
| 163 | |
| 164 | /* mismatch -- return error */ |
| 165 | if (rdev && tmp != rdev) |
| 166 | return ERR_PTR(-EINVAL); |
| 167 | |
| 168 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 169 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 170 | } |
| 171 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 172 | if (!rdev) |
| 173 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 174 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 175 | if (netns != wiphy_net(&rdev->wiphy)) |
| 176 | return ERR_PTR(-ENODEV); |
| 177 | |
| 178 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* |
| 182 | * This function returns a pointer to the driver |
| 183 | * that the genl_info item that is passed refers to. |
| 184 | * If successful, it returns non-NULL and also locks |
| 185 | * the driver's mutex! |
| 186 | * |
| 187 | * This means that you need to call cfg80211_unlock_rdev() |
| 188 | * before being allowed to acquire &cfg80211_mutex! |
| 189 | * |
| 190 | * This is necessary because we need to lock the global |
| 191 | * mutex to get an item off the list safely, and then |
| 192 | * we lock the rdev mutex so it doesn't go away under us. |
| 193 | * |
| 194 | * We don't want to keep cfg80211_mutex locked |
| 195 | * for all the time in order to allow requests on |
| 196 | * other interfaces to go through at the same time. |
| 197 | * |
| 198 | * The result of this can be a PTR_ERR and hence must |
| 199 | * be checked with IS_ERR() for errors. |
| 200 | */ |
| 201 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 202 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 203 | { |
| 204 | struct cfg80211_registered_device *rdev; |
| 205 | |
| 206 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 207 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 208 | |
| 209 | /* if it is not an error we grab the lock on |
| 210 | * it to assure it won't be going away while |
| 211 | * we operate on it */ |
| 212 | if (!IS_ERR(rdev)) |
| 213 | mutex_lock(&rdev->mtx); |
| 214 | |
| 215 | mutex_unlock(&cfg80211_mutex); |
| 216 | |
| 217 | return rdev; |
| 218 | } |
| 219 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 220 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 221 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 222 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 223 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 224 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 225 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 226 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 227 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 229 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 230 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 232 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 233 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 234 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 235 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 236 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 238 | |
| 239 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 240 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 241 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 242 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 243 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 244 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 245 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 246 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 247 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 248 | .len = WLAN_MAX_KEY_LEN }, |
| 249 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 250 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 251 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 252 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 253 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 254 | |
| 255 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 256 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 257 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 258 | .len = IEEE80211_MAX_DATA_LEN }, |
| 259 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 260 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 262 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 263 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 264 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 265 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 266 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 268 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 269 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 270 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 271 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 272 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 273 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 274 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 275 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 276 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 277 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 278 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 279 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 280 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 281 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 282 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 283 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 284 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 285 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 286 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 287 | |
| 288 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 289 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 290 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 291 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 292 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 293 | |
| 294 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 295 | .len = IEEE80211_MAX_SSID_LEN }, |
| 296 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 297 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 298 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 299 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | 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 | 5e76023 | 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 | 5e76023 | 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 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1374 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1375 | |
| 1376 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1377 | return -EINVAL; |
| 1378 | |
| 1379 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1380 | |
| 1381 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1382 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1383 | chandef->center_freq1 = control_freq; |
| 1384 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1385 | |
| 1386 | /* Primary channel not allowed */ |
| 1387 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1388 | return -EINVAL; |
| 1389 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1390 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1391 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1392 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1393 | chantype = nla_get_u32( |
| 1394 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1395 | |
| 1396 | switch (chantype) { |
| 1397 | case NL80211_CHAN_NO_HT: |
| 1398 | case NL80211_CHAN_HT20: |
| 1399 | case NL80211_CHAN_HT40PLUS: |
| 1400 | case NL80211_CHAN_HT40MINUS: |
| 1401 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1402 | chantype); |
| 1403 | break; |
| 1404 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1405 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1406 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1407 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1408 | chandef->width = |
| 1409 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1410 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1411 | chandef->center_freq1 = |
| 1412 | nla_get_u32( |
| 1413 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1414 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1415 | chandef->center_freq2 = |
| 1416 | nla_get_u32( |
| 1417 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1418 | } |
| 1419 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1420 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1421 | return -EINVAL; |
| 1422 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1423 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1424 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1425 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1426 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1427 | return 0; |
| 1428 | } |
| 1429 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1430 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1431 | struct wireless_dev *wdev, |
| 1432 | struct genl_info *info) |
| 1433 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1434 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1435 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1436 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1437 | |
| 1438 | if (wdev) |
| 1439 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1440 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1441 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1442 | return -EOPNOTSUPP; |
| 1443 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1444 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1445 | if (result) |
| 1446 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1447 | |
| 1448 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1449 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1450 | case NL80211_IFTYPE_AP: |
| 1451 | case NL80211_IFTYPE_P2P_GO: |
| 1452 | if (wdev->beacon_interval) { |
| 1453 | result = -EBUSY; |
| 1454 | break; |
| 1455 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1456 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1457 | result = -EINVAL; |
| 1458 | break; |
| 1459 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1460 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1461 | result = 0; |
| 1462 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1463 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1464 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1465 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1466 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1467 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1468 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1469 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1470 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1471 | } |
| 1472 | mutex_unlock(&rdev->devlist_mtx); |
| 1473 | |
| 1474 | return result; |
| 1475 | } |
| 1476 | |
| 1477 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1478 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1479 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1480 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1481 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1482 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1483 | } |
| 1484 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1485 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1486 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1488 | struct net_device *dev = info->user_ptr[1]; |
| 1489 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1490 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1491 | |
| 1492 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1493 | return -EINVAL; |
| 1494 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1495 | if (netif_running(dev)) |
| 1496 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1497 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1498 | if (!rdev->ops->set_wds_peer) |
| 1499 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1500 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1501 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1502 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1503 | |
| 1504 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1505 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1509 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1510 | { |
| 1511 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1512 | struct net_device *netdev = NULL; |
| 1513 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1514 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1515 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1516 | u32 changed; |
| 1517 | u8 retry_short = 0, retry_long = 0; |
| 1518 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1519 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1520 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1521 | /* |
| 1522 | * Try to find the wiphy and netdev. Normally this |
| 1523 | * function shouldn't need the netdev, but this is |
| 1524 | * done for backward compatibility -- previously |
| 1525 | * setting the channel was done per wiphy, but now |
| 1526 | * it is per netdev. Previous userland like hostapd |
| 1527 | * also passed a netdev to set_wiphy, so that it is |
| 1528 | * possible to let that go to the right netdev! |
| 1529 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1530 | mutex_lock(&cfg80211_mutex); |
| 1531 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1532 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1533 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1534 | |
| 1535 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1536 | if (netdev && netdev->ieee80211_ptr) { |
| 1537 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1538 | mutex_lock(&rdev->mtx); |
| 1539 | } else |
| 1540 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1541 | } |
| 1542 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1543 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1544 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1545 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1546 | if (IS_ERR(rdev)) { |
| 1547 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1548 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1549 | } |
| 1550 | wdev = NULL; |
| 1551 | netdev = NULL; |
| 1552 | result = 0; |
| 1553 | |
| 1554 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1555 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1556 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1557 | |
| 1558 | /* |
| 1559 | * end workaround code, by now the rdev is available |
| 1560 | * and locked, and wdev may or may not be NULL. |
| 1561 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1562 | |
| 1563 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1564 | result = cfg80211_dev_rename( |
| 1565 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1566 | |
| 1567 | mutex_unlock(&cfg80211_mutex); |
| 1568 | |
| 1569 | if (result) |
| 1570 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1571 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1572 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1573 | struct ieee80211_txq_params txq_params; |
| 1574 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1575 | |
| 1576 | if (!rdev->ops->set_txq_params) { |
| 1577 | result = -EOPNOTSUPP; |
| 1578 | goto bad_res; |
| 1579 | } |
| 1580 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1581 | if (!netdev) { |
| 1582 | result = -EINVAL; |
| 1583 | goto bad_res; |
| 1584 | } |
| 1585 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1586 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1587 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1588 | result = -EINVAL; |
| 1589 | goto bad_res; |
| 1590 | } |
| 1591 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1592 | if (!netif_running(netdev)) { |
| 1593 | result = -ENETDOWN; |
| 1594 | goto bad_res; |
| 1595 | } |
| 1596 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1597 | nla_for_each_nested(nl_txq_params, |
| 1598 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1599 | rem_txq_params) { |
| 1600 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1601 | nla_data(nl_txq_params), |
| 1602 | nla_len(nl_txq_params), |
| 1603 | txq_params_policy); |
| 1604 | result = parse_txq_params(tb, &txq_params); |
| 1605 | if (result) |
| 1606 | goto bad_res; |
| 1607 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1608 | result = rdev_set_txq_params(rdev, netdev, |
| 1609 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1610 | if (result) |
| 1611 | goto bad_res; |
| 1612 | } |
| 1613 | } |
| 1614 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1615 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1616 | result = __nl80211_set_channel(rdev, |
| 1617 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1618 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1619 | if (result) |
| 1620 | goto bad_res; |
| 1621 | } |
| 1622 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1623 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1624 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1625 | enum nl80211_tx_power_setting type; |
| 1626 | int idx, mbm = 0; |
| 1627 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1628 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1629 | txp_wdev = NULL; |
| 1630 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1631 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1632 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1633 | goto bad_res; |
| 1634 | } |
| 1635 | |
| 1636 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1637 | type = nla_get_u32(info->attrs[idx]); |
| 1638 | |
| 1639 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1640 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1641 | result = -EINVAL; |
| 1642 | goto bad_res; |
| 1643 | } |
| 1644 | |
| 1645 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1646 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1647 | mbm = nla_get_u32(info->attrs[idx]); |
| 1648 | } |
| 1649 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1650 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1651 | if (result) |
| 1652 | goto bad_res; |
| 1653 | } |
| 1654 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1655 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1656 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1657 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1658 | if ((!rdev->wiphy.available_antennas_tx && |
| 1659 | !rdev->wiphy.available_antennas_rx) || |
| 1660 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1661 | result = -EOPNOTSUPP; |
| 1662 | goto bad_res; |
| 1663 | } |
| 1664 | |
| 1665 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1666 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1667 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1668 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1669 | * available antenna masks, except for the "all" mask */ |
| 1670 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1671 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1672 | result = -EINVAL; |
| 1673 | goto bad_res; |
| 1674 | } |
| 1675 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1676 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1677 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1678 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1679 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1680 | if (result) |
| 1681 | goto bad_res; |
| 1682 | } |
| 1683 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1684 | changed = 0; |
| 1685 | |
| 1686 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1687 | retry_short = nla_get_u8( |
| 1688 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1689 | if (retry_short == 0) { |
| 1690 | result = -EINVAL; |
| 1691 | goto bad_res; |
| 1692 | } |
| 1693 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1694 | } |
| 1695 | |
| 1696 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1697 | retry_long = nla_get_u8( |
| 1698 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1699 | if (retry_long == 0) { |
| 1700 | result = -EINVAL; |
| 1701 | goto bad_res; |
| 1702 | } |
| 1703 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1704 | } |
| 1705 | |
| 1706 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1707 | frag_threshold = nla_get_u32( |
| 1708 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1709 | if (frag_threshold < 256) { |
| 1710 | result = -EINVAL; |
| 1711 | goto bad_res; |
| 1712 | } |
| 1713 | if (frag_threshold != (u32) -1) { |
| 1714 | /* |
| 1715 | * Fragments (apart from the last one) are required to |
| 1716 | * have even length. Make the fragmentation code |
| 1717 | * simpler by stripping LSB should someone try to use |
| 1718 | * odd threshold value. |
| 1719 | */ |
| 1720 | frag_threshold &= ~0x1; |
| 1721 | } |
| 1722 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1723 | } |
| 1724 | |
| 1725 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1726 | rts_threshold = nla_get_u32( |
| 1727 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1728 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1729 | } |
| 1730 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1731 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1732 | coverage_class = nla_get_u8( |
| 1733 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1734 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1735 | } |
| 1736 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1737 | if (changed) { |
| 1738 | u8 old_retry_short, old_retry_long; |
| 1739 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1740 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1741 | |
| 1742 | if (!rdev->ops->set_wiphy_params) { |
| 1743 | result = -EOPNOTSUPP; |
| 1744 | goto bad_res; |
| 1745 | } |
| 1746 | |
| 1747 | old_retry_short = rdev->wiphy.retry_short; |
| 1748 | old_retry_long = rdev->wiphy.retry_long; |
| 1749 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1750 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1751 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1752 | |
| 1753 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1754 | rdev->wiphy.retry_short = retry_short; |
| 1755 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1756 | rdev->wiphy.retry_long = retry_long; |
| 1757 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1758 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1759 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1760 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1761 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1762 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1763 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1764 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1765 | if (result) { |
| 1766 | rdev->wiphy.retry_short = old_retry_short; |
| 1767 | rdev->wiphy.retry_long = old_retry_long; |
| 1768 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1769 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1770 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1771 | } |
| 1772 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1773 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1774 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1775 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1776 | if (netdev) |
| 1777 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1778 | return result; |
| 1779 | } |
| 1780 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1781 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1782 | { |
| 1783 | return (u64)wdev->identifier | |
| 1784 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1785 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1786 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1787 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 1788 | struct cfg80211_chan_def *chandef) |
| 1789 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1790 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1791 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1792 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1793 | chandef->chan->center_freq)) |
| 1794 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1795 | switch (chandef->width) { |
| 1796 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1797 | case NL80211_CHAN_WIDTH_20: |
| 1798 | case NL80211_CHAN_WIDTH_40: |
| 1799 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1800 | cfg80211_get_chandef_type(chandef))) |
| 1801 | return -ENOBUFS; |
| 1802 | break; |
| 1803 | default: |
| 1804 | break; |
| 1805 | } |
| 1806 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 1807 | return -ENOBUFS; |
| 1808 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 1809 | return -ENOBUFS; |
| 1810 | if (chandef->center_freq2 && |
| 1811 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1812 | return -ENOBUFS; |
| 1813 | return 0; |
| 1814 | } |
| 1815 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1816 | 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] | 1817 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1818 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1819 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1820 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1821 | void *hdr; |
| 1822 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1823 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1824 | if (!hdr) |
| 1825 | return -1; |
| 1826 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1827 | if (dev && |
| 1828 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1829 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1830 | goto nla_put_failure; |
| 1831 | |
| 1832 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1833 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1834 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1835 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1836 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1837 | rdev->devlist_generation ^ |
| 1838 | (cfg80211_rdev_list_generation << 2))) |
| 1839 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1840 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1841 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1842 | int ret; |
| 1843 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1844 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1845 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 1846 | if (ret == 0) { |
| 1847 | if (nl80211_send_chandef(msg, &chandef)) |
| 1848 | goto nla_put_failure; |
| 1849 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1850 | } |
| 1851 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 1852 | if (wdev->ssid_len) { |
| 1853 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 1854 | goto nla_put_failure; |
| 1855 | } |
| 1856 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1857 | return genlmsg_end(msg, hdr); |
| 1858 | |
| 1859 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1860 | genlmsg_cancel(msg, hdr); |
| 1861 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1865 | { |
| 1866 | int wp_idx = 0; |
| 1867 | int if_idx = 0; |
| 1868 | int wp_start = cb->args[0]; |
| 1869 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1870 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1871 | struct wireless_dev *wdev; |
| 1872 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1873 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1874 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1875 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1876 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1877 | if (wp_idx < wp_start) { |
| 1878 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1879 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1880 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1881 | if_idx = 0; |
| 1882 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1883 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1884 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1885 | if (if_idx < if_start) { |
| 1886 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1887 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1888 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1889 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1890 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1891 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1892 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1893 | goto out; |
| 1894 | } |
| 1895 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1896 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1897 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1898 | |
| 1899 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1900 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1901 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1902 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1903 | |
| 1904 | cb->args[0] = wp_idx; |
| 1905 | cb->args[1] = if_idx; |
| 1906 | |
| 1907 | return skb->len; |
| 1908 | } |
| 1909 | |
| 1910 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1911 | { |
| 1912 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1913 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1914 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1915 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1916 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1917 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1918 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1919 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1920 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1921 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1922 | nlmsg_free(msg); |
| 1923 | return -ENOBUFS; |
| 1924 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1925 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1926 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1927 | } |
| 1928 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1929 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1930 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1931 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1932 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1933 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1934 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1935 | }; |
| 1936 | |
| 1937 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1938 | { |
| 1939 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1940 | int flag; |
| 1941 | |
| 1942 | *mntrflags = 0; |
| 1943 | |
| 1944 | if (!nla) |
| 1945 | return -EINVAL; |
| 1946 | |
| 1947 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1948 | nla, mntr_flags_policy)) |
| 1949 | return -EINVAL; |
| 1950 | |
| 1951 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1952 | if (flags[flag]) |
| 1953 | *mntrflags |= (1<<flag); |
| 1954 | |
| 1955 | return 0; |
| 1956 | } |
| 1957 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1958 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1959 | struct net_device *netdev, u8 use_4addr, |
| 1960 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1961 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1962 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1963 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1964 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1965 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1966 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1967 | |
| 1968 | switch (iftype) { |
| 1969 | case NL80211_IFTYPE_AP_VLAN: |
| 1970 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1971 | return 0; |
| 1972 | break; |
| 1973 | case NL80211_IFTYPE_STATION: |
| 1974 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1975 | return 0; |
| 1976 | break; |
| 1977 | default: |
| 1978 | break; |
| 1979 | } |
| 1980 | |
| 1981 | return -EOPNOTSUPP; |
| 1982 | } |
| 1983 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1984 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1985 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1986 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1987 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1988 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1989 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1990 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1991 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1992 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1993 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1994 | memset(¶ms, 0, sizeof(params)); |
| 1995 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1996 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1997 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1998 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1999 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2000 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2001 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2002 | if (ntype > NL80211_IFTYPE_MAX) |
| 2003 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2004 | } |
| 2005 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2006 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2007 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2008 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2009 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2010 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2011 | if (netif_running(dev)) |
| 2012 | return -EBUSY; |
| 2013 | |
| 2014 | wdev_lock(wdev); |
| 2015 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2016 | IEEE80211_MAX_MESH_ID_LEN); |
| 2017 | wdev->mesh_id_up_len = |
| 2018 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2019 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2020 | wdev->mesh_id_up_len); |
| 2021 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2022 | } |
| 2023 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2024 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2025 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2026 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2027 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2028 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2029 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2030 | } else { |
| 2031 | params.use_4addr = -1; |
| 2032 | } |
| 2033 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2034 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2035 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2036 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2037 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2038 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2039 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2040 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2041 | |
| 2042 | flags = &_flags; |
| 2043 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2044 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2045 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2046 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2047 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2048 | else |
| 2049 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2050 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2051 | if (!err && params.use_4addr != -1) |
| 2052 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2053 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2054 | return err; |
| 2055 | } |
| 2056 | |
| 2057 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2058 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2059 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2060 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2061 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2062 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2063 | int err; |
| 2064 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2065 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2066 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2067 | memset(¶ms, 0, sizeof(params)); |
| 2068 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2069 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2070 | return -EINVAL; |
| 2071 | |
| 2072 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2073 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2074 | if (type > NL80211_IFTYPE_MAX) |
| 2075 | return -EINVAL; |
| 2076 | } |
| 2077 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2078 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2079 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2080 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2081 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2082 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2083 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2084 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2085 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2086 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2087 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2088 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2089 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2090 | if (!msg) |
| 2091 | return -ENOMEM; |
| 2092 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2093 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2094 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2095 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2096 | wdev = rdev_add_virtual_intf(rdev, |
| 2097 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2098 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2099 | if (IS_ERR(wdev)) { |
| 2100 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2101 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2102 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2103 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2104 | switch (type) { |
| 2105 | case NL80211_IFTYPE_MESH_POINT: |
| 2106 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2107 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2108 | wdev_lock(wdev); |
| 2109 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2110 | IEEE80211_MAX_MESH_ID_LEN); |
| 2111 | wdev->mesh_id_up_len = |
| 2112 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2113 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2114 | wdev->mesh_id_up_len); |
| 2115 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2116 | break; |
| 2117 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2118 | /* |
| 2119 | * P2P Device doesn't have a netdev, so doesn't go |
| 2120 | * through the netdev notifier and must be added here |
| 2121 | */ |
| 2122 | mutex_init(&wdev->mtx); |
| 2123 | INIT_LIST_HEAD(&wdev->event_list); |
| 2124 | spin_lock_init(&wdev->event_lock); |
| 2125 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2126 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2127 | |
| 2128 | mutex_lock(&rdev->devlist_mtx); |
| 2129 | wdev->identifier = ++rdev->wdev_id; |
| 2130 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2131 | rdev->devlist_generation++; |
| 2132 | mutex_unlock(&rdev->devlist_mtx); |
| 2133 | break; |
| 2134 | default: |
| 2135 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2136 | } |
| 2137 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2138 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2139 | rdev, wdev) < 0) { |
| 2140 | nlmsg_free(msg); |
| 2141 | return -ENOBUFS; |
| 2142 | } |
| 2143 | |
| 2144 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2148 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2149 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2150 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2151 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2152 | if (!rdev->ops->del_virtual_intf) |
| 2153 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2154 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2155 | /* |
| 2156 | * If we remove a wireless device without a netdev then clear |
| 2157 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2158 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2159 | * since the wdev has been freed, unlike with a netdev where |
| 2160 | * we need the dev_put() for the netdev to really be freed. |
| 2161 | */ |
| 2162 | if (!wdev->netdev) |
| 2163 | info->user_ptr[1] = NULL; |
| 2164 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2165 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2166 | } |
| 2167 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2168 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2169 | { |
| 2170 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2171 | struct net_device *dev = info->user_ptr[1]; |
| 2172 | u16 noack_map; |
| 2173 | |
| 2174 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2175 | return -EINVAL; |
| 2176 | |
| 2177 | if (!rdev->ops->set_noack_map) |
| 2178 | return -EOPNOTSUPP; |
| 2179 | |
| 2180 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2181 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2182 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2183 | } |
| 2184 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2185 | struct get_key_cookie { |
| 2186 | struct sk_buff *msg; |
| 2187 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2188 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2189 | }; |
| 2190 | |
| 2191 | static void get_key_callback(void *c, struct key_params *params) |
| 2192 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2193 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2194 | struct get_key_cookie *cookie = c; |
| 2195 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2196 | if ((params->key && |
| 2197 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2198 | params->key_len, params->key)) || |
| 2199 | (params->seq && |
| 2200 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2201 | params->seq_len, params->seq)) || |
| 2202 | (params->cipher && |
| 2203 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2204 | params->cipher))) |
| 2205 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2206 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2207 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2208 | if (!key) |
| 2209 | goto nla_put_failure; |
| 2210 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2211 | if ((params->key && |
| 2212 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2213 | params->key_len, params->key)) || |
| 2214 | (params->seq && |
| 2215 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2216 | params->seq_len, params->seq)) || |
| 2217 | (params->cipher && |
| 2218 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2219 | params->cipher))) |
| 2220 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2221 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2222 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2223 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2224 | |
| 2225 | nla_nest_end(cookie->msg, key); |
| 2226 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2227 | return; |
| 2228 | nla_put_failure: |
| 2229 | cookie->error = 1; |
| 2230 | } |
| 2231 | |
| 2232 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2233 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2234 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2235 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2236 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2237 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2238 | const u8 *mac_addr = NULL; |
| 2239 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2240 | struct get_key_cookie cookie = { |
| 2241 | .error = 0, |
| 2242 | }; |
| 2243 | void *hdr; |
| 2244 | struct sk_buff *msg; |
| 2245 | |
| 2246 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2247 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2248 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2249 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2250 | return -EINVAL; |
| 2251 | |
| 2252 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2253 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2254 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2255 | pairwise = !!mac_addr; |
| 2256 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2257 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2258 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2259 | return -EINVAL; |
| 2260 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2261 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2262 | return -EINVAL; |
| 2263 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2264 | } |
| 2265 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2266 | if (!rdev->ops->get_key) |
| 2267 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2268 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2269 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2270 | if (!msg) |
| 2271 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2272 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2273 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2274 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2275 | if (IS_ERR(hdr)) |
| 2276 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2277 | |
| 2278 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2279 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2280 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2281 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2282 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2283 | goto nla_put_failure; |
| 2284 | if (mac_addr && |
| 2285 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2286 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2287 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2288 | if (pairwise && mac_addr && |
| 2289 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2290 | return -ENOENT; |
| 2291 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2292 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2293 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2294 | |
| 2295 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2296 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2297 | |
| 2298 | if (cookie.error) |
| 2299 | goto nla_put_failure; |
| 2300 | |
| 2301 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2302 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2303 | |
| 2304 | nla_put_failure: |
| 2305 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2306 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2307 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2308 | return err; |
| 2309 | } |
| 2310 | |
| 2311 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2312 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2313 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2314 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2315 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2316 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2317 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2318 | err = nl80211_parse_key(info, &key); |
| 2319 | if (err) |
| 2320 | return err; |
| 2321 | |
| 2322 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2323 | return -EINVAL; |
| 2324 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2325 | /* only support setting default key */ |
| 2326 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2327 | return -EINVAL; |
| 2328 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2329 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2330 | |
| 2331 | if (key.def) { |
| 2332 | if (!rdev->ops->set_default_key) { |
| 2333 | err = -EOPNOTSUPP; |
| 2334 | goto out; |
| 2335 | } |
| 2336 | |
| 2337 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2338 | if (err) |
| 2339 | goto out; |
| 2340 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2341 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2342 | key.def_uni, key.def_multi); |
| 2343 | |
| 2344 | if (err) |
| 2345 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2346 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2347 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2348 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2349 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2350 | } else { |
| 2351 | if (key.def_uni || !key.def_multi) { |
| 2352 | err = -EINVAL; |
| 2353 | goto out; |
| 2354 | } |
| 2355 | |
| 2356 | if (!rdev->ops->set_default_mgmt_key) { |
| 2357 | err = -EOPNOTSUPP; |
| 2358 | goto out; |
| 2359 | } |
| 2360 | |
| 2361 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2362 | if (err) |
| 2363 | goto out; |
| 2364 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2365 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2366 | if (err) |
| 2367 | goto out; |
| 2368 | |
| 2369 | #ifdef CONFIG_CFG80211_WEXT |
| 2370 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2371 | #endif |
| 2372 | } |
| 2373 | |
| 2374 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2375 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2376 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2377 | return err; |
| 2378 | } |
| 2379 | |
| 2380 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2381 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2382 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2383 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2384 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2385 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2386 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2387 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2388 | err = nl80211_parse_key(info, &key); |
| 2389 | if (err) |
| 2390 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2391 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2392 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2393 | return -EINVAL; |
| 2394 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2395 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2396 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2397 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2398 | if (key.type == -1) { |
| 2399 | if (mac_addr) |
| 2400 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2401 | else |
| 2402 | key.type = NL80211_KEYTYPE_GROUP; |
| 2403 | } |
| 2404 | |
| 2405 | /* for now */ |
| 2406 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2407 | key.type != NL80211_KEYTYPE_GROUP) |
| 2408 | return -EINVAL; |
| 2409 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2410 | if (!rdev->ops->add_key) |
| 2411 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2412 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2413 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2414 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2415 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2416 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2417 | |
| 2418 | wdev_lock(dev->ieee80211_ptr); |
| 2419 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2420 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2421 | err = rdev_add_key(rdev, dev, key.idx, |
| 2422 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2423 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2424 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2425 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2426 | return err; |
| 2427 | } |
| 2428 | |
| 2429 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2430 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2432 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2433 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2434 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2435 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2436 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2437 | err = nl80211_parse_key(info, &key); |
| 2438 | if (err) |
| 2439 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2440 | |
| 2441 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2442 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2443 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2444 | if (key.type == -1) { |
| 2445 | if (mac_addr) |
| 2446 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2447 | else |
| 2448 | key.type = NL80211_KEYTYPE_GROUP; |
| 2449 | } |
| 2450 | |
| 2451 | /* for now */ |
| 2452 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2453 | key.type != NL80211_KEYTYPE_GROUP) |
| 2454 | return -EINVAL; |
| 2455 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2456 | if (!rdev->ops->del_key) |
| 2457 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2458 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2459 | wdev_lock(dev->ieee80211_ptr); |
| 2460 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2461 | |
| 2462 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2463 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2464 | err = -ENOENT; |
| 2465 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2466 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2467 | err = rdev_del_key(rdev, dev, key.idx, |
| 2468 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2469 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2470 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2471 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2472 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2473 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2474 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2475 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2476 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2477 | } |
| 2478 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2479 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2480 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2481 | return err; |
| 2482 | } |
| 2483 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2484 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2485 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2486 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2487 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2488 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2489 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2490 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2491 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2492 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2493 | return -EINVAL; |
| 2494 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2495 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2496 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2497 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2498 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2499 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2500 | if (!bcn->head_len) |
| 2501 | return -EINVAL; |
| 2502 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2506 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2507 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2508 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2509 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2510 | } |
| 2511 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2512 | if (!haveinfo) |
| 2513 | return -EINVAL; |
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 (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2516 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2517 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2521 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2522 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2523 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2524 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2525 | } |
| 2526 | |
| 2527 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2528 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2529 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2530 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2531 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2532 | } |
| 2533 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2534 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2535 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2536 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2537 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2538 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2539 | } |
| 2540 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2541 | return 0; |
| 2542 | } |
| 2543 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2544 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2545 | struct cfg80211_ap_settings *params) |
| 2546 | { |
| 2547 | struct wireless_dev *wdev; |
| 2548 | bool ret = false; |
| 2549 | |
| 2550 | mutex_lock(&rdev->devlist_mtx); |
| 2551 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2552 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2553 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2554 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2555 | continue; |
| 2556 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2557 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2558 | continue; |
| 2559 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2560 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2561 | ret = true; |
| 2562 | break; |
| 2563 | } |
| 2564 | |
| 2565 | mutex_unlock(&rdev->devlist_mtx); |
| 2566 | |
| 2567 | return ret; |
| 2568 | } |
| 2569 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2570 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2571 | enum nl80211_auth_type auth_type, |
| 2572 | enum nl80211_commands cmd) |
| 2573 | { |
| 2574 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2575 | return false; |
| 2576 | |
| 2577 | switch (cmd) { |
| 2578 | case NL80211_CMD_AUTHENTICATE: |
| 2579 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2580 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2581 | return false; |
| 2582 | return true; |
| 2583 | case NL80211_CMD_CONNECT: |
| 2584 | case NL80211_CMD_START_AP: |
| 2585 | /* SAE not supported yet */ |
| 2586 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2587 | return false; |
| 2588 | return true; |
| 2589 | default: |
| 2590 | return false; |
| 2591 | } |
| 2592 | } |
| 2593 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2594 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2595 | { |
| 2596 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2597 | struct net_device *dev = info->user_ptr[1]; |
| 2598 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2599 | struct cfg80211_ap_settings params; |
| 2600 | int err; |
| 2601 | |
| 2602 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2603 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2604 | return -EOPNOTSUPP; |
| 2605 | |
| 2606 | if (!rdev->ops->start_ap) |
| 2607 | return -EOPNOTSUPP; |
| 2608 | |
| 2609 | if (wdev->beacon_interval) |
| 2610 | return -EALREADY; |
| 2611 | |
| 2612 | memset(¶ms, 0, sizeof(params)); |
| 2613 | |
| 2614 | /* these are required for START_AP */ |
| 2615 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2616 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2617 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2618 | return -EINVAL; |
| 2619 | |
| 2620 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2621 | if (err) |
| 2622 | return err; |
| 2623 | |
| 2624 | params.beacon_interval = |
| 2625 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2626 | params.dtim_period = |
| 2627 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2628 | |
| 2629 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2630 | if (err) |
| 2631 | return err; |
| 2632 | |
| 2633 | /* |
| 2634 | * In theory, some of these attributes should be required here |
| 2635 | * but since they were not used when the command was originally |
| 2636 | * added, keep them optional for old user space programs to let |
| 2637 | * them continue to work with drivers that do not need the |
| 2638 | * additional information -- drivers must check! |
| 2639 | */ |
| 2640 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2641 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2642 | params.ssid_len = |
| 2643 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2644 | if (params.ssid_len == 0 || |
| 2645 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2646 | return -EINVAL; |
| 2647 | } |
| 2648 | |
| 2649 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2650 | params.hidden_ssid = nla_get_u32( |
| 2651 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2652 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2653 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2654 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2655 | return -EINVAL; |
| 2656 | } |
| 2657 | |
| 2658 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2659 | |
| 2660 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2661 | params.auth_type = nla_get_u32( |
| 2662 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2663 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 2664 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2665 | return -EINVAL; |
| 2666 | } else |
| 2667 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2668 | |
| 2669 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2670 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2671 | if (err) |
| 2672 | return err; |
| 2673 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2674 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2675 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2676 | return -EOPNOTSUPP; |
| 2677 | params.inactivity_timeout = nla_get_u16( |
| 2678 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2679 | } |
| 2680 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 2681 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 2682 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2683 | return -EINVAL; |
| 2684 | params.p2p_ctwindow = |
| 2685 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 2686 | if (params.p2p_ctwindow > 127) |
| 2687 | return -EINVAL; |
| 2688 | if (params.p2p_ctwindow != 0 && |
| 2689 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 2690 | return -EINVAL; |
| 2691 | } |
| 2692 | |
| 2693 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 2694 | u8 tmp; |
| 2695 | |
| 2696 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2697 | return -EINVAL; |
| 2698 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 2699 | if (tmp > 1) |
| 2700 | return -EINVAL; |
| 2701 | params.p2p_opp_ps = tmp; |
| 2702 | if (params.p2p_opp_ps != 0 && |
| 2703 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 2704 | return -EINVAL; |
| 2705 | } |
| 2706 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2707 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2708 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 2709 | if (err) |
| 2710 | return err; |
| 2711 | } else if (wdev->preset_chandef.chan) { |
| 2712 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2713 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2714 | return -EINVAL; |
| 2715 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2716 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2717 | return -EINVAL; |
| 2718 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2719 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2720 | err = cfg80211_can_use_chan(rdev, wdev, params.chandef.chan, |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2721 | CHAN_MODE_SHARED); |
| 2722 | mutex_unlock(&rdev->devlist_mtx); |
| 2723 | |
| 2724 | if (err) |
| 2725 | return err; |
| 2726 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2727 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2728 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2729 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2730 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2731 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 2732 | wdev->ssid_len = params.ssid_len; |
| 2733 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2734 | } |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2735 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2736 | } |
| 2737 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2738 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2739 | { |
| 2740 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2741 | struct net_device *dev = info->user_ptr[1]; |
| 2742 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2743 | struct cfg80211_beacon_data params; |
| 2744 | int err; |
| 2745 | |
| 2746 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2747 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2748 | return -EOPNOTSUPP; |
| 2749 | |
| 2750 | if (!rdev->ops->change_beacon) |
| 2751 | return -EOPNOTSUPP; |
| 2752 | |
| 2753 | if (!wdev->beacon_interval) |
| 2754 | return -EINVAL; |
| 2755 | |
| 2756 | err = nl80211_parse_beacon(info, ¶ms); |
| 2757 | if (err) |
| 2758 | return err; |
| 2759 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2760 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2761 | } |
| 2762 | |
| 2763 | 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] | 2764 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2766 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2767 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2768 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2769 | } |
| 2770 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2771 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2772 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2773 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2774 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2775 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2776 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2777 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2778 | }; |
| 2779 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2780 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2781 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2782 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2783 | { |
| 2784 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2785 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2786 | int flag; |
| 2787 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2788 | /* |
| 2789 | * Try parsing the new attribute first so userspace |
| 2790 | * can specify both for older kernels. |
| 2791 | */ |
| 2792 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2793 | if (nla) { |
| 2794 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2795 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2796 | sta_flags = nla_data(nla); |
| 2797 | params->sta_flags_mask = sta_flags->mask; |
| 2798 | params->sta_flags_set = sta_flags->set; |
| 2799 | if ((params->sta_flags_mask | |
| 2800 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2801 | return -EINVAL; |
| 2802 | return 0; |
| 2803 | } |
| 2804 | |
| 2805 | /* if present, parse the old attribute */ |
| 2806 | |
| 2807 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2808 | if (!nla) |
| 2809 | return 0; |
| 2810 | |
| 2811 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2812 | nla, sta_flags_policy)) |
| 2813 | return -EINVAL; |
| 2814 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2815 | /* |
| 2816 | * Only allow certain flags for interface types so that |
| 2817 | * other attributes are silently ignored. Remember that |
| 2818 | * this is backward compatibility code with old userspace |
| 2819 | * and shouldn't be hit in other cases anyway. |
| 2820 | */ |
| 2821 | switch (iftype) { |
| 2822 | case NL80211_IFTYPE_AP: |
| 2823 | case NL80211_IFTYPE_AP_VLAN: |
| 2824 | case NL80211_IFTYPE_P2P_GO: |
| 2825 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2826 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2827 | BIT(NL80211_STA_FLAG_WME) | |
| 2828 | BIT(NL80211_STA_FLAG_MFP); |
| 2829 | break; |
| 2830 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2831 | case NL80211_IFTYPE_STATION: |
| 2832 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2833 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2834 | break; |
| 2835 | case NL80211_IFTYPE_MESH_POINT: |
| 2836 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2837 | BIT(NL80211_STA_FLAG_MFP) | |
| 2838 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2839 | default: |
| 2840 | return -EINVAL; |
| 2841 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2842 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2843 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 2844 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2845 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2846 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2847 | /* no longer support new API additions in old API */ |
| 2848 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 2849 | return -EINVAL; |
| 2850 | } |
| 2851 | } |
| 2852 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2853 | return 0; |
| 2854 | } |
| 2855 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2856 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2857 | int attr) |
| 2858 | { |
| 2859 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2860 | u32 bitrate; |
| 2861 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2862 | |
| 2863 | rate = nla_nest_start(msg, attr); |
| 2864 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 2865 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2866 | |
| 2867 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2868 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2869 | /* report 16-bit bitrate only if we can */ |
| 2870 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 2871 | if (bitrate > 0 && |
| 2872 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 2873 | return false; |
| 2874 | if (bitrate_compat > 0 && |
| 2875 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 2876 | return false; |
| 2877 | |
| 2878 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 2879 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 2880 | return false; |
| 2881 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 2882 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 2883 | return false; |
| 2884 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 2885 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 2886 | return false; |
| 2887 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 2888 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 2889 | return false; |
| 2890 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 2891 | return false; |
| 2892 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 2893 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 2894 | return false; |
| 2895 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 2896 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 2897 | return false; |
| 2898 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 2899 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 2900 | return false; |
| 2901 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 2902 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 2903 | return false; |
| 2904 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 2905 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 2906 | return false; |
| 2907 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2908 | |
| 2909 | nla_nest_end(msg, rate); |
| 2910 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2911 | } |
| 2912 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2913 | 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] | 2914 | int flags, |
| 2915 | struct cfg80211_registered_device *rdev, |
| 2916 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2917 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2918 | { |
| 2919 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2920 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2921 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2922 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2923 | if (!hdr) |
| 2924 | return -1; |
| 2925 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2926 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2927 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 2928 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 2929 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2930 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2931 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2932 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2933 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2934 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 2935 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2936 | sinfo->connected_time)) |
| 2937 | goto nla_put_failure; |
| 2938 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 2939 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2940 | sinfo->inactive_time)) |
| 2941 | goto nla_put_failure; |
| 2942 | if ((sinfo->filled & STATION_INFO_RX_BYTES) && |
| 2943 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2944 | sinfo->rx_bytes)) |
| 2945 | goto nla_put_failure; |
| 2946 | if ((sinfo->filled & STATION_INFO_TX_BYTES) && |
| 2947 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2948 | sinfo->tx_bytes)) |
| 2949 | goto nla_put_failure; |
| 2950 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 2951 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 2952 | goto nla_put_failure; |
| 2953 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 2954 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 2955 | goto nla_put_failure; |
| 2956 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 2957 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2958 | sinfo->plink_state)) |
| 2959 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2960 | switch (rdev->wiphy.signal_type) { |
| 2961 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2962 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 2963 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 2964 | sinfo->signal)) |
| 2965 | goto nla_put_failure; |
| 2966 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 2967 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2968 | sinfo->signal_avg)) |
| 2969 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2970 | break; |
| 2971 | default: |
| 2972 | break; |
| 2973 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2974 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2975 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2976 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2977 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2978 | } |
| 2979 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2980 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2981 | NL80211_STA_INFO_RX_BITRATE)) |
| 2982 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2983 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2984 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 2985 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2986 | sinfo->rx_packets)) |
| 2987 | goto nla_put_failure; |
| 2988 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 2989 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2990 | sinfo->tx_packets)) |
| 2991 | goto nla_put_failure; |
| 2992 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 2993 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2994 | sinfo->tx_retries)) |
| 2995 | goto nla_put_failure; |
| 2996 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 2997 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2998 | sinfo->tx_failed)) |
| 2999 | goto nla_put_failure; |
| 3000 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3001 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3002 | sinfo->beacon_loss_count)) |
| 3003 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3004 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3005 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3006 | if (!bss_param) |
| 3007 | goto nla_put_failure; |
| 3008 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3009 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3010 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3011 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3012 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3013 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3014 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3015 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3016 | sinfo->bss_param.dtim_period) || |
| 3017 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3018 | sinfo->bss_param.beacon_interval)) |
| 3019 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3020 | |
| 3021 | nla_nest_end(msg, bss_param); |
| 3022 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3023 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3024 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3025 | sizeof(struct nl80211_sta_flag_update), |
| 3026 | &sinfo->sta_flags)) |
| 3027 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3028 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3029 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3030 | sinfo->t_offset)) |
| 3031 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3032 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3033 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3034 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3035 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3036 | sinfo->assoc_req_ies)) |
| 3037 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3038 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3039 | return genlmsg_end(msg, hdr); |
| 3040 | |
| 3041 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3042 | genlmsg_cancel(msg, hdr); |
| 3043 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3044 | } |
| 3045 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3046 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3047 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3048 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3049 | struct station_info sinfo; |
| 3050 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3051 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3052 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3053 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3054 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3055 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3056 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3057 | if (err) |
| 3058 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3059 | |
| 3060 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3061 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3062 | goto out_err; |
| 3063 | } |
| 3064 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3065 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3066 | memset(&sinfo, 0, sizeof(sinfo)); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3067 | err = rdev_dump_station(dev, netdev, sta_idx, |
| 3068 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3069 | if (err == -ENOENT) |
| 3070 | break; |
| 3071 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3072 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3073 | |
| 3074 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3075 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3076 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3077 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3078 | &sinfo) < 0) |
| 3079 | goto out; |
| 3080 | |
| 3081 | sta_idx++; |
| 3082 | } |
| 3083 | |
| 3084 | |
| 3085 | out: |
| 3086 | cb->args[1] = sta_idx; |
| 3087 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3088 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3089 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3090 | |
| 3091 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3092 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3093 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3094 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3095 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3096 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3097 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3098 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3099 | struct sk_buff *msg; |
| 3100 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3101 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3102 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3103 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3104 | |
| 3105 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3106 | return -EINVAL; |
| 3107 | |
| 3108 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3109 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3110 | if (!rdev->ops->get_station) |
| 3111 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3112 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3113 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3114 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3115 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3116 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3117 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3118 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3119 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3120 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3121 | 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] | 3122 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3123 | nlmsg_free(msg); |
| 3124 | return -ENOBUFS; |
| 3125 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3126 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3127 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3128 | } |
| 3129 | |
| 3130 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3131 | * 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] | 3132 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3133 | static struct net_device *get_vlan(struct genl_info *info, |
| 3134 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3135 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3136 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3137 | struct net_device *v; |
| 3138 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3139 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3140 | if (!vlanattr) |
| 3141 | return NULL; |
| 3142 | |
| 3143 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3144 | if (!v) |
| 3145 | return ERR_PTR(-ENODEV); |
| 3146 | |
| 3147 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3148 | ret = -EINVAL; |
| 3149 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3150 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3151 | |
| 3152 | if (!netif_running(v)) { |
| 3153 | ret = -ENETDOWN; |
| 3154 | goto error; |
| 3155 | } |
| 3156 | |
| 3157 | return v; |
| 3158 | error: |
| 3159 | dev_put(v); |
| 3160 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3164 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3165 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3166 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3167 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3168 | struct station_parameters params; |
| 3169 | u8 *mac_addr = NULL; |
| 3170 | |
| 3171 | memset(¶ms, 0, sizeof(params)); |
| 3172 | |
| 3173 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 3174 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3175 | |
| 3176 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3177 | return -EINVAL; |
| 3178 | |
| 3179 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3180 | return -EINVAL; |
| 3181 | |
| 3182 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3183 | |
| 3184 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3185 | params.supported_rates = |
| 3186 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3187 | params.supported_rates_len = |
| 3188 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3189 | } |
| 3190 | |
| 3191 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3192 | params.listen_interval = |
| 3193 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 3194 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3195 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3196 | params.ht_capa = |
| 3197 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3198 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3199 | if (!rdev->ops->change_station) |
| 3200 | return -EOPNOTSUPP; |
| 3201 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3202 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3203 | return -EINVAL; |
| 3204 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3205 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3206 | params.plink_action = |
| 3207 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3208 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3209 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3210 | params.plink_state = |
| 3211 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3212 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3213 | switch (dev->ieee80211_ptr->iftype) { |
| 3214 | case NL80211_IFTYPE_AP: |
| 3215 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3216 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3217 | /* disallow mesh-specific things */ |
| 3218 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3219 | return -EINVAL; |
| 3220 | |
| 3221 | /* TDLS can't be set, ... */ |
| 3222 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3223 | return -EINVAL; |
| 3224 | /* |
| 3225 | * ... but don't bother the driver with it. This works around |
| 3226 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3227 | * TLDS_PEER flag in the mask even for AP mode. |
| 3228 | */ |
| 3229 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3230 | |
| 3231 | /* accept only the listed bits */ |
| 3232 | if (params.sta_flags_mask & |
| 3233 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3234 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3235 | BIT(NL80211_STA_FLAG_WME) | |
| 3236 | BIT(NL80211_STA_FLAG_MFP))) |
| 3237 | return -EINVAL; |
| 3238 | |
| 3239 | /* must be last in here for error handling */ |
| 3240 | params.vlan = get_vlan(info, rdev); |
| 3241 | if (IS_ERR(params.vlan)) |
| 3242 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3243 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3244 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3245 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3246 | /* |
| 3247 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3248 | * but silently ignore attempts to change it since we |
| 3249 | * don't have state here to verify that it doesn't try |
| 3250 | * to change the flag. |
| 3251 | */ |
| 3252 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3253 | /* fall through */ |
| 3254 | case NL80211_IFTYPE_ADHOC: |
| 3255 | /* disallow things sta doesn't support */ |
| 3256 | if (params.plink_action) |
| 3257 | return -EINVAL; |
| 3258 | if (params.ht_capa) |
| 3259 | return -EINVAL; |
| 3260 | if (params.listen_interval >= 0) |
| 3261 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3262 | /* reject any changes other than AUTHORIZED */ |
| 3263 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3264 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3265 | break; |
| 3266 | case NL80211_IFTYPE_MESH_POINT: |
| 3267 | /* disallow things mesh doesn't support */ |
| 3268 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3269 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3270 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3271 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3272 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3273 | return -EINVAL; |
| 3274 | /* |
| 3275 | * No special handling for TDLS here -- the userspace |
| 3276 | * mesh code doesn't have this bug. |
| 3277 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3278 | if (params.sta_flags_mask & |
| 3279 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3280 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3281 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3282 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3283 | break; |
| 3284 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3285 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3286 | } |
| 3287 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3288 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3289 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3290 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3291 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3292 | if (params.vlan) |
| 3293 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3294 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3295 | return err; |
| 3296 | } |
| 3297 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3298 | static struct nla_policy |
| 3299 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3300 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3301 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3302 | }; |
| 3303 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3304 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3305 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3307 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3308 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3309 | struct station_parameters params; |
| 3310 | u8 *mac_addr = NULL; |
| 3311 | |
| 3312 | memset(¶ms, 0, sizeof(params)); |
| 3313 | |
| 3314 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3315 | return -EINVAL; |
| 3316 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3317 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3318 | return -EINVAL; |
| 3319 | |
| 3320 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3321 | return -EINVAL; |
| 3322 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3323 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3324 | return -EINVAL; |
| 3325 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3326 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3327 | params.supported_rates = |
| 3328 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3329 | params.supported_rates_len = |
| 3330 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3331 | params.listen_interval = |
| 3332 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3333 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3334 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3335 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3336 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3337 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3338 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3339 | params.ht_capa = |
| 3340 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3341 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3342 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3343 | params.vht_capa = |
| 3344 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3345 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3346 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3347 | params.plink_action = |
| 3348 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3349 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3350 | if (!rdev->ops->add_station) |
| 3351 | return -EOPNOTSUPP; |
| 3352 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3353 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3354 | return -EINVAL; |
| 3355 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3356 | switch (dev->ieee80211_ptr->iftype) { |
| 3357 | case NL80211_IFTYPE_AP: |
| 3358 | case NL80211_IFTYPE_AP_VLAN: |
| 3359 | case NL80211_IFTYPE_P2P_GO: |
| 3360 | /* parse WME attributes if sta is WME capable */ |
| 3361 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3362 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3363 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3364 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3365 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3366 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3367 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3368 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3369 | nl80211_sta_wme_policy); |
| 3370 | if (err) |
| 3371 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3372 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3373 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3374 | params.uapsd_queues = |
| 3375 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3376 | if (params.uapsd_queues & |
| 3377 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3378 | return -EINVAL; |
| 3379 | |
| 3380 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3381 | params.max_sp = |
| 3382 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3383 | |
| 3384 | if (params.max_sp & |
| 3385 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3386 | return -EINVAL; |
| 3387 | |
| 3388 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3389 | } |
| 3390 | /* TDLS peers cannot be added */ |
| 3391 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3392 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3393 | /* but don't bother the driver with it */ |
| 3394 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3395 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3396 | /* must be last in here for error handling */ |
| 3397 | params.vlan = get_vlan(info, rdev); |
| 3398 | if (IS_ERR(params.vlan)) |
| 3399 | return PTR_ERR(params.vlan); |
| 3400 | break; |
| 3401 | case NL80211_IFTYPE_MESH_POINT: |
| 3402 | /* TDLS peers cannot be added */ |
| 3403 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3404 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3405 | break; |
| 3406 | case NL80211_IFTYPE_STATION: |
| 3407 | /* Only TDLS peers can be added */ |
| 3408 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3409 | return -EINVAL; |
| 3410 | /* Can only add if TDLS ... */ |
| 3411 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3412 | return -EOPNOTSUPP; |
| 3413 | /* ... with external setup is supported */ |
| 3414 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3415 | return -EOPNOTSUPP; |
| 3416 | break; |
| 3417 | default: |
| 3418 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3419 | } |
| 3420 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3421 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3422 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3423 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3424 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3425 | if (params.vlan) |
| 3426 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3427 | return err; |
| 3428 | } |
| 3429 | |
| 3430 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3431 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3432 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3433 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3434 | u8 *mac_addr = NULL; |
| 3435 | |
| 3436 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3437 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3438 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3439 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3440 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3441 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3442 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3443 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3444 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3445 | if (!rdev->ops->del_station) |
| 3446 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3447 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3448 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3449 | } |
| 3450 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3451 | 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] | 3452 | int flags, struct net_device *dev, |
| 3453 | u8 *dst, u8 *next_hop, |
| 3454 | struct mpath_info *pinfo) |
| 3455 | { |
| 3456 | void *hdr; |
| 3457 | struct nlattr *pinfoattr; |
| 3458 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3459 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3460 | if (!hdr) |
| 3461 | return -1; |
| 3462 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3463 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3464 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3465 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3466 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3467 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3468 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3469 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3470 | if (!pinfoattr) |
| 3471 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3472 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3473 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3474 | pinfo->frame_qlen)) |
| 3475 | goto nla_put_failure; |
| 3476 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3477 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3478 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3479 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3480 | pinfo->metric)) || |
| 3481 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3482 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3483 | pinfo->exptime)) || |
| 3484 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3485 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3486 | pinfo->flags)) || |
| 3487 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3488 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3489 | pinfo->discovery_timeout)) || |
| 3490 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3491 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3492 | pinfo->discovery_retries))) |
| 3493 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3494 | |
| 3495 | nla_nest_end(msg, pinfoattr); |
| 3496 | |
| 3497 | return genlmsg_end(msg, hdr); |
| 3498 | |
| 3499 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3500 | genlmsg_cancel(msg, hdr); |
| 3501 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3505 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3506 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3507 | struct mpath_info pinfo; |
| 3508 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3509 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3510 | u8 dst[ETH_ALEN]; |
| 3511 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3512 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3513 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3514 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3515 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3516 | if (err) |
| 3517 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3518 | |
| 3519 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3520 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3521 | goto out_err; |
| 3522 | } |
| 3523 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3524 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3525 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3526 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3527 | } |
| 3528 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3529 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3530 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 3531 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3532 | if (err == -ENOENT) |
| 3533 | break; |
| 3534 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3535 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3536 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3537 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3538 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3539 | netdev, dst, next_hop, |
| 3540 | &pinfo) < 0) |
| 3541 | goto out; |
| 3542 | |
| 3543 | path_idx++; |
| 3544 | } |
| 3545 | |
| 3546 | |
| 3547 | out: |
| 3548 | cb->args[1] = path_idx; |
| 3549 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3550 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3551 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3552 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3556 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3557 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3558 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3559 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3560 | struct mpath_info pinfo; |
| 3561 | struct sk_buff *msg; |
| 3562 | u8 *dst = NULL; |
| 3563 | u8 next_hop[ETH_ALEN]; |
| 3564 | |
| 3565 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3566 | |
| 3567 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3568 | return -EINVAL; |
| 3569 | |
| 3570 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3571 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3572 | if (!rdev->ops->get_mpath) |
| 3573 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3574 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3575 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3576 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3577 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3578 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3579 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3580 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3581 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3582 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3583 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3584 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3585 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3586 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3587 | dev, dst, next_hop, &pinfo) < 0) { |
| 3588 | nlmsg_free(msg); |
| 3589 | return -ENOBUFS; |
| 3590 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3591 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3592 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3596 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3597 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3598 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3599 | u8 *dst = NULL; |
| 3600 | u8 *next_hop = NULL; |
| 3601 | |
| 3602 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3603 | return -EINVAL; |
| 3604 | |
| 3605 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3606 | return -EINVAL; |
| 3607 | |
| 3608 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3609 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3610 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3611 | if (!rdev->ops->change_mpath) |
| 3612 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3613 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3614 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3615 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3616 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3617 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3618 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3619 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3620 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3621 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3622 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3623 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3624 | u8 *dst = NULL; |
| 3625 | u8 *next_hop = NULL; |
| 3626 | |
| 3627 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3628 | return -EINVAL; |
| 3629 | |
| 3630 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3631 | return -EINVAL; |
| 3632 | |
| 3633 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3634 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3635 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3636 | if (!rdev->ops->add_mpath) |
| 3637 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3638 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3639 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3640 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3641 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3642 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3646 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3647 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3648 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3649 | u8 *dst = NULL; |
| 3650 | |
| 3651 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3652 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3653 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3654 | if (!rdev->ops->del_mpath) |
| 3655 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3656 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3657 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3658 | } |
| 3659 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3660 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3661 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3662 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3663 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3664 | struct bss_parameters params; |
| 3665 | |
| 3666 | memset(¶ms, 0, sizeof(params)); |
| 3667 | /* default to not changing parameters */ |
| 3668 | params.use_cts_prot = -1; |
| 3669 | params.use_short_preamble = -1; |
| 3670 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3671 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3672 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3673 | params.p2p_ctwindow = -1; |
| 3674 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3675 | |
| 3676 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3677 | params.use_cts_prot = |
| 3678 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3679 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3680 | params.use_short_preamble = |
| 3681 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3682 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3683 | params.use_short_slot_time = |
| 3684 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3685 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3686 | params.basic_rates = |
| 3687 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3688 | params.basic_rates_len = |
| 3689 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3690 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3691 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3692 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3693 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3694 | params.ht_opmode = |
| 3695 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3696 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3697 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3698 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3699 | return -EINVAL; |
| 3700 | params.p2p_ctwindow = |
| 3701 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3702 | if (params.p2p_ctwindow < 0) |
| 3703 | return -EINVAL; |
| 3704 | if (params.p2p_ctwindow != 0 && |
| 3705 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3706 | return -EINVAL; |
| 3707 | } |
| 3708 | |
| 3709 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3710 | u8 tmp; |
| 3711 | |
| 3712 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3713 | return -EINVAL; |
| 3714 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3715 | if (tmp > 1) |
| 3716 | return -EINVAL; |
| 3717 | params.p2p_opp_ps = tmp; |
| 3718 | if (params.p2p_opp_ps && |
| 3719 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3720 | return -EINVAL; |
| 3721 | } |
| 3722 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3723 | if (!rdev->ops->change_bss) |
| 3724 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3725 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3726 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3727 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3728 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3729 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3730 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3731 | } |
| 3732 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3733 | 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] | 3734 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3735 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3736 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3737 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3738 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3739 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3740 | }; |
| 3741 | |
| 3742 | static int parse_reg_rule(struct nlattr *tb[], |
| 3743 | struct ieee80211_reg_rule *reg_rule) |
| 3744 | { |
| 3745 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3746 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3747 | |
| 3748 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3749 | return -EINVAL; |
| 3750 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3751 | return -EINVAL; |
| 3752 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3753 | return -EINVAL; |
| 3754 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3755 | return -EINVAL; |
| 3756 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3757 | return -EINVAL; |
| 3758 | |
| 3759 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3760 | |
| 3761 | freq_range->start_freq_khz = |
| 3762 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3763 | freq_range->end_freq_khz = |
| 3764 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3765 | freq_range->max_bandwidth_khz = |
| 3766 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3767 | |
| 3768 | power_rule->max_eirp = |
| 3769 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3770 | |
| 3771 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3772 | power_rule->max_antenna_gain = |
| 3773 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3774 | |
| 3775 | return 0; |
| 3776 | } |
| 3777 | |
| 3778 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3779 | { |
| 3780 | int r; |
| 3781 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3782 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3783 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3784 | /* |
| 3785 | * You should only get this when cfg80211 hasn't yet initialized |
| 3786 | * completely when built-in to the kernel right between the time |
| 3787 | * window between nl80211_init() and regulatory_init(), if that is |
| 3788 | * even possible. |
| 3789 | */ |
| 3790 | mutex_lock(&cfg80211_mutex); |
| 3791 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3792 | mutex_unlock(&cfg80211_mutex); |
| 3793 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3794 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3795 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3796 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3797 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3798 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3799 | |
| 3800 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3801 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3802 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 3803 | user_reg_hint_type = |
| 3804 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 3805 | else |
| 3806 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 3807 | |
| 3808 | switch (user_reg_hint_type) { |
| 3809 | case NL80211_USER_REG_HINT_USER: |
| 3810 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 3811 | break; |
| 3812 | default: |
| 3813 | return -EINVAL; |
| 3814 | } |
| 3815 | |
| 3816 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3817 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3818 | return r; |
| 3819 | } |
| 3820 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3821 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3822 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3823 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3824 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3825 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3826 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3827 | struct mesh_config cur_params; |
| 3828 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3829 | void *hdr; |
| 3830 | struct nlattr *pinfoattr; |
| 3831 | struct sk_buff *msg; |
| 3832 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3833 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3834 | return -EOPNOTSUPP; |
| 3835 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3836 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3837 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3838 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3839 | wdev_lock(wdev); |
| 3840 | /* If not connected, get default parameters */ |
| 3841 | if (!wdev->mesh_id_len) |
| 3842 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3843 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3844 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3845 | wdev_unlock(wdev); |
| 3846 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3847 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3848 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3849 | |
| 3850 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3851 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3852 | if (!msg) |
| 3853 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3854 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3855 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3856 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3857 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3858 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3859 | if (!pinfoattr) |
| 3860 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3861 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3862 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3863 | cur_params.dot11MeshRetryTimeout) || |
| 3864 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3865 | cur_params.dot11MeshConfirmTimeout) || |
| 3866 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3867 | cur_params.dot11MeshHoldingTimeout) || |
| 3868 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3869 | cur_params.dot11MeshMaxPeerLinks) || |
| 3870 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3871 | cur_params.dot11MeshMaxRetries) || |
| 3872 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 3873 | cur_params.dot11MeshTTL) || |
| 3874 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3875 | cur_params.element_ttl) || |
| 3876 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3877 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3878 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3879 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3880 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3881 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 3882 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3883 | cur_params.path_refresh_time) || |
| 3884 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3885 | cur_params.min_discovery_timeout) || |
| 3886 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3887 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 3888 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3889 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 3890 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3891 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 3892 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3893 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 3894 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3895 | cur_params.dot11MeshHWMPRootMode) || |
| 3896 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3897 | cur_params.dot11MeshHWMPRannInterval) || |
| 3898 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3899 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 3900 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 3901 | cur_params.dot11MeshForwarding) || |
| 3902 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3903 | cur_params.rssi_threshold) || |
| 3904 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3905 | cur_params.ht_opmode) || |
| 3906 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3907 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 3908 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3909 | cur_params.dot11MeshHWMProotInterval) || |
| 3910 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3911 | cur_params.dot11MeshHWMPconfirmationInterval)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3912 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3913 | nla_nest_end(msg, pinfoattr); |
| 3914 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3915 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3916 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3917 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3918 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3919 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3920 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3921 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3922 | } |
| 3923 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3924 | 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] | 3925 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3926 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3927 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3928 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3929 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3930 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3931 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3932 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3933 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3934 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3935 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3936 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3937 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3938 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3939 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3940 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3941 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3942 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3943 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3944 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3945 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 3946 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3947 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 3948 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3949 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3950 | }; |
| 3951 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3952 | static const struct nla_policy |
| 3953 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3954 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3955 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3956 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3957 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3958 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3959 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3960 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3961 | }; |
| 3962 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3963 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3964 | struct mesh_config *cfg, |
| 3965 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3966 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3967 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3968 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3969 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3970 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3971 | do {\ |
| 3972 | if (table[attr_num]) {\ |
| 3973 | cfg->param = nla_fn(table[attr_num]); \ |
| 3974 | mask |= (1 << (attr_num - 1)); \ |
| 3975 | } \ |
| 3976 | } while (0);\ |
| 3977 | |
| 3978 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3979 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3980 | return -EINVAL; |
| 3981 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3982 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3983 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3984 | return -EINVAL; |
| 3985 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3986 | /* This makes sure that there aren't more than 32 mesh config |
| 3987 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3988 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3989 | |
| 3990 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3991 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3992 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3993 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3994 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3995 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3996 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3997 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3998 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3999 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4000 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4001 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4002 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4003 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4004 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4005 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4006 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4007 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4008 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4009 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4010 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4011 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4012 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4013 | nla_get_u8); |
| 4014 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask, |
| 4015 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4016 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4017 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4018 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4019 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4020 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4021 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4022 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4023 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4024 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4025 | nla_get_u16); |
| 4026 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask, |
| 4027 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4028 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4029 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4030 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4031 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4032 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4033 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4034 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4035 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4036 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
| 4037 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4038 | nla_get_u16); |
| 4039 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 4040 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 4041 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 4042 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4043 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4044 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4045 | dot11MeshGateAnnouncementProtocol, mask, |
| 4046 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4047 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4048 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4049 | mask, NL80211_MESHCONF_FORWARDING, |
| 4050 | nla_get_u8); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 4051 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4052 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4053 | nla_get_u32); |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4054 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4055 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4056 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4057 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
| 4058 | mask, |
| 4059 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4060 | nla_get_u32); |
| 4061 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, |
| 4062 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4063 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4064 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 4065 | dot11MeshHWMPconfirmationInterval, mask, |
| 4066 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4067 | nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4068 | if (mask_out) |
| 4069 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4070 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4071 | return 0; |
| 4072 | |
| 4073 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4074 | } |
| 4075 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4076 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4077 | struct mesh_setup *setup) |
| 4078 | { |
| 4079 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4080 | |
| 4081 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4082 | return -EINVAL; |
| 4083 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4084 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4085 | nl80211_mesh_setup_params_policy)) |
| 4086 | return -EINVAL; |
| 4087 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4088 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4089 | setup->sync_method = |
| 4090 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4091 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4092 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4093 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4094 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4095 | setup->path_sel_proto = |
| 4096 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4097 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4098 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4099 | |
| 4100 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4101 | setup->path_metric = |
| 4102 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4103 | IEEE80211_PATH_METRIC_VENDOR : |
| 4104 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4105 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4106 | |
| 4107 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4108 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4109 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4110 | if (!is_valid_ie_attr(ieattr)) |
| 4111 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4112 | setup->ie = nla_data(ieattr); |
| 4113 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4114 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4115 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4116 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4117 | |
| 4118 | return 0; |
| 4119 | } |
| 4120 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4121 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4122 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4123 | { |
| 4124 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4125 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4126 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4127 | struct mesh_config cfg; |
| 4128 | u32 mask; |
| 4129 | int err; |
| 4130 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4131 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4132 | return -EOPNOTSUPP; |
| 4133 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4134 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4135 | return -EOPNOTSUPP; |
| 4136 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4137 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4138 | if (err) |
| 4139 | return err; |
| 4140 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4141 | wdev_lock(wdev); |
| 4142 | if (!wdev->mesh_id_len) |
| 4143 | err = -ENOLINK; |
| 4144 | |
| 4145 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4146 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4147 | |
| 4148 | wdev_unlock(wdev); |
| 4149 | |
| 4150 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4151 | } |
| 4152 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4153 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4154 | { |
| 4155 | struct sk_buff *msg; |
| 4156 | void *hdr = NULL; |
| 4157 | struct nlattr *nl_reg_rules; |
| 4158 | unsigned int i; |
| 4159 | int err = -EINVAL; |
| 4160 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4161 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4162 | |
| 4163 | if (!cfg80211_regdomain) |
| 4164 | goto out; |
| 4165 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4166 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4167 | if (!msg) { |
| 4168 | err = -ENOBUFS; |
| 4169 | goto out; |
| 4170 | } |
| 4171 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4172 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4173 | NL80211_CMD_GET_REG); |
| 4174 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4175 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4176 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4177 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 4178 | cfg80211_regdomain->alpha2) || |
| 4179 | (cfg80211_regdomain->dfs_region && |
| 4180 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, |
| 4181 | cfg80211_regdomain->dfs_region))) |
| 4182 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4183 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4184 | if (reg_last_request_cell_base() && |
| 4185 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4186 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4187 | goto nla_put_failure; |
| 4188 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4189 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4190 | if (!nl_reg_rules) |
| 4191 | goto nla_put_failure; |
| 4192 | |
| 4193 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 4194 | struct nlattr *nl_reg_rule; |
| 4195 | const struct ieee80211_reg_rule *reg_rule; |
| 4196 | const struct ieee80211_freq_range *freq_range; |
| 4197 | const struct ieee80211_power_rule *power_rule; |
| 4198 | |
| 4199 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 4200 | freq_range = ®_rule->freq_range; |
| 4201 | power_rule = ®_rule->power_rule; |
| 4202 | |
| 4203 | nl_reg_rule = nla_nest_start(msg, i); |
| 4204 | if (!nl_reg_rule) |
| 4205 | goto nla_put_failure; |
| 4206 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4207 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4208 | reg_rule->flags) || |
| 4209 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4210 | freq_range->start_freq_khz) || |
| 4211 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4212 | freq_range->end_freq_khz) || |
| 4213 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4214 | freq_range->max_bandwidth_khz) || |
| 4215 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4216 | power_rule->max_antenna_gain) || |
| 4217 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4218 | power_rule->max_eirp)) |
| 4219 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4220 | |
| 4221 | nla_nest_end(msg, nl_reg_rule); |
| 4222 | } |
| 4223 | |
| 4224 | nla_nest_end(msg, nl_reg_rules); |
| 4225 | |
| 4226 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4227 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4228 | goto out; |
| 4229 | |
| 4230 | nla_put_failure: |
| 4231 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4232 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4233 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4234 | err = -EMSGSIZE; |
| 4235 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4236 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4237 | return err; |
| 4238 | } |
| 4239 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4240 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4241 | { |
| 4242 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4243 | struct nlattr *nl_reg_rule; |
| 4244 | char *alpha2 = NULL; |
| 4245 | int rem_reg_rules = 0, r = 0; |
| 4246 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4247 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4248 | struct ieee80211_regdomain *rd = NULL; |
| 4249 | |
| 4250 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4251 | return -EINVAL; |
| 4252 | |
| 4253 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4254 | return -EINVAL; |
| 4255 | |
| 4256 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4257 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4258 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4259 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4260 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4261 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4262 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4263 | num_rules++; |
| 4264 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4265 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4266 | } |
| 4267 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4268 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4269 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4270 | |
| 4271 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame^] | 4272 | if (!rd) |
| 4273 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4274 | |
| 4275 | rd->n_reg_rules = num_rules; |
| 4276 | rd->alpha2[0] = alpha2[0]; |
| 4277 | rd->alpha2[1] = alpha2[1]; |
| 4278 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4279 | /* |
| 4280 | * Disable DFS master mode if the DFS region was |
| 4281 | * not supported or known on this kernel. |
| 4282 | */ |
| 4283 | if (reg_supported_dfs_region(dfs_region)) |
| 4284 | rd->dfs_region = dfs_region; |
| 4285 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4286 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4287 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4288 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4289 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4290 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4291 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4292 | if (r) |
| 4293 | goto bad_reg; |
| 4294 | |
| 4295 | rule_idx++; |
| 4296 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4297 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4298 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4299 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4300 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4301 | } |
| 4302 | |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame^] | 4303 | mutex_lock(&cfg80211_mutex); |
| 4304 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4305 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame^] | 4306 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4307 | rd = NULL; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame^] | 4308 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4309 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4310 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4311 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4312 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4313 | } |
| 4314 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4315 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4316 | { |
| 4317 | struct nlattr *attr1, *attr2; |
| 4318 | int n_channels = 0, tmp1, tmp2; |
| 4319 | |
| 4320 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4321 | n_channels++; |
| 4322 | /* |
| 4323 | * Some hardware has a limited channel list for |
| 4324 | * scanning, and it is pretty much nonsensical |
| 4325 | * to scan for a channel twice, so disallow that |
| 4326 | * and don't require drivers to check that the |
| 4327 | * channel list they get isn't longer than what |
| 4328 | * they can scan, as long as they can scan all |
| 4329 | * the channels they registered at once. |
| 4330 | */ |
| 4331 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4332 | if (attr1 != attr2 && |
| 4333 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4334 | return 0; |
| 4335 | } |
| 4336 | |
| 4337 | return n_channels; |
| 4338 | } |
| 4339 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4340 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4341 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4342 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4343 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4344 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4345 | struct nlattr *attr; |
| 4346 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4347 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4348 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4349 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4350 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4351 | return -EINVAL; |
| 4352 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4353 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4354 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4355 | if (!rdev->ops->scan) |
| 4356 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4357 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4358 | if (rdev->scan_req) |
| 4359 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4360 | |
| 4361 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4362 | n_channels = validate_scan_freqs( |
| 4363 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4364 | if (!n_channels) |
| 4365 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4366 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4367 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4368 | n_channels = 0; |
| 4369 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4370 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4371 | if (wiphy->bands[band]) |
| 4372 | n_channels += wiphy->bands[band]->n_channels; |
| 4373 | } |
| 4374 | |
| 4375 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4376 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4377 | n_ssids++; |
| 4378 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4379 | if (n_ssids > wiphy->max_scan_ssids) |
| 4380 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4381 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4382 | if (info->attrs[NL80211_ATTR_IE]) |
| 4383 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4384 | else |
| 4385 | ie_len = 0; |
| 4386 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4387 | if (ie_len > wiphy->max_scan_ie_len) |
| 4388 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4389 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4390 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4391 | + sizeof(*request->ssids) * n_ssids |
| 4392 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4393 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4394 | if (!request) |
| 4395 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4396 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4397 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4398 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4399 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4400 | if (ie_len) { |
| 4401 | if (request->ssids) |
| 4402 | request->ie = (void *)(request->ssids + n_ssids); |
| 4403 | else |
| 4404 | request->ie = (void *)(request->channels + n_channels); |
| 4405 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4406 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4407 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4408 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4409 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4410 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4411 | struct ieee80211_channel *chan; |
| 4412 | |
| 4413 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4414 | |
| 4415 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4416 | err = -EINVAL; |
| 4417 | goto out_free; |
| 4418 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4419 | |
| 4420 | /* ignore disabled channels */ |
| 4421 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4422 | continue; |
| 4423 | |
| 4424 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4425 | i++; |
| 4426 | } |
| 4427 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4428 | enum ieee80211_band band; |
| 4429 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4430 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4431 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4432 | int j; |
| 4433 | if (!wiphy->bands[band]) |
| 4434 | continue; |
| 4435 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4436 | struct ieee80211_channel *chan; |
| 4437 | |
| 4438 | chan = &wiphy->bands[band]->channels[j]; |
| 4439 | |
| 4440 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4441 | continue; |
| 4442 | |
| 4443 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4444 | i++; |
| 4445 | } |
| 4446 | } |
| 4447 | } |
| 4448 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4449 | if (!i) { |
| 4450 | err = -EINVAL; |
| 4451 | goto out_free; |
| 4452 | } |
| 4453 | |
| 4454 | request->n_channels = i; |
| 4455 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4456 | i = 0; |
| 4457 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4458 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4459 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4460 | err = -EINVAL; |
| 4461 | goto out_free; |
| 4462 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4463 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4464 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4465 | i++; |
| 4466 | } |
| 4467 | } |
| 4468 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4469 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4470 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4471 | memcpy((void *)request->ie, |
| 4472 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4473 | request->ie_len); |
| 4474 | } |
| 4475 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4476 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4477 | if (wiphy->bands[i]) |
| 4478 | request->rates[i] = |
| 4479 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4480 | |
| 4481 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4482 | nla_for_each_nested(attr, |
| 4483 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4484 | tmp) { |
| 4485 | enum ieee80211_band band = nla_type(attr); |
| 4486 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4487 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4488 | err = -EINVAL; |
| 4489 | goto out_free; |
| 4490 | } |
| 4491 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4492 | nla_data(attr), |
| 4493 | nla_len(attr), |
| 4494 | &request->rates[band]); |
| 4495 | if (err) |
| 4496 | goto out_free; |
| 4497 | } |
| 4498 | } |
| 4499 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4500 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4501 | request->flags = nla_get_u32( |
| 4502 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4503 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4504 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4505 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4506 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4507 | err = -EOPNOTSUPP; |
| 4508 | goto out_free; |
| 4509 | } |
| 4510 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4511 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4512 | request->no_cck = |
| 4513 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4514 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4515 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4516 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4517 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4518 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4519 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4520 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4521 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4522 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4523 | nl80211_send_scan_start(rdev, wdev); |
| 4524 | if (wdev->netdev) |
| 4525 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4526 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4527 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4528 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4529 | kfree(request); |
| 4530 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4531 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4532 | return err; |
| 4533 | } |
| 4534 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4535 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4536 | struct genl_info *info) |
| 4537 | { |
| 4538 | struct cfg80211_sched_scan_request *request; |
| 4539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4540 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4541 | struct nlattr *attr; |
| 4542 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4543 | 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] | 4544 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4545 | enum ieee80211_band band; |
| 4546 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4547 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4548 | |
| 4549 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4550 | !rdev->ops->sched_scan_start) |
| 4551 | return -EOPNOTSUPP; |
| 4552 | |
| 4553 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4554 | return -EINVAL; |
| 4555 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4556 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4557 | return -EINVAL; |
| 4558 | |
| 4559 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4560 | if (interval == 0) |
| 4561 | return -EINVAL; |
| 4562 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4563 | wiphy = &rdev->wiphy; |
| 4564 | |
| 4565 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4566 | n_channels = validate_scan_freqs( |
| 4567 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4568 | if (!n_channels) |
| 4569 | return -EINVAL; |
| 4570 | } else { |
| 4571 | n_channels = 0; |
| 4572 | |
| 4573 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4574 | if (wiphy->bands[band]) |
| 4575 | n_channels += wiphy->bands[band]->n_channels; |
| 4576 | } |
| 4577 | |
| 4578 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4579 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4580 | tmp) |
| 4581 | n_ssids++; |
| 4582 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4583 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4584 | return -EINVAL; |
| 4585 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4586 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4587 | nla_for_each_nested(attr, |
| 4588 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4589 | tmp) |
| 4590 | n_match_sets++; |
| 4591 | |
| 4592 | if (n_match_sets > wiphy->max_match_sets) |
| 4593 | return -EINVAL; |
| 4594 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4595 | if (info->attrs[NL80211_ATTR_IE]) |
| 4596 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4597 | else |
| 4598 | ie_len = 0; |
| 4599 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4600 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4601 | return -EINVAL; |
| 4602 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4603 | mutex_lock(&rdev->sched_scan_mtx); |
| 4604 | |
| 4605 | if (rdev->sched_scan_req) { |
| 4606 | err = -EINPROGRESS; |
| 4607 | goto out; |
| 4608 | } |
| 4609 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4610 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4611 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4612 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4613 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4614 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4615 | if (!request) { |
| 4616 | err = -ENOMEM; |
| 4617 | goto out; |
| 4618 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4619 | |
| 4620 | if (n_ssids) |
| 4621 | request->ssids = (void *)&request->channels[n_channels]; |
| 4622 | request->n_ssids = n_ssids; |
| 4623 | if (ie_len) { |
| 4624 | if (request->ssids) |
| 4625 | request->ie = (void *)(request->ssids + n_ssids); |
| 4626 | else |
| 4627 | request->ie = (void *)(request->channels + n_channels); |
| 4628 | } |
| 4629 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4630 | if (n_match_sets) { |
| 4631 | if (request->ie) |
| 4632 | request->match_sets = (void *)(request->ie + ie_len); |
| 4633 | else if (request->ssids) |
| 4634 | request->match_sets = |
| 4635 | (void *)(request->ssids + n_ssids); |
| 4636 | else |
| 4637 | request->match_sets = |
| 4638 | (void *)(request->channels + n_channels); |
| 4639 | } |
| 4640 | request->n_match_sets = n_match_sets; |
| 4641 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4642 | i = 0; |
| 4643 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4644 | /* user specified, bail out if channel not found */ |
| 4645 | nla_for_each_nested(attr, |
| 4646 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4647 | tmp) { |
| 4648 | struct ieee80211_channel *chan; |
| 4649 | |
| 4650 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4651 | |
| 4652 | if (!chan) { |
| 4653 | err = -EINVAL; |
| 4654 | goto out_free; |
| 4655 | } |
| 4656 | |
| 4657 | /* ignore disabled channels */ |
| 4658 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4659 | continue; |
| 4660 | |
| 4661 | request->channels[i] = chan; |
| 4662 | i++; |
| 4663 | } |
| 4664 | } else { |
| 4665 | /* all channels */ |
| 4666 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4667 | int j; |
| 4668 | if (!wiphy->bands[band]) |
| 4669 | continue; |
| 4670 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4671 | struct ieee80211_channel *chan; |
| 4672 | |
| 4673 | chan = &wiphy->bands[band]->channels[j]; |
| 4674 | |
| 4675 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4676 | continue; |
| 4677 | |
| 4678 | request->channels[i] = chan; |
| 4679 | i++; |
| 4680 | } |
| 4681 | } |
| 4682 | } |
| 4683 | |
| 4684 | if (!i) { |
| 4685 | err = -EINVAL; |
| 4686 | goto out_free; |
| 4687 | } |
| 4688 | |
| 4689 | request->n_channels = i; |
| 4690 | |
| 4691 | i = 0; |
| 4692 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4693 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4694 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4695 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4696 | err = -EINVAL; |
| 4697 | goto out_free; |
| 4698 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4699 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4700 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4701 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4702 | i++; |
| 4703 | } |
| 4704 | } |
| 4705 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4706 | i = 0; |
| 4707 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4708 | nla_for_each_nested(attr, |
| 4709 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4710 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4711 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4712 | |
| 4713 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4714 | nla_data(attr), nla_len(attr), |
| 4715 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 4716 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4717 | if (ssid) { |
| 4718 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4719 | err = -EINVAL; |
| 4720 | goto out_free; |
| 4721 | } |
| 4722 | memcpy(request->match_sets[i].ssid.ssid, |
| 4723 | nla_data(ssid), nla_len(ssid)); |
| 4724 | request->match_sets[i].ssid.ssid_len = |
| 4725 | nla_len(ssid); |
| 4726 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4727 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 4728 | if (rssi) |
| 4729 | request->rssi_thold = nla_get_u32(rssi); |
| 4730 | else |
| 4731 | request->rssi_thold = |
| 4732 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4733 | i++; |
| 4734 | } |
| 4735 | } |
| 4736 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4737 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4738 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4739 | memcpy((void *)request->ie, |
| 4740 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4741 | request->ie_len); |
| 4742 | } |
| 4743 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4744 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4745 | request->flags = nla_get_u32( |
| 4746 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4747 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4748 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4749 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4750 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4751 | err = -EOPNOTSUPP; |
| 4752 | goto out_free; |
| 4753 | } |
| 4754 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4755 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4756 | request->dev = dev; |
| 4757 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4758 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4759 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4760 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4761 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4762 | if (!err) { |
| 4763 | rdev->sched_scan_req = request; |
| 4764 | nl80211_send_sched_scan(rdev, dev, |
| 4765 | NL80211_CMD_START_SCHED_SCAN); |
| 4766 | goto out; |
| 4767 | } |
| 4768 | |
| 4769 | out_free: |
| 4770 | kfree(request); |
| 4771 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4772 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4773 | return err; |
| 4774 | } |
| 4775 | |
| 4776 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4777 | struct genl_info *info) |
| 4778 | { |
| 4779 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4780 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4781 | |
| 4782 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4783 | !rdev->ops->sched_scan_stop) |
| 4784 | return -EOPNOTSUPP; |
| 4785 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4786 | mutex_lock(&rdev->sched_scan_mtx); |
| 4787 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4788 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4789 | |
| 4790 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4791 | } |
| 4792 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4793 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4794 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4795 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4796 | struct wireless_dev *wdev, |
| 4797 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4798 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4799 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4800 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4801 | void *hdr; |
| 4802 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4803 | |
| 4804 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4805 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4806 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4807 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4808 | if (!hdr) |
| 4809 | return -1; |
| 4810 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4811 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4812 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4813 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 4814 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 4815 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4816 | |
| 4817 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4818 | if (!bss) |
| 4819 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4820 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4821 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4822 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4823 | |
| 4824 | rcu_read_lock(); |
| 4825 | ies = rcu_dereference(res->ies); |
| 4826 | if (ies && ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4827 | ies->len, ies->data)) { |
| 4828 | rcu_read_unlock(); |
| 4829 | goto nla_put_failure; |
| 4830 | } |
| 4831 | ies = rcu_dereference(res->beacon_ies); |
| 4832 | if (ies && ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 4833 | ies->len, ies->data)) { |
| 4834 | rcu_read_unlock(); |
| 4835 | goto nla_put_failure; |
| 4836 | } |
| 4837 | rcu_read_unlock(); |
| 4838 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4839 | if (res->tsf && |
| 4840 | nla_put_u64(msg, NL80211_BSS_TSF, res->tsf)) |
| 4841 | goto nla_put_failure; |
| 4842 | if (res->beacon_interval && |
| 4843 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 4844 | goto nla_put_failure; |
| 4845 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 4846 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 4847 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4848 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 4849 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4850 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4851 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4852 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4853 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 4854 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4855 | break; |
| 4856 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4857 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 4858 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4859 | break; |
| 4860 | default: |
| 4861 | break; |
| 4862 | } |
| 4863 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4864 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4865 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4866 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4867 | if (intbss == wdev->current_bss && |
| 4868 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4869 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 4870 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4871 | break; |
| 4872 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4873 | if (intbss == wdev->current_bss && |
| 4874 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4875 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 4876 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4877 | break; |
| 4878 | default: |
| 4879 | break; |
| 4880 | } |
| 4881 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4882 | nla_nest_end(msg, bss); |
| 4883 | |
| 4884 | return genlmsg_end(msg, hdr); |
| 4885 | |
| 4886 | nla_put_failure: |
| 4887 | genlmsg_cancel(msg, hdr); |
| 4888 | return -EMSGSIZE; |
| 4889 | } |
| 4890 | |
| 4891 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4892 | struct netlink_callback *cb) |
| 4893 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4894 | struct cfg80211_registered_device *rdev; |
| 4895 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4896 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4897 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4898 | int start = cb->args[1], idx = 0; |
| 4899 | int err; |
| 4900 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4901 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4902 | if (err) |
| 4903 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4904 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4905 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4906 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4907 | wdev_lock(wdev); |
| 4908 | spin_lock_bh(&rdev->bss_lock); |
| 4909 | cfg80211_bss_expire(rdev); |
| 4910 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4911 | cb->seq = rdev->bss_generation; |
| 4912 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4913 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4914 | if (++idx <= start) |
| 4915 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4916 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4917 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4918 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4919 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4920 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4921 | } |
| 4922 | } |
| 4923 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4924 | spin_unlock_bh(&rdev->bss_lock); |
| 4925 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4926 | |
| 4927 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4928 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4929 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4930 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4931 | } |
| 4932 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4933 | 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] | 4934 | int flags, struct net_device *dev, |
| 4935 | struct survey_info *survey) |
| 4936 | { |
| 4937 | void *hdr; |
| 4938 | struct nlattr *infoattr; |
| 4939 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4940 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4941 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4942 | if (!hdr) |
| 4943 | return -ENOMEM; |
| 4944 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4945 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 4946 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4947 | |
| 4948 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4949 | if (!infoattr) |
| 4950 | goto nla_put_failure; |
| 4951 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4952 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4953 | survey->channel->center_freq)) |
| 4954 | goto nla_put_failure; |
| 4955 | |
| 4956 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 4957 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 4958 | goto nla_put_failure; |
| 4959 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 4960 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 4961 | goto nla_put_failure; |
| 4962 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 4963 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4964 | survey->channel_time)) |
| 4965 | goto nla_put_failure; |
| 4966 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 4967 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4968 | survey->channel_time_busy)) |
| 4969 | goto nla_put_failure; |
| 4970 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 4971 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4972 | survey->channel_time_ext_busy)) |
| 4973 | goto nla_put_failure; |
| 4974 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 4975 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4976 | survey->channel_time_rx)) |
| 4977 | goto nla_put_failure; |
| 4978 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 4979 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4980 | survey->channel_time_tx)) |
| 4981 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4982 | |
| 4983 | nla_nest_end(msg, infoattr); |
| 4984 | |
| 4985 | return genlmsg_end(msg, hdr); |
| 4986 | |
| 4987 | nla_put_failure: |
| 4988 | genlmsg_cancel(msg, hdr); |
| 4989 | return -EMSGSIZE; |
| 4990 | } |
| 4991 | |
| 4992 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4993 | struct netlink_callback *cb) |
| 4994 | { |
| 4995 | struct survey_info survey; |
| 4996 | struct cfg80211_registered_device *dev; |
| 4997 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4998 | int survey_idx = cb->args[1]; |
| 4999 | int res; |
| 5000 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5001 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 5002 | if (res) |
| 5003 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5004 | |
| 5005 | if (!dev->ops->dump_survey) { |
| 5006 | res = -EOPNOTSUPP; |
| 5007 | goto out_err; |
| 5008 | } |
| 5009 | |
| 5010 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5011 | struct ieee80211_channel *chan; |
| 5012 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5013 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5014 | if (res == -ENOENT) |
| 5015 | break; |
| 5016 | if (res) |
| 5017 | goto out_err; |
| 5018 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5019 | /* Survey without a channel doesn't make sense */ |
| 5020 | if (!survey.channel) { |
| 5021 | res = -EINVAL; |
| 5022 | goto out; |
| 5023 | } |
| 5024 | |
| 5025 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5026 | survey.channel->center_freq); |
| 5027 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5028 | survey_idx++; |
| 5029 | continue; |
| 5030 | } |
| 5031 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5032 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5033 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5034 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5035 | netdev, |
| 5036 | &survey) < 0) |
| 5037 | goto out; |
| 5038 | survey_idx++; |
| 5039 | } |
| 5040 | |
| 5041 | out: |
| 5042 | cb->args[1] = survey_idx; |
| 5043 | res = skb->len; |
| 5044 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5045 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5046 | return res; |
| 5047 | } |
| 5048 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5049 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5050 | { |
| 5051 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5052 | NL80211_WPA_VERSION_2)); |
| 5053 | } |
| 5054 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5055 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5056 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5057 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5058 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5059 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5060 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5061 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5062 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5063 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5064 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5065 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5066 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5067 | return -EINVAL; |
| 5068 | |
| 5069 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5070 | return -EINVAL; |
| 5071 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5072 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5073 | return -EINVAL; |
| 5074 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5075 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5076 | return -EINVAL; |
| 5077 | |
| 5078 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5079 | return -EINVAL; |
| 5080 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5081 | err = nl80211_parse_key(info, &key); |
| 5082 | if (err) |
| 5083 | return err; |
| 5084 | |
| 5085 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5086 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5087 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5088 | if (!key.p.key || !key.p.key_len) |
| 5089 | return -EINVAL; |
| 5090 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5091 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5092 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5093 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5094 | return -EINVAL; |
| 5095 | if (key.idx > 4) |
| 5096 | return -EINVAL; |
| 5097 | } else { |
| 5098 | key.p.key_len = 0; |
| 5099 | key.p.key = NULL; |
| 5100 | } |
| 5101 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5102 | if (key.idx >= 0) { |
| 5103 | int i; |
| 5104 | bool ok = false; |
| 5105 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5106 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5107 | ok = true; |
| 5108 | break; |
| 5109 | } |
| 5110 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5111 | if (!ok) |
| 5112 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5113 | } |
| 5114 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5115 | if (!rdev->ops->auth) |
| 5116 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5117 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5118 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5119 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5120 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5121 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5122 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5123 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5124 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5125 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5126 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5127 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5128 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5129 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5130 | |
| 5131 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5132 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5133 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5134 | } |
| 5135 | |
| 5136 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5137 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5138 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5139 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5140 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5141 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5142 | return -EINVAL; |
| 5143 | |
| 5144 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5145 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5146 | return -EINVAL; |
| 5147 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5148 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5149 | /* need to include at least Auth Transaction and Status Code */ |
| 5150 | if (sae_data_len < 4) |
| 5151 | return -EINVAL; |
| 5152 | } |
| 5153 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5154 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5155 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5156 | /* |
| 5157 | * Since we no longer track auth state, ignore |
| 5158 | * requests to only change local state. |
| 5159 | */ |
| 5160 | if (local_state_change) |
| 5161 | return 0; |
| 5162 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5163 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5164 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5165 | key.p.key, key.p.key_len, key.idx, |
| 5166 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5167 | } |
| 5168 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5169 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5170 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5171 | struct cfg80211_crypto_settings *settings, |
| 5172 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5173 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5174 | memset(settings, 0, sizeof(*settings)); |
| 5175 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5176 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5177 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5178 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5179 | u16 proto; |
| 5180 | proto = nla_get_u16( |
| 5181 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5182 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5183 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5184 | proto != ETH_P_PAE) |
| 5185 | return -EINVAL; |
| 5186 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5187 | settings->control_port_no_encrypt = true; |
| 5188 | } else |
| 5189 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5190 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5191 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5192 | void *data; |
| 5193 | int len, i; |
| 5194 | |
| 5195 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5196 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5197 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5198 | |
| 5199 | if (len % sizeof(u32)) |
| 5200 | return -EINVAL; |
| 5201 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5202 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5203 | return -EINVAL; |
| 5204 | |
| 5205 | memcpy(settings->ciphers_pairwise, data, len); |
| 5206 | |
| 5207 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5208 | if (!cfg80211_supported_cipher_suite( |
| 5209 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5210 | settings->ciphers_pairwise[i])) |
| 5211 | return -EINVAL; |
| 5212 | } |
| 5213 | |
| 5214 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5215 | settings->cipher_group = |
| 5216 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5217 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5218 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5219 | return -EINVAL; |
| 5220 | } |
| 5221 | |
| 5222 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5223 | settings->wpa_versions = |
| 5224 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5225 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5226 | return -EINVAL; |
| 5227 | } |
| 5228 | |
| 5229 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5230 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5231 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5232 | |
| 5233 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5234 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5235 | settings->n_akm_suites = len / sizeof(u32); |
| 5236 | |
| 5237 | if (len % sizeof(u32)) |
| 5238 | return -EINVAL; |
| 5239 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5240 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5241 | return -EINVAL; |
| 5242 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5243 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5244 | } |
| 5245 | |
| 5246 | return 0; |
| 5247 | } |
| 5248 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5249 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5250 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5251 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5252 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5253 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5254 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5255 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5256 | int err, ssid_len, ie_len = 0; |
| 5257 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5258 | u32 flags = 0; |
| 5259 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5260 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5261 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5262 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5263 | return -EINVAL; |
| 5264 | |
| 5265 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5266 | !info->attrs[NL80211_ATTR_SSID] || |
| 5267 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5268 | return -EINVAL; |
| 5269 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5270 | if (!rdev->ops->assoc) |
| 5271 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5272 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5273 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5274 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5275 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5276 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5277 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5278 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5279 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5280 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5281 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5282 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5283 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5284 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5285 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5286 | |
| 5287 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5288 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5289 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5290 | } |
| 5291 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5292 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5293 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5294 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5295 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5296 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5297 | else if (mfp != NL80211_MFP_NO) |
| 5298 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5299 | } |
| 5300 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5301 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5302 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5303 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5304 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5305 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5306 | |
| 5307 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5308 | ht_capa_mask = |
| 5309 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5310 | |
| 5311 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5312 | if (!ht_capa_mask) |
| 5313 | return -EINVAL; |
| 5314 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5315 | } |
| 5316 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5317 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5318 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5319 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5320 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5321 | &crypto, flags, ht_capa, |
| 5322 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5323 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5324 | return err; |
| 5325 | } |
| 5326 | |
| 5327 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5328 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5330 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5331 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5332 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5333 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5334 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5335 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5336 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5337 | return -EINVAL; |
| 5338 | |
| 5339 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5340 | return -EINVAL; |
| 5341 | |
| 5342 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5343 | return -EINVAL; |
| 5344 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5345 | if (!rdev->ops->deauth) |
| 5346 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5347 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5348 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5349 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5350 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5351 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5352 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5353 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5354 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5355 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5356 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5357 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5358 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5359 | |
| 5360 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5361 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5362 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5363 | } |
| 5364 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5365 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5366 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5367 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5368 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5369 | } |
| 5370 | |
| 5371 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5372 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5373 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5374 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5375 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5376 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5377 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5378 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5379 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5380 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5381 | return -EINVAL; |
| 5382 | |
| 5383 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5384 | return -EINVAL; |
| 5385 | |
| 5386 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5387 | return -EINVAL; |
| 5388 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5389 | if (!rdev->ops->disassoc) |
| 5390 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5391 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5392 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5393 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5394 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5395 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5396 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5397 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5398 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5399 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5400 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5401 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5402 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5403 | |
| 5404 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5405 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5406 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5407 | } |
| 5408 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5409 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5410 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5411 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5412 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5413 | } |
| 5414 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5415 | static bool |
| 5416 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5417 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5418 | int rateval) |
| 5419 | { |
| 5420 | struct wiphy *wiphy = &rdev->wiphy; |
| 5421 | bool found = false; |
| 5422 | int band, i; |
| 5423 | |
| 5424 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5425 | struct ieee80211_supported_band *sband; |
| 5426 | |
| 5427 | sband = wiphy->bands[band]; |
| 5428 | if (!sband) |
| 5429 | continue; |
| 5430 | |
| 5431 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5432 | if (sband->bitrates[i].bitrate == rateval) { |
| 5433 | mcast_rate[band] = i + 1; |
| 5434 | found = true; |
| 5435 | break; |
| 5436 | } |
| 5437 | } |
| 5438 | } |
| 5439 | |
| 5440 | return found; |
| 5441 | } |
| 5442 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5443 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5444 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5446 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5447 | struct cfg80211_ibss_params ibss; |
| 5448 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5449 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5450 | int err; |
| 5451 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5452 | memset(&ibss, 0, sizeof(ibss)); |
| 5453 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5454 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5455 | return -EINVAL; |
| 5456 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5457 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5458 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5459 | return -EINVAL; |
| 5460 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5461 | ibss.beacon_interval = 100; |
| 5462 | |
| 5463 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5464 | ibss.beacon_interval = |
| 5465 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5466 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5467 | return -EINVAL; |
| 5468 | } |
| 5469 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5470 | if (!rdev->ops->join_ibss) |
| 5471 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5472 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5473 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5474 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5475 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5476 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5477 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5478 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5479 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5480 | |
| 5481 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5482 | return -EINVAL; |
| 5483 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5484 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5485 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5486 | |
| 5487 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5488 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5489 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5490 | } |
| 5491 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5492 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 5493 | if (err) |
| 5494 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5495 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5496 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5497 | return -EINVAL; |
| 5498 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5499 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 5500 | return -EINVAL; |
| 5501 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 5502 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 5503 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5504 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5505 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5506 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5507 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5508 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5509 | u8 *rates = |
| 5510 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5511 | int n_rates = |
| 5512 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5513 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5514 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5515 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5516 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5517 | &ibss.basic_rates); |
| 5518 | if (err) |
| 5519 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5520 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5521 | |
| 5522 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5523 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5524 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5525 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5526 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5527 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5528 | bool no_ht = false; |
| 5529 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5530 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5531 | info->attrs[NL80211_ATTR_KEYS], |
| 5532 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5533 | if (IS_ERR(connkeys)) |
| 5534 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5535 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 5536 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 5537 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5538 | kfree(connkeys); |
| 5539 | return -EINVAL; |
| 5540 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5541 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5542 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5543 | ibss.control_port = |
| 5544 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5545 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5546 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5547 | if (err) |
| 5548 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5549 | return err; |
| 5550 | } |
| 5551 | |
| 5552 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5553 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5554 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5555 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5556 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5557 | if (!rdev->ops->leave_ibss) |
| 5558 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5559 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5560 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5561 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5562 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5563 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5564 | } |
| 5565 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 5566 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 5567 | { |
| 5568 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5569 | struct net_device *dev = info->user_ptr[1]; |
| 5570 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 5571 | u32 nla_rate; |
| 5572 | int err; |
| 5573 | |
| 5574 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5575 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5576 | return -EOPNOTSUPP; |
| 5577 | |
| 5578 | if (!rdev->ops->set_mcast_rate) |
| 5579 | return -EOPNOTSUPP; |
| 5580 | |
| 5581 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 5582 | |
| 5583 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 5584 | return -EINVAL; |
| 5585 | |
| 5586 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 5587 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 5588 | return -EINVAL; |
| 5589 | |
| 5590 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 5591 | |
| 5592 | return err; |
| 5593 | } |
| 5594 | |
| 5595 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5596 | #ifdef CONFIG_NL80211_TESTMODE |
| 5597 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5598 | .name = "testmode", |
| 5599 | }; |
| 5600 | |
| 5601 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5602 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5603 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5604 | int err; |
| 5605 | |
| 5606 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5607 | return -EINVAL; |
| 5608 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5609 | err = -EOPNOTSUPP; |
| 5610 | if (rdev->ops->testmode_cmd) { |
| 5611 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5612 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5613 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5614 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5615 | rdev->testmode_info = NULL; |
| 5616 | } |
| 5617 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5618 | return err; |
| 5619 | } |
| 5620 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5621 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5622 | struct netlink_callback *cb) |
| 5623 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5624 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5625 | int err; |
| 5626 | long phy_idx; |
| 5627 | void *data = NULL; |
| 5628 | int data_len = 0; |
| 5629 | |
| 5630 | if (cb->args[0]) { |
| 5631 | /* |
| 5632 | * 0 is a valid index, but not valid for args[0], |
| 5633 | * so we need to offset by 1. |
| 5634 | */ |
| 5635 | phy_idx = cb->args[0] - 1; |
| 5636 | } else { |
| 5637 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5638 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5639 | nl80211_policy); |
| 5640 | if (err) |
| 5641 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5642 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5643 | mutex_lock(&cfg80211_mutex); |
| 5644 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 5645 | nl80211_fam.attrbuf); |
| 5646 | if (IS_ERR(rdev)) { |
| 5647 | mutex_unlock(&cfg80211_mutex); |
| 5648 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5649 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5650 | phy_idx = rdev->wiphy_idx; |
| 5651 | rdev = NULL; |
| 5652 | mutex_unlock(&cfg80211_mutex); |
| 5653 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5654 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 5655 | cb->args[1] = |
| 5656 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 5657 | } |
| 5658 | |
| 5659 | if (cb->args[1]) { |
| 5660 | data = nla_data((void *)cb->args[1]); |
| 5661 | data_len = nla_len((void *)cb->args[1]); |
| 5662 | } |
| 5663 | |
| 5664 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5665 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 5666 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5667 | mutex_unlock(&cfg80211_mutex); |
| 5668 | return -ENOENT; |
| 5669 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5670 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5671 | mutex_unlock(&cfg80211_mutex); |
| 5672 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5673 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5674 | err = -EOPNOTSUPP; |
| 5675 | goto out_err; |
| 5676 | } |
| 5677 | |
| 5678 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5679 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5680 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5681 | NL80211_CMD_TESTMODE); |
| 5682 | struct nlattr *tmdata; |
| 5683 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5684 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5685 | genlmsg_cancel(skb, hdr); |
| 5686 | break; |
| 5687 | } |
| 5688 | |
| 5689 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5690 | if (!tmdata) { |
| 5691 | genlmsg_cancel(skb, hdr); |
| 5692 | break; |
| 5693 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5694 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5695 | nla_nest_end(skb, tmdata); |
| 5696 | |
| 5697 | if (err == -ENOBUFS || err == -ENOENT) { |
| 5698 | genlmsg_cancel(skb, hdr); |
| 5699 | break; |
| 5700 | } else if (err) { |
| 5701 | genlmsg_cancel(skb, hdr); |
| 5702 | goto out_err; |
| 5703 | } |
| 5704 | |
| 5705 | genlmsg_end(skb, hdr); |
| 5706 | } |
| 5707 | |
| 5708 | err = skb->len; |
| 5709 | /* see above */ |
| 5710 | cb->args[0] = phy_idx + 1; |
| 5711 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5712 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5713 | return err; |
| 5714 | } |
| 5715 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5716 | static struct sk_buff * |
| 5717 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5718 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5719 | { |
| 5720 | struct sk_buff *skb; |
| 5721 | void *hdr; |
| 5722 | struct nlattr *data; |
| 5723 | |
| 5724 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5725 | if (!skb) |
| 5726 | return NULL; |
| 5727 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5728 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5729 | if (!hdr) { |
| 5730 | kfree_skb(skb); |
| 5731 | return NULL; |
| 5732 | } |
| 5733 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5734 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 5735 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5736 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5737 | |
| 5738 | ((void **)skb->cb)[0] = rdev; |
| 5739 | ((void **)skb->cb)[1] = hdr; |
| 5740 | ((void **)skb->cb)[2] = data; |
| 5741 | |
| 5742 | return skb; |
| 5743 | |
| 5744 | nla_put_failure: |
| 5745 | kfree_skb(skb); |
| 5746 | return NULL; |
| 5747 | } |
| 5748 | |
| 5749 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5750 | int approxlen) |
| 5751 | { |
| 5752 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5753 | |
| 5754 | if (WARN_ON(!rdev->testmode_info)) |
| 5755 | return NULL; |
| 5756 | |
| 5757 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5758 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5759 | rdev->testmode_info->snd_seq, |
| 5760 | GFP_KERNEL); |
| 5761 | } |
| 5762 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5763 | |
| 5764 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5765 | { |
| 5766 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5767 | void *hdr = ((void **)skb->cb)[1]; |
| 5768 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5769 | |
| 5770 | if (WARN_ON(!rdev->testmode_info)) { |
| 5771 | kfree_skb(skb); |
| 5772 | return -EINVAL; |
| 5773 | } |
| 5774 | |
| 5775 | nla_nest_end(skb, data); |
| 5776 | genlmsg_end(skb, hdr); |
| 5777 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5778 | } |
| 5779 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5780 | |
| 5781 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5782 | int approxlen, gfp_t gfp) |
| 5783 | { |
| 5784 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5785 | |
| 5786 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5787 | } |
| 5788 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5789 | |
| 5790 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5791 | { |
| 5792 | void *hdr = ((void **)skb->cb)[1]; |
| 5793 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5794 | |
| 5795 | nla_nest_end(skb, data); |
| 5796 | genlmsg_end(skb, hdr); |
| 5797 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5798 | } |
| 5799 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5800 | #endif |
| 5801 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5802 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5803 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5804 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5805 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5806 | struct cfg80211_connect_params connect; |
| 5807 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5808 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5809 | int err; |
| 5810 | |
| 5811 | memset(&connect, 0, sizeof(connect)); |
| 5812 | |
| 5813 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5814 | return -EINVAL; |
| 5815 | |
| 5816 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5817 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5818 | return -EINVAL; |
| 5819 | |
| 5820 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5821 | connect.auth_type = |
| 5822 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5823 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 5824 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5825 | return -EINVAL; |
| 5826 | } else |
| 5827 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5828 | |
| 5829 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5830 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5831 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5832 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5833 | if (err) |
| 5834 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5835 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5836 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5837 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5838 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5839 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5840 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5841 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 5842 | connect.bg_scan_period = -1; |
| 5843 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 5844 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 5845 | connect.bg_scan_period = |
| 5846 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 5847 | } |
| 5848 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5849 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5850 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5851 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5852 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5853 | |
| 5854 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5855 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5856 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5857 | } |
| 5858 | |
| 5859 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5860 | connect.channel = |
| 5861 | ieee80211_get_channel(wiphy, |
| 5862 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5863 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5864 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5865 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5866 | } |
| 5867 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5868 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5869 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5870 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5871 | if (IS_ERR(connkeys)) |
| 5872 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5873 | } |
| 5874 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5875 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5876 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5877 | |
| 5878 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5879 | memcpy(&connect.ht_capa_mask, |
| 5880 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5881 | sizeof(connect.ht_capa_mask)); |
| 5882 | |
| 5883 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5884 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 5885 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5886 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5887 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5888 | memcpy(&connect.ht_capa, |
| 5889 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5890 | sizeof(connect.ht_capa)); |
| 5891 | } |
| 5892 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5893 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5894 | if (err) |
| 5895 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5896 | return err; |
| 5897 | } |
| 5898 | |
| 5899 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5900 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5901 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5902 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5903 | u16 reason; |
| 5904 | |
| 5905 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5906 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5907 | else |
| 5908 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5909 | |
| 5910 | if (reason == 0) |
| 5911 | return -EINVAL; |
| 5912 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5913 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5914 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5915 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5916 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5917 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5918 | } |
| 5919 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5920 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5921 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5922 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5923 | struct net *net; |
| 5924 | int err; |
| 5925 | u32 pid; |
| 5926 | |
| 5927 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5928 | return -EINVAL; |
| 5929 | |
| 5930 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5931 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5932 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5933 | if (IS_ERR(net)) |
| 5934 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5935 | |
| 5936 | err = 0; |
| 5937 | |
| 5938 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5939 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5940 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5941 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5942 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5943 | return err; |
| 5944 | } |
| 5945 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5946 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5947 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5948 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5949 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5950 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5951 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5952 | struct cfg80211_pmksa pmksa; |
| 5953 | |
| 5954 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5955 | |
| 5956 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5957 | return -EINVAL; |
| 5958 | |
| 5959 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5960 | return -EINVAL; |
| 5961 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5962 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5963 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5964 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5965 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5966 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5967 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5968 | |
| 5969 | switch (info->genlhdr->cmd) { |
| 5970 | case NL80211_CMD_SET_PMKSA: |
| 5971 | rdev_ops = rdev->ops->set_pmksa; |
| 5972 | break; |
| 5973 | case NL80211_CMD_DEL_PMKSA: |
| 5974 | rdev_ops = rdev->ops->del_pmksa; |
| 5975 | break; |
| 5976 | default: |
| 5977 | WARN_ON(1); |
| 5978 | break; |
| 5979 | } |
| 5980 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5981 | if (!rdev_ops) |
| 5982 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5983 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5984 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5985 | } |
| 5986 | |
| 5987 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5988 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5989 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5990 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 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 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5996 | if (!rdev->ops->flush_pmksa) |
| 5997 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5998 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5999 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6000 | } |
| 6001 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6002 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6003 | { |
| 6004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6005 | struct net_device *dev = info->user_ptr[1]; |
| 6006 | u8 action_code, dialog_token; |
| 6007 | u16 status_code; |
| 6008 | u8 *peer; |
| 6009 | |
| 6010 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6011 | !rdev->ops->tdls_mgmt) |
| 6012 | return -EOPNOTSUPP; |
| 6013 | |
| 6014 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6015 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6016 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6017 | !info->attrs[NL80211_ATTR_IE] || |
| 6018 | !info->attrs[NL80211_ATTR_MAC]) |
| 6019 | return -EINVAL; |
| 6020 | |
| 6021 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6022 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6023 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6024 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6025 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6026 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6027 | dialog_token, status_code, |
| 6028 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6029 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6030 | } |
| 6031 | |
| 6032 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6033 | { |
| 6034 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6035 | struct net_device *dev = info->user_ptr[1]; |
| 6036 | enum nl80211_tdls_operation operation; |
| 6037 | u8 *peer; |
| 6038 | |
| 6039 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6040 | !rdev->ops->tdls_oper) |
| 6041 | return -EOPNOTSUPP; |
| 6042 | |
| 6043 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6044 | !info->attrs[NL80211_ATTR_MAC]) |
| 6045 | return -EINVAL; |
| 6046 | |
| 6047 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6048 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6049 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6050 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6051 | } |
| 6052 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6053 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6054 | struct genl_info *info) |
| 6055 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6057 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6058 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6059 | struct sk_buff *msg; |
| 6060 | void *hdr; |
| 6061 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6062 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6063 | int err; |
| 6064 | |
| 6065 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6066 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6067 | return -EINVAL; |
| 6068 | |
| 6069 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6070 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6071 | if (!rdev->ops->remain_on_channel || |
| 6072 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6073 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6074 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6075 | /* |
| 6076 | * We should be on that channel for at least a minimum amount of |
| 6077 | * time (10ms) but no longer than the driver supports. |
| 6078 | */ |
| 6079 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6080 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6081 | return -EINVAL; |
| 6082 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6083 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6084 | if (err) |
| 6085 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6086 | |
| 6087 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6088 | if (!msg) |
| 6089 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6090 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6091 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6092 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6093 | |
| 6094 | if (IS_ERR(hdr)) { |
| 6095 | err = PTR_ERR(hdr); |
| 6096 | goto free_msg; |
| 6097 | } |
| 6098 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6099 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6100 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6101 | |
| 6102 | if (err) |
| 6103 | goto free_msg; |
| 6104 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6105 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6106 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6107 | |
| 6108 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6109 | |
| 6110 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6111 | |
| 6112 | nla_put_failure: |
| 6113 | err = -ENOBUFS; |
| 6114 | free_msg: |
| 6115 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6116 | return err; |
| 6117 | } |
| 6118 | |
| 6119 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6120 | struct genl_info *info) |
| 6121 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6122 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6123 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6124 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6125 | |
| 6126 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6127 | return -EINVAL; |
| 6128 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6129 | if (!rdev->ops->cancel_remain_on_channel) |
| 6130 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6131 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6132 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6133 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6134 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6135 | } |
| 6136 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6137 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6138 | u8 *rates, u8 rates_len) |
| 6139 | { |
| 6140 | u8 i; |
| 6141 | u32 mask = 0; |
| 6142 | |
| 6143 | for (i = 0; i < rates_len; i++) { |
| 6144 | int rate = (rates[i] & 0x7f) * 5; |
| 6145 | int ridx; |
| 6146 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6147 | struct ieee80211_rate *srate = |
| 6148 | &sband->bitrates[ridx]; |
| 6149 | if (rate == srate->bitrate) { |
| 6150 | mask |= 1 << ridx; |
| 6151 | break; |
| 6152 | } |
| 6153 | } |
| 6154 | if (ridx == sband->n_bitrates) |
| 6155 | return 0; /* rate not found */ |
| 6156 | } |
| 6157 | |
| 6158 | return mask; |
| 6159 | } |
| 6160 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6161 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6162 | u8 *rates, u8 rates_len, |
| 6163 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6164 | { |
| 6165 | u8 i; |
| 6166 | |
| 6167 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6168 | |
| 6169 | for (i = 0; i < rates_len; i++) { |
| 6170 | int ridx, rbit; |
| 6171 | |
| 6172 | ridx = rates[i] / 8; |
| 6173 | rbit = BIT(rates[i] % 8); |
| 6174 | |
| 6175 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6176 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6177 | return false; |
| 6178 | |
| 6179 | /* check availability */ |
| 6180 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6181 | mcs[ridx] |= rbit; |
| 6182 | else |
| 6183 | return false; |
| 6184 | } |
| 6185 | |
| 6186 | return true; |
| 6187 | } |
| 6188 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6189 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6190 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6191 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6192 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6193 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6194 | }; |
| 6195 | |
| 6196 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6197 | struct genl_info *info) |
| 6198 | { |
| 6199 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6201 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6202 | int rem, i; |
| 6203 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6204 | struct nlattr *tx_rates; |
| 6205 | struct ieee80211_supported_band *sband; |
| 6206 | |
| 6207 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6208 | return -EINVAL; |
| 6209 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6210 | if (!rdev->ops->set_bitrate_mask) |
| 6211 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6212 | |
| 6213 | memset(&mask, 0, sizeof(mask)); |
| 6214 | /* Default to all rates enabled */ |
| 6215 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6216 | sband = rdev->wiphy.bands[i]; |
| 6217 | mask.control[i].legacy = |
| 6218 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6219 | if (sband) |
| 6220 | memcpy(mask.control[i].mcs, |
| 6221 | sband->ht_cap.mcs.rx_mask, |
| 6222 | sizeof(mask.control[i].mcs)); |
| 6223 | else |
| 6224 | memset(mask.control[i].mcs, 0, |
| 6225 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6226 | } |
| 6227 | |
| 6228 | /* |
| 6229 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6230 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6231 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6232 | 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] | 6233 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6234 | { |
| 6235 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6236 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6237 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6238 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6239 | if (sband == NULL) |
| 6240 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6241 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6242 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6243 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6244 | mask.control[band].legacy = rateset_to_mask( |
| 6245 | sband, |
| 6246 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6247 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6248 | if ((mask.control[band].legacy == 0) && |
| 6249 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6250 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6251 | } |
| 6252 | if (tb[NL80211_TXRATE_MCS]) { |
| 6253 | if (!ht_rateset_to_mask( |
| 6254 | sband, |
| 6255 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6256 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6257 | mask.control[band].mcs)) |
| 6258 | return -EINVAL; |
| 6259 | } |
| 6260 | |
| 6261 | if (mask.control[band].legacy == 0) { |
| 6262 | /* don't allow empty legacy rates if HT |
| 6263 | * is not even supported. */ |
| 6264 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6265 | return -EINVAL; |
| 6266 | |
| 6267 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6268 | if (mask.control[band].mcs[i]) |
| 6269 | break; |
| 6270 | |
| 6271 | /* legacy and mcs rates may not be both empty */ |
| 6272 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6273 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6274 | } |
| 6275 | } |
| 6276 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6277 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6278 | } |
| 6279 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6280 | 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] | 6281 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6282 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6283 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6284 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6285 | |
| 6286 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6287 | return -EINVAL; |
| 6288 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6289 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6290 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6291 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6292 | switch (wdev->iftype) { |
| 6293 | case NL80211_IFTYPE_STATION: |
| 6294 | case NL80211_IFTYPE_ADHOC: |
| 6295 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6296 | case NL80211_IFTYPE_AP: |
| 6297 | case NL80211_IFTYPE_AP_VLAN: |
| 6298 | case NL80211_IFTYPE_MESH_POINT: |
| 6299 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6300 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6301 | break; |
| 6302 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6303 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6304 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6305 | |
| 6306 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6307 | if (!rdev->ops->mgmt_tx) |
| 6308 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6309 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6310 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6311 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6312 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6313 | } |
| 6314 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6315 | 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] | 6316 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6317 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6318 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6319 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6320 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6321 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6322 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6323 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6324 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6325 | bool offchan, no_cck, dont_wait_for_ack; |
| 6326 | |
| 6327 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6328 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6329 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6330 | return -EINVAL; |
| 6331 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6332 | if (!rdev->ops->mgmt_tx) |
| 6333 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6334 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6335 | switch (wdev->iftype) { |
| 6336 | case NL80211_IFTYPE_STATION: |
| 6337 | case NL80211_IFTYPE_ADHOC: |
| 6338 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6339 | case NL80211_IFTYPE_AP: |
| 6340 | case NL80211_IFTYPE_AP_VLAN: |
| 6341 | case NL80211_IFTYPE_MESH_POINT: |
| 6342 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6343 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6344 | break; |
| 6345 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6346 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6347 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6348 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6349 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6350 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6351 | return -EINVAL; |
| 6352 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6353 | |
| 6354 | /* |
| 6355 | * We should wait on the channel for at least a minimum amount |
| 6356 | * of time (10ms) but no longer than the driver supports. |
| 6357 | */ |
| 6358 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6359 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6360 | return -EINVAL; |
| 6361 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6362 | } |
| 6363 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6364 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6365 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6366 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6367 | return -EINVAL; |
| 6368 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6369 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6370 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6371 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6372 | if (err) |
| 6373 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6374 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6375 | if (!dont_wait_for_ack) { |
| 6376 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6377 | if (!msg) |
| 6378 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6379 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6380 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6381 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6382 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6383 | if (IS_ERR(hdr)) { |
| 6384 | err = PTR_ERR(hdr); |
| 6385 | goto free_msg; |
| 6386 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6387 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6388 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6389 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6390 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6391 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6392 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6393 | if (err) |
| 6394 | goto free_msg; |
| 6395 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6396 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6397 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6398 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6399 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6400 | genlmsg_end(msg, hdr); |
| 6401 | return genlmsg_reply(msg, info); |
| 6402 | } |
| 6403 | |
| 6404 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6405 | |
| 6406 | nla_put_failure: |
| 6407 | err = -ENOBUFS; |
| 6408 | free_msg: |
| 6409 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6410 | return err; |
| 6411 | } |
| 6412 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6413 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6414 | { |
| 6415 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6416 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6417 | u64 cookie; |
| 6418 | |
| 6419 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6420 | return -EINVAL; |
| 6421 | |
| 6422 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6423 | return -EOPNOTSUPP; |
| 6424 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6425 | switch (wdev->iftype) { |
| 6426 | case NL80211_IFTYPE_STATION: |
| 6427 | case NL80211_IFTYPE_ADHOC: |
| 6428 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6429 | case NL80211_IFTYPE_AP: |
| 6430 | case NL80211_IFTYPE_AP_VLAN: |
| 6431 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6432 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6433 | break; |
| 6434 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6435 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6436 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6437 | |
| 6438 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6439 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6440 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6441 | } |
| 6442 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6443 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6444 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6446 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6447 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6448 | u8 ps_state; |
| 6449 | bool state; |
| 6450 | int err; |
| 6451 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6452 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6453 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6454 | |
| 6455 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6456 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6457 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6458 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6459 | |
| 6460 | wdev = dev->ieee80211_ptr; |
| 6461 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6462 | if (!rdev->ops->set_power_mgmt) |
| 6463 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6464 | |
| 6465 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6466 | |
| 6467 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6468 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6469 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6470 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6471 | if (!err) |
| 6472 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6473 | return err; |
| 6474 | } |
| 6475 | |
| 6476 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6477 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6478 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6479 | enum nl80211_ps_state ps_state; |
| 6480 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6481 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6482 | struct sk_buff *msg; |
| 6483 | void *hdr; |
| 6484 | int err; |
| 6485 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6486 | wdev = dev->ieee80211_ptr; |
| 6487 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6488 | if (!rdev->ops->set_power_mgmt) |
| 6489 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6490 | |
| 6491 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6492 | if (!msg) |
| 6493 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6494 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6495 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6496 | NL80211_CMD_GET_POWER_SAVE); |
| 6497 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6498 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6499 | goto free_msg; |
| 6500 | } |
| 6501 | |
| 6502 | if (wdev->ps) |
| 6503 | ps_state = NL80211_PS_ENABLED; |
| 6504 | else |
| 6505 | ps_state = NL80211_PS_DISABLED; |
| 6506 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6507 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6508 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6509 | |
| 6510 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6511 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6512 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6513 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6514 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6515 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6516 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6517 | return err; |
| 6518 | } |
| 6519 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6520 | static struct nla_policy |
| 6521 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6522 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6523 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6524 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6525 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 6526 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 6527 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6528 | }; |
| 6529 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6530 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6531 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6532 | { |
| 6533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6534 | struct wireless_dev *wdev; |
| 6535 | struct net_device *dev = info->user_ptr[1]; |
| 6536 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 6537 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6538 | return -EINVAL; |
| 6539 | |
| 6540 | wdev = dev->ieee80211_ptr; |
| 6541 | |
| 6542 | if (!rdev->ops->set_cqm_txe_config) |
| 6543 | return -EOPNOTSUPP; |
| 6544 | |
| 6545 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 6546 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6547 | return -EOPNOTSUPP; |
| 6548 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6549 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6550 | } |
| 6551 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6552 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6553 | s32 threshold, u32 hysteresis) |
| 6554 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6555 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6556 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6557 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6558 | |
| 6559 | if (threshold > 0) |
| 6560 | return -EINVAL; |
| 6561 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6562 | wdev = dev->ieee80211_ptr; |
| 6563 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6564 | if (!rdev->ops->set_cqm_rssi_config) |
| 6565 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6566 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6567 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6568 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6569 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6570 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6571 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6572 | } |
| 6573 | |
| 6574 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6575 | { |
| 6576 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6577 | struct nlattr *cqm; |
| 6578 | int err; |
| 6579 | |
| 6580 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6581 | if (!cqm) { |
| 6582 | err = -EINVAL; |
| 6583 | goto out; |
| 6584 | } |
| 6585 | |
| 6586 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6587 | nl80211_attr_cqm_policy); |
| 6588 | if (err) |
| 6589 | goto out; |
| 6590 | |
| 6591 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6592 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6593 | s32 threshold; |
| 6594 | u32 hysteresis; |
| 6595 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6596 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6597 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6598 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 6599 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 6600 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 6601 | u32 rate, pkts, intvl; |
| 6602 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 6603 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 6604 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 6605 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6606 | } else |
| 6607 | err = -EINVAL; |
| 6608 | |
| 6609 | out: |
| 6610 | return err; |
| 6611 | } |
| 6612 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6613 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6614 | { |
| 6615 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6616 | struct net_device *dev = info->user_ptr[1]; |
| 6617 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6618 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6619 | int err; |
| 6620 | |
| 6621 | /* start with default */ |
| 6622 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6623 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6624 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6625 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6626 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6627 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6628 | if (err) |
| 6629 | return err; |
| 6630 | } |
| 6631 | |
| 6632 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6633 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 6634 | return -EINVAL; |
| 6635 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6636 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6637 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6638 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 6639 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6640 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 6641 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6642 | return -EINVAL; |
| 6643 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6644 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 6645 | /* parse additional setup parameters if given */ |
| 6646 | err = nl80211_parse_mesh_setup(info, &setup); |
| 6647 | if (err) |
| 6648 | return err; |
| 6649 | } |
| 6650 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6651 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6652 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 6653 | if (err) |
| 6654 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6655 | } else { |
| 6656 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6657 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6658 | } |
| 6659 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6660 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6661 | } |
| 6662 | |
| 6663 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6664 | { |
| 6665 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6666 | struct net_device *dev = info->user_ptr[1]; |
| 6667 | |
| 6668 | return cfg80211_leave_mesh(rdev, dev); |
| 6669 | } |
| 6670 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6671 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6672 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6673 | { |
| 6674 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6675 | struct sk_buff *msg; |
| 6676 | void *hdr; |
| 6677 | |
| 6678 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6679 | return -EOPNOTSUPP; |
| 6680 | |
| 6681 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6682 | if (!msg) |
| 6683 | return -ENOMEM; |
| 6684 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6685 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6686 | NL80211_CMD_GET_WOWLAN); |
| 6687 | if (!hdr) |
| 6688 | goto nla_put_failure; |
| 6689 | |
| 6690 | if (rdev->wowlan) { |
| 6691 | struct nlattr *nl_wowlan; |
| 6692 | |
| 6693 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 6694 | if (!nl_wowlan) |
| 6695 | goto nla_put_failure; |
| 6696 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6697 | if ((rdev->wowlan->any && |
| 6698 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 6699 | (rdev->wowlan->disconnect && |
| 6700 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 6701 | (rdev->wowlan->magic_pkt && |
| 6702 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 6703 | (rdev->wowlan->gtk_rekey_failure && |
| 6704 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 6705 | (rdev->wowlan->eap_identity_req && |
| 6706 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 6707 | (rdev->wowlan->four_way_handshake && |
| 6708 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 6709 | (rdev->wowlan->rfkill_release && |
| 6710 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 6711 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6712 | if (rdev->wowlan->n_patterns) { |
| 6713 | struct nlattr *nl_pats, *nl_pat; |
| 6714 | int i, pat_len; |
| 6715 | |
| 6716 | nl_pats = nla_nest_start(msg, |
| 6717 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 6718 | if (!nl_pats) |
| 6719 | goto nla_put_failure; |
| 6720 | |
| 6721 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 6722 | nl_pat = nla_nest_start(msg, i + 1); |
| 6723 | if (!nl_pat) |
| 6724 | goto nla_put_failure; |
| 6725 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6726 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 6727 | DIV_ROUND_UP(pat_len, 8), |
| 6728 | rdev->wowlan->patterns[i].mask) || |
| 6729 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 6730 | pat_len, |
| 6731 | rdev->wowlan->patterns[i].pattern)) |
| 6732 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6733 | nla_nest_end(msg, nl_pat); |
| 6734 | } |
| 6735 | nla_nest_end(msg, nl_pats); |
| 6736 | } |
| 6737 | |
| 6738 | nla_nest_end(msg, nl_wowlan); |
| 6739 | } |
| 6740 | |
| 6741 | genlmsg_end(msg, hdr); |
| 6742 | return genlmsg_reply(msg, info); |
| 6743 | |
| 6744 | nla_put_failure: |
| 6745 | nlmsg_free(msg); |
| 6746 | return -ENOBUFS; |
| 6747 | } |
| 6748 | |
| 6749 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6750 | { |
| 6751 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6752 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6753 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6754 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6755 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 6756 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6757 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6758 | |
| 6759 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6760 | return -EOPNOTSUPP; |
| 6761 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6762 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 6763 | cfg80211_rdev_free_wowlan(rdev); |
| 6764 | rdev->wowlan = NULL; |
| 6765 | goto set_wakeup; |
| 6766 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6767 | |
| 6768 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 6769 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6770 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6771 | nl80211_wowlan_policy); |
| 6772 | if (err) |
| 6773 | return err; |
| 6774 | |
| 6775 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 6776 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 6777 | return -EINVAL; |
| 6778 | new_triggers.any = true; |
| 6779 | } |
| 6780 | |
| 6781 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 6782 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 6783 | return -EINVAL; |
| 6784 | new_triggers.disconnect = true; |
| 6785 | } |
| 6786 | |
| 6787 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 6788 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 6789 | return -EINVAL; |
| 6790 | new_triggers.magic_pkt = true; |
| 6791 | } |
| 6792 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 6793 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 6794 | return -EINVAL; |
| 6795 | |
| 6796 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 6797 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 6798 | return -EINVAL; |
| 6799 | new_triggers.gtk_rekey_failure = true; |
| 6800 | } |
| 6801 | |
| 6802 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 6803 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 6804 | return -EINVAL; |
| 6805 | new_triggers.eap_identity_req = true; |
| 6806 | } |
| 6807 | |
| 6808 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 6809 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 6810 | return -EINVAL; |
| 6811 | new_triggers.four_way_handshake = true; |
| 6812 | } |
| 6813 | |
| 6814 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 6815 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 6816 | return -EINVAL; |
| 6817 | new_triggers.rfkill_release = true; |
| 6818 | } |
| 6819 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6820 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 6821 | struct nlattr *pat; |
| 6822 | int n_patterns = 0; |
| 6823 | int rem, pat_len, mask_len; |
| 6824 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6825 | |
| 6826 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6827 | rem) |
| 6828 | n_patterns++; |
| 6829 | if (n_patterns > wowlan->n_patterns) |
| 6830 | return -EINVAL; |
| 6831 | |
| 6832 | new_triggers.patterns = kcalloc(n_patterns, |
| 6833 | sizeof(new_triggers.patterns[0]), |
| 6834 | GFP_KERNEL); |
| 6835 | if (!new_triggers.patterns) |
| 6836 | return -ENOMEM; |
| 6837 | |
| 6838 | new_triggers.n_patterns = n_patterns; |
| 6839 | i = 0; |
| 6840 | |
| 6841 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6842 | rem) { |
| 6843 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6844 | nla_data(pat), nla_len(pat), NULL); |
| 6845 | err = -EINVAL; |
| 6846 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6847 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6848 | goto error; |
| 6849 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6850 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6851 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6852 | mask_len) |
| 6853 | goto error; |
| 6854 | if (pat_len > wowlan->pattern_max_len || |
| 6855 | pat_len < wowlan->pattern_min_len) |
| 6856 | goto error; |
| 6857 | |
| 6858 | new_triggers.patterns[i].mask = |
| 6859 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6860 | if (!new_triggers.patterns[i].mask) { |
| 6861 | err = -ENOMEM; |
| 6862 | goto error; |
| 6863 | } |
| 6864 | new_triggers.patterns[i].pattern = |
| 6865 | new_triggers.patterns[i].mask + mask_len; |
| 6866 | memcpy(new_triggers.patterns[i].mask, |
| 6867 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6868 | mask_len); |
| 6869 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6870 | memcpy(new_triggers.patterns[i].pattern, |
| 6871 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6872 | pat_len); |
| 6873 | i++; |
| 6874 | } |
| 6875 | } |
| 6876 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6877 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 6878 | if (!ntrig) { |
| 6879 | err = -ENOMEM; |
| 6880 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6881 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6882 | cfg80211_rdev_free_wowlan(rdev); |
| 6883 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6884 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6885 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6886 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6887 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6888 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6889 | return 0; |
| 6890 | error: |
| 6891 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6892 | kfree(new_triggers.patterns[i].mask); |
| 6893 | kfree(new_triggers.patterns); |
| 6894 | return err; |
| 6895 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6896 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6897 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6898 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6899 | { |
| 6900 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6901 | struct net_device *dev = info->user_ptr[1]; |
| 6902 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6903 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6904 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6905 | int err; |
| 6906 | |
| 6907 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6908 | return -EINVAL; |
| 6909 | |
| 6910 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6911 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6912 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6913 | nl80211_rekey_policy); |
| 6914 | if (err) |
| 6915 | return err; |
| 6916 | |
| 6917 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6918 | return -ERANGE; |
| 6919 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6920 | return -ERANGE; |
| 6921 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6922 | return -ERANGE; |
| 6923 | |
| 6924 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6925 | NL80211_KEK_LEN); |
| 6926 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6927 | NL80211_KCK_LEN); |
| 6928 | memcpy(rekey_data.replay_ctr, |
| 6929 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6930 | NL80211_REPLAY_CTR_LEN); |
| 6931 | |
| 6932 | wdev_lock(wdev); |
| 6933 | if (!wdev->current_bss) { |
| 6934 | err = -ENOTCONN; |
| 6935 | goto out; |
| 6936 | } |
| 6937 | |
| 6938 | if (!rdev->ops->set_rekey_data) { |
| 6939 | err = -EOPNOTSUPP; |
| 6940 | goto out; |
| 6941 | } |
| 6942 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6943 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6944 | out: |
| 6945 | wdev_unlock(wdev); |
| 6946 | return err; |
| 6947 | } |
| 6948 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6949 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6950 | struct genl_info *info) |
| 6951 | { |
| 6952 | struct net_device *dev = info->user_ptr[1]; |
| 6953 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6954 | |
| 6955 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6956 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6957 | return -EINVAL; |
| 6958 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6959 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6960 | return -EBUSY; |
| 6961 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6962 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6963 | return 0; |
| 6964 | } |
| 6965 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6966 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6967 | struct genl_info *info) |
| 6968 | { |
| 6969 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6970 | struct net_device *dev = info->user_ptr[1]; |
| 6971 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6972 | struct sk_buff *msg; |
| 6973 | void *hdr; |
| 6974 | const u8 *addr; |
| 6975 | u64 cookie; |
| 6976 | int err; |
| 6977 | |
| 6978 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6979 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6980 | return -EOPNOTSUPP; |
| 6981 | |
| 6982 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6983 | return -EINVAL; |
| 6984 | |
| 6985 | if (!rdev->ops->probe_client) |
| 6986 | return -EOPNOTSUPP; |
| 6987 | |
| 6988 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6989 | if (!msg) |
| 6990 | return -ENOMEM; |
| 6991 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6992 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6993 | NL80211_CMD_PROBE_CLIENT); |
| 6994 | |
| 6995 | if (IS_ERR(hdr)) { |
| 6996 | err = PTR_ERR(hdr); |
| 6997 | goto free_msg; |
| 6998 | } |
| 6999 | |
| 7000 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7001 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7002 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7003 | if (err) |
| 7004 | goto free_msg; |
| 7005 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7006 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7007 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7008 | |
| 7009 | genlmsg_end(msg, hdr); |
| 7010 | |
| 7011 | return genlmsg_reply(msg, info); |
| 7012 | |
| 7013 | nla_put_failure: |
| 7014 | err = -ENOBUFS; |
| 7015 | free_msg: |
| 7016 | nlmsg_free(msg); |
| 7017 | return err; |
| 7018 | } |
| 7019 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7020 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 7021 | { |
| 7022 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7023 | struct cfg80211_beacon_registration *reg, *nreg; |
| 7024 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7025 | |
| 7026 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 7027 | return -EOPNOTSUPP; |
| 7028 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7029 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 7030 | if (!nreg) |
| 7031 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7032 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7033 | /* First, check if already registered. */ |
| 7034 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 7035 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 7036 | if (reg->nlportid == info->snd_portid) { |
| 7037 | rv = -EALREADY; |
| 7038 | goto out_err; |
| 7039 | } |
| 7040 | } |
| 7041 | /* Add it to the list */ |
| 7042 | nreg->nlportid = info->snd_portid; |
| 7043 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 7044 | |
| 7045 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7046 | |
| 7047 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 7048 | out_err: |
| 7049 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 7050 | kfree(nreg); |
| 7051 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7052 | } |
| 7053 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7054 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7055 | { |
| 7056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7057 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7058 | int err; |
| 7059 | |
| 7060 | if (!rdev->ops->start_p2p_device) |
| 7061 | return -EOPNOTSUPP; |
| 7062 | |
| 7063 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7064 | return -EOPNOTSUPP; |
| 7065 | |
| 7066 | if (wdev->p2p_started) |
| 7067 | return 0; |
| 7068 | |
| 7069 | mutex_lock(&rdev->devlist_mtx); |
| 7070 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 7071 | mutex_unlock(&rdev->devlist_mtx); |
| 7072 | if (err) |
| 7073 | return err; |
| 7074 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7075 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7076 | if (err) |
| 7077 | return err; |
| 7078 | |
| 7079 | wdev->p2p_started = true; |
| 7080 | mutex_lock(&rdev->devlist_mtx); |
| 7081 | rdev->opencount++; |
| 7082 | mutex_unlock(&rdev->devlist_mtx); |
| 7083 | |
| 7084 | return 0; |
| 7085 | } |
| 7086 | |
| 7087 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7088 | { |
| 7089 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7090 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7091 | |
| 7092 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7093 | return -EOPNOTSUPP; |
| 7094 | |
| 7095 | if (!rdev->ops->stop_p2p_device) |
| 7096 | return -EOPNOTSUPP; |
| 7097 | |
| 7098 | if (!wdev->p2p_started) |
| 7099 | return 0; |
| 7100 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7101 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7102 | wdev->p2p_started = false; |
| 7103 | |
| 7104 | mutex_lock(&rdev->devlist_mtx); |
| 7105 | rdev->opencount--; |
| 7106 | mutex_unlock(&rdev->devlist_mtx); |
| 7107 | |
| 7108 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 7109 | rdev->scan_req->aborted = true; |
| 7110 | ___cfg80211_scan_done(rdev, true); |
| 7111 | } |
| 7112 | |
| 7113 | return 0; |
| 7114 | } |
| 7115 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7116 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 7117 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 7118 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7119 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 7120 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 7121 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7122 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7123 | /* 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] | 7124 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 7125 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7126 | |
| 7127 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7128 | struct genl_info *info) |
| 7129 | { |
| 7130 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7131 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7132 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7133 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 7134 | |
| 7135 | if (rtnl) |
| 7136 | rtnl_lock(); |
| 7137 | |
| 7138 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 7139 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7140 | if (IS_ERR(rdev)) { |
| 7141 | if (rtnl) |
| 7142 | rtnl_unlock(); |
| 7143 | return PTR_ERR(rdev); |
| 7144 | } |
| 7145 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7146 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7147 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7148 | mutex_lock(&cfg80211_mutex); |
| 7149 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7150 | info->attrs); |
| 7151 | if (IS_ERR(wdev)) { |
| 7152 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7153 | if (rtnl) |
| 7154 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7155 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7156 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7157 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7158 | dev = wdev->netdev; |
| 7159 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7160 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7161 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7162 | if (!dev) { |
| 7163 | mutex_unlock(&cfg80211_mutex); |
| 7164 | if (rtnl) |
| 7165 | rtnl_unlock(); |
| 7166 | return -EINVAL; |
| 7167 | } |
| 7168 | |
| 7169 | info->user_ptr[1] = dev; |
| 7170 | } else { |
| 7171 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7172 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7173 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7174 | if (dev) { |
| 7175 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7176 | !netif_running(dev)) { |
| 7177 | mutex_unlock(&cfg80211_mutex); |
| 7178 | if (rtnl) |
| 7179 | rtnl_unlock(); |
| 7180 | return -ENETDOWN; |
| 7181 | } |
| 7182 | |
| 7183 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7184 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7185 | if (!wdev->p2p_started) { |
| 7186 | mutex_unlock(&cfg80211_mutex); |
| 7187 | if (rtnl) |
| 7188 | rtnl_unlock(); |
| 7189 | return -ENETDOWN; |
| 7190 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7191 | } |
| 7192 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7193 | cfg80211_lock_rdev(rdev); |
| 7194 | |
| 7195 | mutex_unlock(&cfg80211_mutex); |
| 7196 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7197 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7198 | } |
| 7199 | |
| 7200 | return 0; |
| 7201 | } |
| 7202 | |
| 7203 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7204 | struct genl_info *info) |
| 7205 | { |
| 7206 | if (info->user_ptr[0]) |
| 7207 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7208 | if (info->user_ptr[1]) { |
| 7209 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7210 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7211 | |
| 7212 | if (wdev->netdev) |
| 7213 | dev_put(wdev->netdev); |
| 7214 | } else { |
| 7215 | dev_put(info->user_ptr[1]); |
| 7216 | } |
| 7217 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7218 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7219 | rtnl_unlock(); |
| 7220 | } |
| 7221 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7222 | static struct genl_ops nl80211_ops[] = { |
| 7223 | { |
| 7224 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7225 | .doit = nl80211_get_wiphy, |
| 7226 | .dumpit = nl80211_dump_wiphy, |
| 7227 | .policy = nl80211_policy, |
| 7228 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7229 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7230 | }, |
| 7231 | { |
| 7232 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7233 | .doit = nl80211_set_wiphy, |
| 7234 | .policy = nl80211_policy, |
| 7235 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7236 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7237 | }, |
| 7238 | { |
| 7239 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7240 | .doit = nl80211_get_interface, |
| 7241 | .dumpit = nl80211_dump_interface, |
| 7242 | .policy = nl80211_policy, |
| 7243 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7244 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7245 | }, |
| 7246 | { |
| 7247 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7248 | .doit = nl80211_set_interface, |
| 7249 | .policy = nl80211_policy, |
| 7250 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7251 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7252 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7253 | }, |
| 7254 | { |
| 7255 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7256 | .doit = nl80211_new_interface, |
| 7257 | .policy = nl80211_policy, |
| 7258 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7259 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7260 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7261 | }, |
| 7262 | { |
| 7263 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7264 | .doit = nl80211_del_interface, |
| 7265 | .policy = nl80211_policy, |
| 7266 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7267 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7268 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7269 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7270 | { |
| 7271 | .cmd = NL80211_CMD_GET_KEY, |
| 7272 | .doit = nl80211_get_key, |
| 7273 | .policy = nl80211_policy, |
| 7274 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7275 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7276 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7277 | }, |
| 7278 | { |
| 7279 | .cmd = NL80211_CMD_SET_KEY, |
| 7280 | .doit = nl80211_set_key, |
| 7281 | .policy = nl80211_policy, |
| 7282 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7283 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7284 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7285 | }, |
| 7286 | { |
| 7287 | .cmd = NL80211_CMD_NEW_KEY, |
| 7288 | .doit = nl80211_new_key, |
| 7289 | .policy = nl80211_policy, |
| 7290 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7291 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7292 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7293 | }, |
| 7294 | { |
| 7295 | .cmd = NL80211_CMD_DEL_KEY, |
| 7296 | .doit = nl80211_del_key, |
| 7297 | .policy = nl80211_policy, |
| 7298 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7299 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7300 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7301 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7302 | { |
| 7303 | .cmd = NL80211_CMD_SET_BEACON, |
| 7304 | .policy = nl80211_policy, |
| 7305 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7306 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7307 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7308 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7309 | }, |
| 7310 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7311 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7312 | .policy = nl80211_policy, |
| 7313 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7314 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7315 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7316 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7317 | }, |
| 7318 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7319 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7320 | .policy = nl80211_policy, |
| 7321 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7322 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7323 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7324 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7325 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7326 | { |
| 7327 | .cmd = NL80211_CMD_GET_STATION, |
| 7328 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7329 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7330 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7331 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7332 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7333 | }, |
| 7334 | { |
| 7335 | .cmd = NL80211_CMD_SET_STATION, |
| 7336 | .doit = nl80211_set_station, |
| 7337 | .policy = nl80211_policy, |
| 7338 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7339 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7340 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7341 | }, |
| 7342 | { |
| 7343 | .cmd = NL80211_CMD_NEW_STATION, |
| 7344 | .doit = nl80211_new_station, |
| 7345 | .policy = nl80211_policy, |
| 7346 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7347 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7348 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7349 | }, |
| 7350 | { |
| 7351 | .cmd = NL80211_CMD_DEL_STATION, |
| 7352 | .doit = nl80211_del_station, |
| 7353 | .policy = nl80211_policy, |
| 7354 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7355 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7356 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7357 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7358 | { |
| 7359 | .cmd = NL80211_CMD_GET_MPATH, |
| 7360 | .doit = nl80211_get_mpath, |
| 7361 | .dumpit = nl80211_dump_mpath, |
| 7362 | .policy = nl80211_policy, |
| 7363 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7364 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7365 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7366 | }, |
| 7367 | { |
| 7368 | .cmd = NL80211_CMD_SET_MPATH, |
| 7369 | .doit = nl80211_set_mpath, |
| 7370 | .policy = nl80211_policy, |
| 7371 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7372 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7373 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7374 | }, |
| 7375 | { |
| 7376 | .cmd = NL80211_CMD_NEW_MPATH, |
| 7377 | .doit = nl80211_new_mpath, |
| 7378 | .policy = nl80211_policy, |
| 7379 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7380 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7381 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7382 | }, |
| 7383 | { |
| 7384 | .cmd = NL80211_CMD_DEL_MPATH, |
| 7385 | .doit = nl80211_del_mpath, |
| 7386 | .policy = nl80211_policy, |
| 7387 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7388 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7389 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7390 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7391 | { |
| 7392 | .cmd = NL80211_CMD_SET_BSS, |
| 7393 | .doit = nl80211_set_bss, |
| 7394 | .policy = nl80211_policy, |
| 7395 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7396 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7397 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7398 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7399 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7400 | .cmd = NL80211_CMD_GET_REG, |
| 7401 | .doit = nl80211_get_reg, |
| 7402 | .policy = nl80211_policy, |
| 7403 | /* can be retrieved by unprivileged users */ |
| 7404 | }, |
| 7405 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7406 | .cmd = NL80211_CMD_SET_REG, |
| 7407 | .doit = nl80211_set_reg, |
| 7408 | .policy = nl80211_policy, |
| 7409 | .flags = GENL_ADMIN_PERM, |
| 7410 | }, |
| 7411 | { |
| 7412 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 7413 | .doit = nl80211_req_set_reg, |
| 7414 | .policy = nl80211_policy, |
| 7415 | .flags = GENL_ADMIN_PERM, |
| 7416 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7417 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7418 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 7419 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7420 | .policy = nl80211_policy, |
| 7421 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7422 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7423 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7424 | }, |
| 7425 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7426 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 7427 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7428 | .policy = nl80211_policy, |
| 7429 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7430 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7431 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7432 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 7433 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7434 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 7435 | .doit = nl80211_trigger_scan, |
| 7436 | .policy = nl80211_policy, |
| 7437 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7438 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7439 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7440 | }, |
| 7441 | { |
| 7442 | .cmd = NL80211_CMD_GET_SCAN, |
| 7443 | .policy = nl80211_policy, |
| 7444 | .dumpit = nl80211_dump_scan, |
| 7445 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7446 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7447 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 7448 | .doit = nl80211_start_sched_scan, |
| 7449 | .policy = nl80211_policy, |
| 7450 | .flags = GENL_ADMIN_PERM, |
| 7451 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7452 | NL80211_FLAG_NEED_RTNL, |
| 7453 | }, |
| 7454 | { |
| 7455 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 7456 | .doit = nl80211_stop_sched_scan, |
| 7457 | .policy = nl80211_policy, |
| 7458 | .flags = GENL_ADMIN_PERM, |
| 7459 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7460 | NL80211_FLAG_NEED_RTNL, |
| 7461 | }, |
| 7462 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7463 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 7464 | .doit = nl80211_authenticate, |
| 7465 | .policy = nl80211_policy, |
| 7466 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7467 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7468 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7469 | }, |
| 7470 | { |
| 7471 | .cmd = NL80211_CMD_ASSOCIATE, |
| 7472 | .doit = nl80211_associate, |
| 7473 | .policy = nl80211_policy, |
| 7474 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7475 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7476 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7477 | }, |
| 7478 | { |
| 7479 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 7480 | .doit = nl80211_deauthenticate, |
| 7481 | .policy = nl80211_policy, |
| 7482 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7483 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7484 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7485 | }, |
| 7486 | { |
| 7487 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 7488 | .doit = nl80211_disassociate, |
| 7489 | .policy = nl80211_policy, |
| 7490 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7491 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7492 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7493 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7494 | { |
| 7495 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 7496 | .doit = nl80211_join_ibss, |
| 7497 | .policy = nl80211_policy, |
| 7498 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7499 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7500 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7501 | }, |
| 7502 | { |
| 7503 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 7504 | .doit = nl80211_leave_ibss, |
| 7505 | .policy = nl80211_policy, |
| 7506 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7507 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7508 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7509 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7510 | #ifdef CONFIG_NL80211_TESTMODE |
| 7511 | { |
| 7512 | .cmd = NL80211_CMD_TESTMODE, |
| 7513 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7514 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7515 | .policy = nl80211_policy, |
| 7516 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7517 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7518 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7519 | }, |
| 7520 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7521 | { |
| 7522 | .cmd = NL80211_CMD_CONNECT, |
| 7523 | .doit = nl80211_connect, |
| 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, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7528 | }, |
| 7529 | { |
| 7530 | .cmd = NL80211_CMD_DISCONNECT, |
| 7531 | .doit = nl80211_disconnect, |
| 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, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7536 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7537 | { |
| 7538 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 7539 | .doit = nl80211_wiphy_netns, |
| 7540 | .policy = nl80211_policy, |
| 7541 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7542 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7543 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7544 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7545 | { |
| 7546 | .cmd = NL80211_CMD_GET_SURVEY, |
| 7547 | .policy = nl80211_policy, |
| 7548 | .dumpit = nl80211_dump_survey, |
| 7549 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7550 | { |
| 7551 | .cmd = NL80211_CMD_SET_PMKSA, |
| 7552 | .doit = nl80211_setdel_pmksa, |
| 7553 | .policy = nl80211_policy, |
| 7554 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7555 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7556 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7557 | }, |
| 7558 | { |
| 7559 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 7560 | .doit = nl80211_setdel_pmksa, |
| 7561 | .policy = nl80211_policy, |
| 7562 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7563 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7564 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7565 | }, |
| 7566 | { |
| 7567 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 7568 | .doit = nl80211_flush_pmksa, |
| 7569 | .policy = nl80211_policy, |
| 7570 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7571 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7572 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7573 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7574 | { |
| 7575 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7576 | .doit = nl80211_remain_on_channel, |
| 7577 | .policy = nl80211_policy, |
| 7578 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7579 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7580 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7581 | }, |
| 7582 | { |
| 7583 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7584 | .doit = nl80211_cancel_remain_on_channel, |
| 7585 | .policy = nl80211_policy, |
| 7586 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7587 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7588 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7589 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7590 | { |
| 7591 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 7592 | .doit = nl80211_set_tx_bitrate_mask, |
| 7593 | .policy = nl80211_policy, |
| 7594 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7595 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7596 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7597 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7598 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7599 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 7600 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7601 | .policy = nl80211_policy, |
| 7602 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7603 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7604 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7605 | }, |
| 7606 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7607 | .cmd = NL80211_CMD_FRAME, |
| 7608 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7609 | .policy = nl80211_policy, |
| 7610 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7611 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7612 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7613 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7614 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7615 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 7616 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 7617 | .policy = nl80211_policy, |
| 7618 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7619 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7620 | NL80211_FLAG_NEED_RTNL, |
| 7621 | }, |
| 7622 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7623 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 7624 | .doit = nl80211_set_power_save, |
| 7625 | .policy = nl80211_policy, |
| 7626 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7627 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7628 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7629 | }, |
| 7630 | { |
| 7631 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 7632 | .doit = nl80211_get_power_save, |
| 7633 | .policy = nl80211_policy, |
| 7634 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7635 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7636 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7637 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7638 | { |
| 7639 | .cmd = NL80211_CMD_SET_CQM, |
| 7640 | .doit = nl80211_set_cqm, |
| 7641 | .policy = nl80211_policy, |
| 7642 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7643 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7644 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7645 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7646 | { |
| 7647 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 7648 | .doit = nl80211_set_channel, |
| 7649 | .policy = nl80211_policy, |
| 7650 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7651 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7652 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7653 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7654 | { |
| 7655 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 7656 | .doit = nl80211_set_wds_peer, |
| 7657 | .policy = nl80211_policy, |
| 7658 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 7659 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7660 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7661 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7662 | { |
| 7663 | .cmd = NL80211_CMD_JOIN_MESH, |
| 7664 | .doit = nl80211_join_mesh, |
| 7665 | .policy = nl80211_policy, |
| 7666 | .flags = GENL_ADMIN_PERM, |
| 7667 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7668 | NL80211_FLAG_NEED_RTNL, |
| 7669 | }, |
| 7670 | { |
| 7671 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 7672 | .doit = nl80211_leave_mesh, |
| 7673 | .policy = nl80211_policy, |
| 7674 | .flags = GENL_ADMIN_PERM, |
| 7675 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7676 | NL80211_FLAG_NEED_RTNL, |
| 7677 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7678 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7679 | { |
| 7680 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 7681 | .doit = nl80211_get_wowlan, |
| 7682 | .policy = nl80211_policy, |
| 7683 | /* can be retrieved by unprivileged users */ |
| 7684 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7685 | NL80211_FLAG_NEED_RTNL, |
| 7686 | }, |
| 7687 | { |
| 7688 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 7689 | .doit = nl80211_set_wowlan, |
| 7690 | .policy = nl80211_policy, |
| 7691 | .flags = GENL_ADMIN_PERM, |
| 7692 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7693 | NL80211_FLAG_NEED_RTNL, |
| 7694 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7695 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7696 | { |
| 7697 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 7698 | .doit = nl80211_set_rekey_data, |
| 7699 | .policy = nl80211_policy, |
| 7700 | .flags = GENL_ADMIN_PERM, |
| 7701 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7702 | NL80211_FLAG_NEED_RTNL, |
| 7703 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7704 | { |
| 7705 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 7706 | .doit = nl80211_tdls_mgmt, |
| 7707 | .policy = nl80211_policy, |
| 7708 | .flags = GENL_ADMIN_PERM, |
| 7709 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7710 | NL80211_FLAG_NEED_RTNL, |
| 7711 | }, |
| 7712 | { |
| 7713 | .cmd = NL80211_CMD_TDLS_OPER, |
| 7714 | .doit = nl80211_tdls_oper, |
| 7715 | .policy = nl80211_policy, |
| 7716 | .flags = GENL_ADMIN_PERM, |
| 7717 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7718 | NL80211_FLAG_NEED_RTNL, |
| 7719 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7720 | { |
| 7721 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 7722 | .doit = nl80211_register_unexpected_frame, |
| 7723 | .policy = nl80211_policy, |
| 7724 | .flags = GENL_ADMIN_PERM, |
| 7725 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7726 | NL80211_FLAG_NEED_RTNL, |
| 7727 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7728 | { |
| 7729 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 7730 | .doit = nl80211_probe_client, |
| 7731 | .policy = nl80211_policy, |
| 7732 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7733 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7734 | NL80211_FLAG_NEED_RTNL, |
| 7735 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7736 | { |
| 7737 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 7738 | .doit = nl80211_register_beacons, |
| 7739 | .policy = nl80211_policy, |
| 7740 | .flags = GENL_ADMIN_PERM, |
| 7741 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7742 | NL80211_FLAG_NEED_RTNL, |
| 7743 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 7744 | { |
| 7745 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 7746 | .doit = nl80211_set_noack_map, |
| 7747 | .policy = nl80211_policy, |
| 7748 | .flags = GENL_ADMIN_PERM, |
| 7749 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7750 | NL80211_FLAG_NEED_RTNL, |
| 7751 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7752 | { |
| 7753 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 7754 | .doit = nl80211_start_p2p_device, |
| 7755 | .policy = nl80211_policy, |
| 7756 | .flags = GENL_ADMIN_PERM, |
| 7757 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 7758 | NL80211_FLAG_NEED_RTNL, |
| 7759 | }, |
| 7760 | { |
| 7761 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 7762 | .doit = nl80211_stop_p2p_device, |
| 7763 | .policy = nl80211_policy, |
| 7764 | .flags = GENL_ADMIN_PERM, |
| 7765 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 7766 | NL80211_FLAG_NEED_RTNL, |
| 7767 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7768 | { |
| 7769 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 7770 | .doit = nl80211_set_mcast_rate, |
| 7771 | .policy = nl80211_policy, |
| 7772 | .flags = GENL_ADMIN_PERM, |
| 7773 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7774 | NL80211_FLAG_NEED_RTNL, |
| 7775 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7776 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7777 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7778 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 7779 | .name = "mlme", |
| 7780 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7781 | |
| 7782 | /* multicast groups */ |
| 7783 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 7784 | .name = "config", |
| 7785 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7786 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 7787 | .name = "scan", |
| 7788 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7789 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 7790 | .name = "regulatory", |
| 7791 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7792 | |
| 7793 | /* notification functions */ |
| 7794 | |
| 7795 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 7796 | { |
| 7797 | struct sk_buff *msg; |
| 7798 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7799 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7800 | if (!msg) |
| 7801 | return; |
| 7802 | |
| 7803 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 7804 | nlmsg_free(msg); |
| 7805 | return; |
| 7806 | } |
| 7807 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7808 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7809 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7810 | } |
| 7811 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7812 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 7813 | struct cfg80211_registered_device *rdev) |
| 7814 | { |
| 7815 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 7816 | struct nlattr *nest; |
| 7817 | int i; |
| 7818 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7819 | ASSERT_RDEV_LOCK(rdev); |
| 7820 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7821 | if (WARN_ON(!req)) |
| 7822 | return 0; |
| 7823 | |
| 7824 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 7825 | if (!nest) |
| 7826 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7827 | for (i = 0; i < req->n_ssids; i++) { |
| 7828 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 7829 | goto nla_put_failure; |
| 7830 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7831 | nla_nest_end(msg, nest); |
| 7832 | |
| 7833 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 7834 | if (!nest) |
| 7835 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7836 | for (i = 0; i < req->n_channels; i++) { |
| 7837 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 7838 | goto nla_put_failure; |
| 7839 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7840 | nla_nest_end(msg, nest); |
| 7841 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7842 | if (req->ie && |
| 7843 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 7844 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7845 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7846 | if (req->flags) |
| 7847 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 7848 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7849 | return 0; |
| 7850 | nla_put_failure: |
| 7851 | return -ENOBUFS; |
| 7852 | } |
| 7853 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7854 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 7855 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7856 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7857 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7858 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7859 | { |
| 7860 | void *hdr; |
| 7861 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7862 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7863 | if (!hdr) |
| 7864 | return -1; |
| 7865 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7866 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7867 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 7868 | wdev->netdev->ifindex)) || |
| 7869 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7870 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7871 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7872 | /* ignore errors and send incomplete event anyway */ |
| 7873 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7874 | |
| 7875 | return genlmsg_end(msg, hdr); |
| 7876 | |
| 7877 | nla_put_failure: |
| 7878 | genlmsg_cancel(msg, hdr); |
| 7879 | return -EMSGSIZE; |
| 7880 | } |
| 7881 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7882 | static int |
| 7883 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 7884 | struct cfg80211_registered_device *rdev, |
| 7885 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7886 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7887 | { |
| 7888 | void *hdr; |
| 7889 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7890 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7891 | if (!hdr) |
| 7892 | return -1; |
| 7893 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7894 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7895 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7896 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7897 | |
| 7898 | return genlmsg_end(msg, hdr); |
| 7899 | |
| 7900 | nla_put_failure: |
| 7901 | genlmsg_cancel(msg, hdr); |
| 7902 | return -EMSGSIZE; |
| 7903 | } |
| 7904 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7905 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7906 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7907 | { |
| 7908 | struct sk_buff *msg; |
| 7909 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 7910 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7911 | if (!msg) |
| 7912 | return; |
| 7913 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7914 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7915 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 7916 | nlmsg_free(msg); |
| 7917 | return; |
| 7918 | } |
| 7919 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7920 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7921 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7922 | } |
| 7923 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7924 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7925 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7926 | { |
| 7927 | struct sk_buff *msg; |
| 7928 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7929 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7930 | if (!msg) |
| 7931 | return; |
| 7932 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7933 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7934 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7935 | nlmsg_free(msg); |
| 7936 | return; |
| 7937 | } |
| 7938 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7939 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7940 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7941 | } |
| 7942 | |
| 7943 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7944 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7945 | { |
| 7946 | struct sk_buff *msg; |
| 7947 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7948 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7949 | if (!msg) |
| 7950 | return; |
| 7951 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7952 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7953 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7954 | nlmsg_free(msg); |
| 7955 | return; |
| 7956 | } |
| 7957 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7958 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7959 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7960 | } |
| 7961 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7962 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 7963 | struct net_device *netdev) |
| 7964 | { |
| 7965 | struct sk_buff *msg; |
| 7966 | |
| 7967 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7968 | if (!msg) |
| 7969 | return; |
| 7970 | |
| 7971 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7972 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 7973 | nlmsg_free(msg); |
| 7974 | return; |
| 7975 | } |
| 7976 | |
| 7977 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7978 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7979 | } |
| 7980 | |
| 7981 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 7982 | struct net_device *netdev, u32 cmd) |
| 7983 | { |
| 7984 | struct sk_buff *msg; |
| 7985 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 7986 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7987 | if (!msg) |
| 7988 | return; |
| 7989 | |
| 7990 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 7991 | nlmsg_free(msg); |
| 7992 | return; |
| 7993 | } |
| 7994 | |
| 7995 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7996 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7997 | } |
| 7998 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7999 | /* |
| 8000 | * This can happen on global regulatory changes or device specific settings |
| 8001 | * based on custom world regulatory domains. |
| 8002 | */ |
| 8003 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 8004 | { |
| 8005 | struct sk_buff *msg; |
| 8006 | void *hdr; |
| 8007 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8008 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8009 | if (!msg) |
| 8010 | return; |
| 8011 | |
| 8012 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 8013 | if (!hdr) { |
| 8014 | nlmsg_free(msg); |
| 8015 | return; |
| 8016 | } |
| 8017 | |
| 8018 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8019 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 8020 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8021 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8022 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 8023 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8024 | NL80211_REGDOM_TYPE_WORLD)) |
| 8025 | goto nla_put_failure; |
| 8026 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 8027 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8028 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 8029 | goto nla_put_failure; |
| 8030 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 8031 | request->intersect) { |
| 8032 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8033 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 8034 | goto nla_put_failure; |
| 8035 | } else { |
| 8036 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 8037 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 8038 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 8039 | request->alpha2)) |
| 8040 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8041 | } |
| 8042 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 8043 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8044 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 8045 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8046 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8047 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8048 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8049 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8050 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 8051 | GFP_ATOMIC); |
| 8052 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8053 | |
| 8054 | return; |
| 8055 | |
| 8056 | nla_put_failure: |
| 8057 | genlmsg_cancel(msg, hdr); |
| 8058 | nlmsg_free(msg); |
| 8059 | } |
| 8060 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8061 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 8062 | struct net_device *netdev, |
| 8063 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8064 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8065 | { |
| 8066 | struct sk_buff *msg; |
| 8067 | void *hdr; |
| 8068 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8069 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8070 | if (!msg) |
| 8071 | return; |
| 8072 | |
| 8073 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8074 | if (!hdr) { |
| 8075 | nlmsg_free(msg); |
| 8076 | return; |
| 8077 | } |
| 8078 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8079 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8080 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8081 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8082 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8083 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8084 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8085 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8086 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8087 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8088 | return; |
| 8089 | |
| 8090 | nla_put_failure: |
| 8091 | genlmsg_cancel(msg, hdr); |
| 8092 | nlmsg_free(msg); |
| 8093 | } |
| 8094 | |
| 8095 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8096 | struct net_device *netdev, const u8 *buf, |
| 8097 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8098 | { |
| 8099 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8100 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8101 | } |
| 8102 | |
| 8103 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 8104 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8105 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8106 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8107 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8108 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8109 | } |
| 8110 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8111 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8112 | struct net_device *netdev, const u8 *buf, |
| 8113 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8114 | { |
| 8115 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8116 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8117 | } |
| 8118 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8119 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 8120 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8121 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8122 | { |
| 8123 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8124 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8125 | } |
| 8126 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 8127 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 8128 | struct net_device *netdev, const u8 *buf, |
| 8129 | size_t len, gfp_t gfp) |
| 8130 | { |
| 8131 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8132 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 8133 | } |
| 8134 | |
| 8135 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 8136 | struct net_device *netdev, const u8 *buf, |
| 8137 | size_t len, gfp_t gfp) |
| 8138 | { |
| 8139 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8140 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 8141 | } |
| 8142 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 8143 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 8144 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8145 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8146 | { |
| 8147 | struct sk_buff *msg; |
| 8148 | void *hdr; |
| 8149 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8150 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8151 | if (!msg) |
| 8152 | return; |
| 8153 | |
| 8154 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8155 | if (!hdr) { |
| 8156 | nlmsg_free(msg); |
| 8157 | return; |
| 8158 | } |
| 8159 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8160 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8161 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8162 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8163 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8164 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8165 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8166 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8167 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8168 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8169 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8170 | return; |
| 8171 | |
| 8172 | nla_put_failure: |
| 8173 | genlmsg_cancel(msg, hdr); |
| 8174 | nlmsg_free(msg); |
| 8175 | } |
| 8176 | |
| 8177 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8178 | struct net_device *netdev, const u8 *addr, |
| 8179 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8180 | { |
| 8181 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8182 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8183 | } |
| 8184 | |
| 8185 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8186 | struct net_device *netdev, const u8 *addr, |
| 8187 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8188 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8189 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8190 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8191 | } |
| 8192 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8193 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8194 | struct net_device *netdev, const u8 *bssid, |
| 8195 | const u8 *req_ie, size_t req_ie_len, |
| 8196 | const u8 *resp_ie, size_t resp_ie_len, |
| 8197 | u16 status, gfp_t gfp) |
| 8198 | { |
| 8199 | struct sk_buff *msg; |
| 8200 | void *hdr; |
| 8201 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8202 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8203 | if (!msg) |
| 8204 | return; |
| 8205 | |
| 8206 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8207 | if (!hdr) { |
| 8208 | nlmsg_free(msg); |
| 8209 | return; |
| 8210 | } |
| 8211 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8213 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8214 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8215 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8216 | (req_ie && |
| 8217 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8218 | (resp_ie && |
| 8219 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8220 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8221 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8222 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8223 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8224 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8225 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8226 | return; |
| 8227 | |
| 8228 | nla_put_failure: |
| 8229 | genlmsg_cancel(msg, hdr); |
| 8230 | nlmsg_free(msg); |
| 8231 | |
| 8232 | } |
| 8233 | |
| 8234 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8235 | struct net_device *netdev, const u8 *bssid, |
| 8236 | const u8 *req_ie, size_t req_ie_len, |
| 8237 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8238 | { |
| 8239 | struct sk_buff *msg; |
| 8240 | void *hdr; |
| 8241 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8242 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8243 | if (!msg) |
| 8244 | return; |
| 8245 | |
| 8246 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8247 | if (!hdr) { |
| 8248 | nlmsg_free(msg); |
| 8249 | return; |
| 8250 | } |
| 8251 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8252 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8253 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8254 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8255 | (req_ie && |
| 8256 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8257 | (resp_ie && |
| 8258 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8259 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8260 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8261 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8262 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8263 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8264 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8265 | return; |
| 8266 | |
| 8267 | nla_put_failure: |
| 8268 | genlmsg_cancel(msg, hdr); |
| 8269 | nlmsg_free(msg); |
| 8270 | |
| 8271 | } |
| 8272 | |
| 8273 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 8274 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8275 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8276 | { |
| 8277 | struct sk_buff *msg; |
| 8278 | void *hdr; |
| 8279 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8280 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8281 | if (!msg) |
| 8282 | return; |
| 8283 | |
| 8284 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 8285 | if (!hdr) { |
| 8286 | nlmsg_free(msg); |
| 8287 | return; |
| 8288 | } |
| 8289 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8290 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8291 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8292 | (from_ap && reason && |
| 8293 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 8294 | (from_ap && |
| 8295 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 8296 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 8297 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8298 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8299 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8300 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8301 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8302 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8303 | return; |
| 8304 | |
| 8305 | nla_put_failure: |
| 8306 | genlmsg_cancel(msg, hdr); |
| 8307 | nlmsg_free(msg); |
| 8308 | |
| 8309 | } |
| 8310 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8311 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 8312 | struct net_device *netdev, const u8 *bssid, |
| 8313 | gfp_t gfp) |
| 8314 | { |
| 8315 | struct sk_buff *msg; |
| 8316 | void *hdr; |
| 8317 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8318 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8319 | if (!msg) |
| 8320 | return; |
| 8321 | |
| 8322 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 8323 | if (!hdr) { |
| 8324 | nlmsg_free(msg); |
| 8325 | return; |
| 8326 | } |
| 8327 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8328 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8329 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8330 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8331 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8332 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8333 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8334 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8335 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8336 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8337 | return; |
| 8338 | |
| 8339 | nla_put_failure: |
| 8340 | genlmsg_cancel(msg, hdr); |
| 8341 | nlmsg_free(msg); |
| 8342 | } |
| 8343 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8344 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 8345 | struct net_device *netdev, |
| 8346 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 8347 | gfp_t gfp) |
| 8348 | { |
| 8349 | struct sk_buff *msg; |
| 8350 | void *hdr; |
| 8351 | |
| 8352 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8353 | if (!msg) |
| 8354 | return; |
| 8355 | |
| 8356 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 8357 | if (!hdr) { |
| 8358 | nlmsg_free(msg); |
| 8359 | return; |
| 8360 | } |
| 8361 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8362 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8363 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8364 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 8365 | (ie_len && ie && |
| 8366 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 8367 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8368 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8369 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8370 | |
| 8371 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8372 | nl80211_mlme_mcgrp.id, gfp); |
| 8373 | return; |
| 8374 | |
| 8375 | nla_put_failure: |
| 8376 | genlmsg_cancel(msg, hdr); |
| 8377 | nlmsg_free(msg); |
| 8378 | } |
| 8379 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8380 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 8381 | struct net_device *netdev, const u8 *addr, |
| 8382 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8383 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8384 | { |
| 8385 | struct sk_buff *msg; |
| 8386 | void *hdr; |
| 8387 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8388 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8389 | if (!msg) |
| 8390 | return; |
| 8391 | |
| 8392 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 8393 | if (!hdr) { |
| 8394 | nlmsg_free(msg); |
| 8395 | return; |
| 8396 | } |
| 8397 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8398 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8399 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8400 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 8401 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 8402 | (key_id != -1 && |
| 8403 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 8404 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 8405 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8406 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8407 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8408 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8409 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8410 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8411 | return; |
| 8412 | |
| 8413 | nla_put_failure: |
| 8414 | genlmsg_cancel(msg, hdr); |
| 8415 | nlmsg_free(msg); |
| 8416 | } |
| 8417 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8418 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 8419 | struct ieee80211_channel *channel_before, |
| 8420 | struct ieee80211_channel *channel_after) |
| 8421 | { |
| 8422 | struct sk_buff *msg; |
| 8423 | void *hdr; |
| 8424 | struct nlattr *nl_freq; |
| 8425 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8426 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8427 | if (!msg) |
| 8428 | return; |
| 8429 | |
| 8430 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 8431 | if (!hdr) { |
| 8432 | nlmsg_free(msg); |
| 8433 | return; |
| 8434 | } |
| 8435 | |
| 8436 | /* |
| 8437 | * Since we are applying the beacon hint to a wiphy we know its |
| 8438 | * wiphy_idx is valid |
| 8439 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8440 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 8441 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8442 | |
| 8443 | /* Before */ |
| 8444 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 8445 | if (!nl_freq) |
| 8446 | goto nla_put_failure; |
| 8447 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 8448 | goto nla_put_failure; |
| 8449 | nla_nest_end(msg, nl_freq); |
| 8450 | |
| 8451 | /* After */ |
| 8452 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 8453 | if (!nl_freq) |
| 8454 | goto nla_put_failure; |
| 8455 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 8456 | goto nla_put_failure; |
| 8457 | nla_nest_end(msg, nl_freq); |
| 8458 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8459 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8460 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8461 | rcu_read_lock(); |
| 8462 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 8463 | GFP_ATOMIC); |
| 8464 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8465 | |
| 8466 | return; |
| 8467 | |
| 8468 | nla_put_failure: |
| 8469 | genlmsg_cancel(msg, hdr); |
| 8470 | nlmsg_free(msg); |
| 8471 | } |
| 8472 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8473 | static void nl80211_send_remain_on_chan_event( |
| 8474 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8475 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8476 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8477 | unsigned int duration, gfp_t gfp) |
| 8478 | { |
| 8479 | struct sk_buff *msg; |
| 8480 | void *hdr; |
| 8481 | |
| 8482 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8483 | if (!msg) |
| 8484 | return; |
| 8485 | |
| 8486 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8487 | if (!hdr) { |
| 8488 | nlmsg_free(msg); |
| 8489 | return; |
| 8490 | } |
| 8491 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8492 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8493 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8494 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 8495 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8496 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8497 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 8498 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8499 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8500 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8501 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8502 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 8503 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 8504 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8505 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8506 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8507 | |
| 8508 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8509 | nl80211_mlme_mcgrp.id, gfp); |
| 8510 | return; |
| 8511 | |
| 8512 | nla_put_failure: |
| 8513 | genlmsg_cancel(msg, hdr); |
| 8514 | nlmsg_free(msg); |
| 8515 | } |
| 8516 | |
| 8517 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8518 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8519 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8520 | unsigned int duration, gfp_t gfp) |
| 8521 | { |
| 8522 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8523 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8524 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8525 | } |
| 8526 | |
| 8527 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8528 | struct cfg80211_registered_device *rdev, |
| 8529 | struct wireless_dev *wdev, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8530 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8531 | { |
| 8532 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 8533 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8534 | } |
| 8535 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8536 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 8537 | struct net_device *dev, const u8 *mac_addr, |
| 8538 | struct station_info *sinfo, gfp_t gfp) |
| 8539 | { |
| 8540 | struct sk_buff *msg; |
| 8541 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8542 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8543 | if (!msg) |
| 8544 | return; |
| 8545 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 8546 | if (nl80211_send_station(msg, 0, 0, 0, |
| 8547 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8548 | nlmsg_free(msg); |
| 8549 | return; |
| 8550 | } |
| 8551 | |
| 8552 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8553 | nl80211_mlme_mcgrp.id, gfp); |
| 8554 | } |
| 8555 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8556 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 8557 | struct net_device *dev, const u8 *mac_addr, |
| 8558 | gfp_t gfp) |
| 8559 | { |
| 8560 | struct sk_buff *msg; |
| 8561 | void *hdr; |
| 8562 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8563 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8564 | if (!msg) |
| 8565 | return; |
| 8566 | |
| 8567 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 8568 | if (!hdr) { |
| 8569 | nlmsg_free(msg); |
| 8570 | return; |
| 8571 | } |
| 8572 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8573 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8574 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 8575 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8576 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8577 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8578 | |
| 8579 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8580 | nl80211_mlme_mcgrp.id, gfp); |
| 8581 | return; |
| 8582 | |
| 8583 | nla_put_failure: |
| 8584 | genlmsg_cancel(msg, hdr); |
| 8585 | nlmsg_free(msg); |
| 8586 | } |
| 8587 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 8588 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 8589 | struct net_device *dev, const u8 *mac_addr, |
| 8590 | enum nl80211_connect_failed_reason reason, |
| 8591 | gfp_t gfp) |
| 8592 | { |
| 8593 | struct sk_buff *msg; |
| 8594 | void *hdr; |
| 8595 | |
| 8596 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8597 | if (!msg) |
| 8598 | return; |
| 8599 | |
| 8600 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 8601 | if (!hdr) { |
| 8602 | nlmsg_free(msg); |
| 8603 | return; |
| 8604 | } |
| 8605 | |
| 8606 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8607 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 8608 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 8609 | goto nla_put_failure; |
| 8610 | |
| 8611 | genlmsg_end(msg, hdr); |
| 8612 | |
| 8613 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8614 | nl80211_mlme_mcgrp.id, gfp); |
| 8615 | return; |
| 8616 | |
| 8617 | nla_put_failure: |
| 8618 | genlmsg_cancel(msg, hdr); |
| 8619 | nlmsg_free(msg); |
| 8620 | } |
| 8621 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8622 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 8623 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8624 | { |
| 8625 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8626 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8627 | struct sk_buff *msg; |
| 8628 | void *hdr; |
| 8629 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8630 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8631 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8632 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8633 | return false; |
| 8634 | |
| 8635 | msg = nlmsg_new(100, gfp); |
| 8636 | if (!msg) |
| 8637 | return true; |
| 8638 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8639 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8640 | if (!hdr) { |
| 8641 | nlmsg_free(msg); |
| 8642 | return true; |
| 8643 | } |
| 8644 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8645 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8646 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8647 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8648 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8649 | |
| 8650 | err = genlmsg_end(msg, hdr); |
| 8651 | if (err < 0) { |
| 8652 | nlmsg_free(msg); |
| 8653 | return true; |
| 8654 | } |
| 8655 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8656 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8657 | return true; |
| 8658 | |
| 8659 | nla_put_failure: |
| 8660 | genlmsg_cancel(msg, hdr); |
| 8661 | nlmsg_free(msg); |
| 8662 | return true; |
| 8663 | } |
| 8664 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8665 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 8666 | { |
| 8667 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 8668 | addr, gfp); |
| 8669 | } |
| 8670 | |
| 8671 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 8672 | const u8 *addr, gfp_t gfp) |
| 8673 | { |
| 8674 | return __nl80211_unexpected_frame(dev, |
| 8675 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 8676 | addr, gfp); |
| 8677 | } |
| 8678 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8679 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8680 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8681 | int freq, int sig_dbm, |
| 8682 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8683 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8684 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8685 | struct sk_buff *msg; |
| 8686 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8687 | |
| 8688 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8689 | if (!msg) |
| 8690 | return -ENOMEM; |
| 8691 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8692 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8693 | if (!hdr) { |
| 8694 | nlmsg_free(msg); |
| 8695 | return -ENOMEM; |
| 8696 | } |
| 8697 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8698 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8699 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8700 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8701 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8702 | (sig_dbm && |
| 8703 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8704 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8705 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8706 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8707 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8708 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8709 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8710 | |
| 8711 | nla_put_failure: |
| 8712 | genlmsg_cancel(msg, hdr); |
| 8713 | nlmsg_free(msg); |
| 8714 | return -ENOBUFS; |
| 8715 | } |
| 8716 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8717 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8718 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8719 | const u8 *buf, size_t len, bool ack, |
| 8720 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8721 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8722 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8723 | struct sk_buff *msg; |
| 8724 | void *hdr; |
| 8725 | |
| 8726 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8727 | if (!msg) |
| 8728 | return; |
| 8729 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8730 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8731 | if (!hdr) { |
| 8732 | nlmsg_free(msg); |
| 8733 | return; |
| 8734 | } |
| 8735 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8736 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8737 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8738 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8739 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 8740 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8741 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8742 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8743 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8744 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8745 | |
| 8746 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 8747 | return; |
| 8748 | |
| 8749 | nla_put_failure: |
| 8750 | genlmsg_cancel(msg, hdr); |
| 8751 | nlmsg_free(msg); |
| 8752 | } |
| 8753 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8754 | void |
| 8755 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 8756 | struct net_device *netdev, |
| 8757 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 8758 | gfp_t gfp) |
| 8759 | { |
| 8760 | struct sk_buff *msg; |
| 8761 | struct nlattr *pinfoattr; |
| 8762 | void *hdr; |
| 8763 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8764 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8765 | if (!msg) |
| 8766 | return; |
| 8767 | |
| 8768 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8769 | if (!hdr) { |
| 8770 | nlmsg_free(msg); |
| 8771 | return; |
| 8772 | } |
| 8773 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8774 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8775 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8776 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8777 | |
| 8778 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8779 | if (!pinfoattr) |
| 8780 | goto nla_put_failure; |
| 8781 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8782 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 8783 | rssi_event)) |
| 8784 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8785 | |
| 8786 | nla_nest_end(msg, pinfoattr); |
| 8787 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8788 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8789 | |
| 8790 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8791 | nl80211_mlme_mcgrp.id, gfp); |
| 8792 | return; |
| 8793 | |
| 8794 | nla_put_failure: |
| 8795 | genlmsg_cancel(msg, hdr); |
| 8796 | nlmsg_free(msg); |
| 8797 | } |
| 8798 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8799 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 8800 | struct net_device *netdev, const u8 *bssid, |
| 8801 | const u8 *replay_ctr, gfp_t gfp) |
| 8802 | { |
| 8803 | struct sk_buff *msg; |
| 8804 | struct nlattr *rekey_attr; |
| 8805 | void *hdr; |
| 8806 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8807 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8808 | if (!msg) |
| 8809 | return; |
| 8810 | |
| 8811 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 8812 | if (!hdr) { |
| 8813 | nlmsg_free(msg); |
| 8814 | return; |
| 8815 | } |
| 8816 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8817 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8818 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8819 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8820 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8821 | |
| 8822 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 8823 | if (!rekey_attr) |
| 8824 | goto nla_put_failure; |
| 8825 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8826 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 8827 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 8828 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8829 | |
| 8830 | nla_nest_end(msg, rekey_attr); |
| 8831 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8832 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8833 | |
| 8834 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8835 | nl80211_mlme_mcgrp.id, gfp); |
| 8836 | return; |
| 8837 | |
| 8838 | nla_put_failure: |
| 8839 | genlmsg_cancel(msg, hdr); |
| 8840 | nlmsg_free(msg); |
| 8841 | } |
| 8842 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8843 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 8844 | struct net_device *netdev, int index, |
| 8845 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 8846 | { |
| 8847 | struct sk_buff *msg; |
| 8848 | struct nlattr *attr; |
| 8849 | void *hdr; |
| 8850 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8851 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8852 | if (!msg) |
| 8853 | return; |
| 8854 | |
| 8855 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 8856 | if (!hdr) { |
| 8857 | nlmsg_free(msg); |
| 8858 | return; |
| 8859 | } |
| 8860 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8861 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8862 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8863 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8864 | |
| 8865 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 8866 | if (!attr) |
| 8867 | goto nla_put_failure; |
| 8868 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8869 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 8870 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 8871 | (preauth && |
| 8872 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 8873 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8874 | |
| 8875 | nla_nest_end(msg, attr); |
| 8876 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8877 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8878 | |
| 8879 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8880 | nl80211_mlme_mcgrp.id, gfp); |
| 8881 | return; |
| 8882 | |
| 8883 | nla_put_failure: |
| 8884 | genlmsg_cancel(msg, hdr); |
| 8885 | nlmsg_free(msg); |
| 8886 | } |
| 8887 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8888 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8889 | struct net_device *netdev, |
| 8890 | struct cfg80211_chan_def *chandef, gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8891 | { |
| 8892 | struct sk_buff *msg; |
| 8893 | void *hdr; |
| 8894 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8895 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8896 | if (!msg) |
| 8897 | return; |
| 8898 | |
| 8899 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 8900 | if (!hdr) { |
| 8901 | nlmsg_free(msg); |
| 8902 | return; |
| 8903 | } |
| 8904 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8905 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8906 | goto nla_put_failure; |
| 8907 | |
| 8908 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 8909 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8910 | |
| 8911 | genlmsg_end(msg, hdr); |
| 8912 | |
| 8913 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8914 | nl80211_mlme_mcgrp.id, gfp); |
| 8915 | return; |
| 8916 | |
| 8917 | nla_put_failure: |
| 8918 | genlmsg_cancel(msg, hdr); |
| 8919 | nlmsg_free(msg); |
| 8920 | } |
| 8921 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8922 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8923 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 8924 | struct net_device *netdev, const u8 *peer, |
| 8925 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 8926 | { |
| 8927 | struct sk_buff *msg; |
| 8928 | struct nlattr *pinfoattr; |
| 8929 | void *hdr; |
| 8930 | |
| 8931 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8932 | if (!msg) |
| 8933 | return; |
| 8934 | |
| 8935 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8936 | if (!hdr) { |
| 8937 | nlmsg_free(msg); |
| 8938 | return; |
| 8939 | } |
| 8940 | |
| 8941 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8942 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8943 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8944 | goto nla_put_failure; |
| 8945 | |
| 8946 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8947 | if (!pinfoattr) |
| 8948 | goto nla_put_failure; |
| 8949 | |
| 8950 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 8951 | goto nla_put_failure; |
| 8952 | |
| 8953 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 8954 | goto nla_put_failure; |
| 8955 | |
| 8956 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 8957 | goto nla_put_failure; |
| 8958 | |
| 8959 | nla_nest_end(msg, pinfoattr); |
| 8960 | |
| 8961 | genlmsg_end(msg, hdr); |
| 8962 | |
| 8963 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8964 | nl80211_mlme_mcgrp.id, gfp); |
| 8965 | return; |
| 8966 | |
| 8967 | nla_put_failure: |
| 8968 | genlmsg_cancel(msg, hdr); |
| 8969 | nlmsg_free(msg); |
| 8970 | } |
| 8971 | |
| 8972 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8973 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 8974 | struct net_device *netdev, const u8 *peer, |
| 8975 | u32 num_packets, gfp_t gfp) |
| 8976 | { |
| 8977 | struct sk_buff *msg; |
| 8978 | struct nlattr *pinfoattr; |
| 8979 | void *hdr; |
| 8980 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8981 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8982 | if (!msg) |
| 8983 | return; |
| 8984 | |
| 8985 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8986 | if (!hdr) { |
| 8987 | nlmsg_free(msg); |
| 8988 | return; |
| 8989 | } |
| 8990 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8991 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8992 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8993 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8994 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8995 | |
| 8996 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8997 | if (!pinfoattr) |
| 8998 | goto nla_put_failure; |
| 8999 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9000 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 9001 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9002 | |
| 9003 | nla_nest_end(msg, pinfoattr); |
| 9004 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9005 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 9006 | |
| 9007 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9008 | nl80211_mlme_mcgrp.id, gfp); |
| 9009 | return; |
| 9010 | |
| 9011 | nla_put_failure: |
| 9012 | genlmsg_cancel(msg, hdr); |
| 9013 | nlmsg_free(msg); |
| 9014 | } |
| 9015 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9016 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 9017 | u64 cookie, bool acked, gfp_t gfp) |
| 9018 | { |
| 9019 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9020 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9021 | struct sk_buff *msg; |
| 9022 | void *hdr; |
| 9023 | int err; |
| 9024 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9025 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 9026 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9027 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9028 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9029 | if (!msg) |
| 9030 | return; |
| 9031 | |
| 9032 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 9033 | if (!hdr) { |
| 9034 | nlmsg_free(msg); |
| 9035 | return; |
| 9036 | } |
| 9037 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9038 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9039 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9040 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9041 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9042 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9043 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9044 | |
| 9045 | err = genlmsg_end(msg, hdr); |
| 9046 | if (err < 0) { |
| 9047 | nlmsg_free(msg); |
| 9048 | return; |
| 9049 | } |
| 9050 | |
| 9051 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9052 | nl80211_mlme_mcgrp.id, gfp); |
| 9053 | return; |
| 9054 | |
| 9055 | nla_put_failure: |
| 9056 | genlmsg_cancel(msg, hdr); |
| 9057 | nlmsg_free(msg); |
| 9058 | } |
| 9059 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 9060 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9061 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 9062 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9063 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9064 | { |
| 9065 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9066 | struct sk_buff *msg; |
| 9067 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9068 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9069 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 9070 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 9071 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9072 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9073 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9074 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 9075 | if (!msg) { |
| 9076 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9077 | return; |
| 9078 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9079 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9080 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 9081 | if (!hdr) |
| 9082 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9083 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9084 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9085 | (freq && |
| 9086 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9087 | (sig_dbm && |
| 9088 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9089 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 9090 | goto nla_put_failure; |
| 9091 | |
| 9092 | genlmsg_end(msg, hdr); |
| 9093 | |
| 9094 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9095 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9096 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9097 | return; |
| 9098 | |
| 9099 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9100 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9101 | if (hdr) |
| 9102 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9103 | nlmsg_free(msg); |
| 9104 | } |
| 9105 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 9106 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 9107 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 9108 | enum nl80211_tdls_operation oper, |
| 9109 | u16 reason_code, gfp_t gfp) |
| 9110 | { |
| 9111 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9112 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9113 | struct sk_buff *msg; |
| 9114 | void *hdr; |
| 9115 | int err; |
| 9116 | |
| 9117 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 9118 | reason_code); |
| 9119 | |
| 9120 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9121 | if (!msg) |
| 9122 | return; |
| 9123 | |
| 9124 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 9125 | if (!hdr) { |
| 9126 | nlmsg_free(msg); |
| 9127 | return; |
| 9128 | } |
| 9129 | |
| 9130 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9131 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9132 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 9133 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 9134 | (reason_code > 0 && |
| 9135 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 9136 | goto nla_put_failure; |
| 9137 | |
| 9138 | err = genlmsg_end(msg, hdr); |
| 9139 | if (err < 0) { |
| 9140 | nlmsg_free(msg); |
| 9141 | return; |
| 9142 | } |
| 9143 | |
| 9144 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9145 | nl80211_mlme_mcgrp.id, gfp); |
| 9146 | return; |
| 9147 | |
| 9148 | nla_put_failure: |
| 9149 | genlmsg_cancel(msg, hdr); |
| 9150 | nlmsg_free(msg); |
| 9151 | } |
| 9152 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 9153 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9154 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 9155 | unsigned long state, |
| 9156 | void *_notify) |
| 9157 | { |
| 9158 | struct netlink_notify *notify = _notify; |
| 9159 | struct cfg80211_registered_device *rdev; |
| 9160 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9161 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9162 | |
| 9163 | if (state != NETLINK_URELEASE) |
| 9164 | return NOTIFY_DONE; |
| 9165 | |
| 9166 | rcu_read_lock(); |
| 9167 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9168 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9169 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9170 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9171 | |
| 9172 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9173 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 9174 | list) { |
| 9175 | if (reg->nlportid == notify->portid) { |
| 9176 | list_del(®->list); |
| 9177 | kfree(reg); |
| 9178 | break; |
| 9179 | } |
| 9180 | } |
| 9181 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9182 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9183 | |
| 9184 | rcu_read_unlock(); |
| 9185 | |
| 9186 | return NOTIFY_DONE; |
| 9187 | } |
| 9188 | |
| 9189 | static struct notifier_block nl80211_netlink_notifier = { |
| 9190 | .notifier_call = nl80211_netlink_notify, |
| 9191 | }; |
| 9192 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9193 | /* initialisation/exit functions */ |
| 9194 | |
| 9195 | int nl80211_init(void) |
| 9196 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9197 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9198 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9199 | err = genl_register_family_with_ops(&nl80211_fam, |
| 9200 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9201 | if (err) |
| 9202 | return err; |
| 9203 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9204 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 9205 | if (err) |
| 9206 | goto err_out; |
| 9207 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9208 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 9209 | if (err) |
| 9210 | goto err_out; |
| 9211 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9212 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 9213 | if (err) |
| 9214 | goto err_out; |
| 9215 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9216 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 9217 | if (err) |
| 9218 | goto err_out; |
| 9219 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9220 | #ifdef CONFIG_NL80211_TESTMODE |
| 9221 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 9222 | if (err) |
| 9223 | goto err_out; |
| 9224 | #endif |
| 9225 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9226 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 9227 | if (err) |
| 9228 | goto err_out; |
| 9229 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9230 | return 0; |
| 9231 | err_out: |
| 9232 | genl_unregister_family(&nl80211_fam); |
| 9233 | return err; |
| 9234 | } |
| 9235 | |
| 9236 | void nl80211_exit(void) |
| 9237 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9238 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9239 | genl_unregister_family(&nl80211_fam); |
| 9240 | } |