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 }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 226 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 227 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 229 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 230 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 232 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 233 | |
| 234 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 235 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 236 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 237 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 238 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 239 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 240 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 241 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 242 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 243 | .len = WLAN_MAX_KEY_LEN }, |
| 244 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 245 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 246 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 247 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 248 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 249 | |
| 250 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 251 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 252 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 253 | .len = IEEE80211_MAX_DATA_LEN }, |
| 254 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 255 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 256 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 257 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 258 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 259 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 260 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 263 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 264 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 265 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 266 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 267 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 268 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 269 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 270 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 271 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 272 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 273 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 274 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 275 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 276 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 277 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 278 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 279 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 280 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 281 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 282 | |
| 283 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 284 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 285 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 286 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 287 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 288 | |
| 289 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 290 | .len = IEEE80211_MAX_SSID_LEN }, |
| 291 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 292 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 293 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 296 | [NL80211_ATTR_STA_FLAGS2] = { |
| 297 | .len = sizeof(struct nl80211_sta_flag_update), |
| 298 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 299 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 301 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 302 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 303 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 304 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 305 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 306 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 307 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 308 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 309 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 310 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 312 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 313 | .len = IEEE80211_MAX_DATA_LEN }, |
| 314 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 315 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 317 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 319 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 320 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 322 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 323 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 324 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 325 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 326 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 328 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 329 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 330 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 331 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 332 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 333 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 334 | .len = IEEE80211_MAX_DATA_LEN }, |
| 335 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 336 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 337 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 339 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 340 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 341 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 342 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 343 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 344 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 345 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 346 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 347 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 348 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 349 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 350 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 351 | .len = NL80211_HT_CAPABILITY_LEN |
| 352 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 353 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 354 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 355 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 356 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 357 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 358 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 359 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 360 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 361 | }; |
| 362 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 363 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 364 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 365 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 366 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 367 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 368 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 369 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 370 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 371 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 372 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 373 | }; |
| 374 | |
| 375 | /* policy for the key default flags */ |
| 376 | static const struct nla_policy |
| 377 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 378 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 379 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 380 | }; |
| 381 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 382 | /* policy for WoWLAN attributes */ |
| 383 | static const struct nla_policy |
| 384 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 385 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 386 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 387 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 388 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 389 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 390 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 391 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 392 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 393 | }; |
| 394 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 395 | /* policy for GTK rekey offload attributes */ |
| 396 | static const struct nla_policy |
| 397 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 398 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 399 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 400 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 401 | }; |
| 402 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 403 | static const struct nla_policy |
| 404 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 405 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 406 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 407 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 408 | }; |
| 409 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 410 | /* ifidx get helper */ |
| 411 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 412 | { |
| 413 | int res; |
| 414 | |
| 415 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 416 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 417 | nl80211_policy); |
| 418 | if (res) |
| 419 | return res; |
| 420 | |
| 421 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 422 | return -EINVAL; |
| 423 | |
| 424 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 425 | if (!res) |
| 426 | return -EINVAL; |
| 427 | return res; |
| 428 | } |
| 429 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 430 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 431 | struct netlink_callback *cb, |
| 432 | struct cfg80211_registered_device **rdev, |
| 433 | struct net_device **dev) |
| 434 | { |
| 435 | int ifidx = cb->args[0]; |
| 436 | int err; |
| 437 | |
| 438 | if (!ifidx) |
| 439 | ifidx = nl80211_get_ifidx(cb); |
| 440 | if (ifidx < 0) |
| 441 | return ifidx; |
| 442 | |
| 443 | cb->args[0] = ifidx; |
| 444 | |
| 445 | rtnl_lock(); |
| 446 | |
| 447 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 448 | if (!*dev) { |
| 449 | err = -ENODEV; |
| 450 | goto out_rtnl; |
| 451 | } |
| 452 | |
| 453 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 454 | if (IS_ERR(*rdev)) { |
| 455 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 456 | goto out_rtnl; |
| 457 | } |
| 458 | |
| 459 | return 0; |
| 460 | out_rtnl: |
| 461 | rtnl_unlock(); |
| 462 | return err; |
| 463 | } |
| 464 | |
| 465 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 466 | { |
| 467 | cfg80211_unlock_rdev(rdev); |
| 468 | rtnl_unlock(); |
| 469 | } |
| 470 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 471 | /* IE validation */ |
| 472 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 473 | { |
| 474 | const u8 *pos; |
| 475 | int len; |
| 476 | |
| 477 | if (!attr) |
| 478 | return true; |
| 479 | |
| 480 | pos = nla_data(attr); |
| 481 | len = nla_len(attr); |
| 482 | |
| 483 | while (len) { |
| 484 | u8 elemlen; |
| 485 | |
| 486 | if (len < 2) |
| 487 | return false; |
| 488 | len -= 2; |
| 489 | |
| 490 | elemlen = pos[1]; |
| 491 | if (elemlen > len) |
| 492 | return false; |
| 493 | |
| 494 | len -= elemlen; |
| 495 | pos += 2 + elemlen; |
| 496 | } |
| 497 | |
| 498 | return true; |
| 499 | } |
| 500 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 501 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 502 | 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] | 503 | int flags, u8 cmd) |
| 504 | { |
| 505 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 506 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 507 | } |
| 508 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 509 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 510 | struct ieee80211_channel *chan) |
| 511 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 512 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 513 | chan->center_freq)) |
| 514 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 515 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 516 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 517 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 518 | goto nla_put_failure; |
| 519 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 520 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 521 | goto nla_put_failure; |
| 522 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 523 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 524 | goto nla_put_failure; |
| 525 | if ((chan->flags & IEEE80211_CHAN_RADAR) && |
| 526 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 527 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 528 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 529 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 530 | DBM_TO_MBM(chan->max_power))) |
| 531 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 532 | |
| 533 | return 0; |
| 534 | |
| 535 | nla_put_failure: |
| 536 | return -ENOBUFS; |
| 537 | } |
| 538 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 539 | /* netlink command implementations */ |
| 540 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 541 | struct key_parse { |
| 542 | struct key_params p; |
| 543 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 544 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 545 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 546 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 547 | }; |
| 548 | |
| 549 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 550 | { |
| 551 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 552 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 553 | nl80211_key_policy); |
| 554 | if (err) |
| 555 | return err; |
| 556 | |
| 557 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 558 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 559 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 560 | if (k->def) { |
| 561 | k->def_uni = true; |
| 562 | k->def_multi = true; |
| 563 | } |
| 564 | if (k->defmgmt) |
| 565 | k->def_multi = true; |
| 566 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 567 | if (tb[NL80211_KEY_IDX]) |
| 568 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 569 | |
| 570 | if (tb[NL80211_KEY_DATA]) { |
| 571 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 572 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 573 | } |
| 574 | |
| 575 | if (tb[NL80211_KEY_SEQ]) { |
| 576 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 577 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 578 | } |
| 579 | |
| 580 | if (tb[NL80211_KEY_CIPHER]) |
| 581 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 582 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 583 | if (tb[NL80211_KEY_TYPE]) { |
| 584 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 585 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 586 | return -EINVAL; |
| 587 | } |
| 588 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 589 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 590 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 591 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 592 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 593 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 594 | if (err) |
| 595 | return err; |
| 596 | |
| 597 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 598 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 599 | } |
| 600 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 605 | { |
| 606 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 607 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 608 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 609 | } |
| 610 | |
| 611 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 612 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 613 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 614 | } |
| 615 | |
| 616 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 617 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 618 | |
| 619 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 620 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 621 | |
| 622 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 623 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 624 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 625 | if (k->def) { |
| 626 | k->def_uni = true; |
| 627 | k->def_multi = true; |
| 628 | } |
| 629 | if (k->defmgmt) |
| 630 | k->def_multi = true; |
| 631 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 632 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 633 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 634 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 635 | return -EINVAL; |
| 636 | } |
| 637 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 638 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 639 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 640 | int err = nla_parse_nested( |
| 641 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 642 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 643 | nl80211_key_default_policy); |
| 644 | if (err) |
| 645 | return err; |
| 646 | |
| 647 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 648 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 649 | } |
| 650 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 655 | { |
| 656 | int err; |
| 657 | |
| 658 | memset(k, 0, sizeof(*k)); |
| 659 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 660 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 661 | |
| 662 | if (info->attrs[NL80211_ATTR_KEY]) |
| 663 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 664 | else |
| 665 | err = nl80211_parse_key_old(info, k); |
| 666 | |
| 667 | if (err) |
| 668 | return err; |
| 669 | |
| 670 | if (k->def && k->defmgmt) |
| 671 | return -EINVAL; |
| 672 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 673 | if (k->defmgmt) { |
| 674 | if (k->def_uni || !k->def_multi) |
| 675 | return -EINVAL; |
| 676 | } |
| 677 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 678 | if (k->idx != -1) { |
| 679 | if (k->defmgmt) { |
| 680 | if (k->idx < 4 || k->idx > 5) |
| 681 | return -EINVAL; |
| 682 | } else if (k->def) { |
| 683 | if (k->idx < 0 || k->idx > 3) |
| 684 | return -EINVAL; |
| 685 | } else { |
| 686 | if (k->idx < 0 || k->idx > 5) |
| 687 | return -EINVAL; |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | return 0; |
| 692 | } |
| 693 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 694 | static struct cfg80211_cached_keys * |
| 695 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 696 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 697 | { |
| 698 | struct key_parse parse; |
| 699 | struct nlattr *key; |
| 700 | struct cfg80211_cached_keys *result; |
| 701 | int rem, err, def = 0; |
| 702 | |
| 703 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 704 | if (!result) |
| 705 | return ERR_PTR(-ENOMEM); |
| 706 | |
| 707 | result->def = -1; |
| 708 | result->defmgmt = -1; |
| 709 | |
| 710 | nla_for_each_nested(key, keys, rem) { |
| 711 | memset(&parse, 0, sizeof(parse)); |
| 712 | parse.idx = -1; |
| 713 | |
| 714 | err = nl80211_parse_key_new(key, &parse); |
| 715 | if (err) |
| 716 | goto error; |
| 717 | err = -EINVAL; |
| 718 | if (!parse.p.key) |
| 719 | goto error; |
| 720 | if (parse.idx < 0 || parse.idx > 4) |
| 721 | goto error; |
| 722 | if (parse.def) { |
| 723 | if (def) |
| 724 | goto error; |
| 725 | def = 1; |
| 726 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 727 | if (!parse.def_uni || !parse.def_multi) |
| 728 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 729 | } else if (parse.defmgmt) |
| 730 | goto error; |
| 731 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 732 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 733 | if (err) |
| 734 | goto error; |
| 735 | result->params[parse.idx].cipher = parse.p.cipher; |
| 736 | result->params[parse.idx].key_len = parse.p.key_len; |
| 737 | result->params[parse.idx].key = result->data[parse.idx]; |
| 738 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 739 | |
| 740 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 741 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 742 | if (no_ht) |
| 743 | *no_ht = true; |
| 744 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | return result; |
| 748 | error: |
| 749 | kfree(result); |
| 750 | return ERR_PTR(err); |
| 751 | } |
| 752 | |
| 753 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 754 | { |
| 755 | ASSERT_WDEV_LOCK(wdev); |
| 756 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 757 | switch (wdev->iftype) { |
| 758 | case NL80211_IFTYPE_AP: |
| 759 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 760 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 761 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 762 | break; |
| 763 | case NL80211_IFTYPE_ADHOC: |
| 764 | if (!wdev->current_bss) |
| 765 | return -ENOLINK; |
| 766 | break; |
| 767 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 768 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 769 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 770 | return -ENOLINK; |
| 771 | break; |
| 772 | default: |
| 773 | return -EINVAL; |
| 774 | } |
| 775 | |
| 776 | return 0; |
| 777 | } |
| 778 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 779 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 780 | { |
| 781 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 782 | int i; |
| 783 | |
| 784 | if (!nl_modes) |
| 785 | goto nla_put_failure; |
| 786 | |
| 787 | i = 0; |
| 788 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 789 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 790 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 791 | ifmodes >>= 1; |
| 792 | i++; |
| 793 | } |
| 794 | |
| 795 | nla_nest_end(msg, nl_modes); |
| 796 | return 0; |
| 797 | |
| 798 | nla_put_failure: |
| 799 | return -ENOBUFS; |
| 800 | } |
| 801 | |
| 802 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 803 | struct sk_buff *msg) |
| 804 | { |
| 805 | struct nlattr *nl_combis; |
| 806 | int i, j; |
| 807 | |
| 808 | nl_combis = nla_nest_start(msg, |
| 809 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 810 | if (!nl_combis) |
| 811 | goto nla_put_failure; |
| 812 | |
| 813 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 814 | const struct ieee80211_iface_combination *c; |
| 815 | struct nlattr *nl_combi, *nl_limits; |
| 816 | |
| 817 | c = &wiphy->iface_combinations[i]; |
| 818 | |
| 819 | nl_combi = nla_nest_start(msg, i + 1); |
| 820 | if (!nl_combi) |
| 821 | goto nla_put_failure; |
| 822 | |
| 823 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 824 | if (!nl_limits) |
| 825 | goto nla_put_failure; |
| 826 | |
| 827 | for (j = 0; j < c->n_limits; j++) { |
| 828 | struct nlattr *nl_limit; |
| 829 | |
| 830 | nl_limit = nla_nest_start(msg, j + 1); |
| 831 | if (!nl_limit) |
| 832 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 833 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 834 | c->limits[j].max)) |
| 835 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 836 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 837 | c->limits[j].types)) |
| 838 | goto nla_put_failure; |
| 839 | nla_nest_end(msg, nl_limit); |
| 840 | } |
| 841 | |
| 842 | nla_nest_end(msg, nl_limits); |
| 843 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 844 | if (c->beacon_int_infra_match && |
| 845 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 846 | goto nla_put_failure; |
| 847 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 848 | c->num_different_channels) || |
| 849 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 850 | c->max_interfaces)) |
| 851 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 852 | |
| 853 | nla_nest_end(msg, nl_combi); |
| 854 | } |
| 855 | |
| 856 | nla_nest_end(msg, nl_combis); |
| 857 | |
| 858 | return 0; |
| 859 | nla_put_failure: |
| 860 | return -ENOBUFS; |
| 861 | } |
| 862 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 863 | 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] | 864 | struct cfg80211_registered_device *dev) |
| 865 | { |
| 866 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 867 | struct nlattr *nl_bands, *nl_band; |
| 868 | struct nlattr *nl_freqs, *nl_freq; |
| 869 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 870 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 871 | enum ieee80211_band band; |
| 872 | struct ieee80211_channel *chan; |
| 873 | struct ieee80211_rate *rate; |
| 874 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 875 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 876 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 877 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 878 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 879 | if (!hdr) |
| 880 | return -1; |
| 881 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 882 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
| 883 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || |
| 884 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 885 | cfg80211_rdev_list_generation) || |
| 886 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 887 | dev->wiphy.retry_short) || |
| 888 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 889 | dev->wiphy.retry_long) || |
| 890 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 891 | dev->wiphy.frag_threshold) || |
| 892 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 893 | dev->wiphy.rts_threshold) || |
| 894 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 895 | dev->wiphy.coverage_class) || |
| 896 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 897 | dev->wiphy.max_scan_ssids) || |
| 898 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 899 | dev->wiphy.max_sched_scan_ssids) || |
| 900 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 901 | dev->wiphy.max_scan_ie_len) || |
| 902 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 903 | dev->wiphy.max_sched_scan_ie_len) || |
| 904 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 905 | dev->wiphy.max_match_sets)) |
| 906 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 907 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 908 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 909 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 910 | goto nla_put_failure; |
| 911 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 912 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 913 | goto nla_put_failure; |
| 914 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 915 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 916 | goto nla_put_failure; |
| 917 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 918 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 919 | goto nla_put_failure; |
| 920 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 921 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 922 | goto nla_put_failure; |
| 923 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 924 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 925 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 926 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 927 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 928 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 929 | dev->wiphy.cipher_suites)) |
| 930 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 931 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 932 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 933 | dev->wiphy.max_num_pmkids)) |
| 934 | goto nla_put_failure; |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 935 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 936 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 937 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 938 | goto nla_put_failure; |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 939 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 940 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 941 | dev->wiphy.available_antennas_tx) || |
| 942 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 943 | dev->wiphy.available_antennas_rx)) |
| 944 | goto nla_put_failure; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 945 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 946 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 947 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 948 | dev->wiphy.probe_resp_offload)) |
| 949 | goto nla_put_failure; |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 950 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 951 | if ((dev->wiphy.available_antennas_tx || |
| 952 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 953 | u32 tx_ant = 0, rx_ant = 0; |
| 954 | int res; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 955 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 956 | if (!res) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 957 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 958 | tx_ant) || |
| 959 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 960 | rx_ant)) |
| 961 | goto nla_put_failure; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 962 | } |
| 963 | } |
| 964 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 965 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 966 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 967 | goto nla_put_failure; |
| 968 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 969 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 970 | if (!nl_bands) |
| 971 | goto nla_put_failure; |
| 972 | |
| 973 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 974 | if (!dev->wiphy.bands[band]) |
| 975 | continue; |
| 976 | |
| 977 | nl_band = nla_nest_start(msg, band); |
| 978 | if (!nl_band) |
| 979 | goto nla_put_failure; |
| 980 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 981 | /* add HT info */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 982 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
| 983 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 984 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 985 | &dev->wiphy.bands[band]->ht_cap.mcs) || |
| 986 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 987 | dev->wiphy.bands[band]->ht_cap.cap) || |
| 988 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 989 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || |
| 990 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 991 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) |
| 992 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 993 | |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 994 | /* add VHT info */ |
| 995 | if (dev->wiphy.bands[band]->vht_cap.vht_supported && |
| 996 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 997 | sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs), |
| 998 | &dev->wiphy.bands[band]->vht_cap.vht_mcs) || |
| 999 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1000 | dev->wiphy.bands[band]->vht_cap.cap))) |
| 1001 | goto nla_put_failure; |
| 1002 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1003 | /* add frequencies */ |
| 1004 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 1005 | if (!nl_freqs) |
| 1006 | goto nla_put_failure; |
| 1007 | |
| 1008 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 1009 | nl_freq = nla_nest_start(msg, i); |
| 1010 | if (!nl_freq) |
| 1011 | goto nla_put_failure; |
| 1012 | |
| 1013 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1014 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1015 | if (nl80211_msg_put_channel(msg, chan)) |
| 1016 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1017 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1018 | nla_nest_end(msg, nl_freq); |
| 1019 | } |
| 1020 | |
| 1021 | nla_nest_end(msg, nl_freqs); |
| 1022 | |
| 1023 | /* add bitrates */ |
| 1024 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1025 | if (!nl_rates) |
| 1026 | goto nla_put_failure; |
| 1027 | |
| 1028 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 1029 | nl_rate = nla_nest_start(msg, i); |
| 1030 | if (!nl_rate) |
| 1031 | goto nla_put_failure; |
| 1032 | |
| 1033 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1034 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1035 | rate->bitrate)) |
| 1036 | goto nla_put_failure; |
| 1037 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1038 | nla_put_flag(msg, |
| 1039 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1040 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1041 | |
| 1042 | nla_nest_end(msg, nl_rate); |
| 1043 | } |
| 1044 | |
| 1045 | nla_nest_end(msg, nl_rates); |
| 1046 | |
| 1047 | nla_nest_end(msg, nl_band); |
| 1048 | } |
| 1049 | nla_nest_end(msg, nl_bands); |
| 1050 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1051 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1052 | if (!nl_cmds) |
| 1053 | goto nla_put_failure; |
| 1054 | |
| 1055 | i = 0; |
| 1056 | #define CMD(op, n) \ |
| 1057 | do { \ |
| 1058 | if (dev->ops->op) { \ |
| 1059 | i++; \ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1060 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1061 | goto nla_put_failure; \ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1062 | } \ |
| 1063 | } while (0) |
| 1064 | |
| 1065 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1066 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1067 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1068 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1069 | CMD(add_station, NEW_STATION); |
| 1070 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 1071 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1072 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1073 | CMD(auth, AUTHENTICATE); |
| 1074 | CMD(assoc, ASSOCIATE); |
| 1075 | CMD(deauth, DEAUTHENTICATE); |
| 1076 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1077 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1078 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1079 | CMD(set_pmksa, SET_PMKSA); |
| 1080 | CMD(del_pmksa, DEL_PMKSA); |
| 1081 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1082 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1083 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 1084 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1085 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1086 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 1087 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1088 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1089 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1090 | goto nla_put_failure; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1091 | } |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1092 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1093 | dev->ops->join_mesh) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1094 | i++; |
| 1095 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1096 | goto nla_put_failure; |
| 1097 | } |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1098 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 1099 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1100 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1101 | CMD(tdls_oper, TDLS_OPER); |
| 1102 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 1103 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1104 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 1105 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1106 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1107 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1108 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1109 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1110 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1111 | } |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1112 | CMD(start_p2p_device, START_P2P_DEVICE); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 1113 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1114 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1115 | #ifdef CONFIG_NL80211_TESTMODE |
| 1116 | CMD(testmode_cmd, TESTMODE); |
| 1117 | #endif |
| 1118 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1119 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1120 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1121 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1122 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1123 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1124 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1125 | } |
| 1126 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1127 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1128 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1129 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1130 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1131 | } |
| 1132 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1133 | nla_nest_end(msg, nl_cmds); |
| 1134 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1135 | if (dev->ops->remain_on_channel && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1136 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1137 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1138 | dev->wiphy.max_remain_on_channel_duration)) |
| 1139 | goto nla_put_failure; |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 1140 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1141 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1142 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1143 | goto nla_put_failure; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1144 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1145 | if (mgmt_stypes) { |
| 1146 | u16 stypes; |
| 1147 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1148 | enum nl80211_iftype ift; |
| 1149 | |
| 1150 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1151 | if (!nl_ifs) |
| 1152 | goto nla_put_failure; |
| 1153 | |
| 1154 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1155 | nl_ftypes = nla_nest_start(msg, ift); |
| 1156 | if (!nl_ftypes) |
| 1157 | goto nla_put_failure; |
| 1158 | i = 0; |
| 1159 | stypes = mgmt_stypes[ift].tx; |
| 1160 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1161 | if ((stypes & 1) && |
| 1162 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1163 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1164 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1165 | stypes >>= 1; |
| 1166 | i++; |
| 1167 | } |
| 1168 | nla_nest_end(msg, nl_ftypes); |
| 1169 | } |
| 1170 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1171 | nla_nest_end(msg, nl_ifs); |
| 1172 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1173 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1174 | if (!nl_ifs) |
| 1175 | goto nla_put_failure; |
| 1176 | |
| 1177 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1178 | nl_ftypes = nla_nest_start(msg, ift); |
| 1179 | if (!nl_ftypes) |
| 1180 | goto nla_put_failure; |
| 1181 | i = 0; |
| 1182 | stypes = mgmt_stypes[ift].rx; |
| 1183 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1184 | if ((stypes & 1) && |
| 1185 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1186 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1187 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1188 | stypes >>= 1; |
| 1189 | i++; |
| 1190 | } |
| 1191 | nla_nest_end(msg, nl_ftypes); |
| 1192 | } |
| 1193 | nla_nest_end(msg, nl_ifs); |
| 1194 | } |
| 1195 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1196 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1197 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 1198 | struct nlattr *nl_wowlan; |
| 1199 | |
| 1200 | nl_wowlan = nla_nest_start(msg, |
| 1201 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1202 | if (!nl_wowlan) |
| 1203 | goto nla_put_failure; |
| 1204 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1205 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 1206 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1207 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1208 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1209 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1210 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1211 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1212 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1213 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1214 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1215 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1216 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1217 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1218 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1219 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1220 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1221 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1222 | if (dev->wiphy.wowlan.n_patterns) { |
| 1223 | struct nl80211_wowlan_pattern_support pat = { |
| 1224 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1225 | .min_pattern_len = |
| 1226 | dev->wiphy.wowlan.pattern_min_len, |
| 1227 | .max_pattern_len = |
| 1228 | dev->wiphy.wowlan.pattern_max_len, |
| 1229 | }; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1230 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1231 | sizeof(pat), &pat)) |
| 1232 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | nla_nest_end(msg, nl_wowlan); |
| 1236 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1237 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1238 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1239 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1240 | dev->wiphy.software_iftypes)) |
| 1241 | goto nla_put_failure; |
| 1242 | |
| 1243 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1244 | goto nla_put_failure; |
| 1245 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1246 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1247 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1248 | dev->wiphy.ap_sme_capa)) |
| 1249 | goto nla_put_failure; |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1250 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1251 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
| 1252 | dev->wiphy.features)) |
| 1253 | goto nla_put_failure; |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1254 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1255 | if (dev->wiphy.ht_capa_mod_mask && |
| 1256 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1257 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1258 | dev->wiphy.ht_capa_mod_mask)) |
| 1259 | goto nla_put_failure; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1260 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1261 | return genlmsg_end(msg, hdr); |
| 1262 | |
| 1263 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1264 | genlmsg_cancel(msg, hdr); |
| 1265 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1269 | { |
| 1270 | int idx = 0; |
| 1271 | int start = cb->args[0]; |
| 1272 | struct cfg80211_registered_device *dev; |
| 1273 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1274 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1275 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1276 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1277 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1278 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1279 | continue; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1280 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1281 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1282 | dev) < 0) { |
| 1283 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1284 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1285 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1286 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1287 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1288 | |
| 1289 | cb->args[0] = idx; |
| 1290 | |
| 1291 | return skb->len; |
| 1292 | } |
| 1293 | |
| 1294 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1295 | { |
| 1296 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1297 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1298 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1299 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1300 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1301 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1302 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1303 | 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] | 1304 | nlmsg_free(msg); |
| 1305 | return -ENOBUFS; |
| 1306 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1307 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1308 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1309 | } |
| 1310 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1311 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1312 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1313 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1314 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1315 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1316 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1317 | }; |
| 1318 | |
| 1319 | static int parse_txq_params(struct nlattr *tb[], |
| 1320 | struct ieee80211_txq_params *txq_params) |
| 1321 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1322 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1323 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1324 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1325 | return -EINVAL; |
| 1326 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1327 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1328 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1329 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1330 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1331 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1332 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1333 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1334 | return -EINVAL; |
| 1335 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1336 | return 0; |
| 1337 | } |
| 1338 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1339 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1340 | { |
| 1341 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1342 | * You can only set the channel explicitly for WDS interfaces, |
| 1343 | * all others have their channel managed via their respective |
| 1344 | * "establish a connection" command (connect, join, ...) |
| 1345 | * |
| 1346 | * For AP/GO and mesh mode, the channel can be set with the |
| 1347 | * channel userspace API, but is only stored and passed to the |
| 1348 | * low-level driver when the AP starts or the mesh is joined. |
| 1349 | * This is for backward compatibility, userspace can also give |
| 1350 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1351 | * |
| 1352 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1353 | * whatever else is going on, so they have their own special |
| 1354 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1355 | */ |
| 1356 | return !wdev || |
| 1357 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1358 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1359 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1360 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1361 | } |
| 1362 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 1363 | static bool nl80211_valid_channel_type(struct genl_info *info, |
| 1364 | enum nl80211_channel_type *channel_type) |
| 1365 | { |
| 1366 | enum nl80211_channel_type tmp; |
| 1367 | |
| 1368 | if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) |
| 1369 | return false; |
| 1370 | |
| 1371 | tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1372 | if (tmp != NL80211_CHAN_NO_HT && |
| 1373 | tmp != NL80211_CHAN_HT20 && |
| 1374 | tmp != NL80211_CHAN_HT40PLUS && |
| 1375 | tmp != NL80211_CHAN_HT40MINUS) |
| 1376 | return false; |
| 1377 | |
| 1378 | if (channel_type) |
| 1379 | *channel_type = tmp; |
| 1380 | |
| 1381 | return true; |
| 1382 | } |
| 1383 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1384 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1385 | struct wireless_dev *wdev, |
| 1386 | struct genl_info *info) |
| 1387 | { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1388 | struct ieee80211_channel *channel; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1389 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1390 | u32 freq; |
| 1391 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1392 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1393 | |
| 1394 | if (wdev) |
| 1395 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1396 | |
| 1397 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1398 | return -EINVAL; |
| 1399 | |
| 1400 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1401 | return -EOPNOTSUPP; |
| 1402 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 1403 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 1404 | !nl80211_valid_channel_type(info, &channel_type)) |
| 1405 | return -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1406 | |
| 1407 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1408 | |
| 1409 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1410 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1411 | case NL80211_IFTYPE_AP: |
| 1412 | case NL80211_IFTYPE_P2P_GO: |
| 1413 | if (wdev->beacon_interval) { |
| 1414 | result = -EBUSY; |
| 1415 | break; |
| 1416 | } |
| 1417 | channel = rdev_freq_to_chan(rdev, freq, channel_type); |
| 1418 | if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy, |
| 1419 | channel, |
| 1420 | channel_type)) { |
| 1421 | result = -EINVAL; |
| 1422 | break; |
| 1423 | } |
| 1424 | wdev->preset_chan = channel; |
| 1425 | wdev->preset_chantype = channel_type; |
| 1426 | result = 0; |
| 1427 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1428 | case NL80211_IFTYPE_MESH_POINT: |
| 1429 | result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type); |
| 1430 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1431 | case NL80211_IFTYPE_MONITOR: |
| 1432 | result = cfg80211_set_monitor_channel(rdev, freq, channel_type); |
| 1433 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1434 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1435 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1436 | } |
| 1437 | mutex_unlock(&rdev->devlist_mtx); |
| 1438 | |
| 1439 | return result; |
| 1440 | } |
| 1441 | |
| 1442 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1443 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1444 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1445 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1446 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1447 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1448 | } |
| 1449 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1450 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1451 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1452 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1453 | struct net_device *dev = info->user_ptr[1]; |
| 1454 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1455 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1456 | |
| 1457 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1458 | return -EINVAL; |
| 1459 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1460 | if (netif_running(dev)) |
| 1461 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1462 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1463 | if (!rdev->ops->set_wds_peer) |
| 1464 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1465 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1466 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1467 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1468 | |
| 1469 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1470 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1474 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1475 | { |
| 1476 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1477 | struct net_device *netdev = NULL; |
| 1478 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1479 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1480 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1481 | u32 changed; |
| 1482 | u8 retry_short = 0, retry_long = 0; |
| 1483 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1484 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1485 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1486 | /* |
| 1487 | * Try to find the wiphy and netdev. Normally this |
| 1488 | * function shouldn't need the netdev, but this is |
| 1489 | * done for backward compatibility -- previously |
| 1490 | * setting the channel was done per wiphy, but now |
| 1491 | * it is per netdev. Previous userland like hostapd |
| 1492 | * also passed a netdev to set_wiphy, so that it is |
| 1493 | * possible to let that go to the right netdev! |
| 1494 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1495 | mutex_lock(&cfg80211_mutex); |
| 1496 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1497 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1498 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1499 | |
| 1500 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1501 | if (netdev && netdev->ieee80211_ptr) { |
| 1502 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1503 | mutex_lock(&rdev->mtx); |
| 1504 | } else |
| 1505 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1506 | } |
| 1507 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1508 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1509 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1510 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1511 | if (IS_ERR(rdev)) { |
| 1512 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1513 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1514 | } |
| 1515 | wdev = NULL; |
| 1516 | netdev = NULL; |
| 1517 | result = 0; |
| 1518 | |
| 1519 | mutex_lock(&rdev->mtx); |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1520 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1521 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1522 | |
| 1523 | /* |
| 1524 | * end workaround code, by now the rdev is available |
| 1525 | * and locked, and wdev may or may not be NULL. |
| 1526 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1527 | |
| 1528 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1529 | result = cfg80211_dev_rename( |
| 1530 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1531 | |
| 1532 | mutex_unlock(&cfg80211_mutex); |
| 1533 | |
| 1534 | if (result) |
| 1535 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1536 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1537 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1538 | struct ieee80211_txq_params txq_params; |
| 1539 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1540 | |
| 1541 | if (!rdev->ops->set_txq_params) { |
| 1542 | result = -EOPNOTSUPP; |
| 1543 | goto bad_res; |
| 1544 | } |
| 1545 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1546 | if (!netdev) { |
| 1547 | result = -EINVAL; |
| 1548 | goto bad_res; |
| 1549 | } |
| 1550 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1551 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1552 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1553 | result = -EINVAL; |
| 1554 | goto bad_res; |
| 1555 | } |
| 1556 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1557 | if (!netif_running(netdev)) { |
| 1558 | result = -ENETDOWN; |
| 1559 | goto bad_res; |
| 1560 | } |
| 1561 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1562 | nla_for_each_nested(nl_txq_params, |
| 1563 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1564 | rem_txq_params) { |
| 1565 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1566 | nla_data(nl_txq_params), |
| 1567 | nla_len(nl_txq_params), |
| 1568 | txq_params_policy); |
| 1569 | result = parse_txq_params(tb, &txq_params); |
| 1570 | if (result) |
| 1571 | goto bad_res; |
| 1572 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1573 | result = rdev_set_txq_params(rdev, netdev, |
| 1574 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1575 | if (result) |
| 1576 | goto bad_res; |
| 1577 | } |
| 1578 | } |
| 1579 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1580 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1581 | result = __nl80211_set_channel(rdev, |
| 1582 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1583 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1584 | if (result) |
| 1585 | goto bad_res; |
| 1586 | } |
| 1587 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1588 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1589 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1590 | enum nl80211_tx_power_setting type; |
| 1591 | int idx, mbm = 0; |
| 1592 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1593 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1594 | txp_wdev = NULL; |
| 1595 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1596 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1597 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1598 | goto bad_res; |
| 1599 | } |
| 1600 | |
| 1601 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1602 | type = nla_get_u32(info->attrs[idx]); |
| 1603 | |
| 1604 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1605 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1606 | result = -EINVAL; |
| 1607 | goto bad_res; |
| 1608 | } |
| 1609 | |
| 1610 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1611 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1612 | mbm = nla_get_u32(info->attrs[idx]); |
| 1613 | } |
| 1614 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1615 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1616 | if (result) |
| 1617 | goto bad_res; |
| 1618 | } |
| 1619 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1620 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1621 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1622 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1623 | if ((!rdev->wiphy.available_antennas_tx && |
| 1624 | !rdev->wiphy.available_antennas_rx) || |
| 1625 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1626 | result = -EOPNOTSUPP; |
| 1627 | goto bad_res; |
| 1628 | } |
| 1629 | |
| 1630 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1631 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1632 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1633 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1634 | * available antenna masks, except for the "all" mask */ |
| 1635 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1636 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1637 | result = -EINVAL; |
| 1638 | goto bad_res; |
| 1639 | } |
| 1640 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1641 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1642 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1643 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1644 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1645 | if (result) |
| 1646 | goto bad_res; |
| 1647 | } |
| 1648 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1649 | changed = 0; |
| 1650 | |
| 1651 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1652 | retry_short = nla_get_u8( |
| 1653 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1654 | if (retry_short == 0) { |
| 1655 | result = -EINVAL; |
| 1656 | goto bad_res; |
| 1657 | } |
| 1658 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1659 | } |
| 1660 | |
| 1661 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1662 | retry_long = nla_get_u8( |
| 1663 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1664 | if (retry_long == 0) { |
| 1665 | result = -EINVAL; |
| 1666 | goto bad_res; |
| 1667 | } |
| 1668 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1669 | } |
| 1670 | |
| 1671 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1672 | frag_threshold = nla_get_u32( |
| 1673 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1674 | if (frag_threshold < 256) { |
| 1675 | result = -EINVAL; |
| 1676 | goto bad_res; |
| 1677 | } |
| 1678 | if (frag_threshold != (u32) -1) { |
| 1679 | /* |
| 1680 | * Fragments (apart from the last one) are required to |
| 1681 | * have even length. Make the fragmentation code |
| 1682 | * simpler by stripping LSB should someone try to use |
| 1683 | * odd threshold value. |
| 1684 | */ |
| 1685 | frag_threshold &= ~0x1; |
| 1686 | } |
| 1687 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1688 | } |
| 1689 | |
| 1690 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1691 | rts_threshold = nla_get_u32( |
| 1692 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1693 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1694 | } |
| 1695 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1696 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1697 | coverage_class = nla_get_u8( |
| 1698 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1699 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1700 | } |
| 1701 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1702 | if (changed) { |
| 1703 | u8 old_retry_short, old_retry_long; |
| 1704 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1705 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1706 | |
| 1707 | if (!rdev->ops->set_wiphy_params) { |
| 1708 | result = -EOPNOTSUPP; |
| 1709 | goto bad_res; |
| 1710 | } |
| 1711 | |
| 1712 | old_retry_short = rdev->wiphy.retry_short; |
| 1713 | old_retry_long = rdev->wiphy.retry_long; |
| 1714 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1715 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1716 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1717 | |
| 1718 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1719 | rdev->wiphy.retry_short = retry_short; |
| 1720 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1721 | rdev->wiphy.retry_long = retry_long; |
| 1722 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1723 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1724 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1725 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1726 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1727 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1728 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1729 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1730 | if (result) { |
| 1731 | rdev->wiphy.retry_short = old_retry_short; |
| 1732 | rdev->wiphy.retry_long = old_retry_long; |
| 1733 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1734 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1735 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1736 | } |
| 1737 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1738 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1739 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1740 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1741 | if (netdev) |
| 1742 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1743 | return result; |
| 1744 | } |
| 1745 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1746 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1747 | { |
| 1748 | return (u64)wdev->identifier | |
| 1749 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1750 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1751 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1752 | 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] | 1753 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1754 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1755 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1756 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1757 | void *hdr; |
| 1758 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1759 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1760 | if (!hdr) |
| 1761 | return -1; |
| 1762 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1763 | if (dev && |
| 1764 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1765 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1766 | goto nla_put_failure; |
| 1767 | |
| 1768 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1769 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1770 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1771 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1772 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1773 | rdev->devlist_generation ^ |
| 1774 | (cfg80211_rdev_list_generation << 2))) |
| 1775 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1776 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1777 | if (rdev->ops->get_channel) { |
| 1778 | struct ieee80211_channel *chan; |
| 1779 | enum nl80211_channel_type channel_type; |
| 1780 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1781 | chan = rdev_get_channel(rdev, wdev, &channel_type); |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1782 | if (chan && |
| 1783 | (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1784 | chan->center_freq) || |
| 1785 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1786 | channel_type))) |
John W. Linville | 59ef43e | 2012-04-18 14:17:13 -0400 | [diff] [blame] | 1787 | goto nla_put_failure; |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1788 | } |
| 1789 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 1790 | if (wdev->ssid_len) { |
| 1791 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 1792 | goto nla_put_failure; |
| 1793 | } |
| 1794 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1795 | return genlmsg_end(msg, hdr); |
| 1796 | |
| 1797 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1798 | genlmsg_cancel(msg, hdr); |
| 1799 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1803 | { |
| 1804 | int wp_idx = 0; |
| 1805 | int if_idx = 0; |
| 1806 | int wp_start = cb->args[0]; |
| 1807 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1808 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1809 | struct wireless_dev *wdev; |
| 1810 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1811 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1812 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1813 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1814 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1815 | if (wp_idx < wp_start) { |
| 1816 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1817 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1818 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1819 | if_idx = 0; |
| 1820 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1821 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1822 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1823 | if (if_idx < if_start) { |
| 1824 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1825 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1826 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1827 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1828 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1829 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1830 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1831 | goto out; |
| 1832 | } |
| 1833 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1834 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1835 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1836 | |
| 1837 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1838 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1839 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1840 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1841 | |
| 1842 | cb->args[0] = wp_idx; |
| 1843 | cb->args[1] = if_idx; |
| 1844 | |
| 1845 | return skb->len; |
| 1846 | } |
| 1847 | |
| 1848 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1849 | { |
| 1850 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1851 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1852 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1853 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1854 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1855 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1856 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1857 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1858 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1859 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1860 | nlmsg_free(msg); |
| 1861 | return -ENOBUFS; |
| 1862 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1863 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1864 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1865 | } |
| 1866 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1867 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1868 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1869 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1870 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1871 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1872 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1873 | }; |
| 1874 | |
| 1875 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1876 | { |
| 1877 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1878 | int flag; |
| 1879 | |
| 1880 | *mntrflags = 0; |
| 1881 | |
| 1882 | if (!nla) |
| 1883 | return -EINVAL; |
| 1884 | |
| 1885 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1886 | nla, mntr_flags_policy)) |
| 1887 | return -EINVAL; |
| 1888 | |
| 1889 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1890 | if (flags[flag]) |
| 1891 | *mntrflags |= (1<<flag); |
| 1892 | |
| 1893 | return 0; |
| 1894 | } |
| 1895 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1896 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1897 | struct net_device *netdev, u8 use_4addr, |
| 1898 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1899 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1900 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1901 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1902 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1903 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1904 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1905 | |
| 1906 | switch (iftype) { |
| 1907 | case NL80211_IFTYPE_AP_VLAN: |
| 1908 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1909 | return 0; |
| 1910 | break; |
| 1911 | case NL80211_IFTYPE_STATION: |
| 1912 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1913 | return 0; |
| 1914 | break; |
| 1915 | default: |
| 1916 | break; |
| 1917 | } |
| 1918 | |
| 1919 | return -EOPNOTSUPP; |
| 1920 | } |
| 1921 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1922 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1923 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1924 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1925 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1926 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1927 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1928 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1929 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1930 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1931 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1932 | memset(¶ms, 0, sizeof(params)); |
| 1933 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1934 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1935 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1936 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1937 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1938 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1939 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1940 | if (ntype > NL80211_IFTYPE_MAX) |
| 1941 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1942 | } |
| 1943 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1944 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1945 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1946 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1947 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1948 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1949 | if (netif_running(dev)) |
| 1950 | return -EBUSY; |
| 1951 | |
| 1952 | wdev_lock(wdev); |
| 1953 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1954 | IEEE80211_MAX_MESH_ID_LEN); |
| 1955 | wdev->mesh_id_up_len = |
| 1956 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1957 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1958 | wdev->mesh_id_up_len); |
| 1959 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1960 | } |
| 1961 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1962 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1963 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1964 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1965 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1966 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1967 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1968 | } else { |
| 1969 | params.use_4addr = -1; |
| 1970 | } |
| 1971 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1972 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1973 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1974 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1975 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1976 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1977 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1978 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1979 | |
| 1980 | flags = &_flags; |
| 1981 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1982 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1983 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1984 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1985 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1986 | else |
| 1987 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1988 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1989 | if (!err && params.use_4addr != -1) |
| 1990 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1991 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1992 | return err; |
| 1993 | } |
| 1994 | |
| 1995 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1996 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1997 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1998 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 1999 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2000 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2001 | int err; |
| 2002 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2003 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2004 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2005 | memset(¶ms, 0, sizeof(params)); |
| 2006 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2007 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2008 | return -EINVAL; |
| 2009 | |
| 2010 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2011 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2012 | if (type > NL80211_IFTYPE_MAX) |
| 2013 | return -EINVAL; |
| 2014 | } |
| 2015 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2016 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2017 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2018 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2019 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2020 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2021 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2022 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2023 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2024 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2025 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2026 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2027 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2028 | if (!msg) |
| 2029 | return -ENOMEM; |
| 2030 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2031 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2032 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2033 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2034 | wdev = rdev_add_virtual_intf(rdev, |
| 2035 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2036 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2037 | if (IS_ERR(wdev)) { |
| 2038 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2039 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2040 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2041 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2042 | switch (type) { |
| 2043 | case NL80211_IFTYPE_MESH_POINT: |
| 2044 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2045 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2046 | wdev_lock(wdev); |
| 2047 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2048 | IEEE80211_MAX_MESH_ID_LEN); |
| 2049 | wdev->mesh_id_up_len = |
| 2050 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2051 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2052 | wdev->mesh_id_up_len); |
| 2053 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2054 | break; |
| 2055 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2056 | /* |
| 2057 | * P2P Device doesn't have a netdev, so doesn't go |
| 2058 | * through the netdev notifier and must be added here |
| 2059 | */ |
| 2060 | mutex_init(&wdev->mtx); |
| 2061 | INIT_LIST_HEAD(&wdev->event_list); |
| 2062 | spin_lock_init(&wdev->event_lock); |
| 2063 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2064 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2065 | |
| 2066 | mutex_lock(&rdev->devlist_mtx); |
| 2067 | wdev->identifier = ++rdev->wdev_id; |
| 2068 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2069 | rdev->devlist_generation++; |
| 2070 | mutex_unlock(&rdev->devlist_mtx); |
| 2071 | break; |
| 2072 | default: |
| 2073 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2074 | } |
| 2075 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2076 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2077 | rdev, wdev) < 0) { |
| 2078 | nlmsg_free(msg); |
| 2079 | return -ENOBUFS; |
| 2080 | } |
| 2081 | |
| 2082 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2086 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2087 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2088 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2089 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2090 | if (!rdev->ops->del_virtual_intf) |
| 2091 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2092 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2093 | /* |
| 2094 | * If we remove a wireless device without a netdev then clear |
| 2095 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2096 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2097 | * since the wdev has been freed, unlike with a netdev where |
| 2098 | * we need the dev_put() for the netdev to really be freed. |
| 2099 | */ |
| 2100 | if (!wdev->netdev) |
| 2101 | info->user_ptr[1] = NULL; |
| 2102 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2103 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2104 | } |
| 2105 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2106 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2107 | { |
| 2108 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2109 | struct net_device *dev = info->user_ptr[1]; |
| 2110 | u16 noack_map; |
| 2111 | |
| 2112 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2113 | return -EINVAL; |
| 2114 | |
| 2115 | if (!rdev->ops->set_noack_map) |
| 2116 | return -EOPNOTSUPP; |
| 2117 | |
| 2118 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2119 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2120 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2121 | } |
| 2122 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2123 | struct get_key_cookie { |
| 2124 | struct sk_buff *msg; |
| 2125 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2126 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2127 | }; |
| 2128 | |
| 2129 | static void get_key_callback(void *c, struct key_params *params) |
| 2130 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2131 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2132 | struct get_key_cookie *cookie = c; |
| 2133 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2134 | if ((params->key && |
| 2135 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2136 | params->key_len, params->key)) || |
| 2137 | (params->seq && |
| 2138 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2139 | params->seq_len, params->seq)) || |
| 2140 | (params->cipher && |
| 2141 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2142 | params->cipher))) |
| 2143 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2144 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2145 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2146 | if (!key) |
| 2147 | goto nla_put_failure; |
| 2148 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2149 | if ((params->key && |
| 2150 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2151 | params->key_len, params->key)) || |
| 2152 | (params->seq && |
| 2153 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2154 | params->seq_len, params->seq)) || |
| 2155 | (params->cipher && |
| 2156 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2157 | params->cipher))) |
| 2158 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2159 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2160 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2161 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2162 | |
| 2163 | nla_nest_end(cookie->msg, key); |
| 2164 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2165 | return; |
| 2166 | nla_put_failure: |
| 2167 | cookie->error = 1; |
| 2168 | } |
| 2169 | |
| 2170 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2171 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2172 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2173 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2174 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2175 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2176 | const u8 *mac_addr = NULL; |
| 2177 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2178 | struct get_key_cookie cookie = { |
| 2179 | .error = 0, |
| 2180 | }; |
| 2181 | void *hdr; |
| 2182 | struct sk_buff *msg; |
| 2183 | |
| 2184 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2185 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2186 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2187 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2188 | return -EINVAL; |
| 2189 | |
| 2190 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2191 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2192 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2193 | pairwise = !!mac_addr; |
| 2194 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2195 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2196 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2197 | return -EINVAL; |
| 2198 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2199 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2200 | return -EINVAL; |
| 2201 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2202 | } |
| 2203 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2204 | if (!rdev->ops->get_key) |
| 2205 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2206 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2207 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2208 | if (!msg) |
| 2209 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2210 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2211 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2212 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2213 | if (IS_ERR(hdr)) |
| 2214 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2215 | |
| 2216 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2217 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2218 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2219 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2220 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2221 | goto nla_put_failure; |
| 2222 | if (mac_addr && |
| 2223 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2224 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2225 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2226 | if (pairwise && mac_addr && |
| 2227 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2228 | return -ENOENT; |
| 2229 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2230 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2231 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2232 | |
| 2233 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2234 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2235 | |
| 2236 | if (cookie.error) |
| 2237 | goto nla_put_failure; |
| 2238 | |
| 2239 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2240 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2241 | |
| 2242 | nla_put_failure: |
| 2243 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2244 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2245 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2246 | return err; |
| 2247 | } |
| 2248 | |
| 2249 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2250 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2251 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2252 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2253 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2254 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2255 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2256 | err = nl80211_parse_key(info, &key); |
| 2257 | if (err) |
| 2258 | return err; |
| 2259 | |
| 2260 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2261 | return -EINVAL; |
| 2262 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2263 | /* only support setting default key */ |
| 2264 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2265 | return -EINVAL; |
| 2266 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2267 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2268 | |
| 2269 | if (key.def) { |
| 2270 | if (!rdev->ops->set_default_key) { |
| 2271 | err = -EOPNOTSUPP; |
| 2272 | goto out; |
| 2273 | } |
| 2274 | |
| 2275 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2276 | if (err) |
| 2277 | goto out; |
| 2278 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2279 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2280 | key.def_uni, key.def_multi); |
| 2281 | |
| 2282 | if (err) |
| 2283 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2284 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2285 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2286 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2287 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2288 | } else { |
| 2289 | if (key.def_uni || !key.def_multi) { |
| 2290 | err = -EINVAL; |
| 2291 | goto out; |
| 2292 | } |
| 2293 | |
| 2294 | if (!rdev->ops->set_default_mgmt_key) { |
| 2295 | err = -EOPNOTSUPP; |
| 2296 | goto out; |
| 2297 | } |
| 2298 | |
| 2299 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2300 | if (err) |
| 2301 | goto out; |
| 2302 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2303 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2304 | if (err) |
| 2305 | goto out; |
| 2306 | |
| 2307 | #ifdef CONFIG_CFG80211_WEXT |
| 2308 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2309 | #endif |
| 2310 | } |
| 2311 | |
| 2312 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2313 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2314 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2315 | return err; |
| 2316 | } |
| 2317 | |
| 2318 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2319 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2321 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2322 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2323 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2324 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2325 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2326 | err = nl80211_parse_key(info, &key); |
| 2327 | if (err) |
| 2328 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2329 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2330 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2331 | return -EINVAL; |
| 2332 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2333 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2334 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2335 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2336 | if (key.type == -1) { |
| 2337 | if (mac_addr) |
| 2338 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2339 | else |
| 2340 | key.type = NL80211_KEYTYPE_GROUP; |
| 2341 | } |
| 2342 | |
| 2343 | /* for now */ |
| 2344 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2345 | key.type != NL80211_KEYTYPE_GROUP) |
| 2346 | return -EINVAL; |
| 2347 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2348 | if (!rdev->ops->add_key) |
| 2349 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2350 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2351 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2352 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2353 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2354 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2355 | |
| 2356 | wdev_lock(dev->ieee80211_ptr); |
| 2357 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2358 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2359 | err = rdev_add_key(rdev, dev, key.idx, |
| 2360 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2361 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2362 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2363 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2364 | return err; |
| 2365 | } |
| 2366 | |
| 2367 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2368 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2369 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2370 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2371 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2372 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2373 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2374 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2375 | err = nl80211_parse_key(info, &key); |
| 2376 | if (err) |
| 2377 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2378 | |
| 2379 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2380 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2381 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2382 | if (key.type == -1) { |
| 2383 | if (mac_addr) |
| 2384 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2385 | else |
| 2386 | key.type = NL80211_KEYTYPE_GROUP; |
| 2387 | } |
| 2388 | |
| 2389 | /* for now */ |
| 2390 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2391 | key.type != NL80211_KEYTYPE_GROUP) |
| 2392 | return -EINVAL; |
| 2393 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2394 | if (!rdev->ops->del_key) |
| 2395 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2396 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2397 | wdev_lock(dev->ieee80211_ptr); |
| 2398 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2399 | |
| 2400 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2401 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2402 | err = -ENOENT; |
| 2403 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2404 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2405 | err = rdev_del_key(rdev, dev, key.idx, |
| 2406 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2407 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2408 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2409 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2410 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2411 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2412 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2413 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2414 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2415 | } |
| 2416 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2417 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2418 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2419 | return err; |
| 2420 | } |
| 2421 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2422 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2423 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2424 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2425 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2426 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2427 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2428 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2429 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2430 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2431 | return -EINVAL; |
| 2432 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2433 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2434 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2435 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2436 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2437 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2438 | if (!bcn->head_len) |
| 2439 | return -EINVAL; |
| 2440 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2444 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2445 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2446 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2447 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2448 | } |
| 2449 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2450 | if (!haveinfo) |
| 2451 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2452 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2453 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2454 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2455 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2459 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2460 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2461 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2462 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2463 | } |
| 2464 | |
| 2465 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2466 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2467 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2468 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2469 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2470 | } |
| 2471 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2472 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2473 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2474 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2475 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2476 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2477 | } |
| 2478 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2479 | return 0; |
| 2480 | } |
| 2481 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2482 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2483 | struct cfg80211_ap_settings *params) |
| 2484 | { |
| 2485 | struct wireless_dev *wdev; |
| 2486 | bool ret = false; |
| 2487 | |
| 2488 | mutex_lock(&rdev->devlist_mtx); |
| 2489 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2490 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2491 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2492 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2493 | continue; |
| 2494 | |
| 2495 | if (!wdev->preset_chan) |
| 2496 | continue; |
| 2497 | |
| 2498 | params->channel = wdev->preset_chan; |
| 2499 | params->channel_type = wdev->preset_chantype; |
| 2500 | ret = true; |
| 2501 | break; |
| 2502 | } |
| 2503 | |
| 2504 | mutex_unlock(&rdev->devlist_mtx); |
| 2505 | |
| 2506 | return ret; |
| 2507 | } |
| 2508 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2509 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2510 | enum nl80211_auth_type auth_type, |
| 2511 | enum nl80211_commands cmd) |
| 2512 | { |
| 2513 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2514 | return false; |
| 2515 | |
| 2516 | switch (cmd) { |
| 2517 | case NL80211_CMD_AUTHENTICATE: |
| 2518 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2519 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2520 | return false; |
| 2521 | return true; |
| 2522 | case NL80211_CMD_CONNECT: |
| 2523 | case NL80211_CMD_START_AP: |
| 2524 | /* SAE not supported yet */ |
| 2525 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2526 | return false; |
| 2527 | return true; |
| 2528 | default: |
| 2529 | return false; |
| 2530 | } |
| 2531 | } |
| 2532 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2533 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2534 | { |
| 2535 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2536 | struct net_device *dev = info->user_ptr[1]; |
| 2537 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2538 | struct cfg80211_ap_settings params; |
| 2539 | int err; |
| 2540 | |
| 2541 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2542 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2543 | return -EOPNOTSUPP; |
| 2544 | |
| 2545 | if (!rdev->ops->start_ap) |
| 2546 | return -EOPNOTSUPP; |
| 2547 | |
| 2548 | if (wdev->beacon_interval) |
| 2549 | return -EALREADY; |
| 2550 | |
| 2551 | memset(¶ms, 0, sizeof(params)); |
| 2552 | |
| 2553 | /* these are required for START_AP */ |
| 2554 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2555 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2556 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2557 | return -EINVAL; |
| 2558 | |
| 2559 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2560 | if (err) |
| 2561 | return err; |
| 2562 | |
| 2563 | params.beacon_interval = |
| 2564 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2565 | params.dtim_period = |
| 2566 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2567 | |
| 2568 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2569 | if (err) |
| 2570 | return err; |
| 2571 | |
| 2572 | /* |
| 2573 | * In theory, some of these attributes should be required here |
| 2574 | * but since they were not used when the command was originally |
| 2575 | * added, keep them optional for old user space programs to let |
| 2576 | * them continue to work with drivers that do not need the |
| 2577 | * additional information -- drivers must check! |
| 2578 | */ |
| 2579 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2580 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2581 | params.ssid_len = |
| 2582 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2583 | if (params.ssid_len == 0 || |
| 2584 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2585 | return -EINVAL; |
| 2586 | } |
| 2587 | |
| 2588 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2589 | params.hidden_ssid = nla_get_u32( |
| 2590 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2591 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2592 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2593 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2594 | return -EINVAL; |
| 2595 | } |
| 2596 | |
| 2597 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2598 | |
| 2599 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2600 | params.auth_type = nla_get_u32( |
| 2601 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2602 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 2603 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2604 | return -EINVAL; |
| 2605 | } else |
| 2606 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2607 | |
| 2608 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2609 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2610 | if (err) |
| 2611 | return err; |
| 2612 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2613 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2614 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2615 | return -EOPNOTSUPP; |
| 2616 | params.inactivity_timeout = nla_get_u16( |
| 2617 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2618 | } |
| 2619 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2620 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 2621 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 2622 | |
| 2623 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 2624 | !nl80211_valid_channel_type(info, &channel_type)) |
| 2625 | return -EINVAL; |
| 2626 | |
| 2627 | params.channel = rdev_freq_to_chan(rdev, |
| 2628 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 2629 | channel_type); |
| 2630 | if (!params.channel) |
| 2631 | return -EINVAL; |
| 2632 | params.channel_type = channel_type; |
| 2633 | } else if (wdev->preset_chan) { |
| 2634 | params.channel = wdev->preset_chan; |
| 2635 | params.channel_type = wdev->preset_chantype; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2636 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2637 | return -EINVAL; |
| 2638 | |
| 2639 | if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel, |
| 2640 | params.channel_type)) |
| 2641 | return -EINVAL; |
| 2642 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2643 | mutex_lock(&rdev->devlist_mtx); |
| 2644 | err = cfg80211_can_use_chan(rdev, wdev, params.channel, |
| 2645 | CHAN_MODE_SHARED); |
| 2646 | mutex_unlock(&rdev->devlist_mtx); |
| 2647 | |
| 2648 | if (err) |
| 2649 | return err; |
| 2650 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2651 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2652 | if (!err) { |
| 2653 | wdev->preset_chan = params.channel; |
| 2654 | wdev->preset_chantype = params.channel_type; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2655 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | f4489eb | 2012-06-29 12:46:58 +0200 | [diff] [blame] | 2656 | wdev->channel = params.channel; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 2657 | wdev->ssid_len = params.ssid_len; |
| 2658 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2659 | } |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2660 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2661 | } |
| 2662 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2663 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2664 | { |
| 2665 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2666 | struct net_device *dev = info->user_ptr[1]; |
| 2667 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2668 | struct cfg80211_beacon_data params; |
| 2669 | int err; |
| 2670 | |
| 2671 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2672 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2673 | return -EOPNOTSUPP; |
| 2674 | |
| 2675 | if (!rdev->ops->change_beacon) |
| 2676 | return -EOPNOTSUPP; |
| 2677 | |
| 2678 | if (!wdev->beacon_interval) |
| 2679 | return -EINVAL; |
| 2680 | |
| 2681 | err = nl80211_parse_beacon(info, ¶ms); |
| 2682 | if (err) |
| 2683 | return err; |
| 2684 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2685 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | 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] | 2689 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2690 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2691 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2692 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2693 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2694 | } |
| 2695 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2696 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2697 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2698 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2699 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2700 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2701 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2702 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2703 | }; |
| 2704 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2705 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2706 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2707 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2708 | { |
| 2709 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2710 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2711 | int flag; |
| 2712 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2713 | /* |
| 2714 | * Try parsing the new attribute first so userspace |
| 2715 | * can specify both for older kernels. |
| 2716 | */ |
| 2717 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2718 | if (nla) { |
| 2719 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2720 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2721 | sta_flags = nla_data(nla); |
| 2722 | params->sta_flags_mask = sta_flags->mask; |
| 2723 | params->sta_flags_set = sta_flags->set; |
| 2724 | if ((params->sta_flags_mask | |
| 2725 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2726 | return -EINVAL; |
| 2727 | return 0; |
| 2728 | } |
| 2729 | |
| 2730 | /* if present, parse the old attribute */ |
| 2731 | |
| 2732 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2733 | if (!nla) |
| 2734 | return 0; |
| 2735 | |
| 2736 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2737 | nla, sta_flags_policy)) |
| 2738 | return -EINVAL; |
| 2739 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2740 | /* |
| 2741 | * Only allow certain flags for interface types so that |
| 2742 | * other attributes are silently ignored. Remember that |
| 2743 | * this is backward compatibility code with old userspace |
| 2744 | * and shouldn't be hit in other cases anyway. |
| 2745 | */ |
| 2746 | switch (iftype) { |
| 2747 | case NL80211_IFTYPE_AP: |
| 2748 | case NL80211_IFTYPE_AP_VLAN: |
| 2749 | case NL80211_IFTYPE_P2P_GO: |
| 2750 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2751 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2752 | BIT(NL80211_STA_FLAG_WME) | |
| 2753 | BIT(NL80211_STA_FLAG_MFP); |
| 2754 | break; |
| 2755 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2756 | case NL80211_IFTYPE_STATION: |
| 2757 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2758 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2759 | break; |
| 2760 | case NL80211_IFTYPE_MESH_POINT: |
| 2761 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2762 | BIT(NL80211_STA_FLAG_MFP) | |
| 2763 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2764 | default: |
| 2765 | return -EINVAL; |
| 2766 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2767 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2768 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 2769 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2770 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2771 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2772 | /* no longer support new API additions in old API */ |
| 2773 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 2774 | return -EINVAL; |
| 2775 | } |
| 2776 | } |
| 2777 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2778 | return 0; |
| 2779 | } |
| 2780 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2781 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2782 | int attr) |
| 2783 | { |
| 2784 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2785 | u32 bitrate; |
| 2786 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2787 | |
| 2788 | rate = nla_nest_start(msg, attr); |
| 2789 | if (!rate) |
| 2790 | goto nla_put_failure; |
| 2791 | |
| 2792 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2793 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2794 | /* report 16-bit bitrate only if we can */ |
| 2795 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2796 | if ((bitrate > 0 && |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2797 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) || |
| 2798 | (bitrate_compat > 0 && |
| 2799 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2800 | ((info->flags & RATE_INFO_FLAGS_MCS) && |
| 2801 | nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) || |
| 2802 | ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) && |
| 2803 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) || |
| 2804 | ((info->flags & RATE_INFO_FLAGS_SHORT_GI) && |
| 2805 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))) |
| 2806 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2807 | |
| 2808 | nla_nest_end(msg, rate); |
| 2809 | return true; |
| 2810 | |
| 2811 | nla_put_failure: |
| 2812 | return false; |
| 2813 | } |
| 2814 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2815 | 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] | 2816 | int flags, |
| 2817 | struct cfg80211_registered_device *rdev, |
| 2818 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2819 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2820 | { |
| 2821 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2822 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2823 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2824 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2825 | if (!hdr) |
| 2826 | return -1; |
| 2827 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2828 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2829 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 2830 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 2831 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2832 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2833 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2834 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2835 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2836 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 2837 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2838 | sinfo->connected_time)) |
| 2839 | goto nla_put_failure; |
| 2840 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 2841 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2842 | sinfo->inactive_time)) |
| 2843 | goto nla_put_failure; |
| 2844 | if ((sinfo->filled & STATION_INFO_RX_BYTES) && |
| 2845 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2846 | sinfo->rx_bytes)) |
| 2847 | goto nla_put_failure; |
| 2848 | if ((sinfo->filled & STATION_INFO_TX_BYTES) && |
| 2849 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2850 | sinfo->tx_bytes)) |
| 2851 | goto nla_put_failure; |
| 2852 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 2853 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 2854 | goto nla_put_failure; |
| 2855 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 2856 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 2857 | goto nla_put_failure; |
| 2858 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 2859 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2860 | sinfo->plink_state)) |
| 2861 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2862 | switch (rdev->wiphy.signal_type) { |
| 2863 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2864 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 2865 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 2866 | sinfo->signal)) |
| 2867 | goto nla_put_failure; |
| 2868 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 2869 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2870 | sinfo->signal_avg)) |
| 2871 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2872 | break; |
| 2873 | default: |
| 2874 | break; |
| 2875 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2876 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2877 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2878 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2879 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2880 | } |
| 2881 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2882 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2883 | NL80211_STA_INFO_RX_BITRATE)) |
| 2884 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2885 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2886 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 2887 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2888 | sinfo->rx_packets)) |
| 2889 | goto nla_put_failure; |
| 2890 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 2891 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2892 | sinfo->tx_packets)) |
| 2893 | goto nla_put_failure; |
| 2894 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 2895 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2896 | sinfo->tx_retries)) |
| 2897 | goto nla_put_failure; |
| 2898 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 2899 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2900 | sinfo->tx_failed)) |
| 2901 | goto nla_put_failure; |
| 2902 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 2903 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 2904 | sinfo->beacon_loss_count)) |
| 2905 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2906 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2907 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2908 | if (!bss_param) |
| 2909 | goto nla_put_failure; |
| 2910 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2911 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 2912 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 2913 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 2914 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 2915 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 2916 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 2917 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2918 | sinfo->bss_param.dtim_period) || |
| 2919 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2920 | sinfo->bss_param.beacon_interval)) |
| 2921 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2922 | |
| 2923 | nla_nest_end(msg, bss_param); |
| 2924 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2925 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 2926 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2927 | sizeof(struct nl80211_sta_flag_update), |
| 2928 | &sinfo->sta_flags)) |
| 2929 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 2930 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 2931 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 2932 | sinfo->t_offset)) |
| 2933 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2934 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2935 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2936 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 2937 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2938 | sinfo->assoc_req_ies)) |
| 2939 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2940 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2941 | return genlmsg_end(msg, hdr); |
| 2942 | |
| 2943 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2944 | genlmsg_cancel(msg, hdr); |
| 2945 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2946 | } |
| 2947 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2948 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2949 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2950 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2951 | struct station_info sinfo; |
| 2952 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2953 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2954 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2955 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2956 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2957 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2958 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2959 | if (err) |
| 2960 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2961 | |
| 2962 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2963 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2964 | goto out_err; |
| 2965 | } |
| 2966 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2967 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2968 | memset(&sinfo, 0, sizeof(sinfo)); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2969 | err = rdev_dump_station(dev, netdev, sta_idx, |
| 2970 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2971 | if (err == -ENOENT) |
| 2972 | break; |
| 2973 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2974 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2975 | |
| 2976 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2977 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2978 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2979 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2980 | &sinfo) < 0) |
| 2981 | goto out; |
| 2982 | |
| 2983 | sta_idx++; |
| 2984 | } |
| 2985 | |
| 2986 | |
| 2987 | out: |
| 2988 | cb->args[1] = sta_idx; |
| 2989 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2990 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2991 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2992 | |
| 2993 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2994 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2995 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2996 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2997 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2998 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2999 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3000 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3001 | struct sk_buff *msg; |
| 3002 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3003 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3004 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3005 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3006 | |
| 3007 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3008 | return -EINVAL; |
| 3009 | |
| 3010 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3011 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3012 | if (!rdev->ops->get_station) |
| 3013 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3014 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3015 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3016 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3017 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3018 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3019 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3020 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3021 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3022 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3023 | 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] | 3024 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3025 | nlmsg_free(msg); |
| 3026 | return -ENOBUFS; |
| 3027 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3028 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3029 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3033 | * 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] | 3034 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3035 | static struct net_device *get_vlan(struct genl_info *info, |
| 3036 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3037 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3038 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3039 | struct net_device *v; |
| 3040 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3041 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3042 | if (!vlanattr) |
| 3043 | return NULL; |
| 3044 | |
| 3045 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3046 | if (!v) |
| 3047 | return ERR_PTR(-ENODEV); |
| 3048 | |
| 3049 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3050 | ret = -EINVAL; |
| 3051 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3052 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3053 | |
| 3054 | if (!netif_running(v)) { |
| 3055 | ret = -ENETDOWN; |
| 3056 | goto error; |
| 3057 | } |
| 3058 | |
| 3059 | return v; |
| 3060 | error: |
| 3061 | dev_put(v); |
| 3062 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3066 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3067 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3068 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3069 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3070 | struct station_parameters params; |
| 3071 | u8 *mac_addr = NULL; |
| 3072 | |
| 3073 | memset(¶ms, 0, sizeof(params)); |
| 3074 | |
| 3075 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 3076 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3077 | |
| 3078 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3079 | return -EINVAL; |
| 3080 | |
| 3081 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3082 | return -EINVAL; |
| 3083 | |
| 3084 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3085 | |
| 3086 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3087 | params.supported_rates = |
| 3088 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3089 | params.supported_rates_len = |
| 3090 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3091 | } |
| 3092 | |
| 3093 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3094 | params.listen_interval = |
| 3095 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 3096 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3097 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3098 | params.ht_capa = |
| 3099 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3100 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3101 | if (!rdev->ops->change_station) |
| 3102 | return -EOPNOTSUPP; |
| 3103 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3104 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3105 | return -EINVAL; |
| 3106 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3107 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3108 | params.plink_action = |
| 3109 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3110 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3111 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3112 | params.plink_state = |
| 3113 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3114 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3115 | switch (dev->ieee80211_ptr->iftype) { |
| 3116 | case NL80211_IFTYPE_AP: |
| 3117 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3118 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3119 | /* disallow mesh-specific things */ |
| 3120 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3121 | return -EINVAL; |
| 3122 | |
| 3123 | /* TDLS can't be set, ... */ |
| 3124 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3125 | return -EINVAL; |
| 3126 | /* |
| 3127 | * ... but don't bother the driver with it. This works around |
| 3128 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3129 | * TLDS_PEER flag in the mask even for AP mode. |
| 3130 | */ |
| 3131 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3132 | |
| 3133 | /* accept only the listed bits */ |
| 3134 | if (params.sta_flags_mask & |
| 3135 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3136 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3137 | BIT(NL80211_STA_FLAG_WME) | |
| 3138 | BIT(NL80211_STA_FLAG_MFP))) |
| 3139 | return -EINVAL; |
| 3140 | |
| 3141 | /* must be last in here for error handling */ |
| 3142 | params.vlan = get_vlan(info, rdev); |
| 3143 | if (IS_ERR(params.vlan)) |
| 3144 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3145 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3146 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3147 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3148 | /* |
| 3149 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3150 | * but silently ignore attempts to change it since we |
| 3151 | * don't have state here to verify that it doesn't try |
| 3152 | * to change the flag. |
| 3153 | */ |
| 3154 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3155 | /* fall through */ |
| 3156 | case NL80211_IFTYPE_ADHOC: |
| 3157 | /* disallow things sta doesn't support */ |
| 3158 | if (params.plink_action) |
| 3159 | return -EINVAL; |
| 3160 | if (params.ht_capa) |
| 3161 | return -EINVAL; |
| 3162 | if (params.listen_interval >= 0) |
| 3163 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3164 | /* reject any changes other than AUTHORIZED */ |
| 3165 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3166 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3167 | break; |
| 3168 | case NL80211_IFTYPE_MESH_POINT: |
| 3169 | /* disallow things mesh doesn't support */ |
| 3170 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3171 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3172 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3173 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3174 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3175 | return -EINVAL; |
| 3176 | /* |
| 3177 | * No special handling for TDLS here -- the userspace |
| 3178 | * mesh code doesn't have this bug. |
| 3179 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3180 | if (params.sta_flags_mask & |
| 3181 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3182 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3183 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3184 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3185 | break; |
| 3186 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3187 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3188 | } |
| 3189 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3190 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3191 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3192 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3193 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3194 | if (params.vlan) |
| 3195 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3196 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3197 | return err; |
| 3198 | } |
| 3199 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3200 | static struct nla_policy |
| 3201 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3202 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3203 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3204 | }; |
| 3205 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3206 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3207 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3208 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3209 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3210 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3211 | struct station_parameters params; |
| 3212 | u8 *mac_addr = NULL; |
| 3213 | |
| 3214 | memset(¶ms, 0, sizeof(params)); |
| 3215 | |
| 3216 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3217 | return -EINVAL; |
| 3218 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3219 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3220 | return -EINVAL; |
| 3221 | |
| 3222 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3223 | return -EINVAL; |
| 3224 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3225 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3226 | return -EINVAL; |
| 3227 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3228 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3229 | params.supported_rates = |
| 3230 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3231 | params.supported_rates_len = |
| 3232 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3233 | params.listen_interval = |
| 3234 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3235 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3236 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3237 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3238 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3239 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3240 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3241 | params.ht_capa = |
| 3242 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3243 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3244 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3245 | params.vht_capa = |
| 3246 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3247 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3248 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3249 | params.plink_action = |
| 3250 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3251 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3252 | if (!rdev->ops->add_station) |
| 3253 | return -EOPNOTSUPP; |
| 3254 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3255 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3256 | return -EINVAL; |
| 3257 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3258 | switch (dev->ieee80211_ptr->iftype) { |
| 3259 | case NL80211_IFTYPE_AP: |
| 3260 | case NL80211_IFTYPE_AP_VLAN: |
| 3261 | case NL80211_IFTYPE_P2P_GO: |
| 3262 | /* parse WME attributes if sta is WME capable */ |
| 3263 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3264 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3265 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3266 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3267 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3268 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3269 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3270 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3271 | nl80211_sta_wme_policy); |
| 3272 | if (err) |
| 3273 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3274 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3275 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3276 | params.uapsd_queues = |
| 3277 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3278 | if (params.uapsd_queues & |
| 3279 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3280 | return -EINVAL; |
| 3281 | |
| 3282 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3283 | params.max_sp = |
| 3284 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3285 | |
| 3286 | if (params.max_sp & |
| 3287 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3288 | return -EINVAL; |
| 3289 | |
| 3290 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3291 | } |
| 3292 | /* TDLS peers cannot be added */ |
| 3293 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3294 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3295 | /* but don't bother the driver with it */ |
| 3296 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3297 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3298 | /* must be last in here for error handling */ |
| 3299 | params.vlan = get_vlan(info, rdev); |
| 3300 | if (IS_ERR(params.vlan)) |
| 3301 | return PTR_ERR(params.vlan); |
| 3302 | break; |
| 3303 | case NL80211_IFTYPE_MESH_POINT: |
| 3304 | /* TDLS peers cannot be added */ |
| 3305 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3306 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3307 | break; |
| 3308 | case NL80211_IFTYPE_STATION: |
| 3309 | /* Only TDLS peers can be added */ |
| 3310 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3311 | return -EINVAL; |
| 3312 | /* Can only add if TDLS ... */ |
| 3313 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3314 | return -EOPNOTSUPP; |
| 3315 | /* ... with external setup is supported */ |
| 3316 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3317 | return -EOPNOTSUPP; |
| 3318 | break; |
| 3319 | default: |
| 3320 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3321 | } |
| 3322 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3323 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3324 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3325 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3326 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3327 | if (params.vlan) |
| 3328 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3329 | return err; |
| 3330 | } |
| 3331 | |
| 3332 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3333 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3334 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3335 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3336 | u8 *mac_addr = NULL; |
| 3337 | |
| 3338 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3339 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3340 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3341 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3342 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3343 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3344 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3345 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3346 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3347 | if (!rdev->ops->del_station) |
| 3348 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3349 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3350 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3351 | } |
| 3352 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3353 | 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] | 3354 | int flags, struct net_device *dev, |
| 3355 | u8 *dst, u8 *next_hop, |
| 3356 | struct mpath_info *pinfo) |
| 3357 | { |
| 3358 | void *hdr; |
| 3359 | struct nlattr *pinfoattr; |
| 3360 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3361 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3362 | if (!hdr) |
| 3363 | return -1; |
| 3364 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3365 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3366 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3367 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3368 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3369 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3370 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3371 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3372 | if (!pinfoattr) |
| 3373 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3374 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3375 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3376 | pinfo->frame_qlen)) |
| 3377 | goto nla_put_failure; |
| 3378 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3379 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3380 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3381 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3382 | pinfo->metric)) || |
| 3383 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3384 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3385 | pinfo->exptime)) || |
| 3386 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3387 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3388 | pinfo->flags)) || |
| 3389 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3390 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3391 | pinfo->discovery_timeout)) || |
| 3392 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3393 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3394 | pinfo->discovery_retries))) |
| 3395 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3396 | |
| 3397 | nla_nest_end(msg, pinfoattr); |
| 3398 | |
| 3399 | return genlmsg_end(msg, hdr); |
| 3400 | |
| 3401 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3402 | genlmsg_cancel(msg, hdr); |
| 3403 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3404 | } |
| 3405 | |
| 3406 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3407 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3408 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3409 | struct mpath_info pinfo; |
| 3410 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3411 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3412 | u8 dst[ETH_ALEN]; |
| 3413 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3414 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3415 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3416 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3417 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3418 | if (err) |
| 3419 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3420 | |
| 3421 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3422 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3423 | goto out_err; |
| 3424 | } |
| 3425 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3426 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3427 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3428 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3429 | } |
| 3430 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3431 | while (1) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3432 | err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop, |
| 3433 | &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3434 | if (err == -ENOENT) |
| 3435 | break; |
| 3436 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3437 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3438 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3439 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3440 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3441 | netdev, dst, next_hop, |
| 3442 | &pinfo) < 0) |
| 3443 | goto out; |
| 3444 | |
| 3445 | path_idx++; |
| 3446 | } |
| 3447 | |
| 3448 | |
| 3449 | out: |
| 3450 | cb->args[1] = path_idx; |
| 3451 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3452 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3453 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3454 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3455 | } |
| 3456 | |
| 3457 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3458 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3459 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3460 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3461 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3462 | struct mpath_info pinfo; |
| 3463 | struct sk_buff *msg; |
| 3464 | u8 *dst = NULL; |
| 3465 | u8 next_hop[ETH_ALEN]; |
| 3466 | |
| 3467 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3468 | |
| 3469 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3470 | return -EINVAL; |
| 3471 | |
| 3472 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3473 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3474 | if (!rdev->ops->get_mpath) |
| 3475 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3476 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3477 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3478 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3479 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3480 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3481 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3482 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3483 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3484 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3485 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3486 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3487 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3488 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3489 | dev, dst, next_hop, &pinfo) < 0) { |
| 3490 | nlmsg_free(msg); |
| 3491 | return -ENOBUFS; |
| 3492 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3493 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3494 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3498 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3499 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3500 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3501 | u8 *dst = NULL; |
| 3502 | u8 *next_hop = NULL; |
| 3503 | |
| 3504 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3505 | return -EINVAL; |
| 3506 | |
| 3507 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3508 | return -EINVAL; |
| 3509 | |
| 3510 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3511 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3512 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3513 | if (!rdev->ops->change_mpath) |
| 3514 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3515 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3516 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3517 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3518 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3519 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3520 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3521 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3522 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3523 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3524 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3525 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3526 | u8 *dst = NULL; |
| 3527 | u8 *next_hop = NULL; |
| 3528 | |
| 3529 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3530 | return -EINVAL; |
| 3531 | |
| 3532 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3533 | return -EINVAL; |
| 3534 | |
| 3535 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3536 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3537 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3538 | if (!rdev->ops->add_mpath) |
| 3539 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3540 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3541 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3542 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3543 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3544 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3548 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3549 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3550 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3551 | u8 *dst = NULL; |
| 3552 | |
| 3553 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3554 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3555 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3556 | if (!rdev->ops->del_mpath) |
| 3557 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3558 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3559 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3560 | } |
| 3561 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3562 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3563 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3564 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3565 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3566 | struct bss_parameters params; |
| 3567 | |
| 3568 | memset(¶ms, 0, sizeof(params)); |
| 3569 | /* default to not changing parameters */ |
| 3570 | params.use_cts_prot = -1; |
| 3571 | params.use_short_preamble = -1; |
| 3572 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3573 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3574 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3575 | |
| 3576 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3577 | params.use_cts_prot = |
| 3578 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3579 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3580 | params.use_short_preamble = |
| 3581 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3582 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3583 | params.use_short_slot_time = |
| 3584 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3585 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3586 | params.basic_rates = |
| 3587 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3588 | params.basic_rates_len = |
| 3589 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3590 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3591 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3592 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3593 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3594 | params.ht_opmode = |
| 3595 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3596 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3597 | if (!rdev->ops->change_bss) |
| 3598 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3599 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3600 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3601 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3602 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3603 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3604 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3605 | } |
| 3606 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3607 | 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] | 3608 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3609 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3610 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3611 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3612 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3613 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3614 | }; |
| 3615 | |
| 3616 | static int parse_reg_rule(struct nlattr *tb[], |
| 3617 | struct ieee80211_reg_rule *reg_rule) |
| 3618 | { |
| 3619 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3620 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3621 | |
| 3622 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3623 | return -EINVAL; |
| 3624 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3625 | return -EINVAL; |
| 3626 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3627 | return -EINVAL; |
| 3628 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3629 | return -EINVAL; |
| 3630 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3631 | return -EINVAL; |
| 3632 | |
| 3633 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3634 | |
| 3635 | freq_range->start_freq_khz = |
| 3636 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3637 | freq_range->end_freq_khz = |
| 3638 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3639 | freq_range->max_bandwidth_khz = |
| 3640 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3641 | |
| 3642 | power_rule->max_eirp = |
| 3643 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3644 | |
| 3645 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3646 | power_rule->max_antenna_gain = |
| 3647 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3648 | |
| 3649 | return 0; |
| 3650 | } |
| 3651 | |
| 3652 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3653 | { |
| 3654 | int r; |
| 3655 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3656 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3657 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3658 | /* |
| 3659 | * You should only get this when cfg80211 hasn't yet initialized |
| 3660 | * completely when built-in to the kernel right between the time |
| 3661 | * window between nl80211_init() and regulatory_init(), if that is |
| 3662 | * even possible. |
| 3663 | */ |
| 3664 | mutex_lock(&cfg80211_mutex); |
| 3665 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3666 | mutex_unlock(&cfg80211_mutex); |
| 3667 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3668 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3669 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3670 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3671 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3672 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3673 | |
| 3674 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3675 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3676 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 3677 | user_reg_hint_type = |
| 3678 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 3679 | else |
| 3680 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 3681 | |
| 3682 | switch (user_reg_hint_type) { |
| 3683 | case NL80211_USER_REG_HINT_USER: |
| 3684 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 3685 | break; |
| 3686 | default: |
| 3687 | return -EINVAL; |
| 3688 | } |
| 3689 | |
| 3690 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3691 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3692 | return r; |
| 3693 | } |
| 3694 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3695 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3696 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3697 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3698 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3699 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3700 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3701 | struct mesh_config cur_params; |
| 3702 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3703 | void *hdr; |
| 3704 | struct nlattr *pinfoattr; |
| 3705 | struct sk_buff *msg; |
| 3706 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3707 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3708 | return -EOPNOTSUPP; |
| 3709 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3710 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3711 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3712 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3713 | wdev_lock(wdev); |
| 3714 | /* If not connected, get default parameters */ |
| 3715 | if (!wdev->mesh_id_len) |
| 3716 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3717 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3718 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3719 | wdev_unlock(wdev); |
| 3720 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3721 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3722 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3723 | |
| 3724 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3725 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3726 | if (!msg) |
| 3727 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3728 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3729 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3730 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3731 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3732 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3733 | if (!pinfoattr) |
| 3734 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3735 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3736 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3737 | cur_params.dot11MeshRetryTimeout) || |
| 3738 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3739 | cur_params.dot11MeshConfirmTimeout) || |
| 3740 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3741 | cur_params.dot11MeshHoldingTimeout) || |
| 3742 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3743 | cur_params.dot11MeshMaxPeerLinks) || |
| 3744 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3745 | cur_params.dot11MeshMaxRetries) || |
| 3746 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 3747 | cur_params.dot11MeshTTL) || |
| 3748 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3749 | cur_params.element_ttl) || |
| 3750 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3751 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3752 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3753 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3754 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3755 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 3756 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3757 | cur_params.path_refresh_time) || |
| 3758 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3759 | cur_params.min_discovery_timeout) || |
| 3760 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3761 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 3762 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3763 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 3764 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3765 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 3766 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3767 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 3768 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3769 | cur_params.dot11MeshHWMPRootMode) || |
| 3770 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3771 | cur_params.dot11MeshHWMPRannInterval) || |
| 3772 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3773 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 3774 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 3775 | cur_params.dot11MeshForwarding) || |
| 3776 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3777 | cur_params.rssi_threshold) || |
| 3778 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3779 | cur_params.ht_opmode) || |
| 3780 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3781 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 3782 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3783 | cur_params.dot11MeshHWMProotInterval) || |
| 3784 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3785 | cur_params.dot11MeshHWMPconfirmationInterval)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3786 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3787 | nla_nest_end(msg, pinfoattr); |
| 3788 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3789 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3790 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3791 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3792 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3793 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3794 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3795 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3796 | } |
| 3797 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3798 | 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] | 3799 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3800 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3801 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3802 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3803 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3804 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3805 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3806 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3807 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3808 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3809 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3810 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3811 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3812 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3813 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3814 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3815 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3816 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3817 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3818 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3819 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 3820 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3821 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 3822 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3823 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3824 | }; |
| 3825 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3826 | static const struct nla_policy |
| 3827 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3828 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3829 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3830 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3831 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3832 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3833 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3834 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3835 | }; |
| 3836 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3837 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3838 | struct mesh_config *cfg, |
| 3839 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3840 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3841 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3842 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3843 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3844 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3845 | do {\ |
| 3846 | if (table[attr_num]) {\ |
| 3847 | cfg->param = nla_fn(table[attr_num]); \ |
| 3848 | mask |= (1 << (attr_num - 1)); \ |
| 3849 | } \ |
| 3850 | } while (0);\ |
| 3851 | |
| 3852 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3853 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3854 | return -EINVAL; |
| 3855 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3856 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3857 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3858 | return -EINVAL; |
| 3859 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3860 | /* This makes sure that there aren't more than 32 mesh config |
| 3861 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3862 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3863 | |
| 3864 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3865 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3866 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3867 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3868 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3869 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3870 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3871 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3872 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3873 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3874 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3875 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3876 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3877 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3878 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 3879 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3880 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3881 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3882 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3883 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 3884 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3885 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3886 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3887 | nla_get_u8); |
| 3888 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask, |
| 3889 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3890 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3891 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3892 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3893 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3894 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3895 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3896 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3897 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3898 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3899 | nla_get_u16); |
| 3900 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask, |
| 3901 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3902 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3903 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3904 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3905 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3906 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3907 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3908 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3909 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3910 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
| 3911 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3912 | nla_get_u16); |
| 3913 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 3914 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 3915 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 3916 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3917 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3918 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3919 | dot11MeshGateAnnouncementProtocol, mask, |
| 3920 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3921 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3922 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3923 | mask, NL80211_MESHCONF_FORWARDING, |
| 3924 | nla_get_u8); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 3925 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3926 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 3927 | nla_get_u32); |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3928 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3929 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 3930 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3931 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
| 3932 | mask, |
| 3933 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3934 | nla_get_u32); |
| 3935 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, |
| 3936 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 3937 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3938 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3939 | dot11MeshHWMPconfirmationInterval, mask, |
| 3940 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3941 | nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3942 | if (mask_out) |
| 3943 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3944 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3945 | return 0; |
| 3946 | |
| 3947 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3948 | } |
| 3949 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3950 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3951 | struct mesh_setup *setup) |
| 3952 | { |
| 3953 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3954 | |
| 3955 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3956 | return -EINVAL; |
| 3957 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3958 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3959 | nl80211_mesh_setup_params_policy)) |
| 3960 | return -EINVAL; |
| 3961 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3962 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 3963 | setup->sync_method = |
| 3964 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 3965 | IEEE80211_SYNC_METHOD_VENDOR : |
| 3966 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 3967 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3968 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3969 | setup->path_sel_proto = |
| 3970 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3971 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3972 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3973 | |
| 3974 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3975 | setup->path_metric = |
| 3976 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3977 | IEEE80211_PATH_METRIC_VENDOR : |
| 3978 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3979 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3980 | |
| 3981 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3982 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3983 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3984 | if (!is_valid_ie_attr(ieattr)) |
| 3985 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3986 | setup->ie = nla_data(ieattr); |
| 3987 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3988 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3989 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3990 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3991 | |
| 3992 | return 0; |
| 3993 | } |
| 3994 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3995 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3996 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3997 | { |
| 3998 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3999 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4000 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4001 | struct mesh_config cfg; |
| 4002 | u32 mask; |
| 4003 | int err; |
| 4004 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4005 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4006 | return -EOPNOTSUPP; |
| 4007 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4008 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4009 | return -EOPNOTSUPP; |
| 4010 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4011 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4012 | if (err) |
| 4013 | return err; |
| 4014 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4015 | wdev_lock(wdev); |
| 4016 | if (!wdev->mesh_id_len) |
| 4017 | err = -ENOLINK; |
| 4018 | |
| 4019 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4020 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4021 | |
| 4022 | wdev_unlock(wdev); |
| 4023 | |
| 4024 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4025 | } |
| 4026 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4027 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4028 | { |
| 4029 | struct sk_buff *msg; |
| 4030 | void *hdr = NULL; |
| 4031 | struct nlattr *nl_reg_rules; |
| 4032 | unsigned int i; |
| 4033 | int err = -EINVAL; |
| 4034 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4035 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4036 | |
| 4037 | if (!cfg80211_regdomain) |
| 4038 | goto out; |
| 4039 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4040 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4041 | if (!msg) { |
| 4042 | err = -ENOBUFS; |
| 4043 | goto out; |
| 4044 | } |
| 4045 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4046 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4047 | NL80211_CMD_GET_REG); |
| 4048 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4049 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4050 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4051 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 4052 | cfg80211_regdomain->alpha2) || |
| 4053 | (cfg80211_regdomain->dfs_region && |
| 4054 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, |
| 4055 | cfg80211_regdomain->dfs_region))) |
| 4056 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4057 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4058 | if (reg_last_request_cell_base() && |
| 4059 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4060 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4061 | goto nla_put_failure; |
| 4062 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4063 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4064 | if (!nl_reg_rules) |
| 4065 | goto nla_put_failure; |
| 4066 | |
| 4067 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 4068 | struct nlattr *nl_reg_rule; |
| 4069 | const struct ieee80211_reg_rule *reg_rule; |
| 4070 | const struct ieee80211_freq_range *freq_range; |
| 4071 | const struct ieee80211_power_rule *power_rule; |
| 4072 | |
| 4073 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 4074 | freq_range = ®_rule->freq_range; |
| 4075 | power_rule = ®_rule->power_rule; |
| 4076 | |
| 4077 | nl_reg_rule = nla_nest_start(msg, i); |
| 4078 | if (!nl_reg_rule) |
| 4079 | goto nla_put_failure; |
| 4080 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4081 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4082 | reg_rule->flags) || |
| 4083 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4084 | freq_range->start_freq_khz) || |
| 4085 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4086 | freq_range->end_freq_khz) || |
| 4087 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4088 | freq_range->max_bandwidth_khz) || |
| 4089 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4090 | power_rule->max_antenna_gain) || |
| 4091 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4092 | power_rule->max_eirp)) |
| 4093 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4094 | |
| 4095 | nla_nest_end(msg, nl_reg_rule); |
| 4096 | } |
| 4097 | |
| 4098 | nla_nest_end(msg, nl_reg_rules); |
| 4099 | |
| 4100 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4101 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4102 | goto out; |
| 4103 | |
| 4104 | nla_put_failure: |
| 4105 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4106 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4107 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4108 | err = -EMSGSIZE; |
| 4109 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4110 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4111 | return err; |
| 4112 | } |
| 4113 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4114 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4115 | { |
| 4116 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4117 | struct nlattr *nl_reg_rule; |
| 4118 | char *alpha2 = NULL; |
| 4119 | int rem_reg_rules = 0, r = 0; |
| 4120 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4121 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4122 | struct ieee80211_regdomain *rd = NULL; |
| 4123 | |
| 4124 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4125 | return -EINVAL; |
| 4126 | |
| 4127 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4128 | return -EINVAL; |
| 4129 | |
| 4130 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4131 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4132 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4133 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4134 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4135 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4136 | rem_reg_rules) { |
| 4137 | num_rules++; |
| 4138 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4139 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4140 | } |
| 4141 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4142 | mutex_lock(&cfg80211_mutex); |
| 4143 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4144 | if (!reg_is_valid_request(alpha2)) { |
| 4145 | r = -EINVAL; |
| 4146 | goto bad_reg; |
| 4147 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4148 | |
| 4149 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 4150 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 4151 | |
| 4152 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4153 | if (!rd) { |
| 4154 | r = -ENOMEM; |
| 4155 | goto bad_reg; |
| 4156 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4157 | |
| 4158 | rd->n_reg_rules = num_rules; |
| 4159 | rd->alpha2[0] = alpha2[0]; |
| 4160 | rd->alpha2[1] = alpha2[1]; |
| 4161 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4162 | /* |
| 4163 | * Disable DFS master mode if the DFS region was |
| 4164 | * not supported or known on this kernel. |
| 4165 | */ |
| 4166 | if (reg_supported_dfs_region(dfs_region)) |
| 4167 | rd->dfs_region = dfs_region; |
| 4168 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4169 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4170 | rem_reg_rules) { |
| 4171 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 4172 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4173 | reg_rule_policy); |
| 4174 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4175 | if (r) |
| 4176 | goto bad_reg; |
| 4177 | |
| 4178 | rule_idx++; |
| 4179 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4180 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4181 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4182 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4183 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | BUG_ON(rule_idx != num_rules); |
| 4187 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4188 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4189 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4190 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4191 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4192 | return r; |
| 4193 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4194 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4195 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4196 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4197 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4198 | } |
| 4199 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4200 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4201 | { |
| 4202 | struct nlattr *attr1, *attr2; |
| 4203 | int n_channels = 0, tmp1, tmp2; |
| 4204 | |
| 4205 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4206 | n_channels++; |
| 4207 | /* |
| 4208 | * Some hardware has a limited channel list for |
| 4209 | * scanning, and it is pretty much nonsensical |
| 4210 | * to scan for a channel twice, so disallow that |
| 4211 | * and don't require drivers to check that the |
| 4212 | * channel list they get isn't longer than what |
| 4213 | * they can scan, as long as they can scan all |
| 4214 | * the channels they registered at once. |
| 4215 | */ |
| 4216 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4217 | if (attr1 != attr2 && |
| 4218 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4219 | return 0; |
| 4220 | } |
| 4221 | |
| 4222 | return n_channels; |
| 4223 | } |
| 4224 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4225 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4226 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4227 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4228 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4229 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4230 | struct nlattr *attr; |
| 4231 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4232 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4233 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4234 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4235 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4236 | return -EINVAL; |
| 4237 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4238 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4239 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4240 | if (!rdev->ops->scan) |
| 4241 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4242 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4243 | if (rdev->scan_req) |
| 4244 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4245 | |
| 4246 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4247 | n_channels = validate_scan_freqs( |
| 4248 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4249 | if (!n_channels) |
| 4250 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4251 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4252 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4253 | n_channels = 0; |
| 4254 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4255 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4256 | if (wiphy->bands[band]) |
| 4257 | n_channels += wiphy->bands[band]->n_channels; |
| 4258 | } |
| 4259 | |
| 4260 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4261 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4262 | n_ssids++; |
| 4263 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4264 | if (n_ssids > wiphy->max_scan_ssids) |
| 4265 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4266 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4267 | if (info->attrs[NL80211_ATTR_IE]) |
| 4268 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4269 | else |
| 4270 | ie_len = 0; |
| 4271 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4272 | if (ie_len > wiphy->max_scan_ie_len) |
| 4273 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4274 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4275 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4276 | + sizeof(*request->ssids) * n_ssids |
| 4277 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4278 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4279 | if (!request) |
| 4280 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4281 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4282 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4283 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4284 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4285 | if (ie_len) { |
| 4286 | if (request->ssids) |
| 4287 | request->ie = (void *)(request->ssids + n_ssids); |
| 4288 | else |
| 4289 | request->ie = (void *)(request->channels + n_channels); |
| 4290 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4291 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4292 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4293 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4294 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4295 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4296 | struct ieee80211_channel *chan; |
| 4297 | |
| 4298 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4299 | |
| 4300 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4301 | err = -EINVAL; |
| 4302 | goto out_free; |
| 4303 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4304 | |
| 4305 | /* ignore disabled channels */ |
| 4306 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4307 | continue; |
| 4308 | |
| 4309 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4310 | i++; |
| 4311 | } |
| 4312 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4313 | enum ieee80211_band band; |
| 4314 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4315 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4316 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4317 | int j; |
| 4318 | if (!wiphy->bands[band]) |
| 4319 | continue; |
| 4320 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4321 | struct ieee80211_channel *chan; |
| 4322 | |
| 4323 | chan = &wiphy->bands[band]->channels[j]; |
| 4324 | |
| 4325 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4326 | continue; |
| 4327 | |
| 4328 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4329 | i++; |
| 4330 | } |
| 4331 | } |
| 4332 | } |
| 4333 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4334 | if (!i) { |
| 4335 | err = -EINVAL; |
| 4336 | goto out_free; |
| 4337 | } |
| 4338 | |
| 4339 | request->n_channels = i; |
| 4340 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4341 | i = 0; |
| 4342 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4343 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4344 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4345 | err = -EINVAL; |
| 4346 | goto out_free; |
| 4347 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4348 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4349 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4350 | i++; |
| 4351 | } |
| 4352 | } |
| 4353 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4354 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4355 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4356 | memcpy((void *)request->ie, |
| 4357 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4358 | request->ie_len); |
| 4359 | } |
| 4360 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4361 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4362 | if (wiphy->bands[i]) |
| 4363 | request->rates[i] = |
| 4364 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4365 | |
| 4366 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4367 | nla_for_each_nested(attr, |
| 4368 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4369 | tmp) { |
| 4370 | enum ieee80211_band band = nla_type(attr); |
| 4371 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4372 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4373 | err = -EINVAL; |
| 4374 | goto out_free; |
| 4375 | } |
| 4376 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4377 | nla_data(attr), |
| 4378 | nla_len(attr), |
| 4379 | &request->rates[band]); |
| 4380 | if (err) |
| 4381 | goto out_free; |
| 4382 | } |
| 4383 | } |
| 4384 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4385 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4386 | request->flags = nla_get_u32( |
| 4387 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4388 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4389 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4390 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4391 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4392 | err = -EOPNOTSUPP; |
| 4393 | goto out_free; |
| 4394 | } |
| 4395 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4396 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4397 | request->no_cck = |
| 4398 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4399 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4400 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4401 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4402 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4403 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4404 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4405 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4406 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4407 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4408 | nl80211_send_scan_start(rdev, wdev); |
| 4409 | if (wdev->netdev) |
| 4410 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4411 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4412 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4413 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4414 | kfree(request); |
| 4415 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4416 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4417 | return err; |
| 4418 | } |
| 4419 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4420 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4421 | struct genl_info *info) |
| 4422 | { |
| 4423 | struct cfg80211_sched_scan_request *request; |
| 4424 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4425 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4426 | struct nlattr *attr; |
| 4427 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4428 | 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] | 4429 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4430 | enum ieee80211_band band; |
| 4431 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4432 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4433 | |
| 4434 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4435 | !rdev->ops->sched_scan_start) |
| 4436 | return -EOPNOTSUPP; |
| 4437 | |
| 4438 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4439 | return -EINVAL; |
| 4440 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4441 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4442 | return -EINVAL; |
| 4443 | |
| 4444 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4445 | if (interval == 0) |
| 4446 | return -EINVAL; |
| 4447 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4448 | wiphy = &rdev->wiphy; |
| 4449 | |
| 4450 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4451 | n_channels = validate_scan_freqs( |
| 4452 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4453 | if (!n_channels) |
| 4454 | return -EINVAL; |
| 4455 | } else { |
| 4456 | n_channels = 0; |
| 4457 | |
| 4458 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4459 | if (wiphy->bands[band]) |
| 4460 | n_channels += wiphy->bands[band]->n_channels; |
| 4461 | } |
| 4462 | |
| 4463 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4464 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4465 | tmp) |
| 4466 | n_ssids++; |
| 4467 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4468 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4469 | return -EINVAL; |
| 4470 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4471 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4472 | nla_for_each_nested(attr, |
| 4473 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4474 | tmp) |
| 4475 | n_match_sets++; |
| 4476 | |
| 4477 | if (n_match_sets > wiphy->max_match_sets) |
| 4478 | return -EINVAL; |
| 4479 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4480 | if (info->attrs[NL80211_ATTR_IE]) |
| 4481 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4482 | else |
| 4483 | ie_len = 0; |
| 4484 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4485 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4486 | return -EINVAL; |
| 4487 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4488 | mutex_lock(&rdev->sched_scan_mtx); |
| 4489 | |
| 4490 | if (rdev->sched_scan_req) { |
| 4491 | err = -EINPROGRESS; |
| 4492 | goto out; |
| 4493 | } |
| 4494 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4495 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4496 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4497 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4498 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4499 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4500 | if (!request) { |
| 4501 | err = -ENOMEM; |
| 4502 | goto out; |
| 4503 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4504 | |
| 4505 | if (n_ssids) |
| 4506 | request->ssids = (void *)&request->channels[n_channels]; |
| 4507 | request->n_ssids = n_ssids; |
| 4508 | if (ie_len) { |
| 4509 | if (request->ssids) |
| 4510 | request->ie = (void *)(request->ssids + n_ssids); |
| 4511 | else |
| 4512 | request->ie = (void *)(request->channels + n_channels); |
| 4513 | } |
| 4514 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4515 | if (n_match_sets) { |
| 4516 | if (request->ie) |
| 4517 | request->match_sets = (void *)(request->ie + ie_len); |
| 4518 | else if (request->ssids) |
| 4519 | request->match_sets = |
| 4520 | (void *)(request->ssids + n_ssids); |
| 4521 | else |
| 4522 | request->match_sets = |
| 4523 | (void *)(request->channels + n_channels); |
| 4524 | } |
| 4525 | request->n_match_sets = n_match_sets; |
| 4526 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4527 | i = 0; |
| 4528 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4529 | /* user specified, bail out if channel not found */ |
| 4530 | nla_for_each_nested(attr, |
| 4531 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4532 | tmp) { |
| 4533 | struct ieee80211_channel *chan; |
| 4534 | |
| 4535 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4536 | |
| 4537 | if (!chan) { |
| 4538 | err = -EINVAL; |
| 4539 | goto out_free; |
| 4540 | } |
| 4541 | |
| 4542 | /* ignore disabled channels */ |
| 4543 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4544 | continue; |
| 4545 | |
| 4546 | request->channels[i] = chan; |
| 4547 | i++; |
| 4548 | } |
| 4549 | } else { |
| 4550 | /* all channels */ |
| 4551 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4552 | int j; |
| 4553 | if (!wiphy->bands[band]) |
| 4554 | continue; |
| 4555 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4556 | struct ieee80211_channel *chan; |
| 4557 | |
| 4558 | chan = &wiphy->bands[band]->channels[j]; |
| 4559 | |
| 4560 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4561 | continue; |
| 4562 | |
| 4563 | request->channels[i] = chan; |
| 4564 | i++; |
| 4565 | } |
| 4566 | } |
| 4567 | } |
| 4568 | |
| 4569 | if (!i) { |
| 4570 | err = -EINVAL; |
| 4571 | goto out_free; |
| 4572 | } |
| 4573 | |
| 4574 | request->n_channels = i; |
| 4575 | |
| 4576 | i = 0; |
| 4577 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4578 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4579 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4580 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4581 | err = -EINVAL; |
| 4582 | goto out_free; |
| 4583 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4584 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4585 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4586 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4587 | i++; |
| 4588 | } |
| 4589 | } |
| 4590 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4591 | i = 0; |
| 4592 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4593 | nla_for_each_nested(attr, |
| 4594 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4595 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4596 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4597 | |
| 4598 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4599 | nla_data(attr), nla_len(attr), |
| 4600 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 4601 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4602 | if (ssid) { |
| 4603 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4604 | err = -EINVAL; |
| 4605 | goto out_free; |
| 4606 | } |
| 4607 | memcpy(request->match_sets[i].ssid.ssid, |
| 4608 | nla_data(ssid), nla_len(ssid)); |
| 4609 | request->match_sets[i].ssid.ssid_len = |
| 4610 | nla_len(ssid); |
| 4611 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4612 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 4613 | if (rssi) |
| 4614 | request->rssi_thold = nla_get_u32(rssi); |
| 4615 | else |
| 4616 | request->rssi_thold = |
| 4617 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4618 | i++; |
| 4619 | } |
| 4620 | } |
| 4621 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4622 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4623 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4624 | memcpy((void *)request->ie, |
| 4625 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4626 | request->ie_len); |
| 4627 | } |
| 4628 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4629 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4630 | request->flags = nla_get_u32( |
| 4631 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4632 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4633 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4634 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4635 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4636 | err = -EOPNOTSUPP; |
| 4637 | goto out_free; |
| 4638 | } |
| 4639 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4640 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4641 | request->dev = dev; |
| 4642 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4643 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 4644 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4645 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4646 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4647 | if (!err) { |
| 4648 | rdev->sched_scan_req = request; |
| 4649 | nl80211_send_sched_scan(rdev, dev, |
| 4650 | NL80211_CMD_START_SCHED_SCAN); |
| 4651 | goto out; |
| 4652 | } |
| 4653 | |
| 4654 | out_free: |
| 4655 | kfree(request); |
| 4656 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4657 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4658 | return err; |
| 4659 | } |
| 4660 | |
| 4661 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4662 | struct genl_info *info) |
| 4663 | { |
| 4664 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4665 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4666 | |
| 4667 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4668 | !rdev->ops->sched_scan_stop) |
| 4669 | return -EOPNOTSUPP; |
| 4670 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4671 | mutex_lock(&rdev->sched_scan_mtx); |
| 4672 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4673 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4674 | |
| 4675 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4676 | } |
| 4677 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4678 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4679 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4680 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4681 | struct wireless_dev *wdev, |
| 4682 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4683 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4684 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4685 | void *hdr; |
| 4686 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4687 | |
| 4688 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4689 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4690 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4691 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4692 | if (!hdr) |
| 4693 | return -1; |
| 4694 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4695 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4696 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4697 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 4698 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 4699 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4700 | |
| 4701 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4702 | if (!bss) |
| 4703 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4704 | if ((!is_zero_ether_addr(res->bssid) && |
| 4705 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) || |
| 4706 | (res->information_elements && res->len_information_elements && |
| 4707 | nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4708 | res->len_information_elements, |
| 4709 | res->information_elements)) || |
| 4710 | (res->beacon_ies && res->len_beacon_ies && |
| 4711 | res->beacon_ies != res->information_elements && |
| 4712 | nla_put(msg, NL80211_BSS_BEACON_IES, |
| 4713 | res->len_beacon_ies, res->beacon_ies))) |
| 4714 | goto nla_put_failure; |
| 4715 | if (res->tsf && |
| 4716 | nla_put_u64(msg, NL80211_BSS_TSF, res->tsf)) |
| 4717 | goto nla_put_failure; |
| 4718 | if (res->beacon_interval && |
| 4719 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 4720 | goto nla_put_failure; |
| 4721 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 4722 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 4723 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4724 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 4725 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4726 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4727 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4728 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4729 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 4730 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4731 | break; |
| 4732 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4733 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 4734 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4735 | break; |
| 4736 | default: |
| 4737 | break; |
| 4738 | } |
| 4739 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4740 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4741 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4742 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4743 | if (intbss == wdev->current_bss && |
| 4744 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4745 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 4746 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4747 | break; |
| 4748 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4749 | if (intbss == wdev->current_bss && |
| 4750 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4751 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 4752 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4753 | break; |
| 4754 | default: |
| 4755 | break; |
| 4756 | } |
| 4757 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4758 | nla_nest_end(msg, bss); |
| 4759 | |
| 4760 | return genlmsg_end(msg, hdr); |
| 4761 | |
| 4762 | nla_put_failure: |
| 4763 | genlmsg_cancel(msg, hdr); |
| 4764 | return -EMSGSIZE; |
| 4765 | } |
| 4766 | |
| 4767 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4768 | struct netlink_callback *cb) |
| 4769 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4770 | struct cfg80211_registered_device *rdev; |
| 4771 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4772 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4773 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4774 | int start = cb->args[1], idx = 0; |
| 4775 | int err; |
| 4776 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4777 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4778 | if (err) |
| 4779 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4780 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4781 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4782 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4783 | wdev_lock(wdev); |
| 4784 | spin_lock_bh(&rdev->bss_lock); |
| 4785 | cfg80211_bss_expire(rdev); |
| 4786 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4787 | cb->seq = rdev->bss_generation; |
| 4788 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4789 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4790 | if (++idx <= start) |
| 4791 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4792 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4793 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4794 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4795 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4796 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4797 | } |
| 4798 | } |
| 4799 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4800 | spin_unlock_bh(&rdev->bss_lock); |
| 4801 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4802 | |
| 4803 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4804 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4805 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4806 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4807 | } |
| 4808 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4809 | 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] | 4810 | int flags, struct net_device *dev, |
| 4811 | struct survey_info *survey) |
| 4812 | { |
| 4813 | void *hdr; |
| 4814 | struct nlattr *infoattr; |
| 4815 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4816 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4817 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4818 | if (!hdr) |
| 4819 | return -ENOMEM; |
| 4820 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4821 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 4822 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4823 | |
| 4824 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4825 | if (!infoattr) |
| 4826 | goto nla_put_failure; |
| 4827 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4828 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4829 | survey->channel->center_freq)) |
| 4830 | goto nla_put_failure; |
| 4831 | |
| 4832 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 4833 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 4834 | goto nla_put_failure; |
| 4835 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 4836 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 4837 | goto nla_put_failure; |
| 4838 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 4839 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4840 | survey->channel_time)) |
| 4841 | goto nla_put_failure; |
| 4842 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 4843 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4844 | survey->channel_time_busy)) |
| 4845 | goto nla_put_failure; |
| 4846 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 4847 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4848 | survey->channel_time_ext_busy)) |
| 4849 | goto nla_put_failure; |
| 4850 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 4851 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4852 | survey->channel_time_rx)) |
| 4853 | goto nla_put_failure; |
| 4854 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 4855 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4856 | survey->channel_time_tx)) |
| 4857 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4858 | |
| 4859 | nla_nest_end(msg, infoattr); |
| 4860 | |
| 4861 | return genlmsg_end(msg, hdr); |
| 4862 | |
| 4863 | nla_put_failure: |
| 4864 | genlmsg_cancel(msg, hdr); |
| 4865 | return -EMSGSIZE; |
| 4866 | } |
| 4867 | |
| 4868 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4869 | struct netlink_callback *cb) |
| 4870 | { |
| 4871 | struct survey_info survey; |
| 4872 | struct cfg80211_registered_device *dev; |
| 4873 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4874 | int survey_idx = cb->args[1]; |
| 4875 | int res; |
| 4876 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4877 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4878 | if (res) |
| 4879 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4880 | |
| 4881 | if (!dev->ops->dump_survey) { |
| 4882 | res = -EOPNOTSUPP; |
| 4883 | goto out_err; |
| 4884 | } |
| 4885 | |
| 4886 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4887 | struct ieee80211_channel *chan; |
| 4888 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4889 | res = rdev_dump_survey(dev, netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4890 | if (res == -ENOENT) |
| 4891 | break; |
| 4892 | if (res) |
| 4893 | goto out_err; |
| 4894 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4895 | /* Survey without a channel doesn't make sense */ |
| 4896 | if (!survey.channel) { |
| 4897 | res = -EINVAL; |
| 4898 | goto out; |
| 4899 | } |
| 4900 | |
| 4901 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4902 | survey.channel->center_freq); |
| 4903 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4904 | survey_idx++; |
| 4905 | continue; |
| 4906 | } |
| 4907 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4908 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4909 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4910 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4911 | netdev, |
| 4912 | &survey) < 0) |
| 4913 | goto out; |
| 4914 | survey_idx++; |
| 4915 | } |
| 4916 | |
| 4917 | out: |
| 4918 | cb->args[1] = survey_idx; |
| 4919 | res = skb->len; |
| 4920 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4921 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4922 | return res; |
| 4923 | } |
| 4924 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4925 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4926 | { |
| 4927 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4928 | NL80211_WPA_VERSION_2)); |
| 4929 | } |
| 4930 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4931 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4932 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4933 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4934 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4935 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4936 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 4937 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4938 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4939 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4940 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4941 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4942 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4943 | return -EINVAL; |
| 4944 | |
| 4945 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4946 | return -EINVAL; |
| 4947 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4948 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4949 | return -EINVAL; |
| 4950 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4951 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4952 | return -EINVAL; |
| 4953 | |
| 4954 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4955 | return -EINVAL; |
| 4956 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4957 | err = nl80211_parse_key(info, &key); |
| 4958 | if (err) |
| 4959 | return err; |
| 4960 | |
| 4961 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4962 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4963 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4964 | if (!key.p.key || !key.p.key_len) |
| 4965 | return -EINVAL; |
| 4966 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4967 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4968 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4969 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4970 | return -EINVAL; |
| 4971 | if (key.idx > 4) |
| 4972 | return -EINVAL; |
| 4973 | } else { |
| 4974 | key.p.key_len = 0; |
| 4975 | key.p.key = NULL; |
| 4976 | } |
| 4977 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4978 | if (key.idx >= 0) { |
| 4979 | int i; |
| 4980 | bool ok = false; |
| 4981 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4982 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4983 | ok = true; |
| 4984 | break; |
| 4985 | } |
| 4986 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4987 | if (!ok) |
| 4988 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4989 | } |
| 4990 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4991 | if (!rdev->ops->auth) |
| 4992 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4993 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4994 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4995 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4996 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4997 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4998 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4999 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5000 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5001 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5002 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5003 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5004 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5005 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5006 | |
| 5007 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5008 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5009 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5010 | } |
| 5011 | |
| 5012 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5013 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5014 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5015 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5016 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5017 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5018 | return -EINVAL; |
| 5019 | |
| 5020 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5021 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5022 | return -EINVAL; |
| 5023 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5024 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5025 | /* need to include at least Auth Transaction and Status Code */ |
| 5026 | if (sae_data_len < 4) |
| 5027 | return -EINVAL; |
| 5028 | } |
| 5029 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5030 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5031 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5032 | /* |
| 5033 | * Since we no longer track auth state, ignore |
| 5034 | * requests to only change local state. |
| 5035 | */ |
| 5036 | if (local_state_change) |
| 5037 | return 0; |
| 5038 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5039 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5040 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5041 | key.p.key, key.p.key_len, key.idx, |
| 5042 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5043 | } |
| 5044 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5045 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5046 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5047 | struct cfg80211_crypto_settings *settings, |
| 5048 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5049 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5050 | memset(settings, 0, sizeof(*settings)); |
| 5051 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5052 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5053 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5054 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5055 | u16 proto; |
| 5056 | proto = nla_get_u16( |
| 5057 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5058 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5059 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5060 | proto != ETH_P_PAE) |
| 5061 | return -EINVAL; |
| 5062 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5063 | settings->control_port_no_encrypt = true; |
| 5064 | } else |
| 5065 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5066 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5067 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5068 | void *data; |
| 5069 | int len, i; |
| 5070 | |
| 5071 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5072 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5073 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5074 | |
| 5075 | if (len % sizeof(u32)) |
| 5076 | return -EINVAL; |
| 5077 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5078 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5079 | return -EINVAL; |
| 5080 | |
| 5081 | memcpy(settings->ciphers_pairwise, data, len); |
| 5082 | |
| 5083 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5084 | if (!cfg80211_supported_cipher_suite( |
| 5085 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5086 | settings->ciphers_pairwise[i])) |
| 5087 | return -EINVAL; |
| 5088 | } |
| 5089 | |
| 5090 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5091 | settings->cipher_group = |
| 5092 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5093 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5094 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5095 | return -EINVAL; |
| 5096 | } |
| 5097 | |
| 5098 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5099 | settings->wpa_versions = |
| 5100 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5101 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5102 | return -EINVAL; |
| 5103 | } |
| 5104 | |
| 5105 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5106 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5107 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5108 | |
| 5109 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5110 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5111 | settings->n_akm_suites = len / sizeof(u32); |
| 5112 | |
| 5113 | if (len % sizeof(u32)) |
| 5114 | return -EINVAL; |
| 5115 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5116 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5117 | return -EINVAL; |
| 5118 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5119 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | return 0; |
| 5123 | } |
| 5124 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5125 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5126 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5127 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5128 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5129 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5130 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5131 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5132 | int err, ssid_len, ie_len = 0; |
| 5133 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5134 | u32 flags = 0; |
| 5135 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5136 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5137 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5138 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5139 | return -EINVAL; |
| 5140 | |
| 5141 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5142 | !info->attrs[NL80211_ATTR_SSID] || |
| 5143 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5144 | return -EINVAL; |
| 5145 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5146 | if (!rdev->ops->assoc) |
| 5147 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5148 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5149 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5150 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5151 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5152 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5153 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5154 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5155 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5156 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5157 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5158 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5159 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5160 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5161 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5162 | |
| 5163 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5164 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5165 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5166 | } |
| 5167 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5168 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5169 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5170 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5171 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5172 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5173 | else if (mfp != NL80211_MFP_NO) |
| 5174 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5175 | } |
| 5176 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5177 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5178 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5179 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5180 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5181 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5182 | |
| 5183 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5184 | ht_capa_mask = |
| 5185 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5186 | |
| 5187 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5188 | if (!ht_capa_mask) |
| 5189 | return -EINVAL; |
| 5190 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5191 | } |
| 5192 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5193 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5194 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5195 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5196 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5197 | &crypto, flags, ht_capa, |
| 5198 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5199 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5200 | return err; |
| 5201 | } |
| 5202 | |
| 5203 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5204 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5205 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5206 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5207 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5208 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5209 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5210 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5211 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5212 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5213 | return -EINVAL; |
| 5214 | |
| 5215 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5216 | return -EINVAL; |
| 5217 | |
| 5218 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5219 | return -EINVAL; |
| 5220 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5221 | if (!rdev->ops->deauth) |
| 5222 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5223 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5224 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5225 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5226 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5227 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5228 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5229 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5230 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5231 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5232 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5233 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5234 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5235 | |
| 5236 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5237 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5238 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5239 | } |
| 5240 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5241 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5242 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5243 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5244 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5245 | } |
| 5246 | |
| 5247 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5248 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5249 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5250 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5251 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5252 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5253 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5254 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5255 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5256 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5257 | return -EINVAL; |
| 5258 | |
| 5259 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5260 | return -EINVAL; |
| 5261 | |
| 5262 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5263 | return -EINVAL; |
| 5264 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5265 | if (!rdev->ops->disassoc) |
| 5266 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5267 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5268 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5269 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5270 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5271 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5272 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5273 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5274 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5275 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5276 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5277 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5278 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5279 | |
| 5280 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5281 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5282 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5283 | } |
| 5284 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5285 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5286 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5287 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5288 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5289 | } |
| 5290 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5291 | static bool |
| 5292 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5293 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5294 | int rateval) |
| 5295 | { |
| 5296 | struct wiphy *wiphy = &rdev->wiphy; |
| 5297 | bool found = false; |
| 5298 | int band, i; |
| 5299 | |
| 5300 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5301 | struct ieee80211_supported_band *sband; |
| 5302 | |
| 5303 | sband = wiphy->bands[band]; |
| 5304 | if (!sband) |
| 5305 | continue; |
| 5306 | |
| 5307 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5308 | if (sband->bitrates[i].bitrate == rateval) { |
| 5309 | mcast_rate[band] = i + 1; |
| 5310 | found = true; |
| 5311 | break; |
| 5312 | } |
| 5313 | } |
| 5314 | } |
| 5315 | |
| 5316 | return found; |
| 5317 | } |
| 5318 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5319 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5320 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5321 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5322 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5323 | struct cfg80211_ibss_params ibss; |
| 5324 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5325 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5326 | int err; |
| 5327 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5328 | memset(&ibss, 0, sizeof(ibss)); |
| 5329 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5330 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5331 | return -EINVAL; |
| 5332 | |
| 5333 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5334 | !info->attrs[NL80211_ATTR_SSID] || |
| 5335 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5336 | return -EINVAL; |
| 5337 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5338 | ibss.beacon_interval = 100; |
| 5339 | |
| 5340 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5341 | ibss.beacon_interval = |
| 5342 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5343 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5344 | return -EINVAL; |
| 5345 | } |
| 5346 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5347 | if (!rdev->ops->join_ibss) |
| 5348 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5349 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5350 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5351 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5352 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5353 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5354 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5355 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5356 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5357 | |
| 5358 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5359 | return -EINVAL; |
| 5360 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5361 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5362 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5363 | |
| 5364 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5365 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5366 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5367 | } |
| 5368 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5369 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5370 | enum nl80211_channel_type channel_type; |
| 5371 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5372 | if (!nl80211_valid_channel_type(info, &channel_type)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5373 | return -EINVAL; |
| 5374 | |
| 5375 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5376 | !(wiphy->features & NL80211_FEATURE_HT_IBSS)) |
| 5377 | return -EINVAL; |
| 5378 | |
| 5379 | ibss.channel_type = channel_type; |
| 5380 | } else { |
| 5381 | ibss.channel_type = NL80211_CHAN_NO_HT; |
| 5382 | } |
| 5383 | |
| 5384 | ibss.channel = rdev_freq_to_chan(rdev, |
| 5385 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 5386 | ibss.channel_type); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5387 | if (!ibss.channel || |
| 5388 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5389 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5390 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5391 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5392 | /* Both channels should be able to initiate communication */ |
| 5393 | if ((ibss.channel_type == NL80211_CHAN_HT40PLUS || |
| 5394 | ibss.channel_type == NL80211_CHAN_HT40MINUS) && |
| 5395 | !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel, |
| 5396 | ibss.channel_type)) |
| 5397 | return -EINVAL; |
| 5398 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5399 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5400 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5401 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5402 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5403 | u8 *rates = |
| 5404 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5405 | int n_rates = |
| 5406 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5407 | struct ieee80211_supported_band *sband = |
| 5408 | wiphy->bands[ibss.channel->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5409 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5410 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5411 | &ibss.basic_rates); |
| 5412 | if (err) |
| 5413 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5414 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5415 | |
| 5416 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5417 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5418 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5419 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5420 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5421 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5422 | bool no_ht = false; |
| 5423 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5424 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5425 | info->attrs[NL80211_ATTR_KEYS], |
| 5426 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5427 | if (IS_ERR(connkeys)) |
| 5428 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5429 | |
| 5430 | if ((ibss.channel_type != NL80211_CHAN_NO_HT) && no_ht) { |
| 5431 | kfree(connkeys); |
| 5432 | return -EINVAL; |
| 5433 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5434 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5435 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5436 | ibss.control_port = |
| 5437 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5438 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5439 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5440 | if (err) |
| 5441 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5442 | return err; |
| 5443 | } |
| 5444 | |
| 5445 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5446 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5447 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5448 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5449 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5450 | if (!rdev->ops->leave_ibss) |
| 5451 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5452 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5453 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5454 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5455 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5456 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5457 | } |
| 5458 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 5459 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 5460 | { |
| 5461 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5462 | struct net_device *dev = info->user_ptr[1]; |
| 5463 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 5464 | u32 nla_rate; |
| 5465 | int err; |
| 5466 | |
| 5467 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5468 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5469 | return -EOPNOTSUPP; |
| 5470 | |
| 5471 | if (!rdev->ops->set_mcast_rate) |
| 5472 | return -EOPNOTSUPP; |
| 5473 | |
| 5474 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 5475 | |
| 5476 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 5477 | return -EINVAL; |
| 5478 | |
| 5479 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 5480 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 5481 | return -EINVAL; |
| 5482 | |
| 5483 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 5484 | |
| 5485 | return err; |
| 5486 | } |
| 5487 | |
| 5488 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5489 | #ifdef CONFIG_NL80211_TESTMODE |
| 5490 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5491 | .name = "testmode", |
| 5492 | }; |
| 5493 | |
| 5494 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5495 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5496 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5497 | int err; |
| 5498 | |
| 5499 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5500 | return -EINVAL; |
| 5501 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5502 | err = -EOPNOTSUPP; |
| 5503 | if (rdev->ops->testmode_cmd) { |
| 5504 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5505 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5506 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5507 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5508 | rdev->testmode_info = NULL; |
| 5509 | } |
| 5510 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5511 | return err; |
| 5512 | } |
| 5513 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5514 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5515 | struct netlink_callback *cb) |
| 5516 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5517 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5518 | int err; |
| 5519 | long phy_idx; |
| 5520 | void *data = NULL; |
| 5521 | int data_len = 0; |
| 5522 | |
| 5523 | if (cb->args[0]) { |
| 5524 | /* |
| 5525 | * 0 is a valid index, but not valid for args[0], |
| 5526 | * so we need to offset by 1. |
| 5527 | */ |
| 5528 | phy_idx = cb->args[0] - 1; |
| 5529 | } else { |
| 5530 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5531 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5532 | nl80211_policy); |
| 5533 | if (err) |
| 5534 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5535 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5536 | mutex_lock(&cfg80211_mutex); |
| 5537 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 5538 | nl80211_fam.attrbuf); |
| 5539 | if (IS_ERR(rdev)) { |
| 5540 | mutex_unlock(&cfg80211_mutex); |
| 5541 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5542 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5543 | phy_idx = rdev->wiphy_idx; |
| 5544 | rdev = NULL; |
| 5545 | mutex_unlock(&cfg80211_mutex); |
| 5546 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5547 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 5548 | cb->args[1] = |
| 5549 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 5550 | } |
| 5551 | |
| 5552 | if (cb->args[1]) { |
| 5553 | data = nla_data((void *)cb->args[1]); |
| 5554 | data_len = nla_len((void *)cb->args[1]); |
| 5555 | } |
| 5556 | |
| 5557 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5558 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 5559 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5560 | mutex_unlock(&cfg80211_mutex); |
| 5561 | return -ENOENT; |
| 5562 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5563 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5564 | mutex_unlock(&cfg80211_mutex); |
| 5565 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5566 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5567 | err = -EOPNOTSUPP; |
| 5568 | goto out_err; |
| 5569 | } |
| 5570 | |
| 5571 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5572 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5573 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5574 | NL80211_CMD_TESTMODE); |
| 5575 | struct nlattr *tmdata; |
| 5576 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5577 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5578 | genlmsg_cancel(skb, hdr); |
| 5579 | break; |
| 5580 | } |
| 5581 | |
| 5582 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5583 | if (!tmdata) { |
| 5584 | genlmsg_cancel(skb, hdr); |
| 5585 | break; |
| 5586 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5587 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5588 | nla_nest_end(skb, tmdata); |
| 5589 | |
| 5590 | if (err == -ENOBUFS || err == -ENOENT) { |
| 5591 | genlmsg_cancel(skb, hdr); |
| 5592 | break; |
| 5593 | } else if (err) { |
| 5594 | genlmsg_cancel(skb, hdr); |
| 5595 | goto out_err; |
| 5596 | } |
| 5597 | |
| 5598 | genlmsg_end(skb, hdr); |
| 5599 | } |
| 5600 | |
| 5601 | err = skb->len; |
| 5602 | /* see above */ |
| 5603 | cb->args[0] = phy_idx + 1; |
| 5604 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5605 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5606 | return err; |
| 5607 | } |
| 5608 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5609 | static struct sk_buff * |
| 5610 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5611 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5612 | { |
| 5613 | struct sk_buff *skb; |
| 5614 | void *hdr; |
| 5615 | struct nlattr *data; |
| 5616 | |
| 5617 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5618 | if (!skb) |
| 5619 | return NULL; |
| 5620 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5621 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5622 | if (!hdr) { |
| 5623 | kfree_skb(skb); |
| 5624 | return NULL; |
| 5625 | } |
| 5626 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5627 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 5628 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5629 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5630 | |
| 5631 | ((void **)skb->cb)[0] = rdev; |
| 5632 | ((void **)skb->cb)[1] = hdr; |
| 5633 | ((void **)skb->cb)[2] = data; |
| 5634 | |
| 5635 | return skb; |
| 5636 | |
| 5637 | nla_put_failure: |
| 5638 | kfree_skb(skb); |
| 5639 | return NULL; |
| 5640 | } |
| 5641 | |
| 5642 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5643 | int approxlen) |
| 5644 | { |
| 5645 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5646 | |
| 5647 | if (WARN_ON(!rdev->testmode_info)) |
| 5648 | return NULL; |
| 5649 | |
| 5650 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5651 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5652 | rdev->testmode_info->snd_seq, |
| 5653 | GFP_KERNEL); |
| 5654 | } |
| 5655 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5656 | |
| 5657 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5658 | { |
| 5659 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5660 | void *hdr = ((void **)skb->cb)[1]; |
| 5661 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5662 | |
| 5663 | if (WARN_ON(!rdev->testmode_info)) { |
| 5664 | kfree_skb(skb); |
| 5665 | return -EINVAL; |
| 5666 | } |
| 5667 | |
| 5668 | nla_nest_end(skb, data); |
| 5669 | genlmsg_end(skb, hdr); |
| 5670 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5671 | } |
| 5672 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5673 | |
| 5674 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5675 | int approxlen, gfp_t gfp) |
| 5676 | { |
| 5677 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5678 | |
| 5679 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5680 | } |
| 5681 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5682 | |
| 5683 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5684 | { |
| 5685 | void *hdr = ((void **)skb->cb)[1]; |
| 5686 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5687 | |
| 5688 | nla_nest_end(skb, data); |
| 5689 | genlmsg_end(skb, hdr); |
| 5690 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5691 | } |
| 5692 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5693 | #endif |
| 5694 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5695 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5696 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5697 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5698 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5699 | struct cfg80211_connect_params connect; |
| 5700 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5701 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5702 | int err; |
| 5703 | |
| 5704 | memset(&connect, 0, sizeof(connect)); |
| 5705 | |
| 5706 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5707 | return -EINVAL; |
| 5708 | |
| 5709 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5710 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5711 | return -EINVAL; |
| 5712 | |
| 5713 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5714 | connect.auth_type = |
| 5715 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5716 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 5717 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5718 | return -EINVAL; |
| 5719 | } else |
| 5720 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5721 | |
| 5722 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5723 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5724 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5725 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5726 | if (err) |
| 5727 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5728 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5729 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5730 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5731 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5732 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5733 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5734 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 5735 | connect.bg_scan_period = -1; |
| 5736 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 5737 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 5738 | connect.bg_scan_period = |
| 5739 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 5740 | } |
| 5741 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5742 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5743 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5744 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5745 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5746 | |
| 5747 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5748 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5749 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5750 | } |
| 5751 | |
| 5752 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5753 | connect.channel = |
| 5754 | ieee80211_get_channel(wiphy, |
| 5755 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5756 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5757 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5758 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5759 | } |
| 5760 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5761 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5762 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 5763 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5764 | if (IS_ERR(connkeys)) |
| 5765 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5766 | } |
| 5767 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5768 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5769 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5770 | |
| 5771 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5772 | memcpy(&connect.ht_capa_mask, |
| 5773 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5774 | sizeof(connect.ht_capa_mask)); |
| 5775 | |
| 5776 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5777 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 5778 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5779 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5780 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5781 | memcpy(&connect.ht_capa, |
| 5782 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5783 | sizeof(connect.ht_capa)); |
| 5784 | } |
| 5785 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5786 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5787 | if (err) |
| 5788 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5789 | return err; |
| 5790 | } |
| 5791 | |
| 5792 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5793 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5795 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5796 | u16 reason; |
| 5797 | |
| 5798 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5799 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5800 | else |
| 5801 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5802 | |
| 5803 | if (reason == 0) |
| 5804 | return -EINVAL; |
| 5805 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5806 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5807 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5808 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5809 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5810 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5811 | } |
| 5812 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5813 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5814 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5815 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5816 | struct net *net; |
| 5817 | int err; |
| 5818 | u32 pid; |
| 5819 | |
| 5820 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5821 | return -EINVAL; |
| 5822 | |
| 5823 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5824 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5825 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5826 | if (IS_ERR(net)) |
| 5827 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5828 | |
| 5829 | err = 0; |
| 5830 | |
| 5831 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5832 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5833 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5834 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5835 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5836 | return err; |
| 5837 | } |
| 5838 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5839 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5840 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5841 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5842 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5843 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5844 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5845 | struct cfg80211_pmksa pmksa; |
| 5846 | |
| 5847 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5848 | |
| 5849 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5850 | return -EINVAL; |
| 5851 | |
| 5852 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5853 | return -EINVAL; |
| 5854 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5855 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5856 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5857 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5858 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5859 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5860 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5861 | |
| 5862 | switch (info->genlhdr->cmd) { |
| 5863 | case NL80211_CMD_SET_PMKSA: |
| 5864 | rdev_ops = rdev->ops->set_pmksa; |
| 5865 | break; |
| 5866 | case NL80211_CMD_DEL_PMKSA: |
| 5867 | rdev_ops = rdev->ops->del_pmksa; |
| 5868 | break; |
| 5869 | default: |
| 5870 | WARN_ON(1); |
| 5871 | break; |
| 5872 | } |
| 5873 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5874 | if (!rdev_ops) |
| 5875 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5876 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5877 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5878 | } |
| 5879 | |
| 5880 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5881 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5882 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5883 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5884 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5885 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5886 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5887 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5888 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5889 | if (!rdev->ops->flush_pmksa) |
| 5890 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5891 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5892 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5893 | } |
| 5894 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5895 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5896 | { |
| 5897 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5898 | struct net_device *dev = info->user_ptr[1]; |
| 5899 | u8 action_code, dialog_token; |
| 5900 | u16 status_code; |
| 5901 | u8 *peer; |
| 5902 | |
| 5903 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5904 | !rdev->ops->tdls_mgmt) |
| 5905 | return -EOPNOTSUPP; |
| 5906 | |
| 5907 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5908 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5909 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5910 | !info->attrs[NL80211_ATTR_IE] || |
| 5911 | !info->attrs[NL80211_ATTR_MAC]) |
| 5912 | return -EINVAL; |
| 5913 | |
| 5914 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5915 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5916 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5917 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5918 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5919 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 5920 | dialog_token, status_code, |
| 5921 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5922 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5923 | } |
| 5924 | |
| 5925 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5926 | { |
| 5927 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5928 | struct net_device *dev = info->user_ptr[1]; |
| 5929 | enum nl80211_tdls_operation operation; |
| 5930 | u8 *peer; |
| 5931 | |
| 5932 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5933 | !rdev->ops->tdls_oper) |
| 5934 | return -EOPNOTSUPP; |
| 5935 | |
| 5936 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5937 | !info->attrs[NL80211_ATTR_MAC]) |
| 5938 | return -EINVAL; |
| 5939 | |
| 5940 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5941 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5942 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5943 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5944 | } |
| 5945 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5946 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5947 | struct genl_info *info) |
| 5948 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5949 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 5950 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5951 | struct ieee80211_channel *chan; |
| 5952 | struct sk_buff *msg; |
| 5953 | void *hdr; |
| 5954 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5955 | u32 freq, duration; |
| 5956 | int err; |
| 5957 | |
| 5958 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5959 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5960 | return -EINVAL; |
| 5961 | |
| 5962 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5963 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5964 | if (!rdev->ops->remain_on_channel || |
| 5965 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5966 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5967 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 5968 | /* |
| 5969 | * We should be on that channel for at least a minimum amount of |
| 5970 | * time (10ms) but no longer than the driver supports. |
| 5971 | */ |
| 5972 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 5973 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 5974 | return -EINVAL; |
| 5975 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5976 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame^] | 5977 | !nl80211_valid_channel_type(info, NULL)) |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5978 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5979 | |
| 5980 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame^] | 5981 | chan = rdev_freq_to_chan(rdev, freq, NL80211_CHAN_NO_HT); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5982 | if (chan == NULL) |
| 5983 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5984 | |
| 5985 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5986 | if (!msg) |
| 5987 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5988 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5989 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5990 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5991 | |
| 5992 | if (IS_ERR(hdr)) { |
| 5993 | err = PTR_ERR(hdr); |
| 5994 | goto free_msg; |
| 5995 | } |
| 5996 | |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame^] | 5997 | err = rdev_remain_on_channel(rdev, wdev, chan, duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5998 | |
| 5999 | if (err) |
| 6000 | goto free_msg; |
| 6001 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6002 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6003 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6004 | |
| 6005 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6006 | |
| 6007 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6008 | |
| 6009 | nla_put_failure: |
| 6010 | err = -ENOBUFS; |
| 6011 | free_msg: |
| 6012 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6013 | return err; |
| 6014 | } |
| 6015 | |
| 6016 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6017 | struct genl_info *info) |
| 6018 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6019 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6020 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6021 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6022 | |
| 6023 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6024 | return -EINVAL; |
| 6025 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6026 | if (!rdev->ops->cancel_remain_on_channel) |
| 6027 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6028 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6029 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6030 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6031 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6032 | } |
| 6033 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6034 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6035 | u8 *rates, u8 rates_len) |
| 6036 | { |
| 6037 | u8 i; |
| 6038 | u32 mask = 0; |
| 6039 | |
| 6040 | for (i = 0; i < rates_len; i++) { |
| 6041 | int rate = (rates[i] & 0x7f) * 5; |
| 6042 | int ridx; |
| 6043 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6044 | struct ieee80211_rate *srate = |
| 6045 | &sband->bitrates[ridx]; |
| 6046 | if (rate == srate->bitrate) { |
| 6047 | mask |= 1 << ridx; |
| 6048 | break; |
| 6049 | } |
| 6050 | } |
| 6051 | if (ridx == sband->n_bitrates) |
| 6052 | return 0; /* rate not found */ |
| 6053 | } |
| 6054 | |
| 6055 | return mask; |
| 6056 | } |
| 6057 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6058 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6059 | u8 *rates, u8 rates_len, |
| 6060 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6061 | { |
| 6062 | u8 i; |
| 6063 | |
| 6064 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6065 | |
| 6066 | for (i = 0; i < rates_len; i++) { |
| 6067 | int ridx, rbit; |
| 6068 | |
| 6069 | ridx = rates[i] / 8; |
| 6070 | rbit = BIT(rates[i] % 8); |
| 6071 | |
| 6072 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6073 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6074 | return false; |
| 6075 | |
| 6076 | /* check availability */ |
| 6077 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6078 | mcs[ridx] |= rbit; |
| 6079 | else |
| 6080 | return false; |
| 6081 | } |
| 6082 | |
| 6083 | return true; |
| 6084 | } |
| 6085 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6086 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6087 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6088 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6089 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6090 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6091 | }; |
| 6092 | |
| 6093 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6094 | struct genl_info *info) |
| 6095 | { |
| 6096 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6098 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6099 | int rem, i; |
| 6100 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6101 | struct nlattr *tx_rates; |
| 6102 | struct ieee80211_supported_band *sband; |
| 6103 | |
| 6104 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6105 | return -EINVAL; |
| 6106 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6107 | if (!rdev->ops->set_bitrate_mask) |
| 6108 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6109 | |
| 6110 | memset(&mask, 0, sizeof(mask)); |
| 6111 | /* Default to all rates enabled */ |
| 6112 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6113 | sband = rdev->wiphy.bands[i]; |
| 6114 | mask.control[i].legacy = |
| 6115 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6116 | if (sband) |
| 6117 | memcpy(mask.control[i].mcs, |
| 6118 | sband->ht_cap.mcs.rx_mask, |
| 6119 | sizeof(mask.control[i].mcs)); |
| 6120 | else |
| 6121 | memset(mask.control[i].mcs, 0, |
| 6122 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6123 | } |
| 6124 | |
| 6125 | /* |
| 6126 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6127 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6128 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6129 | 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] | 6130 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6131 | { |
| 6132 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6133 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6134 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6135 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6136 | if (sband == NULL) |
| 6137 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6138 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6139 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6140 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6141 | mask.control[band].legacy = rateset_to_mask( |
| 6142 | sband, |
| 6143 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6144 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6145 | if ((mask.control[band].legacy == 0) && |
| 6146 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6147 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6148 | } |
| 6149 | if (tb[NL80211_TXRATE_MCS]) { |
| 6150 | if (!ht_rateset_to_mask( |
| 6151 | sband, |
| 6152 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6153 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6154 | mask.control[band].mcs)) |
| 6155 | return -EINVAL; |
| 6156 | } |
| 6157 | |
| 6158 | if (mask.control[band].legacy == 0) { |
| 6159 | /* don't allow empty legacy rates if HT |
| 6160 | * is not even supported. */ |
| 6161 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6162 | return -EINVAL; |
| 6163 | |
| 6164 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6165 | if (mask.control[band].mcs[i]) |
| 6166 | break; |
| 6167 | |
| 6168 | /* legacy and mcs rates may not be both empty */ |
| 6169 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6170 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6171 | } |
| 6172 | } |
| 6173 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6174 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6175 | } |
| 6176 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6177 | 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] | 6178 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6179 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6180 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6181 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6182 | |
| 6183 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6184 | return -EINVAL; |
| 6185 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6186 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6187 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6188 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6189 | switch (wdev->iftype) { |
| 6190 | case NL80211_IFTYPE_STATION: |
| 6191 | case NL80211_IFTYPE_ADHOC: |
| 6192 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6193 | case NL80211_IFTYPE_AP: |
| 6194 | case NL80211_IFTYPE_AP_VLAN: |
| 6195 | case NL80211_IFTYPE_MESH_POINT: |
| 6196 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6197 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6198 | break; |
| 6199 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6200 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6201 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6202 | |
| 6203 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6204 | if (!rdev->ops->mgmt_tx) |
| 6205 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6206 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6207 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6208 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6209 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6210 | } |
| 6211 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6212 | 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] | 6213 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6215 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6216 | struct ieee80211_channel *chan; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6217 | u32 freq; |
| 6218 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6219 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6220 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6221 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6222 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6223 | bool offchan, no_cck, dont_wait_for_ack; |
| 6224 | |
| 6225 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6226 | |
| 6227 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 6228 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6229 | return -EINVAL; |
| 6230 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6231 | if (!rdev->ops->mgmt_tx) |
| 6232 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6233 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6234 | switch (wdev->iftype) { |
| 6235 | case NL80211_IFTYPE_STATION: |
| 6236 | case NL80211_IFTYPE_ADHOC: |
| 6237 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6238 | case NL80211_IFTYPE_AP: |
| 6239 | case NL80211_IFTYPE_AP_VLAN: |
| 6240 | case NL80211_IFTYPE_MESH_POINT: |
| 6241 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6242 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6243 | break; |
| 6244 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6245 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6246 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6247 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6248 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6249 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6250 | return -EINVAL; |
| 6251 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6252 | |
| 6253 | /* |
| 6254 | * We should wait on the channel for at least a minimum amount |
| 6255 | * of time (10ms) but no longer than the driver supports. |
| 6256 | */ |
| 6257 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6258 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6259 | return -EINVAL; |
| 6260 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6261 | } |
| 6262 | |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame^] | 6263 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 6264 | !nl80211_valid_channel_type(info, NULL)) |
| 6265 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6266 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6267 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6268 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6269 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6270 | return -EINVAL; |
| 6271 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6272 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6273 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6274 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame^] | 6275 | chan = rdev_freq_to_chan(rdev, freq, NL80211_CHAN_NO_HT); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6276 | if (chan == NULL) |
| 6277 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6278 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6279 | if (!dont_wait_for_ack) { |
| 6280 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6281 | if (!msg) |
| 6282 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6283 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6284 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6285 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6286 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6287 | if (IS_ERR(hdr)) { |
| 6288 | err = PTR_ERR(hdr); |
| 6289 | goto free_msg; |
| 6290 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6291 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6292 | |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame^] | 6293 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6294 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6295 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6296 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6297 | if (err) |
| 6298 | goto free_msg; |
| 6299 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6300 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6301 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6302 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6303 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6304 | genlmsg_end(msg, hdr); |
| 6305 | return genlmsg_reply(msg, info); |
| 6306 | } |
| 6307 | |
| 6308 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6309 | |
| 6310 | nla_put_failure: |
| 6311 | err = -ENOBUFS; |
| 6312 | free_msg: |
| 6313 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6314 | return err; |
| 6315 | } |
| 6316 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6317 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6318 | { |
| 6319 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6320 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6321 | u64 cookie; |
| 6322 | |
| 6323 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6324 | return -EINVAL; |
| 6325 | |
| 6326 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6327 | return -EOPNOTSUPP; |
| 6328 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6329 | switch (wdev->iftype) { |
| 6330 | case NL80211_IFTYPE_STATION: |
| 6331 | case NL80211_IFTYPE_ADHOC: |
| 6332 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6333 | case NL80211_IFTYPE_AP: |
| 6334 | case NL80211_IFTYPE_AP_VLAN: |
| 6335 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6336 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6337 | break; |
| 6338 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6339 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6340 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6341 | |
| 6342 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6343 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6344 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6345 | } |
| 6346 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6347 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6348 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6349 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6350 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6351 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6352 | u8 ps_state; |
| 6353 | bool state; |
| 6354 | int err; |
| 6355 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6356 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6357 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6358 | |
| 6359 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6360 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6361 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6362 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6363 | |
| 6364 | wdev = dev->ieee80211_ptr; |
| 6365 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6366 | if (!rdev->ops->set_power_mgmt) |
| 6367 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6368 | |
| 6369 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6370 | |
| 6371 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6372 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6373 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6374 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6375 | if (!err) |
| 6376 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6377 | return err; |
| 6378 | } |
| 6379 | |
| 6380 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6381 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6382 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6383 | enum nl80211_ps_state ps_state; |
| 6384 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6385 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6386 | struct sk_buff *msg; |
| 6387 | void *hdr; |
| 6388 | int err; |
| 6389 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6390 | wdev = dev->ieee80211_ptr; |
| 6391 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6392 | if (!rdev->ops->set_power_mgmt) |
| 6393 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6394 | |
| 6395 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6396 | if (!msg) |
| 6397 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6398 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6399 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6400 | NL80211_CMD_GET_POWER_SAVE); |
| 6401 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6402 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6403 | goto free_msg; |
| 6404 | } |
| 6405 | |
| 6406 | if (wdev->ps) |
| 6407 | ps_state = NL80211_PS_ENABLED; |
| 6408 | else |
| 6409 | ps_state = NL80211_PS_DISABLED; |
| 6410 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6411 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6412 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6413 | |
| 6414 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6415 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6416 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6417 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6418 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6419 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6420 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6421 | return err; |
| 6422 | } |
| 6423 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6424 | static struct nla_policy |
| 6425 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6426 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6427 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6428 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6429 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 6430 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 6431 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6432 | }; |
| 6433 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6434 | static int nl80211_set_cqm_txe(struct genl_info *info, |
| 6435 | u32 rate, u32 pkts, u32 intvl) |
| 6436 | { |
| 6437 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6438 | struct wireless_dev *wdev; |
| 6439 | struct net_device *dev = info->user_ptr[1]; |
| 6440 | |
| 6441 | if ((rate < 0 || rate > 100) || |
| 6442 | (intvl < 0 || intvl > NL80211_CQM_TXE_MAX_INTVL)) |
| 6443 | return -EINVAL; |
| 6444 | |
| 6445 | wdev = dev->ieee80211_ptr; |
| 6446 | |
| 6447 | if (!rdev->ops->set_cqm_txe_config) |
| 6448 | return -EOPNOTSUPP; |
| 6449 | |
| 6450 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 6451 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6452 | return -EOPNOTSUPP; |
| 6453 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6454 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6455 | } |
| 6456 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6457 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6458 | s32 threshold, u32 hysteresis) |
| 6459 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6460 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6461 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6462 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6463 | |
| 6464 | if (threshold > 0) |
| 6465 | return -EINVAL; |
| 6466 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6467 | wdev = dev->ieee80211_ptr; |
| 6468 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6469 | if (!rdev->ops->set_cqm_rssi_config) |
| 6470 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6471 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6472 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6473 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6474 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6475 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6476 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6477 | } |
| 6478 | |
| 6479 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6480 | { |
| 6481 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6482 | struct nlattr *cqm; |
| 6483 | int err; |
| 6484 | |
| 6485 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6486 | if (!cqm) { |
| 6487 | err = -EINVAL; |
| 6488 | goto out; |
| 6489 | } |
| 6490 | |
| 6491 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6492 | nl80211_attr_cqm_policy); |
| 6493 | if (err) |
| 6494 | goto out; |
| 6495 | |
| 6496 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6497 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6498 | s32 threshold; |
| 6499 | u32 hysteresis; |
| 6500 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6501 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6502 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6503 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 6504 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 6505 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 6506 | u32 rate, pkts, intvl; |
| 6507 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 6508 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 6509 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 6510 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6511 | } else |
| 6512 | err = -EINVAL; |
| 6513 | |
| 6514 | out: |
| 6515 | return err; |
| 6516 | } |
| 6517 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6518 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6519 | { |
| 6520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6521 | struct net_device *dev = info->user_ptr[1]; |
| 6522 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6523 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6524 | int err; |
| 6525 | |
| 6526 | /* start with default */ |
| 6527 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6528 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6529 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6530 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6531 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6532 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6533 | if (err) |
| 6534 | return err; |
| 6535 | } |
| 6536 | |
| 6537 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6538 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 6539 | return -EINVAL; |
| 6540 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6541 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6542 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6543 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 6544 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6545 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 6546 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6547 | return -EINVAL; |
| 6548 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6549 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 6550 | /* parse additional setup parameters if given */ |
| 6551 | err = nl80211_parse_mesh_setup(info, &setup); |
| 6552 | if (err) |
| 6553 | return err; |
| 6554 | } |
| 6555 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6556 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6557 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 6558 | |
| 6559 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 6560 | !nl80211_valid_channel_type(info, &channel_type)) |
| 6561 | return -EINVAL; |
| 6562 | |
| 6563 | setup.channel = rdev_freq_to_chan(rdev, |
| 6564 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 6565 | channel_type); |
| 6566 | if (!setup.channel) |
| 6567 | return -EINVAL; |
| 6568 | setup.channel_type = channel_type; |
| 6569 | } else { |
| 6570 | /* cfg80211_join_mesh() will sort it out */ |
| 6571 | setup.channel = NULL; |
| 6572 | } |
| 6573 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6574 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6575 | } |
| 6576 | |
| 6577 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6578 | { |
| 6579 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6580 | struct net_device *dev = info->user_ptr[1]; |
| 6581 | |
| 6582 | return cfg80211_leave_mesh(rdev, dev); |
| 6583 | } |
| 6584 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6585 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6586 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6587 | { |
| 6588 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6589 | struct sk_buff *msg; |
| 6590 | void *hdr; |
| 6591 | |
| 6592 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6593 | return -EOPNOTSUPP; |
| 6594 | |
| 6595 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6596 | if (!msg) |
| 6597 | return -ENOMEM; |
| 6598 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6599 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6600 | NL80211_CMD_GET_WOWLAN); |
| 6601 | if (!hdr) |
| 6602 | goto nla_put_failure; |
| 6603 | |
| 6604 | if (rdev->wowlan) { |
| 6605 | struct nlattr *nl_wowlan; |
| 6606 | |
| 6607 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 6608 | if (!nl_wowlan) |
| 6609 | goto nla_put_failure; |
| 6610 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6611 | if ((rdev->wowlan->any && |
| 6612 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 6613 | (rdev->wowlan->disconnect && |
| 6614 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 6615 | (rdev->wowlan->magic_pkt && |
| 6616 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 6617 | (rdev->wowlan->gtk_rekey_failure && |
| 6618 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 6619 | (rdev->wowlan->eap_identity_req && |
| 6620 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 6621 | (rdev->wowlan->four_way_handshake && |
| 6622 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 6623 | (rdev->wowlan->rfkill_release && |
| 6624 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 6625 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6626 | if (rdev->wowlan->n_patterns) { |
| 6627 | struct nlattr *nl_pats, *nl_pat; |
| 6628 | int i, pat_len; |
| 6629 | |
| 6630 | nl_pats = nla_nest_start(msg, |
| 6631 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 6632 | if (!nl_pats) |
| 6633 | goto nla_put_failure; |
| 6634 | |
| 6635 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 6636 | nl_pat = nla_nest_start(msg, i + 1); |
| 6637 | if (!nl_pat) |
| 6638 | goto nla_put_failure; |
| 6639 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6640 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 6641 | DIV_ROUND_UP(pat_len, 8), |
| 6642 | rdev->wowlan->patterns[i].mask) || |
| 6643 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 6644 | pat_len, |
| 6645 | rdev->wowlan->patterns[i].pattern)) |
| 6646 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6647 | nla_nest_end(msg, nl_pat); |
| 6648 | } |
| 6649 | nla_nest_end(msg, nl_pats); |
| 6650 | } |
| 6651 | |
| 6652 | nla_nest_end(msg, nl_wowlan); |
| 6653 | } |
| 6654 | |
| 6655 | genlmsg_end(msg, hdr); |
| 6656 | return genlmsg_reply(msg, info); |
| 6657 | |
| 6658 | nla_put_failure: |
| 6659 | nlmsg_free(msg); |
| 6660 | return -ENOBUFS; |
| 6661 | } |
| 6662 | |
| 6663 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6664 | { |
| 6665 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6666 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6667 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6668 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6669 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 6670 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6671 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6672 | |
| 6673 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6674 | return -EOPNOTSUPP; |
| 6675 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6676 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 6677 | cfg80211_rdev_free_wowlan(rdev); |
| 6678 | rdev->wowlan = NULL; |
| 6679 | goto set_wakeup; |
| 6680 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6681 | |
| 6682 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 6683 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6684 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6685 | nl80211_wowlan_policy); |
| 6686 | if (err) |
| 6687 | return err; |
| 6688 | |
| 6689 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 6690 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 6691 | return -EINVAL; |
| 6692 | new_triggers.any = true; |
| 6693 | } |
| 6694 | |
| 6695 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 6696 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 6697 | return -EINVAL; |
| 6698 | new_triggers.disconnect = true; |
| 6699 | } |
| 6700 | |
| 6701 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 6702 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 6703 | return -EINVAL; |
| 6704 | new_triggers.magic_pkt = true; |
| 6705 | } |
| 6706 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 6707 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 6708 | return -EINVAL; |
| 6709 | |
| 6710 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 6711 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 6712 | return -EINVAL; |
| 6713 | new_triggers.gtk_rekey_failure = true; |
| 6714 | } |
| 6715 | |
| 6716 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 6717 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 6718 | return -EINVAL; |
| 6719 | new_triggers.eap_identity_req = true; |
| 6720 | } |
| 6721 | |
| 6722 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 6723 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 6724 | return -EINVAL; |
| 6725 | new_triggers.four_way_handshake = true; |
| 6726 | } |
| 6727 | |
| 6728 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 6729 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 6730 | return -EINVAL; |
| 6731 | new_triggers.rfkill_release = true; |
| 6732 | } |
| 6733 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6734 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 6735 | struct nlattr *pat; |
| 6736 | int n_patterns = 0; |
| 6737 | int rem, pat_len, mask_len; |
| 6738 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6739 | |
| 6740 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6741 | rem) |
| 6742 | n_patterns++; |
| 6743 | if (n_patterns > wowlan->n_patterns) |
| 6744 | return -EINVAL; |
| 6745 | |
| 6746 | new_triggers.patterns = kcalloc(n_patterns, |
| 6747 | sizeof(new_triggers.patterns[0]), |
| 6748 | GFP_KERNEL); |
| 6749 | if (!new_triggers.patterns) |
| 6750 | return -ENOMEM; |
| 6751 | |
| 6752 | new_triggers.n_patterns = n_patterns; |
| 6753 | i = 0; |
| 6754 | |
| 6755 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6756 | rem) { |
| 6757 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6758 | nla_data(pat), nla_len(pat), NULL); |
| 6759 | err = -EINVAL; |
| 6760 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6761 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6762 | goto error; |
| 6763 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6764 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6765 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6766 | mask_len) |
| 6767 | goto error; |
| 6768 | if (pat_len > wowlan->pattern_max_len || |
| 6769 | pat_len < wowlan->pattern_min_len) |
| 6770 | goto error; |
| 6771 | |
| 6772 | new_triggers.patterns[i].mask = |
| 6773 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6774 | if (!new_triggers.patterns[i].mask) { |
| 6775 | err = -ENOMEM; |
| 6776 | goto error; |
| 6777 | } |
| 6778 | new_triggers.patterns[i].pattern = |
| 6779 | new_triggers.patterns[i].mask + mask_len; |
| 6780 | memcpy(new_triggers.patterns[i].mask, |
| 6781 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6782 | mask_len); |
| 6783 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6784 | memcpy(new_triggers.patterns[i].pattern, |
| 6785 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6786 | pat_len); |
| 6787 | i++; |
| 6788 | } |
| 6789 | } |
| 6790 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6791 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 6792 | if (!ntrig) { |
| 6793 | err = -ENOMEM; |
| 6794 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6795 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6796 | cfg80211_rdev_free_wowlan(rdev); |
| 6797 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6798 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6799 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6800 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6801 | rdev_set_wakeup(rdev, rdev->wowlan); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6802 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6803 | return 0; |
| 6804 | error: |
| 6805 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6806 | kfree(new_triggers.patterns[i].mask); |
| 6807 | kfree(new_triggers.patterns); |
| 6808 | return err; |
| 6809 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6810 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6811 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6812 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6813 | { |
| 6814 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6815 | struct net_device *dev = info->user_ptr[1]; |
| 6816 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6817 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6818 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6819 | int err; |
| 6820 | |
| 6821 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6822 | return -EINVAL; |
| 6823 | |
| 6824 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6825 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6826 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6827 | nl80211_rekey_policy); |
| 6828 | if (err) |
| 6829 | return err; |
| 6830 | |
| 6831 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6832 | return -ERANGE; |
| 6833 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6834 | return -ERANGE; |
| 6835 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6836 | return -ERANGE; |
| 6837 | |
| 6838 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6839 | NL80211_KEK_LEN); |
| 6840 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6841 | NL80211_KCK_LEN); |
| 6842 | memcpy(rekey_data.replay_ctr, |
| 6843 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6844 | NL80211_REPLAY_CTR_LEN); |
| 6845 | |
| 6846 | wdev_lock(wdev); |
| 6847 | if (!wdev->current_bss) { |
| 6848 | err = -ENOTCONN; |
| 6849 | goto out; |
| 6850 | } |
| 6851 | |
| 6852 | if (!rdev->ops->set_rekey_data) { |
| 6853 | err = -EOPNOTSUPP; |
| 6854 | goto out; |
| 6855 | } |
| 6856 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6857 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6858 | out: |
| 6859 | wdev_unlock(wdev); |
| 6860 | return err; |
| 6861 | } |
| 6862 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6863 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6864 | struct genl_info *info) |
| 6865 | { |
| 6866 | struct net_device *dev = info->user_ptr[1]; |
| 6867 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6868 | |
| 6869 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6870 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6871 | return -EINVAL; |
| 6872 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6873 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6874 | return -EBUSY; |
| 6875 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6876 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6877 | return 0; |
| 6878 | } |
| 6879 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6880 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6881 | struct genl_info *info) |
| 6882 | { |
| 6883 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6884 | struct net_device *dev = info->user_ptr[1]; |
| 6885 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6886 | struct sk_buff *msg; |
| 6887 | void *hdr; |
| 6888 | const u8 *addr; |
| 6889 | u64 cookie; |
| 6890 | int err; |
| 6891 | |
| 6892 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6893 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6894 | return -EOPNOTSUPP; |
| 6895 | |
| 6896 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6897 | return -EINVAL; |
| 6898 | |
| 6899 | if (!rdev->ops->probe_client) |
| 6900 | return -EOPNOTSUPP; |
| 6901 | |
| 6902 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6903 | if (!msg) |
| 6904 | return -ENOMEM; |
| 6905 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6906 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6907 | NL80211_CMD_PROBE_CLIENT); |
| 6908 | |
| 6909 | if (IS_ERR(hdr)) { |
| 6910 | err = PTR_ERR(hdr); |
| 6911 | goto free_msg; |
| 6912 | } |
| 6913 | |
| 6914 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6915 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6916 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6917 | if (err) |
| 6918 | goto free_msg; |
| 6919 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6920 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6921 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6922 | |
| 6923 | genlmsg_end(msg, hdr); |
| 6924 | |
| 6925 | return genlmsg_reply(msg, info); |
| 6926 | |
| 6927 | nla_put_failure: |
| 6928 | err = -ENOBUFS; |
| 6929 | free_msg: |
| 6930 | nlmsg_free(msg); |
| 6931 | return err; |
| 6932 | } |
| 6933 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6934 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 6935 | { |
| 6936 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 6937 | struct cfg80211_beacon_registration *reg, *nreg; |
| 6938 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6939 | |
| 6940 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 6941 | return -EOPNOTSUPP; |
| 6942 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 6943 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 6944 | if (!nreg) |
| 6945 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6946 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 6947 | /* First, check if already registered. */ |
| 6948 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 6949 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 6950 | if (reg->nlportid == info->snd_portid) { |
| 6951 | rv = -EALREADY; |
| 6952 | goto out_err; |
| 6953 | } |
| 6954 | } |
| 6955 | /* Add it to the list */ |
| 6956 | nreg->nlportid = info->snd_portid; |
| 6957 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 6958 | |
| 6959 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6960 | |
| 6961 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 6962 | out_err: |
| 6963 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 6964 | kfree(nreg); |
| 6965 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6966 | } |
| 6967 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6968 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 6969 | { |
| 6970 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6971 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6972 | int err; |
| 6973 | |
| 6974 | if (!rdev->ops->start_p2p_device) |
| 6975 | return -EOPNOTSUPP; |
| 6976 | |
| 6977 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 6978 | return -EOPNOTSUPP; |
| 6979 | |
| 6980 | if (wdev->p2p_started) |
| 6981 | return 0; |
| 6982 | |
| 6983 | mutex_lock(&rdev->devlist_mtx); |
| 6984 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 6985 | mutex_unlock(&rdev->devlist_mtx); |
| 6986 | if (err) |
| 6987 | return err; |
| 6988 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 6989 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6990 | if (err) |
| 6991 | return err; |
| 6992 | |
| 6993 | wdev->p2p_started = true; |
| 6994 | mutex_lock(&rdev->devlist_mtx); |
| 6995 | rdev->opencount++; |
| 6996 | mutex_unlock(&rdev->devlist_mtx); |
| 6997 | |
| 6998 | return 0; |
| 6999 | } |
| 7000 | |
| 7001 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 7002 | { |
| 7003 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7004 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7005 | |
| 7006 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 7007 | return -EOPNOTSUPP; |
| 7008 | |
| 7009 | if (!rdev->ops->stop_p2p_device) |
| 7010 | return -EOPNOTSUPP; |
| 7011 | |
| 7012 | if (!wdev->p2p_started) |
| 7013 | return 0; |
| 7014 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 7015 | rdev_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7016 | wdev->p2p_started = false; |
| 7017 | |
| 7018 | mutex_lock(&rdev->devlist_mtx); |
| 7019 | rdev->opencount--; |
| 7020 | mutex_unlock(&rdev->devlist_mtx); |
| 7021 | |
| 7022 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 7023 | rdev->scan_req->aborted = true; |
| 7024 | ___cfg80211_scan_done(rdev, true); |
| 7025 | } |
| 7026 | |
| 7027 | return 0; |
| 7028 | } |
| 7029 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7030 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 7031 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 7032 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7033 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 7034 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 7035 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7036 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7037 | /* 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] | 7038 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 7039 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7040 | |
| 7041 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7042 | struct genl_info *info) |
| 7043 | { |
| 7044 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7045 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7046 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7047 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 7048 | |
| 7049 | if (rtnl) |
| 7050 | rtnl_lock(); |
| 7051 | |
| 7052 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 7053 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7054 | if (IS_ERR(rdev)) { |
| 7055 | if (rtnl) |
| 7056 | rtnl_unlock(); |
| 7057 | return PTR_ERR(rdev); |
| 7058 | } |
| 7059 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7060 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7061 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7062 | mutex_lock(&cfg80211_mutex); |
| 7063 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7064 | info->attrs); |
| 7065 | if (IS_ERR(wdev)) { |
| 7066 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7067 | if (rtnl) |
| 7068 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7069 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7070 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7071 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7072 | dev = wdev->netdev; |
| 7073 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7074 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7075 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7076 | if (!dev) { |
| 7077 | mutex_unlock(&cfg80211_mutex); |
| 7078 | if (rtnl) |
| 7079 | rtnl_unlock(); |
| 7080 | return -EINVAL; |
| 7081 | } |
| 7082 | |
| 7083 | info->user_ptr[1] = dev; |
| 7084 | } else { |
| 7085 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7086 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7087 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7088 | if (dev) { |
| 7089 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7090 | !netif_running(dev)) { |
| 7091 | mutex_unlock(&cfg80211_mutex); |
| 7092 | if (rtnl) |
| 7093 | rtnl_unlock(); |
| 7094 | return -ENETDOWN; |
| 7095 | } |
| 7096 | |
| 7097 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7098 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7099 | if (!wdev->p2p_started) { |
| 7100 | mutex_unlock(&cfg80211_mutex); |
| 7101 | if (rtnl) |
| 7102 | rtnl_unlock(); |
| 7103 | return -ENETDOWN; |
| 7104 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7105 | } |
| 7106 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7107 | cfg80211_lock_rdev(rdev); |
| 7108 | |
| 7109 | mutex_unlock(&cfg80211_mutex); |
| 7110 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7111 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7112 | } |
| 7113 | |
| 7114 | return 0; |
| 7115 | } |
| 7116 | |
| 7117 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7118 | struct genl_info *info) |
| 7119 | { |
| 7120 | if (info->user_ptr[0]) |
| 7121 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7122 | if (info->user_ptr[1]) { |
| 7123 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7124 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7125 | |
| 7126 | if (wdev->netdev) |
| 7127 | dev_put(wdev->netdev); |
| 7128 | } else { |
| 7129 | dev_put(info->user_ptr[1]); |
| 7130 | } |
| 7131 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7132 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7133 | rtnl_unlock(); |
| 7134 | } |
| 7135 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7136 | static struct genl_ops nl80211_ops[] = { |
| 7137 | { |
| 7138 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7139 | .doit = nl80211_get_wiphy, |
| 7140 | .dumpit = nl80211_dump_wiphy, |
| 7141 | .policy = nl80211_policy, |
| 7142 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7143 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7144 | }, |
| 7145 | { |
| 7146 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7147 | .doit = nl80211_set_wiphy, |
| 7148 | .policy = nl80211_policy, |
| 7149 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7150 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7151 | }, |
| 7152 | { |
| 7153 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7154 | .doit = nl80211_get_interface, |
| 7155 | .dumpit = nl80211_dump_interface, |
| 7156 | .policy = nl80211_policy, |
| 7157 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7158 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7159 | }, |
| 7160 | { |
| 7161 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7162 | .doit = nl80211_set_interface, |
| 7163 | .policy = nl80211_policy, |
| 7164 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7165 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7166 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7167 | }, |
| 7168 | { |
| 7169 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7170 | .doit = nl80211_new_interface, |
| 7171 | .policy = nl80211_policy, |
| 7172 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7173 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7174 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7175 | }, |
| 7176 | { |
| 7177 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7178 | .doit = nl80211_del_interface, |
| 7179 | .policy = nl80211_policy, |
| 7180 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7181 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7182 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7183 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7184 | { |
| 7185 | .cmd = NL80211_CMD_GET_KEY, |
| 7186 | .doit = nl80211_get_key, |
| 7187 | .policy = nl80211_policy, |
| 7188 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7189 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7190 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7191 | }, |
| 7192 | { |
| 7193 | .cmd = NL80211_CMD_SET_KEY, |
| 7194 | .doit = nl80211_set_key, |
| 7195 | .policy = nl80211_policy, |
| 7196 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7197 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7198 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7199 | }, |
| 7200 | { |
| 7201 | .cmd = NL80211_CMD_NEW_KEY, |
| 7202 | .doit = nl80211_new_key, |
| 7203 | .policy = nl80211_policy, |
| 7204 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7205 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7206 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7207 | }, |
| 7208 | { |
| 7209 | .cmd = NL80211_CMD_DEL_KEY, |
| 7210 | .doit = nl80211_del_key, |
| 7211 | .policy = nl80211_policy, |
| 7212 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7213 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7214 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7215 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7216 | { |
| 7217 | .cmd = NL80211_CMD_SET_BEACON, |
| 7218 | .policy = nl80211_policy, |
| 7219 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7220 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7221 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7222 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7223 | }, |
| 7224 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7225 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7226 | .policy = nl80211_policy, |
| 7227 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7228 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7229 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7230 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7231 | }, |
| 7232 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7233 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7234 | .policy = nl80211_policy, |
| 7235 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7236 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7237 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7238 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7239 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7240 | { |
| 7241 | .cmd = NL80211_CMD_GET_STATION, |
| 7242 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7243 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7244 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7245 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7246 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7247 | }, |
| 7248 | { |
| 7249 | .cmd = NL80211_CMD_SET_STATION, |
| 7250 | .doit = nl80211_set_station, |
| 7251 | .policy = nl80211_policy, |
| 7252 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7253 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7254 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7255 | }, |
| 7256 | { |
| 7257 | .cmd = NL80211_CMD_NEW_STATION, |
| 7258 | .doit = nl80211_new_station, |
| 7259 | .policy = nl80211_policy, |
| 7260 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7261 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7262 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7263 | }, |
| 7264 | { |
| 7265 | .cmd = NL80211_CMD_DEL_STATION, |
| 7266 | .doit = nl80211_del_station, |
| 7267 | .policy = nl80211_policy, |
| 7268 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7269 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7270 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7271 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7272 | { |
| 7273 | .cmd = NL80211_CMD_GET_MPATH, |
| 7274 | .doit = nl80211_get_mpath, |
| 7275 | .dumpit = nl80211_dump_mpath, |
| 7276 | .policy = nl80211_policy, |
| 7277 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7278 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7279 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7280 | }, |
| 7281 | { |
| 7282 | .cmd = NL80211_CMD_SET_MPATH, |
| 7283 | .doit = nl80211_set_mpath, |
| 7284 | .policy = nl80211_policy, |
| 7285 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7286 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7287 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7288 | }, |
| 7289 | { |
| 7290 | .cmd = NL80211_CMD_NEW_MPATH, |
| 7291 | .doit = nl80211_new_mpath, |
| 7292 | .policy = nl80211_policy, |
| 7293 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7294 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7295 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7296 | }, |
| 7297 | { |
| 7298 | .cmd = NL80211_CMD_DEL_MPATH, |
| 7299 | .doit = nl80211_del_mpath, |
| 7300 | .policy = nl80211_policy, |
| 7301 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7302 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7303 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7304 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7305 | { |
| 7306 | .cmd = NL80211_CMD_SET_BSS, |
| 7307 | .doit = nl80211_set_bss, |
| 7308 | .policy = nl80211_policy, |
| 7309 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7310 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7311 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7312 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7313 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7314 | .cmd = NL80211_CMD_GET_REG, |
| 7315 | .doit = nl80211_get_reg, |
| 7316 | .policy = nl80211_policy, |
| 7317 | /* can be retrieved by unprivileged users */ |
| 7318 | }, |
| 7319 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7320 | .cmd = NL80211_CMD_SET_REG, |
| 7321 | .doit = nl80211_set_reg, |
| 7322 | .policy = nl80211_policy, |
| 7323 | .flags = GENL_ADMIN_PERM, |
| 7324 | }, |
| 7325 | { |
| 7326 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 7327 | .doit = nl80211_req_set_reg, |
| 7328 | .policy = nl80211_policy, |
| 7329 | .flags = GENL_ADMIN_PERM, |
| 7330 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7331 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7332 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 7333 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7334 | .policy = nl80211_policy, |
| 7335 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7336 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7337 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7338 | }, |
| 7339 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7340 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 7341 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7342 | .policy = nl80211_policy, |
| 7343 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7344 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7345 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7346 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 7347 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7348 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 7349 | .doit = nl80211_trigger_scan, |
| 7350 | .policy = nl80211_policy, |
| 7351 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7352 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7353 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7354 | }, |
| 7355 | { |
| 7356 | .cmd = NL80211_CMD_GET_SCAN, |
| 7357 | .policy = nl80211_policy, |
| 7358 | .dumpit = nl80211_dump_scan, |
| 7359 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7360 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7361 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 7362 | .doit = nl80211_start_sched_scan, |
| 7363 | .policy = nl80211_policy, |
| 7364 | .flags = GENL_ADMIN_PERM, |
| 7365 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7366 | NL80211_FLAG_NEED_RTNL, |
| 7367 | }, |
| 7368 | { |
| 7369 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 7370 | .doit = nl80211_stop_sched_scan, |
| 7371 | .policy = nl80211_policy, |
| 7372 | .flags = GENL_ADMIN_PERM, |
| 7373 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7374 | NL80211_FLAG_NEED_RTNL, |
| 7375 | }, |
| 7376 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7377 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 7378 | .doit = nl80211_authenticate, |
| 7379 | .policy = nl80211_policy, |
| 7380 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7381 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7382 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7383 | }, |
| 7384 | { |
| 7385 | .cmd = NL80211_CMD_ASSOCIATE, |
| 7386 | .doit = nl80211_associate, |
| 7387 | .policy = nl80211_policy, |
| 7388 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7389 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7390 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7391 | }, |
| 7392 | { |
| 7393 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 7394 | .doit = nl80211_deauthenticate, |
| 7395 | .policy = nl80211_policy, |
| 7396 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7397 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7398 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7399 | }, |
| 7400 | { |
| 7401 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 7402 | .doit = nl80211_disassociate, |
| 7403 | .policy = nl80211_policy, |
| 7404 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7405 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7406 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7407 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7408 | { |
| 7409 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 7410 | .doit = nl80211_join_ibss, |
| 7411 | .policy = nl80211_policy, |
| 7412 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7413 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7414 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7415 | }, |
| 7416 | { |
| 7417 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 7418 | .doit = nl80211_leave_ibss, |
| 7419 | .policy = nl80211_policy, |
| 7420 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7421 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7422 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7423 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7424 | #ifdef CONFIG_NL80211_TESTMODE |
| 7425 | { |
| 7426 | .cmd = NL80211_CMD_TESTMODE, |
| 7427 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7428 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7429 | .policy = nl80211_policy, |
| 7430 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7431 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7432 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7433 | }, |
| 7434 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7435 | { |
| 7436 | .cmd = NL80211_CMD_CONNECT, |
| 7437 | .doit = nl80211_connect, |
| 7438 | .policy = nl80211_policy, |
| 7439 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7440 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7441 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7442 | }, |
| 7443 | { |
| 7444 | .cmd = NL80211_CMD_DISCONNECT, |
| 7445 | .doit = nl80211_disconnect, |
| 7446 | .policy = nl80211_policy, |
| 7447 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7448 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7449 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7450 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7451 | { |
| 7452 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 7453 | .doit = nl80211_wiphy_netns, |
| 7454 | .policy = nl80211_policy, |
| 7455 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7456 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7457 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7458 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7459 | { |
| 7460 | .cmd = NL80211_CMD_GET_SURVEY, |
| 7461 | .policy = nl80211_policy, |
| 7462 | .dumpit = nl80211_dump_survey, |
| 7463 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7464 | { |
| 7465 | .cmd = NL80211_CMD_SET_PMKSA, |
| 7466 | .doit = nl80211_setdel_pmksa, |
| 7467 | .policy = nl80211_policy, |
| 7468 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7469 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7470 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7471 | }, |
| 7472 | { |
| 7473 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 7474 | .doit = nl80211_setdel_pmksa, |
| 7475 | .policy = nl80211_policy, |
| 7476 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7477 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7478 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7479 | }, |
| 7480 | { |
| 7481 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 7482 | .doit = nl80211_flush_pmksa, |
| 7483 | .policy = nl80211_policy, |
| 7484 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7485 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7486 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7487 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7488 | { |
| 7489 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7490 | .doit = nl80211_remain_on_channel, |
| 7491 | .policy = nl80211_policy, |
| 7492 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7493 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7494 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7495 | }, |
| 7496 | { |
| 7497 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7498 | .doit = nl80211_cancel_remain_on_channel, |
| 7499 | .policy = nl80211_policy, |
| 7500 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7501 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7502 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7503 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7504 | { |
| 7505 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 7506 | .doit = nl80211_set_tx_bitrate_mask, |
| 7507 | .policy = nl80211_policy, |
| 7508 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7509 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7510 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7511 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7512 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7513 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 7514 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7515 | .policy = nl80211_policy, |
| 7516 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7517 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7518 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7519 | }, |
| 7520 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7521 | .cmd = NL80211_CMD_FRAME, |
| 7522 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7523 | .policy = nl80211_policy, |
| 7524 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7525 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7526 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7527 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7528 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7529 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 7530 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 7531 | .policy = nl80211_policy, |
| 7532 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7533 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7534 | NL80211_FLAG_NEED_RTNL, |
| 7535 | }, |
| 7536 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7537 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 7538 | .doit = nl80211_set_power_save, |
| 7539 | .policy = nl80211_policy, |
| 7540 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7541 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7542 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7543 | }, |
| 7544 | { |
| 7545 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 7546 | .doit = nl80211_get_power_save, |
| 7547 | .policy = nl80211_policy, |
| 7548 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7549 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7550 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7551 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7552 | { |
| 7553 | .cmd = NL80211_CMD_SET_CQM, |
| 7554 | .doit = nl80211_set_cqm, |
| 7555 | .policy = nl80211_policy, |
| 7556 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7557 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7558 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7559 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7560 | { |
| 7561 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 7562 | .doit = nl80211_set_channel, |
| 7563 | .policy = nl80211_policy, |
| 7564 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7565 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7566 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7567 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7568 | { |
| 7569 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 7570 | .doit = nl80211_set_wds_peer, |
| 7571 | .policy = nl80211_policy, |
| 7572 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 7573 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7574 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7575 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7576 | { |
| 7577 | .cmd = NL80211_CMD_JOIN_MESH, |
| 7578 | .doit = nl80211_join_mesh, |
| 7579 | .policy = nl80211_policy, |
| 7580 | .flags = GENL_ADMIN_PERM, |
| 7581 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7582 | NL80211_FLAG_NEED_RTNL, |
| 7583 | }, |
| 7584 | { |
| 7585 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 7586 | .doit = nl80211_leave_mesh, |
| 7587 | .policy = nl80211_policy, |
| 7588 | .flags = GENL_ADMIN_PERM, |
| 7589 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7590 | NL80211_FLAG_NEED_RTNL, |
| 7591 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7592 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7593 | { |
| 7594 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 7595 | .doit = nl80211_get_wowlan, |
| 7596 | .policy = nl80211_policy, |
| 7597 | /* can be retrieved by unprivileged users */ |
| 7598 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7599 | NL80211_FLAG_NEED_RTNL, |
| 7600 | }, |
| 7601 | { |
| 7602 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 7603 | .doit = nl80211_set_wowlan, |
| 7604 | .policy = nl80211_policy, |
| 7605 | .flags = GENL_ADMIN_PERM, |
| 7606 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7607 | NL80211_FLAG_NEED_RTNL, |
| 7608 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7609 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7610 | { |
| 7611 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 7612 | .doit = nl80211_set_rekey_data, |
| 7613 | .policy = nl80211_policy, |
| 7614 | .flags = GENL_ADMIN_PERM, |
| 7615 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7616 | NL80211_FLAG_NEED_RTNL, |
| 7617 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7618 | { |
| 7619 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 7620 | .doit = nl80211_tdls_mgmt, |
| 7621 | .policy = nl80211_policy, |
| 7622 | .flags = GENL_ADMIN_PERM, |
| 7623 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7624 | NL80211_FLAG_NEED_RTNL, |
| 7625 | }, |
| 7626 | { |
| 7627 | .cmd = NL80211_CMD_TDLS_OPER, |
| 7628 | .doit = nl80211_tdls_oper, |
| 7629 | .policy = nl80211_policy, |
| 7630 | .flags = GENL_ADMIN_PERM, |
| 7631 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7632 | NL80211_FLAG_NEED_RTNL, |
| 7633 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7634 | { |
| 7635 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 7636 | .doit = nl80211_register_unexpected_frame, |
| 7637 | .policy = nl80211_policy, |
| 7638 | .flags = GENL_ADMIN_PERM, |
| 7639 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7640 | NL80211_FLAG_NEED_RTNL, |
| 7641 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7642 | { |
| 7643 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 7644 | .doit = nl80211_probe_client, |
| 7645 | .policy = nl80211_policy, |
| 7646 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7647 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7648 | NL80211_FLAG_NEED_RTNL, |
| 7649 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7650 | { |
| 7651 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 7652 | .doit = nl80211_register_beacons, |
| 7653 | .policy = nl80211_policy, |
| 7654 | .flags = GENL_ADMIN_PERM, |
| 7655 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7656 | NL80211_FLAG_NEED_RTNL, |
| 7657 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 7658 | { |
| 7659 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 7660 | .doit = nl80211_set_noack_map, |
| 7661 | .policy = nl80211_policy, |
| 7662 | .flags = GENL_ADMIN_PERM, |
| 7663 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7664 | NL80211_FLAG_NEED_RTNL, |
| 7665 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7666 | { |
| 7667 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 7668 | .doit = nl80211_start_p2p_device, |
| 7669 | .policy = nl80211_policy, |
| 7670 | .flags = GENL_ADMIN_PERM, |
| 7671 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 7672 | NL80211_FLAG_NEED_RTNL, |
| 7673 | }, |
| 7674 | { |
| 7675 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 7676 | .doit = nl80211_stop_p2p_device, |
| 7677 | .policy = nl80211_policy, |
| 7678 | .flags = GENL_ADMIN_PERM, |
| 7679 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 7680 | NL80211_FLAG_NEED_RTNL, |
| 7681 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7682 | { |
| 7683 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 7684 | .doit = nl80211_set_mcast_rate, |
| 7685 | .policy = nl80211_policy, |
| 7686 | .flags = GENL_ADMIN_PERM, |
| 7687 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7688 | NL80211_FLAG_NEED_RTNL, |
| 7689 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7690 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7691 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7692 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 7693 | .name = "mlme", |
| 7694 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7695 | |
| 7696 | /* multicast groups */ |
| 7697 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 7698 | .name = "config", |
| 7699 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7700 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 7701 | .name = "scan", |
| 7702 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7703 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 7704 | .name = "regulatory", |
| 7705 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7706 | |
| 7707 | /* notification functions */ |
| 7708 | |
| 7709 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 7710 | { |
| 7711 | struct sk_buff *msg; |
| 7712 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7713 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7714 | if (!msg) |
| 7715 | return; |
| 7716 | |
| 7717 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 7718 | nlmsg_free(msg); |
| 7719 | return; |
| 7720 | } |
| 7721 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7722 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7723 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7724 | } |
| 7725 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7726 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 7727 | struct cfg80211_registered_device *rdev) |
| 7728 | { |
| 7729 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 7730 | struct nlattr *nest; |
| 7731 | int i; |
| 7732 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7733 | ASSERT_RDEV_LOCK(rdev); |
| 7734 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7735 | if (WARN_ON(!req)) |
| 7736 | return 0; |
| 7737 | |
| 7738 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 7739 | if (!nest) |
| 7740 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7741 | for (i = 0; i < req->n_ssids; i++) { |
| 7742 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 7743 | goto nla_put_failure; |
| 7744 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7745 | nla_nest_end(msg, nest); |
| 7746 | |
| 7747 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 7748 | if (!nest) |
| 7749 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7750 | for (i = 0; i < req->n_channels; i++) { |
| 7751 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 7752 | goto nla_put_failure; |
| 7753 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7754 | nla_nest_end(msg, nest); |
| 7755 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7756 | if (req->ie && |
| 7757 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 7758 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7759 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7760 | if (req->flags) |
| 7761 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 7762 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7763 | return 0; |
| 7764 | nla_put_failure: |
| 7765 | return -ENOBUFS; |
| 7766 | } |
| 7767 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7768 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 7769 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7770 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7771 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7772 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7773 | { |
| 7774 | void *hdr; |
| 7775 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7776 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7777 | if (!hdr) |
| 7778 | return -1; |
| 7779 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7780 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7781 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 7782 | wdev->netdev->ifindex)) || |
| 7783 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7784 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7785 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7786 | /* ignore errors and send incomplete event anyway */ |
| 7787 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7788 | |
| 7789 | return genlmsg_end(msg, hdr); |
| 7790 | |
| 7791 | nla_put_failure: |
| 7792 | genlmsg_cancel(msg, hdr); |
| 7793 | return -EMSGSIZE; |
| 7794 | } |
| 7795 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7796 | static int |
| 7797 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 7798 | struct cfg80211_registered_device *rdev, |
| 7799 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7800 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7801 | { |
| 7802 | void *hdr; |
| 7803 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7804 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7805 | if (!hdr) |
| 7806 | return -1; |
| 7807 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7808 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7809 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7810 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7811 | |
| 7812 | return genlmsg_end(msg, hdr); |
| 7813 | |
| 7814 | nla_put_failure: |
| 7815 | genlmsg_cancel(msg, hdr); |
| 7816 | return -EMSGSIZE; |
| 7817 | } |
| 7818 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7819 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7820 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7821 | { |
| 7822 | struct sk_buff *msg; |
| 7823 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 7824 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7825 | if (!msg) |
| 7826 | return; |
| 7827 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7828 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7829 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 7830 | nlmsg_free(msg); |
| 7831 | return; |
| 7832 | } |
| 7833 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7834 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7835 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7836 | } |
| 7837 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7838 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7839 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7840 | { |
| 7841 | struct sk_buff *msg; |
| 7842 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7843 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7844 | if (!msg) |
| 7845 | return; |
| 7846 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7847 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7848 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7849 | nlmsg_free(msg); |
| 7850 | return; |
| 7851 | } |
| 7852 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7853 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7854 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7855 | } |
| 7856 | |
| 7857 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7858 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7859 | { |
| 7860 | struct sk_buff *msg; |
| 7861 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7862 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7863 | if (!msg) |
| 7864 | return; |
| 7865 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7866 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7867 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7868 | nlmsg_free(msg); |
| 7869 | return; |
| 7870 | } |
| 7871 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7872 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7873 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7874 | } |
| 7875 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7876 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 7877 | struct net_device *netdev) |
| 7878 | { |
| 7879 | struct sk_buff *msg; |
| 7880 | |
| 7881 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7882 | if (!msg) |
| 7883 | return; |
| 7884 | |
| 7885 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7886 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 7887 | nlmsg_free(msg); |
| 7888 | return; |
| 7889 | } |
| 7890 | |
| 7891 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7892 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7893 | } |
| 7894 | |
| 7895 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 7896 | struct net_device *netdev, u32 cmd) |
| 7897 | { |
| 7898 | struct sk_buff *msg; |
| 7899 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 7900 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7901 | if (!msg) |
| 7902 | return; |
| 7903 | |
| 7904 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 7905 | nlmsg_free(msg); |
| 7906 | return; |
| 7907 | } |
| 7908 | |
| 7909 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7910 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7911 | } |
| 7912 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7913 | /* |
| 7914 | * This can happen on global regulatory changes or device specific settings |
| 7915 | * based on custom world regulatory domains. |
| 7916 | */ |
| 7917 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 7918 | { |
| 7919 | struct sk_buff *msg; |
| 7920 | void *hdr; |
| 7921 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7922 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7923 | if (!msg) |
| 7924 | return; |
| 7925 | |
| 7926 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 7927 | if (!hdr) { |
| 7928 | nlmsg_free(msg); |
| 7929 | return; |
| 7930 | } |
| 7931 | |
| 7932 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7933 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 7934 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7935 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7936 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 7937 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7938 | NL80211_REGDOM_TYPE_WORLD)) |
| 7939 | goto nla_put_failure; |
| 7940 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 7941 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7942 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 7943 | goto nla_put_failure; |
| 7944 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 7945 | request->intersect) { |
| 7946 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7947 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 7948 | goto nla_put_failure; |
| 7949 | } else { |
| 7950 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7951 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 7952 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 7953 | request->alpha2)) |
| 7954 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7955 | } |
| 7956 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7957 | if (wiphy_idx_valid(request->wiphy_idx) && |
| 7958 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 7959 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7960 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7961 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7962 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7963 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7964 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7965 | GFP_ATOMIC); |
| 7966 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7967 | |
| 7968 | return; |
| 7969 | |
| 7970 | nla_put_failure: |
| 7971 | genlmsg_cancel(msg, hdr); |
| 7972 | nlmsg_free(msg); |
| 7973 | } |
| 7974 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7975 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 7976 | struct net_device *netdev, |
| 7977 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7978 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7979 | { |
| 7980 | struct sk_buff *msg; |
| 7981 | void *hdr; |
| 7982 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7983 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7984 | if (!msg) |
| 7985 | return; |
| 7986 | |
| 7987 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7988 | if (!hdr) { |
| 7989 | nlmsg_free(msg); |
| 7990 | return; |
| 7991 | } |
| 7992 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7993 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7994 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7995 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 7996 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7997 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7998 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7999 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8000 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8001 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8002 | return; |
| 8003 | |
| 8004 | nla_put_failure: |
| 8005 | genlmsg_cancel(msg, hdr); |
| 8006 | nlmsg_free(msg); |
| 8007 | } |
| 8008 | |
| 8009 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8010 | struct net_device *netdev, const u8 *buf, |
| 8011 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8012 | { |
| 8013 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8014 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8015 | } |
| 8016 | |
| 8017 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 8018 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8019 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8020 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8021 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8022 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8023 | } |
| 8024 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8025 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8026 | struct net_device *netdev, const u8 *buf, |
| 8027 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8028 | { |
| 8029 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8030 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8031 | } |
| 8032 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 8033 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 8034 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8035 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8036 | { |
| 8037 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8038 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8039 | } |
| 8040 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 8041 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 8042 | struct net_device *netdev, const u8 *buf, |
| 8043 | size_t len, gfp_t gfp) |
| 8044 | { |
| 8045 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8046 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 8047 | } |
| 8048 | |
| 8049 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 8050 | struct net_device *netdev, const u8 *buf, |
| 8051 | size_t len, gfp_t gfp) |
| 8052 | { |
| 8053 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 8054 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 8055 | } |
| 8056 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 8057 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 8058 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8059 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8060 | { |
| 8061 | struct sk_buff *msg; |
| 8062 | void *hdr; |
| 8063 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8064 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8065 | if (!msg) |
| 8066 | return; |
| 8067 | |
| 8068 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8069 | if (!hdr) { |
| 8070 | nlmsg_free(msg); |
| 8071 | return; |
| 8072 | } |
| 8073 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8074 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8075 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8076 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8077 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8078 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8079 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8080 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8081 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8082 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8083 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8084 | return; |
| 8085 | |
| 8086 | nla_put_failure: |
| 8087 | genlmsg_cancel(msg, hdr); |
| 8088 | nlmsg_free(msg); |
| 8089 | } |
| 8090 | |
| 8091 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8092 | struct net_device *netdev, const u8 *addr, |
| 8093 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8094 | { |
| 8095 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8096 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8097 | } |
| 8098 | |
| 8099 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8100 | struct net_device *netdev, const u8 *addr, |
| 8101 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8102 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8103 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8104 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8105 | } |
| 8106 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8107 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8108 | struct net_device *netdev, const u8 *bssid, |
| 8109 | const u8 *req_ie, size_t req_ie_len, |
| 8110 | const u8 *resp_ie, size_t resp_ie_len, |
| 8111 | u16 status, gfp_t gfp) |
| 8112 | { |
| 8113 | struct sk_buff *msg; |
| 8114 | void *hdr; |
| 8115 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8116 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8117 | if (!msg) |
| 8118 | return; |
| 8119 | |
| 8120 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8121 | if (!hdr) { |
| 8122 | nlmsg_free(msg); |
| 8123 | return; |
| 8124 | } |
| 8125 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8126 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8127 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8128 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8129 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8130 | (req_ie && |
| 8131 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8132 | (resp_ie && |
| 8133 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8134 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8135 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8136 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8137 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8138 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8139 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8140 | return; |
| 8141 | |
| 8142 | nla_put_failure: |
| 8143 | genlmsg_cancel(msg, hdr); |
| 8144 | nlmsg_free(msg); |
| 8145 | |
| 8146 | } |
| 8147 | |
| 8148 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8149 | struct net_device *netdev, const u8 *bssid, |
| 8150 | const u8 *req_ie, size_t req_ie_len, |
| 8151 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8152 | { |
| 8153 | struct sk_buff *msg; |
| 8154 | void *hdr; |
| 8155 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8156 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8157 | if (!msg) |
| 8158 | return; |
| 8159 | |
| 8160 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8161 | if (!hdr) { |
| 8162 | nlmsg_free(msg); |
| 8163 | return; |
| 8164 | } |
| 8165 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8166 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8167 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8168 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8169 | (req_ie && |
| 8170 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8171 | (resp_ie && |
| 8172 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8173 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8174 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8175 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8176 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8177 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8178 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8179 | return; |
| 8180 | |
| 8181 | nla_put_failure: |
| 8182 | genlmsg_cancel(msg, hdr); |
| 8183 | nlmsg_free(msg); |
| 8184 | |
| 8185 | } |
| 8186 | |
| 8187 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 8188 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8189 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8190 | { |
| 8191 | struct sk_buff *msg; |
| 8192 | void *hdr; |
| 8193 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8194 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8195 | if (!msg) |
| 8196 | return; |
| 8197 | |
| 8198 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 8199 | if (!hdr) { |
| 8200 | nlmsg_free(msg); |
| 8201 | return; |
| 8202 | } |
| 8203 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8204 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8205 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8206 | (from_ap && reason && |
| 8207 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 8208 | (from_ap && |
| 8209 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 8210 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 8211 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8212 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8213 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8214 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8215 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8216 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8217 | return; |
| 8218 | |
| 8219 | nla_put_failure: |
| 8220 | genlmsg_cancel(msg, hdr); |
| 8221 | nlmsg_free(msg); |
| 8222 | |
| 8223 | } |
| 8224 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8225 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 8226 | struct net_device *netdev, const u8 *bssid, |
| 8227 | gfp_t gfp) |
| 8228 | { |
| 8229 | struct sk_buff *msg; |
| 8230 | void *hdr; |
| 8231 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8232 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8233 | if (!msg) |
| 8234 | return; |
| 8235 | |
| 8236 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 8237 | if (!hdr) { |
| 8238 | nlmsg_free(msg); |
| 8239 | return; |
| 8240 | } |
| 8241 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8242 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8243 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8244 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8245 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8246 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8247 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8248 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8249 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8250 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8251 | return; |
| 8252 | |
| 8253 | nla_put_failure: |
| 8254 | genlmsg_cancel(msg, hdr); |
| 8255 | nlmsg_free(msg); |
| 8256 | } |
| 8257 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8258 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 8259 | struct net_device *netdev, |
| 8260 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 8261 | gfp_t gfp) |
| 8262 | { |
| 8263 | struct sk_buff *msg; |
| 8264 | void *hdr; |
| 8265 | |
| 8266 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8267 | if (!msg) |
| 8268 | return; |
| 8269 | |
| 8270 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 8271 | if (!hdr) { |
| 8272 | nlmsg_free(msg); |
| 8273 | return; |
| 8274 | } |
| 8275 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8276 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8277 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8278 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 8279 | (ie_len && ie && |
| 8280 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 8281 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8282 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8283 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8284 | |
| 8285 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8286 | nl80211_mlme_mcgrp.id, gfp); |
| 8287 | return; |
| 8288 | |
| 8289 | nla_put_failure: |
| 8290 | genlmsg_cancel(msg, hdr); |
| 8291 | nlmsg_free(msg); |
| 8292 | } |
| 8293 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8294 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 8295 | struct net_device *netdev, const u8 *addr, |
| 8296 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8297 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8298 | { |
| 8299 | struct sk_buff *msg; |
| 8300 | void *hdr; |
| 8301 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8302 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8303 | if (!msg) |
| 8304 | return; |
| 8305 | |
| 8306 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 8307 | if (!hdr) { |
| 8308 | nlmsg_free(msg); |
| 8309 | return; |
| 8310 | } |
| 8311 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8312 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8313 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8314 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 8315 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 8316 | (key_id != -1 && |
| 8317 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 8318 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 8319 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8320 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8321 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8322 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8323 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8324 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8325 | return; |
| 8326 | |
| 8327 | nla_put_failure: |
| 8328 | genlmsg_cancel(msg, hdr); |
| 8329 | nlmsg_free(msg); |
| 8330 | } |
| 8331 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8332 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 8333 | struct ieee80211_channel *channel_before, |
| 8334 | struct ieee80211_channel *channel_after) |
| 8335 | { |
| 8336 | struct sk_buff *msg; |
| 8337 | void *hdr; |
| 8338 | struct nlattr *nl_freq; |
| 8339 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8340 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8341 | if (!msg) |
| 8342 | return; |
| 8343 | |
| 8344 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 8345 | if (!hdr) { |
| 8346 | nlmsg_free(msg); |
| 8347 | return; |
| 8348 | } |
| 8349 | |
| 8350 | /* |
| 8351 | * Since we are applying the beacon hint to a wiphy we know its |
| 8352 | * wiphy_idx is valid |
| 8353 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8354 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 8355 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8356 | |
| 8357 | /* Before */ |
| 8358 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 8359 | if (!nl_freq) |
| 8360 | goto nla_put_failure; |
| 8361 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 8362 | goto nla_put_failure; |
| 8363 | nla_nest_end(msg, nl_freq); |
| 8364 | |
| 8365 | /* After */ |
| 8366 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 8367 | if (!nl_freq) |
| 8368 | goto nla_put_failure; |
| 8369 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 8370 | goto nla_put_failure; |
| 8371 | nla_nest_end(msg, nl_freq); |
| 8372 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8373 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8374 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8375 | rcu_read_lock(); |
| 8376 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 8377 | GFP_ATOMIC); |
| 8378 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8379 | |
| 8380 | return; |
| 8381 | |
| 8382 | nla_put_failure: |
| 8383 | genlmsg_cancel(msg, hdr); |
| 8384 | nlmsg_free(msg); |
| 8385 | } |
| 8386 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8387 | static void nl80211_send_remain_on_chan_event( |
| 8388 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8389 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8390 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8391 | unsigned int duration, gfp_t gfp) |
| 8392 | { |
| 8393 | struct sk_buff *msg; |
| 8394 | void *hdr; |
| 8395 | |
| 8396 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8397 | if (!msg) |
| 8398 | return; |
| 8399 | |
| 8400 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8401 | if (!hdr) { |
| 8402 | nlmsg_free(msg); |
| 8403 | return; |
| 8404 | } |
| 8405 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8406 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8407 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8408 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 8409 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8410 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame^] | 8411 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 8412 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8413 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8414 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8415 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8416 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 8417 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 8418 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8419 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8420 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8421 | |
| 8422 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8423 | nl80211_mlme_mcgrp.id, gfp); |
| 8424 | return; |
| 8425 | |
| 8426 | nla_put_failure: |
| 8427 | genlmsg_cancel(msg, hdr); |
| 8428 | nlmsg_free(msg); |
| 8429 | } |
| 8430 | |
| 8431 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8432 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8433 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8434 | unsigned int duration, gfp_t gfp) |
| 8435 | { |
| 8436 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8437 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame^] | 8438 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8439 | } |
| 8440 | |
| 8441 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8442 | struct cfg80211_registered_device *rdev, |
| 8443 | struct wireless_dev *wdev, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame^] | 8444 | u64 cookie, struct ieee80211_channel *chan, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8445 | { |
| 8446 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame^] | 8447 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8448 | } |
| 8449 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8450 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 8451 | struct net_device *dev, const u8 *mac_addr, |
| 8452 | struct station_info *sinfo, gfp_t gfp) |
| 8453 | { |
| 8454 | struct sk_buff *msg; |
| 8455 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8456 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8457 | if (!msg) |
| 8458 | return; |
| 8459 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 8460 | if (nl80211_send_station(msg, 0, 0, 0, |
| 8461 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8462 | nlmsg_free(msg); |
| 8463 | return; |
| 8464 | } |
| 8465 | |
| 8466 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8467 | nl80211_mlme_mcgrp.id, gfp); |
| 8468 | } |
| 8469 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8470 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 8471 | struct net_device *dev, const u8 *mac_addr, |
| 8472 | gfp_t gfp) |
| 8473 | { |
| 8474 | struct sk_buff *msg; |
| 8475 | void *hdr; |
| 8476 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8477 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8478 | if (!msg) |
| 8479 | return; |
| 8480 | |
| 8481 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 8482 | if (!hdr) { |
| 8483 | nlmsg_free(msg); |
| 8484 | return; |
| 8485 | } |
| 8486 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8487 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8488 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 8489 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8490 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8491 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8492 | |
| 8493 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8494 | nl80211_mlme_mcgrp.id, gfp); |
| 8495 | return; |
| 8496 | |
| 8497 | nla_put_failure: |
| 8498 | genlmsg_cancel(msg, hdr); |
| 8499 | nlmsg_free(msg); |
| 8500 | } |
| 8501 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 8502 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 8503 | struct net_device *dev, const u8 *mac_addr, |
| 8504 | enum nl80211_connect_failed_reason reason, |
| 8505 | gfp_t gfp) |
| 8506 | { |
| 8507 | struct sk_buff *msg; |
| 8508 | void *hdr; |
| 8509 | |
| 8510 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8511 | if (!msg) |
| 8512 | return; |
| 8513 | |
| 8514 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 8515 | if (!hdr) { |
| 8516 | nlmsg_free(msg); |
| 8517 | return; |
| 8518 | } |
| 8519 | |
| 8520 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8521 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 8522 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 8523 | goto nla_put_failure; |
| 8524 | |
| 8525 | genlmsg_end(msg, hdr); |
| 8526 | |
| 8527 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8528 | nl80211_mlme_mcgrp.id, gfp); |
| 8529 | return; |
| 8530 | |
| 8531 | nla_put_failure: |
| 8532 | genlmsg_cancel(msg, hdr); |
| 8533 | nlmsg_free(msg); |
| 8534 | } |
| 8535 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8536 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 8537 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8538 | { |
| 8539 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8540 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8541 | struct sk_buff *msg; |
| 8542 | void *hdr; |
| 8543 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8544 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8545 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8546 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8547 | return false; |
| 8548 | |
| 8549 | msg = nlmsg_new(100, gfp); |
| 8550 | if (!msg) |
| 8551 | return true; |
| 8552 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8553 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8554 | if (!hdr) { |
| 8555 | nlmsg_free(msg); |
| 8556 | return true; |
| 8557 | } |
| 8558 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8559 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8560 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8561 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8562 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8563 | |
| 8564 | err = genlmsg_end(msg, hdr); |
| 8565 | if (err < 0) { |
| 8566 | nlmsg_free(msg); |
| 8567 | return true; |
| 8568 | } |
| 8569 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8570 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8571 | return true; |
| 8572 | |
| 8573 | nla_put_failure: |
| 8574 | genlmsg_cancel(msg, hdr); |
| 8575 | nlmsg_free(msg); |
| 8576 | return true; |
| 8577 | } |
| 8578 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8579 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 8580 | { |
| 8581 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 8582 | addr, gfp); |
| 8583 | } |
| 8584 | |
| 8585 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 8586 | const u8 *addr, gfp_t gfp) |
| 8587 | { |
| 8588 | return __nl80211_unexpected_frame(dev, |
| 8589 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 8590 | addr, gfp); |
| 8591 | } |
| 8592 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8593 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8594 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8595 | int freq, int sig_dbm, |
| 8596 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8597 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8598 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8599 | struct sk_buff *msg; |
| 8600 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8601 | |
| 8602 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8603 | if (!msg) |
| 8604 | return -ENOMEM; |
| 8605 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8606 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8607 | if (!hdr) { |
| 8608 | nlmsg_free(msg); |
| 8609 | return -ENOMEM; |
| 8610 | } |
| 8611 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8612 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8613 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8614 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8615 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8616 | (sig_dbm && |
| 8617 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8618 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8619 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8620 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8621 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8622 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8623 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8624 | |
| 8625 | nla_put_failure: |
| 8626 | genlmsg_cancel(msg, hdr); |
| 8627 | nlmsg_free(msg); |
| 8628 | return -ENOBUFS; |
| 8629 | } |
| 8630 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8631 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8632 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8633 | const u8 *buf, size_t len, bool ack, |
| 8634 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8635 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8636 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8637 | struct sk_buff *msg; |
| 8638 | void *hdr; |
| 8639 | |
| 8640 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8641 | if (!msg) |
| 8642 | return; |
| 8643 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8644 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8645 | if (!hdr) { |
| 8646 | nlmsg_free(msg); |
| 8647 | return; |
| 8648 | } |
| 8649 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8650 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8651 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8652 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8653 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 8654 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8655 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8656 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8657 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8658 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8659 | |
| 8660 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 8661 | return; |
| 8662 | |
| 8663 | nla_put_failure: |
| 8664 | genlmsg_cancel(msg, hdr); |
| 8665 | nlmsg_free(msg); |
| 8666 | } |
| 8667 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8668 | void |
| 8669 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 8670 | struct net_device *netdev, |
| 8671 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 8672 | gfp_t gfp) |
| 8673 | { |
| 8674 | struct sk_buff *msg; |
| 8675 | struct nlattr *pinfoattr; |
| 8676 | void *hdr; |
| 8677 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8678 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8679 | if (!msg) |
| 8680 | return; |
| 8681 | |
| 8682 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8683 | if (!hdr) { |
| 8684 | nlmsg_free(msg); |
| 8685 | return; |
| 8686 | } |
| 8687 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8688 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8689 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8690 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8691 | |
| 8692 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8693 | if (!pinfoattr) |
| 8694 | goto nla_put_failure; |
| 8695 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8696 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 8697 | rssi_event)) |
| 8698 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8699 | |
| 8700 | nla_nest_end(msg, pinfoattr); |
| 8701 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8702 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8703 | |
| 8704 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8705 | nl80211_mlme_mcgrp.id, gfp); |
| 8706 | return; |
| 8707 | |
| 8708 | nla_put_failure: |
| 8709 | genlmsg_cancel(msg, hdr); |
| 8710 | nlmsg_free(msg); |
| 8711 | } |
| 8712 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8713 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 8714 | struct net_device *netdev, const u8 *bssid, |
| 8715 | const u8 *replay_ctr, gfp_t gfp) |
| 8716 | { |
| 8717 | struct sk_buff *msg; |
| 8718 | struct nlattr *rekey_attr; |
| 8719 | void *hdr; |
| 8720 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8721 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8722 | if (!msg) |
| 8723 | return; |
| 8724 | |
| 8725 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 8726 | if (!hdr) { |
| 8727 | nlmsg_free(msg); |
| 8728 | return; |
| 8729 | } |
| 8730 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8731 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8732 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8733 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8734 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8735 | |
| 8736 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 8737 | if (!rekey_attr) |
| 8738 | goto nla_put_failure; |
| 8739 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8740 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 8741 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 8742 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8743 | |
| 8744 | nla_nest_end(msg, rekey_attr); |
| 8745 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8746 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8747 | |
| 8748 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8749 | nl80211_mlme_mcgrp.id, gfp); |
| 8750 | return; |
| 8751 | |
| 8752 | nla_put_failure: |
| 8753 | genlmsg_cancel(msg, hdr); |
| 8754 | nlmsg_free(msg); |
| 8755 | } |
| 8756 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8757 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 8758 | struct net_device *netdev, int index, |
| 8759 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 8760 | { |
| 8761 | struct sk_buff *msg; |
| 8762 | struct nlattr *attr; |
| 8763 | void *hdr; |
| 8764 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8765 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8766 | if (!msg) |
| 8767 | return; |
| 8768 | |
| 8769 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 8770 | if (!hdr) { |
| 8771 | nlmsg_free(msg); |
| 8772 | return; |
| 8773 | } |
| 8774 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8775 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8776 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8777 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8778 | |
| 8779 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 8780 | if (!attr) |
| 8781 | goto nla_put_failure; |
| 8782 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8783 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 8784 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 8785 | (preauth && |
| 8786 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 8787 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8788 | |
| 8789 | nla_nest_end(msg, attr); |
| 8790 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8791 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8792 | |
| 8793 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8794 | nl80211_mlme_mcgrp.id, gfp); |
| 8795 | return; |
| 8796 | |
| 8797 | nla_put_failure: |
| 8798 | genlmsg_cancel(msg, hdr); |
| 8799 | nlmsg_free(msg); |
| 8800 | } |
| 8801 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8802 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 8803 | struct net_device *netdev, int freq, |
| 8804 | enum nl80211_channel_type type, gfp_t gfp) |
| 8805 | { |
| 8806 | struct sk_buff *msg; |
| 8807 | void *hdr; |
| 8808 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8809 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8810 | if (!msg) |
| 8811 | return; |
| 8812 | |
| 8813 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 8814 | if (!hdr) { |
| 8815 | nlmsg_free(msg); |
| 8816 | return; |
| 8817 | } |
| 8818 | |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 8819 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8820 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8821 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type)) |
| 8822 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8823 | |
| 8824 | genlmsg_end(msg, hdr); |
| 8825 | |
| 8826 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8827 | nl80211_mlme_mcgrp.id, gfp); |
| 8828 | return; |
| 8829 | |
| 8830 | nla_put_failure: |
| 8831 | genlmsg_cancel(msg, hdr); |
| 8832 | nlmsg_free(msg); |
| 8833 | } |
| 8834 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8835 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8836 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 8837 | struct net_device *netdev, const u8 *peer, |
| 8838 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 8839 | { |
| 8840 | struct sk_buff *msg; |
| 8841 | struct nlattr *pinfoattr; |
| 8842 | void *hdr; |
| 8843 | |
| 8844 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8845 | if (!msg) |
| 8846 | return; |
| 8847 | |
| 8848 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8849 | if (!hdr) { |
| 8850 | nlmsg_free(msg); |
| 8851 | return; |
| 8852 | } |
| 8853 | |
| 8854 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8855 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8856 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8857 | goto nla_put_failure; |
| 8858 | |
| 8859 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8860 | if (!pinfoattr) |
| 8861 | goto nla_put_failure; |
| 8862 | |
| 8863 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 8864 | goto nla_put_failure; |
| 8865 | |
| 8866 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 8867 | goto nla_put_failure; |
| 8868 | |
| 8869 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 8870 | goto nla_put_failure; |
| 8871 | |
| 8872 | nla_nest_end(msg, pinfoattr); |
| 8873 | |
| 8874 | genlmsg_end(msg, hdr); |
| 8875 | |
| 8876 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8877 | nl80211_mlme_mcgrp.id, gfp); |
| 8878 | return; |
| 8879 | |
| 8880 | nla_put_failure: |
| 8881 | genlmsg_cancel(msg, hdr); |
| 8882 | nlmsg_free(msg); |
| 8883 | } |
| 8884 | |
| 8885 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8886 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 8887 | struct net_device *netdev, const u8 *peer, |
| 8888 | u32 num_packets, gfp_t gfp) |
| 8889 | { |
| 8890 | struct sk_buff *msg; |
| 8891 | struct nlattr *pinfoattr; |
| 8892 | void *hdr; |
| 8893 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8894 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8895 | if (!msg) |
| 8896 | return; |
| 8897 | |
| 8898 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8899 | if (!hdr) { |
| 8900 | nlmsg_free(msg); |
| 8901 | return; |
| 8902 | } |
| 8903 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8904 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8905 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8906 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8907 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8908 | |
| 8909 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8910 | if (!pinfoattr) |
| 8911 | goto nla_put_failure; |
| 8912 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8913 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 8914 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8915 | |
| 8916 | nla_nest_end(msg, pinfoattr); |
| 8917 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8918 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8919 | |
| 8920 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8921 | nl80211_mlme_mcgrp.id, gfp); |
| 8922 | return; |
| 8923 | |
| 8924 | nla_put_failure: |
| 8925 | genlmsg_cancel(msg, hdr); |
| 8926 | nlmsg_free(msg); |
| 8927 | } |
| 8928 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8929 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 8930 | u64 cookie, bool acked, gfp_t gfp) |
| 8931 | { |
| 8932 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8933 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8934 | struct sk_buff *msg; |
| 8935 | void *hdr; |
| 8936 | int err; |
| 8937 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 8938 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 8939 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8940 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 8941 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8942 | if (!msg) |
| 8943 | return; |
| 8944 | |
| 8945 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 8946 | if (!hdr) { |
| 8947 | nlmsg_free(msg); |
| 8948 | return; |
| 8949 | } |
| 8950 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8951 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8952 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8953 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8954 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8955 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8956 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8957 | |
| 8958 | err = genlmsg_end(msg, hdr); |
| 8959 | if (err < 0) { |
| 8960 | nlmsg_free(msg); |
| 8961 | return; |
| 8962 | } |
| 8963 | |
| 8964 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8965 | nl80211_mlme_mcgrp.id, gfp); |
| 8966 | return; |
| 8967 | |
| 8968 | nla_put_failure: |
| 8969 | genlmsg_cancel(msg, hdr); |
| 8970 | nlmsg_free(msg); |
| 8971 | } |
| 8972 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 8973 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8974 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 8975 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8976 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8977 | { |
| 8978 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 8979 | struct sk_buff *msg; |
| 8980 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8981 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8982 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 8983 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 8984 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8985 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8986 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8987 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 8988 | if (!msg) { |
| 8989 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8990 | return; |
| 8991 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8992 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8993 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 8994 | if (!hdr) |
| 8995 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8996 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8997 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8998 | (freq && |
| 8999 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 9000 | (sig_dbm && |
| 9001 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9002 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 9003 | goto nla_put_failure; |
| 9004 | |
| 9005 | genlmsg_end(msg, hdr); |
| 9006 | |
| 9007 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9008 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9009 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9010 | return; |
| 9011 | |
| 9012 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9013 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9014 | if (hdr) |
| 9015 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9016 | nlmsg_free(msg); |
| 9017 | } |
| 9018 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 9019 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 9020 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 9021 | enum nl80211_tdls_operation oper, |
| 9022 | u16 reason_code, gfp_t gfp) |
| 9023 | { |
| 9024 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9025 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9026 | struct sk_buff *msg; |
| 9027 | void *hdr; |
| 9028 | int err; |
| 9029 | |
| 9030 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 9031 | reason_code); |
| 9032 | |
| 9033 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9034 | if (!msg) |
| 9035 | return; |
| 9036 | |
| 9037 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 9038 | if (!hdr) { |
| 9039 | nlmsg_free(msg); |
| 9040 | return; |
| 9041 | } |
| 9042 | |
| 9043 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9044 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9045 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 9046 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 9047 | (reason_code > 0 && |
| 9048 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 9049 | goto nla_put_failure; |
| 9050 | |
| 9051 | err = genlmsg_end(msg, hdr); |
| 9052 | if (err < 0) { |
| 9053 | nlmsg_free(msg); |
| 9054 | return; |
| 9055 | } |
| 9056 | |
| 9057 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9058 | nl80211_mlme_mcgrp.id, gfp); |
| 9059 | return; |
| 9060 | |
| 9061 | nla_put_failure: |
| 9062 | genlmsg_cancel(msg, hdr); |
| 9063 | nlmsg_free(msg); |
| 9064 | } |
| 9065 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 9066 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9067 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 9068 | unsigned long state, |
| 9069 | void *_notify) |
| 9070 | { |
| 9071 | struct netlink_notify *notify = _notify; |
| 9072 | struct cfg80211_registered_device *rdev; |
| 9073 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9074 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9075 | |
| 9076 | if (state != NETLINK_URELEASE) |
| 9077 | return NOTIFY_DONE; |
| 9078 | |
| 9079 | rcu_read_lock(); |
| 9080 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9081 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9082 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9083 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9084 | |
| 9085 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9086 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 9087 | list) { |
| 9088 | if (reg->nlportid == notify->portid) { |
| 9089 | list_del(®->list); |
| 9090 | kfree(reg); |
| 9091 | break; |
| 9092 | } |
| 9093 | } |
| 9094 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9095 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9096 | |
| 9097 | rcu_read_unlock(); |
| 9098 | |
| 9099 | return NOTIFY_DONE; |
| 9100 | } |
| 9101 | |
| 9102 | static struct notifier_block nl80211_netlink_notifier = { |
| 9103 | .notifier_call = nl80211_netlink_notify, |
| 9104 | }; |
| 9105 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9106 | /* initialisation/exit functions */ |
| 9107 | |
| 9108 | int nl80211_init(void) |
| 9109 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9110 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9111 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 9112 | err = genl_register_family_with_ops(&nl80211_fam, |
| 9113 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9114 | if (err) |
| 9115 | return err; |
| 9116 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9117 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 9118 | if (err) |
| 9119 | goto err_out; |
| 9120 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9121 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 9122 | if (err) |
| 9123 | goto err_out; |
| 9124 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9125 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 9126 | if (err) |
| 9127 | goto err_out; |
| 9128 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9129 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 9130 | if (err) |
| 9131 | goto err_out; |
| 9132 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9133 | #ifdef CONFIG_NL80211_TESTMODE |
| 9134 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 9135 | if (err) |
| 9136 | goto err_out; |
| 9137 | #endif |
| 9138 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9139 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 9140 | if (err) |
| 9141 | goto err_out; |
| 9142 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9143 | return 0; |
| 9144 | err_out: |
| 9145 | genl_unregister_family(&nl80211_fam); |
| 9146 | return err; |
| 9147 | } |
| 9148 | |
| 9149 | void nl80211_exit(void) |
| 9150 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9151 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9152 | genl_unregister_family(&nl80211_fam); |
| 9153 | } |