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" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 26 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 27 | struct genl_info *info, |
| 28 | struct cfg80211_crypto_settings *settings, |
| 29 | int cipher_limit); |
| 30 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 31 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 32 | struct genl_info *info); |
| 33 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 36 | /* the netlink family */ |
| 37 | static struct genl_family nl80211_fam = { |
| 38 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 39 | .name = "nl80211", /* have users key off the name instead */ |
| 40 | .hdrsize = 0, /* no private header */ |
| 41 | .version = 1, /* no particular meaning now */ |
| 42 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 43 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 44 | .pre_doit = nl80211_pre_doit, |
| 45 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 46 | }; |
| 47 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 48 | /* returns ERR_PTR values */ |
| 49 | static struct wireless_dev * |
| 50 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 51 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 52 | struct cfg80211_registered_device *rdev; |
| 53 | struct wireless_dev *result = NULL; |
| 54 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 55 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 56 | u64 wdev_id; |
| 57 | int wiphy_idx = -1; |
| 58 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 59 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 60 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 62 | if (!have_ifidx && !have_wdev_id) |
| 63 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 64 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 65 | if (have_ifidx) |
| 66 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 67 | if (have_wdev_id) { |
| 68 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 69 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 70 | } |
| 71 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 72 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 73 | struct wireless_dev *wdev; |
| 74 | |
| 75 | if (wiphy_net(&rdev->wiphy) != netns) |
| 76 | continue; |
| 77 | |
| 78 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 79 | continue; |
| 80 | |
| 81 | mutex_lock(&rdev->devlist_mtx); |
| 82 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 83 | if (have_ifidx && wdev->netdev && |
| 84 | wdev->netdev->ifindex == ifidx) { |
| 85 | result = wdev; |
| 86 | break; |
| 87 | } |
| 88 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 89 | result = wdev; |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | mutex_unlock(&rdev->devlist_mtx); |
| 94 | |
| 95 | if (result) |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | if (result) |
| 100 | return result; |
| 101 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 104 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 105 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 107 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 108 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 109 | |
| 110 | assert_cfg80211_lock(); |
| 111 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 112 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 113 | !attrs[NL80211_ATTR_IFINDEX] && |
| 114 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 115 | return ERR_PTR(-EINVAL); |
| 116 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 117 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 118 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 120 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 121 | if (attrs[NL80211_ATTR_WDEV]) { |
| 122 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 123 | struct wireless_dev *wdev; |
| 124 | bool found = false; |
| 125 | |
| 126 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 127 | if (tmp) { |
| 128 | /* make sure wdev exists */ |
| 129 | mutex_lock(&tmp->devlist_mtx); |
| 130 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 131 | if (wdev->identifier != (u32)wdev_id) |
| 132 | continue; |
| 133 | found = true; |
| 134 | break; |
| 135 | } |
| 136 | mutex_unlock(&tmp->devlist_mtx); |
| 137 | |
| 138 | if (!found) |
| 139 | tmp = NULL; |
| 140 | |
| 141 | if (rdev && tmp != rdev) |
| 142 | return ERR_PTR(-EINVAL); |
| 143 | rdev = tmp; |
| 144 | } |
| 145 | } |
| 146 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 147 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 148 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 149 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 150 | if (netdev) { |
| 151 | if (netdev->ieee80211_ptr) |
| 152 | tmp = wiphy_to_dev( |
| 153 | netdev->ieee80211_ptr->wiphy); |
| 154 | else |
| 155 | tmp = NULL; |
| 156 | |
| 157 | dev_put(netdev); |
| 158 | |
| 159 | /* not wireless device -- return error */ |
| 160 | if (!tmp) |
| 161 | return ERR_PTR(-EINVAL); |
| 162 | |
| 163 | /* mismatch -- return error */ |
| 164 | if (rdev && tmp != rdev) |
| 165 | return ERR_PTR(-EINVAL); |
| 166 | |
| 167 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 168 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 169 | } |
| 170 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 171 | if (!rdev) |
| 172 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 173 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 174 | if (netns != wiphy_net(&rdev->wiphy)) |
| 175 | return ERR_PTR(-ENODEV); |
| 176 | |
| 177 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /* |
| 181 | * This function returns a pointer to the driver |
| 182 | * that the genl_info item that is passed refers to. |
| 183 | * If successful, it returns non-NULL and also locks |
| 184 | * the driver's mutex! |
| 185 | * |
| 186 | * This means that you need to call cfg80211_unlock_rdev() |
| 187 | * before being allowed to acquire &cfg80211_mutex! |
| 188 | * |
| 189 | * This is necessary because we need to lock the global |
| 190 | * mutex to get an item off the list safely, and then |
| 191 | * we lock the rdev mutex so it doesn't go away under us. |
| 192 | * |
| 193 | * We don't want to keep cfg80211_mutex locked |
| 194 | * for all the time in order to allow requests on |
| 195 | * other interfaces to go through at the same time. |
| 196 | * |
| 197 | * The result of this can be a PTR_ERR and hence must |
| 198 | * be checked with IS_ERR() for errors. |
| 199 | */ |
| 200 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 201 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 202 | { |
| 203 | struct cfg80211_registered_device *rdev; |
| 204 | |
| 205 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 206 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 207 | |
| 208 | /* if it is not an error we grab the lock on |
| 209 | * it to assure it won't be going away while |
| 210 | * we operate on it */ |
| 211 | if (!IS_ERR(rdev)) |
| 212 | mutex_lock(&rdev->mtx); |
| 213 | |
| 214 | mutex_unlock(&cfg80211_mutex); |
| 215 | |
| 216 | return rdev; |
| 217 | } |
| 218 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 219 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 220 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 221 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 222 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 223 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 224 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 225 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 226 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 227 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 228 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 229 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 230 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 231 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 232 | |
| 233 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 234 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 235 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 236 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 237 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 238 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 239 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 240 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 241 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 242 | .len = WLAN_MAX_KEY_LEN }, |
| 243 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 244 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 245 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 246 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 247 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 248 | |
| 249 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 250 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 251 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 252 | .len = IEEE80211_MAX_DATA_LEN }, |
| 253 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 254 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 255 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 256 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 257 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 258 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 259 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 260 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 262 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 263 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 264 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 265 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 266 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 267 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 268 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 269 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 270 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 271 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 272 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 273 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 274 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 275 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 276 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 277 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 278 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 279 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 280 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 281 | |
| 282 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 283 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 284 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 285 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 286 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 287 | |
| 288 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 289 | .len = IEEE80211_MAX_SSID_LEN }, |
| 290 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 291 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 292 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_STA_FLAGS2] = { |
| 296 | .len = sizeof(struct nl80211_sta_flag_update), |
| 297 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 298 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 299 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 300 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 301 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 302 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 303 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 304 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 305 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 306 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 307 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 308 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 309 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 312 | .len = IEEE80211_MAX_DATA_LEN }, |
| 313 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 314 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 315 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 318 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 319 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 320 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 321 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 322 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 323 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 324 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 325 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 327 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 328 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 329 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 330 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 331 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 332 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 333 | .len = IEEE80211_MAX_DATA_LEN }, |
| 334 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 335 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 336 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 337 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 338 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 339 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 340 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 341 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 342 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 343 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 344 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 345 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 346 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 347 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 348 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 349 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 350 | .len = NL80211_HT_CAPABILITY_LEN |
| 351 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 352 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 353 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 354 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 355 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 356 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 357 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 358 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 359 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 360 | }; |
| 361 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 362 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 363 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 364 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 365 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 366 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 367 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 368 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 369 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 370 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 371 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 372 | }; |
| 373 | |
| 374 | /* policy for the key default flags */ |
| 375 | static const struct nla_policy |
| 376 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 377 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 378 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 379 | }; |
| 380 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 381 | /* policy for WoWLAN attributes */ |
| 382 | static const struct nla_policy |
| 383 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 384 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 385 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 386 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 387 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 388 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 389 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 390 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 391 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 392 | }; |
| 393 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 394 | /* policy for GTK rekey offload attributes */ |
| 395 | static const struct nla_policy |
| 396 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 397 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 398 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 399 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 400 | }; |
| 401 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 402 | static const struct nla_policy |
| 403 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 404 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 405 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 406 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 407 | }; |
| 408 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 409 | /* ifidx get helper */ |
| 410 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 411 | { |
| 412 | int res; |
| 413 | |
| 414 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 415 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 416 | nl80211_policy); |
| 417 | if (res) |
| 418 | return res; |
| 419 | |
| 420 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 421 | return -EINVAL; |
| 422 | |
| 423 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 424 | if (!res) |
| 425 | return -EINVAL; |
| 426 | return res; |
| 427 | } |
| 428 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 429 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 430 | struct netlink_callback *cb, |
| 431 | struct cfg80211_registered_device **rdev, |
| 432 | struct net_device **dev) |
| 433 | { |
| 434 | int ifidx = cb->args[0]; |
| 435 | int err; |
| 436 | |
| 437 | if (!ifidx) |
| 438 | ifidx = nl80211_get_ifidx(cb); |
| 439 | if (ifidx < 0) |
| 440 | return ifidx; |
| 441 | |
| 442 | cb->args[0] = ifidx; |
| 443 | |
| 444 | rtnl_lock(); |
| 445 | |
| 446 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 447 | if (!*dev) { |
| 448 | err = -ENODEV; |
| 449 | goto out_rtnl; |
| 450 | } |
| 451 | |
| 452 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 453 | if (IS_ERR(*rdev)) { |
| 454 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 455 | goto out_rtnl; |
| 456 | } |
| 457 | |
| 458 | return 0; |
| 459 | out_rtnl: |
| 460 | rtnl_unlock(); |
| 461 | return err; |
| 462 | } |
| 463 | |
| 464 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 465 | { |
| 466 | cfg80211_unlock_rdev(rdev); |
| 467 | rtnl_unlock(); |
| 468 | } |
| 469 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 470 | /* IE validation */ |
| 471 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 472 | { |
| 473 | const u8 *pos; |
| 474 | int len; |
| 475 | |
| 476 | if (!attr) |
| 477 | return true; |
| 478 | |
| 479 | pos = nla_data(attr); |
| 480 | len = nla_len(attr); |
| 481 | |
| 482 | while (len) { |
| 483 | u8 elemlen; |
| 484 | |
| 485 | if (len < 2) |
| 486 | return false; |
| 487 | len -= 2; |
| 488 | |
| 489 | elemlen = pos[1]; |
| 490 | if (elemlen > len) |
| 491 | return false; |
| 492 | |
| 493 | len -= elemlen; |
| 494 | pos += 2 + elemlen; |
| 495 | } |
| 496 | |
| 497 | return true; |
| 498 | } |
| 499 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 500 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 501 | 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] | 502 | int flags, u8 cmd) |
| 503 | { |
| 504 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 505 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 506 | } |
| 507 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 508 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 509 | struct ieee80211_channel *chan) |
| 510 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 511 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 512 | chan->center_freq)) |
| 513 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 514 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 515 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 516 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 517 | goto nla_put_failure; |
| 518 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 519 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 520 | goto nla_put_failure; |
| 521 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 522 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 523 | goto nla_put_failure; |
| 524 | if ((chan->flags & IEEE80211_CHAN_RADAR) && |
| 525 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 526 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 527 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 528 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 529 | DBM_TO_MBM(chan->max_power))) |
| 530 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 531 | |
| 532 | return 0; |
| 533 | |
| 534 | nla_put_failure: |
| 535 | return -ENOBUFS; |
| 536 | } |
| 537 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 538 | /* netlink command implementations */ |
| 539 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 540 | struct key_parse { |
| 541 | struct key_params p; |
| 542 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 543 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 544 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 545 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 546 | }; |
| 547 | |
| 548 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 549 | { |
| 550 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 551 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 552 | nl80211_key_policy); |
| 553 | if (err) |
| 554 | return err; |
| 555 | |
| 556 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 557 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 558 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 559 | if (k->def) { |
| 560 | k->def_uni = true; |
| 561 | k->def_multi = true; |
| 562 | } |
| 563 | if (k->defmgmt) |
| 564 | k->def_multi = true; |
| 565 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 566 | if (tb[NL80211_KEY_IDX]) |
| 567 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 568 | |
| 569 | if (tb[NL80211_KEY_DATA]) { |
| 570 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 571 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 572 | } |
| 573 | |
| 574 | if (tb[NL80211_KEY_SEQ]) { |
| 575 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 576 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 577 | } |
| 578 | |
| 579 | if (tb[NL80211_KEY_CIPHER]) |
| 580 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 581 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 582 | if (tb[NL80211_KEY_TYPE]) { |
| 583 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 584 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 585 | return -EINVAL; |
| 586 | } |
| 587 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 588 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 589 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 590 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 591 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 592 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 593 | if (err) |
| 594 | return err; |
| 595 | |
| 596 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 597 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 598 | } |
| 599 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 604 | { |
| 605 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 606 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 607 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 608 | } |
| 609 | |
| 610 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 611 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 612 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 613 | } |
| 614 | |
| 615 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 616 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 617 | |
| 618 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 619 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 620 | |
| 621 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 622 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 623 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 624 | if (k->def) { |
| 625 | k->def_uni = true; |
| 626 | k->def_multi = true; |
| 627 | } |
| 628 | if (k->defmgmt) |
| 629 | k->def_multi = true; |
| 630 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 631 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 632 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 633 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 634 | return -EINVAL; |
| 635 | } |
| 636 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 637 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 638 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 639 | int err = nla_parse_nested( |
| 640 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 641 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 642 | nl80211_key_default_policy); |
| 643 | if (err) |
| 644 | return err; |
| 645 | |
| 646 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 647 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 648 | } |
| 649 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 654 | { |
| 655 | int err; |
| 656 | |
| 657 | memset(k, 0, sizeof(*k)); |
| 658 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 659 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 660 | |
| 661 | if (info->attrs[NL80211_ATTR_KEY]) |
| 662 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 663 | else |
| 664 | err = nl80211_parse_key_old(info, k); |
| 665 | |
| 666 | if (err) |
| 667 | return err; |
| 668 | |
| 669 | if (k->def && k->defmgmt) |
| 670 | return -EINVAL; |
| 671 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 672 | if (k->defmgmt) { |
| 673 | if (k->def_uni || !k->def_multi) |
| 674 | return -EINVAL; |
| 675 | } |
| 676 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 677 | if (k->idx != -1) { |
| 678 | if (k->defmgmt) { |
| 679 | if (k->idx < 4 || k->idx > 5) |
| 680 | return -EINVAL; |
| 681 | } else if (k->def) { |
| 682 | if (k->idx < 0 || k->idx > 3) |
| 683 | return -EINVAL; |
| 684 | } else { |
| 685 | if (k->idx < 0 || k->idx > 5) |
| 686 | return -EINVAL; |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | return 0; |
| 691 | } |
| 692 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 693 | static struct cfg80211_cached_keys * |
| 694 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 695 | struct nlattr *keys) |
| 696 | { |
| 697 | struct key_parse parse; |
| 698 | struct nlattr *key; |
| 699 | struct cfg80211_cached_keys *result; |
| 700 | int rem, err, def = 0; |
| 701 | |
| 702 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 703 | if (!result) |
| 704 | return ERR_PTR(-ENOMEM); |
| 705 | |
| 706 | result->def = -1; |
| 707 | result->defmgmt = -1; |
| 708 | |
| 709 | nla_for_each_nested(key, keys, rem) { |
| 710 | memset(&parse, 0, sizeof(parse)); |
| 711 | parse.idx = -1; |
| 712 | |
| 713 | err = nl80211_parse_key_new(key, &parse); |
| 714 | if (err) |
| 715 | goto error; |
| 716 | err = -EINVAL; |
| 717 | if (!parse.p.key) |
| 718 | goto error; |
| 719 | if (parse.idx < 0 || parse.idx > 4) |
| 720 | goto error; |
| 721 | if (parse.def) { |
| 722 | if (def) |
| 723 | goto error; |
| 724 | def = 1; |
| 725 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 726 | if (!parse.def_uni || !parse.def_multi) |
| 727 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 728 | } else if (parse.defmgmt) |
| 729 | goto error; |
| 730 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 731 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 732 | if (err) |
| 733 | goto error; |
| 734 | result->params[parse.idx].cipher = parse.p.cipher; |
| 735 | result->params[parse.idx].key_len = parse.p.key_len; |
| 736 | result->params[parse.idx].key = result->data[parse.idx]; |
| 737 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 738 | } |
| 739 | |
| 740 | return result; |
| 741 | error: |
| 742 | kfree(result); |
| 743 | return ERR_PTR(err); |
| 744 | } |
| 745 | |
| 746 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 747 | { |
| 748 | ASSERT_WDEV_LOCK(wdev); |
| 749 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 750 | switch (wdev->iftype) { |
| 751 | case NL80211_IFTYPE_AP: |
| 752 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 753 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 754 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 755 | break; |
| 756 | case NL80211_IFTYPE_ADHOC: |
| 757 | if (!wdev->current_bss) |
| 758 | return -ENOLINK; |
| 759 | break; |
| 760 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 761 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 762 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 763 | return -ENOLINK; |
| 764 | break; |
| 765 | default: |
| 766 | return -EINVAL; |
| 767 | } |
| 768 | |
| 769 | return 0; |
| 770 | } |
| 771 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 772 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 773 | { |
| 774 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 775 | int i; |
| 776 | |
| 777 | if (!nl_modes) |
| 778 | goto nla_put_failure; |
| 779 | |
| 780 | i = 0; |
| 781 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 782 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 783 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 784 | ifmodes >>= 1; |
| 785 | i++; |
| 786 | } |
| 787 | |
| 788 | nla_nest_end(msg, nl_modes); |
| 789 | return 0; |
| 790 | |
| 791 | nla_put_failure: |
| 792 | return -ENOBUFS; |
| 793 | } |
| 794 | |
| 795 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 796 | struct sk_buff *msg) |
| 797 | { |
| 798 | struct nlattr *nl_combis; |
| 799 | int i, j; |
| 800 | |
| 801 | nl_combis = nla_nest_start(msg, |
| 802 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 803 | if (!nl_combis) |
| 804 | goto nla_put_failure; |
| 805 | |
| 806 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 807 | const struct ieee80211_iface_combination *c; |
| 808 | struct nlattr *nl_combi, *nl_limits; |
| 809 | |
| 810 | c = &wiphy->iface_combinations[i]; |
| 811 | |
| 812 | nl_combi = nla_nest_start(msg, i + 1); |
| 813 | if (!nl_combi) |
| 814 | goto nla_put_failure; |
| 815 | |
| 816 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 817 | if (!nl_limits) |
| 818 | goto nla_put_failure; |
| 819 | |
| 820 | for (j = 0; j < c->n_limits; j++) { |
| 821 | struct nlattr *nl_limit; |
| 822 | |
| 823 | nl_limit = nla_nest_start(msg, j + 1); |
| 824 | if (!nl_limit) |
| 825 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 826 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 827 | c->limits[j].max)) |
| 828 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 829 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 830 | c->limits[j].types)) |
| 831 | goto nla_put_failure; |
| 832 | nla_nest_end(msg, nl_limit); |
| 833 | } |
| 834 | |
| 835 | nla_nest_end(msg, nl_limits); |
| 836 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 837 | if (c->beacon_int_infra_match && |
| 838 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 839 | goto nla_put_failure; |
| 840 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 841 | c->num_different_channels) || |
| 842 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 843 | c->max_interfaces)) |
| 844 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 845 | |
| 846 | nla_nest_end(msg, nl_combi); |
| 847 | } |
| 848 | |
| 849 | nla_nest_end(msg, nl_combis); |
| 850 | |
| 851 | return 0; |
| 852 | nla_put_failure: |
| 853 | return -ENOBUFS; |
| 854 | } |
| 855 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 856 | 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] | 857 | struct cfg80211_registered_device *dev) |
| 858 | { |
| 859 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 860 | struct nlattr *nl_bands, *nl_band; |
| 861 | struct nlattr *nl_freqs, *nl_freq; |
| 862 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 863 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 864 | enum ieee80211_band band; |
| 865 | struct ieee80211_channel *chan; |
| 866 | struct ieee80211_rate *rate; |
| 867 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 868 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 869 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 870 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 871 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 872 | if (!hdr) |
| 873 | return -1; |
| 874 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 875 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
| 876 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || |
| 877 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 878 | cfg80211_rdev_list_generation) || |
| 879 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 880 | dev->wiphy.retry_short) || |
| 881 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 882 | dev->wiphy.retry_long) || |
| 883 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 884 | dev->wiphy.frag_threshold) || |
| 885 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 886 | dev->wiphy.rts_threshold) || |
| 887 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 888 | dev->wiphy.coverage_class) || |
| 889 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 890 | dev->wiphy.max_scan_ssids) || |
| 891 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 892 | dev->wiphy.max_sched_scan_ssids) || |
| 893 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 894 | dev->wiphy.max_scan_ie_len) || |
| 895 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 896 | dev->wiphy.max_sched_scan_ie_len) || |
| 897 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 898 | dev->wiphy.max_match_sets)) |
| 899 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 900 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 901 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 902 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 903 | goto nla_put_failure; |
| 904 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 905 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 906 | goto nla_put_failure; |
| 907 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 908 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 909 | goto nla_put_failure; |
| 910 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 911 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 912 | goto nla_put_failure; |
| 913 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 914 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 915 | goto nla_put_failure; |
| 916 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 917 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 918 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 919 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 920 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 921 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 922 | dev->wiphy.cipher_suites)) |
| 923 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 924 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 925 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 926 | dev->wiphy.max_num_pmkids)) |
| 927 | goto nla_put_failure; |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 928 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 929 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 930 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 931 | goto nla_put_failure; |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 932 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 933 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 934 | dev->wiphy.available_antennas_tx) || |
| 935 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 936 | dev->wiphy.available_antennas_rx)) |
| 937 | goto nla_put_failure; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 938 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 939 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 940 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 941 | dev->wiphy.probe_resp_offload)) |
| 942 | goto nla_put_failure; |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 943 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 944 | if ((dev->wiphy.available_antennas_tx || |
| 945 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 946 | u32 tx_ant = 0, rx_ant = 0; |
| 947 | int res; |
| 948 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 949 | if (!res) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 950 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 951 | tx_ant) || |
| 952 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 953 | rx_ant)) |
| 954 | goto nla_put_failure; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 955 | } |
| 956 | } |
| 957 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 958 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 959 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 960 | goto nla_put_failure; |
| 961 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 962 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 963 | if (!nl_bands) |
| 964 | goto nla_put_failure; |
| 965 | |
| 966 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 967 | if (!dev->wiphy.bands[band]) |
| 968 | continue; |
| 969 | |
| 970 | nl_band = nla_nest_start(msg, band); |
| 971 | if (!nl_band) |
| 972 | goto nla_put_failure; |
| 973 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 974 | /* add HT info */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 975 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
| 976 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 977 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 978 | &dev->wiphy.bands[band]->ht_cap.mcs) || |
| 979 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 980 | dev->wiphy.bands[band]->ht_cap.cap) || |
| 981 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 982 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || |
| 983 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 984 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) |
| 985 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 986 | |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 987 | /* add VHT info */ |
| 988 | if (dev->wiphy.bands[band]->vht_cap.vht_supported && |
| 989 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 990 | sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs), |
| 991 | &dev->wiphy.bands[band]->vht_cap.vht_mcs) || |
| 992 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 993 | dev->wiphy.bands[band]->vht_cap.cap))) |
| 994 | goto nla_put_failure; |
| 995 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 996 | /* add frequencies */ |
| 997 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 998 | if (!nl_freqs) |
| 999 | goto nla_put_failure; |
| 1000 | |
| 1001 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 1002 | nl_freq = nla_nest_start(msg, i); |
| 1003 | if (!nl_freq) |
| 1004 | goto nla_put_failure; |
| 1005 | |
| 1006 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1007 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1008 | if (nl80211_msg_put_channel(msg, chan)) |
| 1009 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1010 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1011 | nla_nest_end(msg, nl_freq); |
| 1012 | } |
| 1013 | |
| 1014 | nla_nest_end(msg, nl_freqs); |
| 1015 | |
| 1016 | /* add bitrates */ |
| 1017 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1018 | if (!nl_rates) |
| 1019 | goto nla_put_failure; |
| 1020 | |
| 1021 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 1022 | nl_rate = nla_nest_start(msg, i); |
| 1023 | if (!nl_rate) |
| 1024 | goto nla_put_failure; |
| 1025 | |
| 1026 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1027 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1028 | rate->bitrate)) |
| 1029 | goto nla_put_failure; |
| 1030 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1031 | nla_put_flag(msg, |
| 1032 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1033 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1034 | |
| 1035 | nla_nest_end(msg, nl_rate); |
| 1036 | } |
| 1037 | |
| 1038 | nla_nest_end(msg, nl_rates); |
| 1039 | |
| 1040 | nla_nest_end(msg, nl_band); |
| 1041 | } |
| 1042 | nla_nest_end(msg, nl_bands); |
| 1043 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1044 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1045 | if (!nl_cmds) |
| 1046 | goto nla_put_failure; |
| 1047 | |
| 1048 | i = 0; |
| 1049 | #define CMD(op, n) \ |
| 1050 | do { \ |
| 1051 | if (dev->ops->op) { \ |
| 1052 | i++; \ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1053 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1054 | goto nla_put_failure; \ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1055 | } \ |
| 1056 | } while (0) |
| 1057 | |
| 1058 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1059 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1060 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1061 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1062 | CMD(add_station, NEW_STATION); |
| 1063 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 1064 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1065 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1066 | CMD(auth, AUTHENTICATE); |
| 1067 | CMD(assoc, ASSOCIATE); |
| 1068 | CMD(deauth, DEAUTHENTICATE); |
| 1069 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1070 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1071 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1072 | CMD(set_pmksa, SET_PMKSA); |
| 1073 | CMD(del_pmksa, DEL_PMKSA); |
| 1074 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1075 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1076 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 1077 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1078 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1079 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 1080 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1081 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1082 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1083 | goto nla_put_failure; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1084 | } |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1085 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1086 | dev->ops->join_mesh) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1087 | i++; |
| 1088 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1089 | goto nla_put_failure; |
| 1090 | } |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1091 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 1092 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1093 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1094 | CMD(tdls_oper, TDLS_OPER); |
| 1095 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 1096 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1097 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 1098 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1099 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1100 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1101 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1102 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1103 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1104 | } |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1105 | CMD(start_p2p_device, START_P2P_DEVICE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1106 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1107 | #ifdef CONFIG_NL80211_TESTMODE |
| 1108 | CMD(testmode_cmd, TESTMODE); |
| 1109 | #endif |
| 1110 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1111 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1112 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1113 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1114 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1115 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1116 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1117 | } |
| 1118 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1119 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1120 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1121 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1122 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1123 | } |
| 1124 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1125 | nla_nest_end(msg, nl_cmds); |
| 1126 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1127 | if (dev->ops->remain_on_channel && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1128 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1129 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1130 | dev->wiphy.max_remain_on_channel_duration)) |
| 1131 | goto nla_put_failure; |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 1132 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1133 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1134 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1135 | goto nla_put_failure; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1136 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1137 | if (mgmt_stypes) { |
| 1138 | u16 stypes; |
| 1139 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1140 | enum nl80211_iftype ift; |
| 1141 | |
| 1142 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1143 | if (!nl_ifs) |
| 1144 | goto nla_put_failure; |
| 1145 | |
| 1146 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1147 | nl_ftypes = nla_nest_start(msg, ift); |
| 1148 | if (!nl_ftypes) |
| 1149 | goto nla_put_failure; |
| 1150 | i = 0; |
| 1151 | stypes = mgmt_stypes[ift].tx; |
| 1152 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1153 | if ((stypes & 1) && |
| 1154 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1155 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1156 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1157 | stypes >>= 1; |
| 1158 | i++; |
| 1159 | } |
| 1160 | nla_nest_end(msg, nl_ftypes); |
| 1161 | } |
| 1162 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1163 | nla_nest_end(msg, nl_ifs); |
| 1164 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1165 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1166 | if (!nl_ifs) |
| 1167 | goto nla_put_failure; |
| 1168 | |
| 1169 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1170 | nl_ftypes = nla_nest_start(msg, ift); |
| 1171 | if (!nl_ftypes) |
| 1172 | goto nla_put_failure; |
| 1173 | i = 0; |
| 1174 | stypes = mgmt_stypes[ift].rx; |
| 1175 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1176 | if ((stypes & 1) && |
| 1177 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1178 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1179 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1180 | stypes >>= 1; |
| 1181 | i++; |
| 1182 | } |
| 1183 | nla_nest_end(msg, nl_ftypes); |
| 1184 | } |
| 1185 | nla_nest_end(msg, nl_ifs); |
| 1186 | } |
| 1187 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1188 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1189 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 1190 | struct nlattr *nl_wowlan; |
| 1191 | |
| 1192 | nl_wowlan = nla_nest_start(msg, |
| 1193 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1194 | if (!nl_wowlan) |
| 1195 | goto nla_put_failure; |
| 1196 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1197 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 1198 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1199 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1200 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1201 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1202 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1203 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1204 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1205 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1206 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1207 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1208 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1209 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1210 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1211 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1212 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1213 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1214 | if (dev->wiphy.wowlan.n_patterns) { |
| 1215 | struct nl80211_wowlan_pattern_support pat = { |
| 1216 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1217 | .min_pattern_len = |
| 1218 | dev->wiphy.wowlan.pattern_min_len, |
| 1219 | .max_pattern_len = |
| 1220 | dev->wiphy.wowlan.pattern_max_len, |
| 1221 | }; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1222 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1223 | sizeof(pat), &pat)) |
| 1224 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | nla_nest_end(msg, nl_wowlan); |
| 1228 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1229 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1230 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1231 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1232 | dev->wiphy.software_iftypes)) |
| 1233 | goto nla_put_failure; |
| 1234 | |
| 1235 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1236 | goto nla_put_failure; |
| 1237 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1238 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1239 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1240 | dev->wiphy.ap_sme_capa)) |
| 1241 | goto nla_put_failure; |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1242 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1243 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
| 1244 | dev->wiphy.features)) |
| 1245 | goto nla_put_failure; |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1246 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1247 | if (dev->wiphy.ht_capa_mod_mask && |
| 1248 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1249 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1250 | dev->wiphy.ht_capa_mod_mask)) |
| 1251 | goto nla_put_failure; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1252 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1253 | return genlmsg_end(msg, hdr); |
| 1254 | |
| 1255 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1256 | genlmsg_cancel(msg, hdr); |
| 1257 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1261 | { |
| 1262 | int idx = 0; |
| 1263 | int start = cb->args[0]; |
| 1264 | struct cfg80211_registered_device *dev; |
| 1265 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1266 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1267 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1268 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1269 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1270 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1271 | continue; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1272 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1273 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1274 | dev) < 0) { |
| 1275 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1276 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1277 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1278 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1279 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1280 | |
| 1281 | cb->args[0] = idx; |
| 1282 | |
| 1283 | return skb->len; |
| 1284 | } |
| 1285 | |
| 1286 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1287 | { |
| 1288 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1289 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1290 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1291 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1292 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1293 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1294 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1295 | 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] | 1296 | nlmsg_free(msg); |
| 1297 | return -ENOBUFS; |
| 1298 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1299 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1300 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1301 | } |
| 1302 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1303 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1304 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1305 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1306 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1307 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1308 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1309 | }; |
| 1310 | |
| 1311 | static int parse_txq_params(struct nlattr *tb[], |
| 1312 | struct ieee80211_txq_params *txq_params) |
| 1313 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1314 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1315 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1316 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1317 | return -EINVAL; |
| 1318 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1319 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1320 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1321 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1322 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1323 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1324 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1325 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1326 | return -EINVAL; |
| 1327 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1328 | return 0; |
| 1329 | } |
| 1330 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1331 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1332 | { |
| 1333 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1334 | * You can only set the channel explicitly for WDS interfaces, |
| 1335 | * all others have their channel managed via their respective |
| 1336 | * "establish a connection" command (connect, join, ...) |
| 1337 | * |
| 1338 | * For AP/GO and mesh mode, the channel can be set with the |
| 1339 | * channel userspace API, but is only stored and passed to the |
| 1340 | * low-level driver when the AP starts or the mesh is joined. |
| 1341 | * This is for backward compatibility, userspace can also give |
| 1342 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1343 | * |
| 1344 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1345 | * whatever else is going on, so they have their own special |
| 1346 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1347 | */ |
| 1348 | return !wdev || |
| 1349 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1350 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1351 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1352 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1353 | } |
| 1354 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 1355 | static bool nl80211_valid_channel_type(struct genl_info *info, |
| 1356 | enum nl80211_channel_type *channel_type) |
| 1357 | { |
| 1358 | enum nl80211_channel_type tmp; |
| 1359 | |
| 1360 | if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) |
| 1361 | return false; |
| 1362 | |
| 1363 | tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1364 | if (tmp != NL80211_CHAN_NO_HT && |
| 1365 | tmp != NL80211_CHAN_HT20 && |
| 1366 | tmp != NL80211_CHAN_HT40PLUS && |
| 1367 | tmp != NL80211_CHAN_HT40MINUS) |
| 1368 | return false; |
| 1369 | |
| 1370 | if (channel_type) |
| 1371 | *channel_type = tmp; |
| 1372 | |
| 1373 | return true; |
| 1374 | } |
| 1375 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1376 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1377 | struct wireless_dev *wdev, |
| 1378 | struct genl_info *info) |
| 1379 | { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1380 | struct ieee80211_channel *channel; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1381 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1382 | u32 freq; |
| 1383 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1384 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1385 | |
| 1386 | if (wdev) |
| 1387 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1388 | |
| 1389 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1390 | return -EINVAL; |
| 1391 | |
| 1392 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1393 | return -EOPNOTSUPP; |
| 1394 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 1395 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 1396 | !nl80211_valid_channel_type(info, &channel_type)) |
| 1397 | return -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1398 | |
| 1399 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1400 | |
| 1401 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1402 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1403 | case NL80211_IFTYPE_AP: |
| 1404 | case NL80211_IFTYPE_P2P_GO: |
| 1405 | if (wdev->beacon_interval) { |
| 1406 | result = -EBUSY; |
| 1407 | break; |
| 1408 | } |
| 1409 | channel = rdev_freq_to_chan(rdev, freq, channel_type); |
| 1410 | if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy, |
| 1411 | channel, |
| 1412 | channel_type)) { |
| 1413 | result = -EINVAL; |
| 1414 | break; |
| 1415 | } |
| 1416 | wdev->preset_chan = channel; |
| 1417 | wdev->preset_chantype = channel_type; |
| 1418 | result = 0; |
| 1419 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1420 | case NL80211_IFTYPE_MESH_POINT: |
| 1421 | result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type); |
| 1422 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1423 | case NL80211_IFTYPE_MONITOR: |
| 1424 | result = cfg80211_set_monitor_channel(rdev, freq, channel_type); |
| 1425 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1426 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1427 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1428 | } |
| 1429 | mutex_unlock(&rdev->devlist_mtx); |
| 1430 | |
| 1431 | return result; |
| 1432 | } |
| 1433 | |
| 1434 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1435 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1436 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1437 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1438 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1439 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1440 | } |
| 1441 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1442 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1443 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1444 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1445 | struct net_device *dev = info->user_ptr[1]; |
| 1446 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1447 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1448 | |
| 1449 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1450 | return -EINVAL; |
| 1451 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1452 | if (netif_running(dev)) |
| 1453 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1454 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1455 | if (!rdev->ops->set_wds_peer) |
| 1456 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1457 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1458 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1459 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1460 | |
| 1461 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1462 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1466 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1467 | { |
| 1468 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1469 | struct net_device *netdev = NULL; |
| 1470 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1471 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1472 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1473 | u32 changed; |
| 1474 | u8 retry_short = 0, retry_long = 0; |
| 1475 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1476 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1477 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1478 | /* |
| 1479 | * Try to find the wiphy and netdev. Normally this |
| 1480 | * function shouldn't need the netdev, but this is |
| 1481 | * done for backward compatibility -- previously |
| 1482 | * setting the channel was done per wiphy, but now |
| 1483 | * it is per netdev. Previous userland like hostapd |
| 1484 | * also passed a netdev to set_wiphy, so that it is |
| 1485 | * possible to let that go to the right netdev! |
| 1486 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1487 | mutex_lock(&cfg80211_mutex); |
| 1488 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1489 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1490 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1491 | |
| 1492 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1493 | if (netdev && netdev->ieee80211_ptr) { |
| 1494 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1495 | mutex_lock(&rdev->mtx); |
| 1496 | } else |
| 1497 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1498 | } |
| 1499 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1500 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1501 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1502 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1503 | if (IS_ERR(rdev)) { |
| 1504 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1505 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1506 | } |
| 1507 | wdev = NULL; |
| 1508 | netdev = NULL; |
| 1509 | result = 0; |
| 1510 | |
| 1511 | mutex_lock(&rdev->mtx); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1512 | } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1513 | wdev = netdev->ieee80211_ptr; |
| 1514 | else |
| 1515 | wdev = NULL; |
| 1516 | |
| 1517 | /* |
| 1518 | * end workaround code, by now the rdev is available |
| 1519 | * and locked, and wdev may or may not be NULL. |
| 1520 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1521 | |
| 1522 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1523 | result = cfg80211_dev_rename( |
| 1524 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1525 | |
| 1526 | mutex_unlock(&cfg80211_mutex); |
| 1527 | |
| 1528 | if (result) |
| 1529 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1530 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1531 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1532 | struct ieee80211_txq_params txq_params; |
| 1533 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1534 | |
| 1535 | if (!rdev->ops->set_txq_params) { |
| 1536 | result = -EOPNOTSUPP; |
| 1537 | goto bad_res; |
| 1538 | } |
| 1539 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1540 | if (!netdev) { |
| 1541 | result = -EINVAL; |
| 1542 | goto bad_res; |
| 1543 | } |
| 1544 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1545 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1546 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1547 | result = -EINVAL; |
| 1548 | goto bad_res; |
| 1549 | } |
| 1550 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1551 | if (!netif_running(netdev)) { |
| 1552 | result = -ENETDOWN; |
| 1553 | goto bad_res; |
| 1554 | } |
| 1555 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1556 | nla_for_each_nested(nl_txq_params, |
| 1557 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1558 | rem_txq_params) { |
| 1559 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1560 | nla_data(nl_txq_params), |
| 1561 | nla_len(nl_txq_params), |
| 1562 | txq_params_policy); |
| 1563 | result = parse_txq_params(tb, &txq_params); |
| 1564 | if (result) |
| 1565 | goto bad_res; |
| 1566 | |
| 1567 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1568 | netdev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1569 | &txq_params); |
| 1570 | if (result) |
| 1571 | goto bad_res; |
| 1572 | } |
| 1573 | } |
| 1574 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1575 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1576 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1577 | if (result) |
| 1578 | goto bad_res; |
| 1579 | } |
| 1580 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1581 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1582 | enum nl80211_tx_power_setting type; |
| 1583 | int idx, mbm = 0; |
| 1584 | |
| 1585 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1586 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1587 | goto bad_res; |
| 1588 | } |
| 1589 | |
| 1590 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1591 | type = nla_get_u32(info->attrs[idx]); |
| 1592 | |
| 1593 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1594 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1595 | result = -EINVAL; |
| 1596 | goto bad_res; |
| 1597 | } |
| 1598 | |
| 1599 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1600 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1601 | mbm = nla_get_u32(info->attrs[idx]); |
| 1602 | } |
| 1603 | |
| 1604 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1605 | if (result) |
| 1606 | goto bad_res; |
| 1607 | } |
| 1608 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1609 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1610 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1611 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1612 | if ((!rdev->wiphy.available_antennas_tx && |
| 1613 | !rdev->wiphy.available_antennas_rx) || |
| 1614 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1615 | result = -EOPNOTSUPP; |
| 1616 | goto bad_res; |
| 1617 | } |
| 1618 | |
| 1619 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1620 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1621 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1622 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1623 | * available antenna masks, except for the "all" mask */ |
| 1624 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1625 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1626 | result = -EINVAL; |
| 1627 | goto bad_res; |
| 1628 | } |
| 1629 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1630 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1631 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1632 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1633 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1634 | if (result) |
| 1635 | goto bad_res; |
| 1636 | } |
| 1637 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1638 | changed = 0; |
| 1639 | |
| 1640 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1641 | retry_short = nla_get_u8( |
| 1642 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1643 | if (retry_short == 0) { |
| 1644 | result = -EINVAL; |
| 1645 | goto bad_res; |
| 1646 | } |
| 1647 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1648 | } |
| 1649 | |
| 1650 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1651 | retry_long = nla_get_u8( |
| 1652 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1653 | if (retry_long == 0) { |
| 1654 | result = -EINVAL; |
| 1655 | goto bad_res; |
| 1656 | } |
| 1657 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1658 | } |
| 1659 | |
| 1660 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1661 | frag_threshold = nla_get_u32( |
| 1662 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1663 | if (frag_threshold < 256) { |
| 1664 | result = -EINVAL; |
| 1665 | goto bad_res; |
| 1666 | } |
| 1667 | if (frag_threshold != (u32) -1) { |
| 1668 | /* |
| 1669 | * Fragments (apart from the last one) are required to |
| 1670 | * have even length. Make the fragmentation code |
| 1671 | * simpler by stripping LSB should someone try to use |
| 1672 | * odd threshold value. |
| 1673 | */ |
| 1674 | frag_threshold &= ~0x1; |
| 1675 | } |
| 1676 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1677 | } |
| 1678 | |
| 1679 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1680 | rts_threshold = nla_get_u32( |
| 1681 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1682 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1683 | } |
| 1684 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1685 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1686 | coverage_class = nla_get_u8( |
| 1687 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1688 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1689 | } |
| 1690 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1691 | if (changed) { |
| 1692 | u8 old_retry_short, old_retry_long; |
| 1693 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1694 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1695 | |
| 1696 | if (!rdev->ops->set_wiphy_params) { |
| 1697 | result = -EOPNOTSUPP; |
| 1698 | goto bad_res; |
| 1699 | } |
| 1700 | |
| 1701 | old_retry_short = rdev->wiphy.retry_short; |
| 1702 | old_retry_long = rdev->wiphy.retry_long; |
| 1703 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1704 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1705 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1706 | |
| 1707 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1708 | rdev->wiphy.retry_short = retry_short; |
| 1709 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1710 | rdev->wiphy.retry_long = retry_long; |
| 1711 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1712 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1713 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1714 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1715 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1716 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1717 | |
| 1718 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1719 | if (result) { |
| 1720 | rdev->wiphy.retry_short = old_retry_short; |
| 1721 | rdev->wiphy.retry_long = old_retry_long; |
| 1722 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1723 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1724 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1725 | } |
| 1726 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1727 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1728 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1729 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1730 | if (netdev) |
| 1731 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1732 | return result; |
| 1733 | } |
| 1734 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1735 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1736 | { |
| 1737 | return (u64)wdev->identifier | |
| 1738 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1739 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1740 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1741 | 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] | 1742 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1743 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1744 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1745 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1746 | void *hdr; |
| 1747 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1748 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1749 | if (!hdr) |
| 1750 | return -1; |
| 1751 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1752 | if (dev && |
| 1753 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1754 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1755 | goto nla_put_failure; |
| 1756 | |
| 1757 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1758 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1759 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1760 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1761 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1762 | rdev->devlist_generation ^ |
| 1763 | (cfg80211_rdev_list_generation << 2))) |
| 1764 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1765 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1766 | if (rdev->ops->get_channel) { |
| 1767 | struct ieee80211_channel *chan; |
| 1768 | enum nl80211_channel_type channel_type; |
| 1769 | |
| 1770 | chan = rdev->ops->get_channel(&rdev->wiphy, wdev, |
| 1771 | &channel_type); |
| 1772 | if (chan && |
| 1773 | (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1774 | chan->center_freq) || |
| 1775 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1776 | channel_type))) |
John W. Linville | 59ef43e | 2012-04-18 14:17:13 -0400 | [diff] [blame] | 1777 | goto nla_put_failure; |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1778 | } |
| 1779 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1780 | return genlmsg_end(msg, hdr); |
| 1781 | |
| 1782 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1783 | genlmsg_cancel(msg, hdr); |
| 1784 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1788 | { |
| 1789 | int wp_idx = 0; |
| 1790 | int if_idx = 0; |
| 1791 | int wp_start = cb->args[0]; |
| 1792 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1793 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1794 | struct wireless_dev *wdev; |
| 1795 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1796 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1797 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1798 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1799 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1800 | if (wp_idx < wp_start) { |
| 1801 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1802 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1803 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1804 | if_idx = 0; |
| 1805 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1806 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1807 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1808 | if (if_idx < if_start) { |
| 1809 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1810 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1811 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1812 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1813 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1814 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1815 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1816 | goto out; |
| 1817 | } |
| 1818 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1819 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1820 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1821 | |
| 1822 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1823 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1824 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1825 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1826 | |
| 1827 | cb->args[0] = wp_idx; |
| 1828 | cb->args[1] = if_idx; |
| 1829 | |
| 1830 | return skb->len; |
| 1831 | } |
| 1832 | |
| 1833 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1834 | { |
| 1835 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1836 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1837 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1838 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1839 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1840 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1841 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1842 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1843 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1844 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1845 | nlmsg_free(msg); |
| 1846 | return -ENOBUFS; |
| 1847 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1848 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1849 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1850 | } |
| 1851 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1852 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1853 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1854 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1855 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1856 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1857 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1858 | }; |
| 1859 | |
| 1860 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1861 | { |
| 1862 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1863 | int flag; |
| 1864 | |
| 1865 | *mntrflags = 0; |
| 1866 | |
| 1867 | if (!nla) |
| 1868 | return -EINVAL; |
| 1869 | |
| 1870 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1871 | nla, mntr_flags_policy)) |
| 1872 | return -EINVAL; |
| 1873 | |
| 1874 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1875 | if (flags[flag]) |
| 1876 | *mntrflags |= (1<<flag); |
| 1877 | |
| 1878 | return 0; |
| 1879 | } |
| 1880 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1881 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1882 | struct net_device *netdev, u8 use_4addr, |
| 1883 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1884 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1885 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1886 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1887 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1888 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1889 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1890 | |
| 1891 | switch (iftype) { |
| 1892 | case NL80211_IFTYPE_AP_VLAN: |
| 1893 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1894 | return 0; |
| 1895 | break; |
| 1896 | case NL80211_IFTYPE_STATION: |
| 1897 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1898 | return 0; |
| 1899 | break; |
| 1900 | default: |
| 1901 | break; |
| 1902 | } |
| 1903 | |
| 1904 | return -EOPNOTSUPP; |
| 1905 | } |
| 1906 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1907 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1908 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1909 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1910 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1911 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1912 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1913 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1914 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1915 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1916 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1917 | memset(¶ms, 0, sizeof(params)); |
| 1918 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1919 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1920 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1921 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1922 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1923 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1924 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1925 | if (ntype > NL80211_IFTYPE_MAX) |
| 1926 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1927 | } |
| 1928 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1929 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1930 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1931 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1932 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1933 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1934 | if (netif_running(dev)) |
| 1935 | return -EBUSY; |
| 1936 | |
| 1937 | wdev_lock(wdev); |
| 1938 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1939 | IEEE80211_MAX_MESH_ID_LEN); |
| 1940 | wdev->mesh_id_up_len = |
| 1941 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1942 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1943 | wdev->mesh_id_up_len); |
| 1944 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1945 | } |
| 1946 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1947 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1948 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1949 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1950 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1951 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1952 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1953 | } else { |
| 1954 | params.use_4addr = -1; |
| 1955 | } |
| 1956 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1957 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1958 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1959 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1960 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1961 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1962 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1963 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1964 | |
| 1965 | flags = &_flags; |
| 1966 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1967 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1968 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1969 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1970 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1971 | else |
| 1972 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1973 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1974 | if (!err && params.use_4addr != -1) |
| 1975 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1976 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1977 | return err; |
| 1978 | } |
| 1979 | |
| 1980 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1981 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1982 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1983 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 1984 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 1985 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1986 | int err; |
| 1987 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1988 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1989 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1990 | memset(¶ms, 0, sizeof(params)); |
| 1991 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1992 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1993 | return -EINVAL; |
| 1994 | |
| 1995 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1996 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1997 | if (type > NL80211_IFTYPE_MAX) |
| 1998 | return -EINVAL; |
| 1999 | } |
| 2000 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2001 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2002 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2003 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2004 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2005 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2006 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2007 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2008 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2009 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2010 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2011 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2012 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2013 | if (!msg) |
| 2014 | return -ENOMEM; |
| 2015 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2016 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2017 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2018 | &flags); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2019 | wdev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2020 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2021 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2022 | if (IS_ERR(wdev)) { |
| 2023 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2024 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2025 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2026 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2027 | switch (type) { |
| 2028 | case NL80211_IFTYPE_MESH_POINT: |
| 2029 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2030 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2031 | wdev_lock(wdev); |
| 2032 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2033 | IEEE80211_MAX_MESH_ID_LEN); |
| 2034 | wdev->mesh_id_up_len = |
| 2035 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2036 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2037 | wdev->mesh_id_up_len); |
| 2038 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2039 | break; |
| 2040 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2041 | /* |
| 2042 | * P2P Device doesn't have a netdev, so doesn't go |
| 2043 | * through the netdev notifier and must be added here |
| 2044 | */ |
| 2045 | mutex_init(&wdev->mtx); |
| 2046 | INIT_LIST_HEAD(&wdev->event_list); |
| 2047 | spin_lock_init(&wdev->event_lock); |
| 2048 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2049 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2050 | |
| 2051 | mutex_lock(&rdev->devlist_mtx); |
| 2052 | wdev->identifier = ++rdev->wdev_id; |
| 2053 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2054 | rdev->devlist_generation++; |
| 2055 | mutex_unlock(&rdev->devlist_mtx); |
| 2056 | break; |
| 2057 | default: |
| 2058 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2059 | } |
| 2060 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2061 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2062 | rdev, wdev) < 0) { |
| 2063 | nlmsg_free(msg); |
| 2064 | return -ENOBUFS; |
| 2065 | } |
| 2066 | |
| 2067 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2068 | } |
| 2069 | |
| 2070 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2071 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2072 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2073 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2074 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2075 | if (!rdev->ops->del_virtual_intf) |
| 2076 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2077 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2078 | /* |
| 2079 | * If we remove a wireless device without a netdev then clear |
| 2080 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2081 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2082 | * since the wdev has been freed, unlike with a netdev where |
| 2083 | * we need the dev_put() for the netdev to really be freed. |
| 2084 | */ |
| 2085 | if (!wdev->netdev) |
| 2086 | info->user_ptr[1] = NULL; |
| 2087 | |
| 2088 | return rdev->ops->del_virtual_intf(&rdev->wiphy, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2089 | } |
| 2090 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2091 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2092 | { |
| 2093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2094 | struct net_device *dev = info->user_ptr[1]; |
| 2095 | u16 noack_map; |
| 2096 | |
| 2097 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2098 | return -EINVAL; |
| 2099 | |
| 2100 | if (!rdev->ops->set_noack_map) |
| 2101 | return -EOPNOTSUPP; |
| 2102 | |
| 2103 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2104 | |
| 2105 | return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map); |
| 2106 | } |
| 2107 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2108 | struct get_key_cookie { |
| 2109 | struct sk_buff *msg; |
| 2110 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2111 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2112 | }; |
| 2113 | |
| 2114 | static void get_key_callback(void *c, struct key_params *params) |
| 2115 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2116 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2117 | struct get_key_cookie *cookie = c; |
| 2118 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2119 | if ((params->key && |
| 2120 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2121 | params->key_len, params->key)) || |
| 2122 | (params->seq && |
| 2123 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2124 | params->seq_len, params->seq)) || |
| 2125 | (params->cipher && |
| 2126 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2127 | params->cipher))) |
| 2128 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2129 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2130 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2131 | if (!key) |
| 2132 | goto nla_put_failure; |
| 2133 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2134 | if ((params->key && |
| 2135 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2136 | params->key_len, params->key)) || |
| 2137 | (params->seq && |
| 2138 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2139 | params->seq_len, params->seq)) || |
| 2140 | (params->cipher && |
| 2141 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2142 | params->cipher))) |
| 2143 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2144 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2145 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2146 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2147 | |
| 2148 | nla_nest_end(cookie->msg, key); |
| 2149 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2150 | return; |
| 2151 | nla_put_failure: |
| 2152 | cookie->error = 1; |
| 2153 | } |
| 2154 | |
| 2155 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2156 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2157 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2158 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2159 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2160 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2161 | const u8 *mac_addr = NULL; |
| 2162 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2163 | struct get_key_cookie cookie = { |
| 2164 | .error = 0, |
| 2165 | }; |
| 2166 | void *hdr; |
| 2167 | struct sk_buff *msg; |
| 2168 | |
| 2169 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2170 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2171 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2172 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2173 | return -EINVAL; |
| 2174 | |
| 2175 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2176 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2177 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2178 | pairwise = !!mac_addr; |
| 2179 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2180 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2181 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2182 | return -EINVAL; |
| 2183 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2184 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2185 | return -EINVAL; |
| 2186 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2187 | } |
| 2188 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2189 | if (!rdev->ops->get_key) |
| 2190 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2191 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2192 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2193 | if (!msg) |
| 2194 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2195 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2196 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2197 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2198 | if (IS_ERR(hdr)) |
| 2199 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2200 | |
| 2201 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2202 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2203 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2204 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2205 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2206 | goto nla_put_failure; |
| 2207 | if (mac_addr && |
| 2208 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2209 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2210 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2211 | if (pairwise && mac_addr && |
| 2212 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2213 | return -ENOENT; |
| 2214 | |
| 2215 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 2216 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2217 | |
| 2218 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2219 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2220 | |
| 2221 | if (cookie.error) |
| 2222 | goto nla_put_failure; |
| 2223 | |
| 2224 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2225 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2226 | |
| 2227 | nla_put_failure: |
| 2228 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2229 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2230 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2231 | return err; |
| 2232 | } |
| 2233 | |
| 2234 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2235 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2236 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2237 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2238 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2239 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2240 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2241 | err = nl80211_parse_key(info, &key); |
| 2242 | if (err) |
| 2243 | return err; |
| 2244 | |
| 2245 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2246 | return -EINVAL; |
| 2247 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2248 | /* only support setting default key */ |
| 2249 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2250 | return -EINVAL; |
| 2251 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2252 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2253 | |
| 2254 | if (key.def) { |
| 2255 | if (!rdev->ops->set_default_key) { |
| 2256 | err = -EOPNOTSUPP; |
| 2257 | goto out; |
| 2258 | } |
| 2259 | |
| 2260 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2261 | if (err) |
| 2262 | goto out; |
| 2263 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2264 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 2265 | key.def_uni, key.def_multi); |
| 2266 | |
| 2267 | if (err) |
| 2268 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2269 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2270 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2271 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2272 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2273 | } else { |
| 2274 | if (key.def_uni || !key.def_multi) { |
| 2275 | err = -EINVAL; |
| 2276 | goto out; |
| 2277 | } |
| 2278 | |
| 2279 | if (!rdev->ops->set_default_mgmt_key) { |
| 2280 | err = -EOPNOTSUPP; |
| 2281 | goto out; |
| 2282 | } |
| 2283 | |
| 2284 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2285 | if (err) |
| 2286 | goto out; |
| 2287 | |
| 2288 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 2289 | dev, key.idx); |
| 2290 | if (err) |
| 2291 | goto out; |
| 2292 | |
| 2293 | #ifdef CONFIG_CFG80211_WEXT |
| 2294 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2295 | #endif |
| 2296 | } |
| 2297 | |
| 2298 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2299 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2300 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2301 | return err; |
| 2302 | } |
| 2303 | |
| 2304 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2305 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2307 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2308 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2309 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2310 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2311 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2312 | err = nl80211_parse_key(info, &key); |
| 2313 | if (err) |
| 2314 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2315 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2316 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2317 | return -EINVAL; |
| 2318 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2319 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2320 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2321 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2322 | if (key.type == -1) { |
| 2323 | if (mac_addr) |
| 2324 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2325 | else |
| 2326 | key.type = NL80211_KEYTYPE_GROUP; |
| 2327 | } |
| 2328 | |
| 2329 | /* for now */ |
| 2330 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2331 | key.type != NL80211_KEYTYPE_GROUP) |
| 2332 | return -EINVAL; |
| 2333 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2334 | if (!rdev->ops->add_key) |
| 2335 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2336 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2337 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2338 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2339 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2340 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2341 | |
| 2342 | wdev_lock(dev->ieee80211_ptr); |
| 2343 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2344 | if (!err) |
| 2345 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2346 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2347 | mac_addr, &key.p); |
| 2348 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2349 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2350 | return err; |
| 2351 | } |
| 2352 | |
| 2353 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2354 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2355 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2356 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2357 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2358 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2359 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2360 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2361 | err = nl80211_parse_key(info, &key); |
| 2362 | if (err) |
| 2363 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2364 | |
| 2365 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2366 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2367 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2368 | if (key.type == -1) { |
| 2369 | if (mac_addr) |
| 2370 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2371 | else |
| 2372 | key.type = NL80211_KEYTYPE_GROUP; |
| 2373 | } |
| 2374 | |
| 2375 | /* for now */ |
| 2376 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2377 | key.type != NL80211_KEYTYPE_GROUP) |
| 2378 | return -EINVAL; |
| 2379 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2380 | if (!rdev->ops->del_key) |
| 2381 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2382 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2383 | wdev_lock(dev->ieee80211_ptr); |
| 2384 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2385 | |
| 2386 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2387 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2388 | err = -ENOENT; |
| 2389 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2390 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2391 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 2392 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2393 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2394 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2395 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2396 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2397 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2398 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2399 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2400 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2401 | } |
| 2402 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2403 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2404 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2405 | return err; |
| 2406 | } |
| 2407 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2408 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2409 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2410 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2411 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2412 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2413 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2414 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2415 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2416 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2417 | return -EINVAL; |
| 2418 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2419 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2420 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2421 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2422 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2423 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2424 | if (!bcn->head_len) |
| 2425 | return -EINVAL; |
| 2426 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2430 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2431 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2432 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2433 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2434 | } |
| 2435 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2436 | if (!haveinfo) |
| 2437 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2438 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2439 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2440 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2441 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2445 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2446 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2447 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2448 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2449 | } |
| 2450 | |
| 2451 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2452 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2453 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2454 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2455 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2456 | } |
| 2457 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2458 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2459 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2460 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2461 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2462 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2463 | } |
| 2464 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2465 | return 0; |
| 2466 | } |
| 2467 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2468 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2469 | struct cfg80211_ap_settings *params) |
| 2470 | { |
| 2471 | struct wireless_dev *wdev; |
| 2472 | bool ret = false; |
| 2473 | |
| 2474 | mutex_lock(&rdev->devlist_mtx); |
| 2475 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2476 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2477 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2478 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2479 | continue; |
| 2480 | |
| 2481 | if (!wdev->preset_chan) |
| 2482 | continue; |
| 2483 | |
| 2484 | params->channel = wdev->preset_chan; |
| 2485 | params->channel_type = wdev->preset_chantype; |
| 2486 | ret = true; |
| 2487 | break; |
| 2488 | } |
| 2489 | |
| 2490 | mutex_unlock(&rdev->devlist_mtx); |
| 2491 | |
| 2492 | return ret; |
| 2493 | } |
| 2494 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2495 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2496 | enum nl80211_auth_type auth_type, |
| 2497 | enum nl80211_commands cmd) |
| 2498 | { |
| 2499 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2500 | return false; |
| 2501 | |
| 2502 | switch (cmd) { |
| 2503 | case NL80211_CMD_AUTHENTICATE: |
| 2504 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2505 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2506 | return false; |
| 2507 | return true; |
| 2508 | case NL80211_CMD_CONNECT: |
| 2509 | case NL80211_CMD_START_AP: |
| 2510 | /* SAE not supported yet */ |
| 2511 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2512 | return false; |
| 2513 | return true; |
| 2514 | default: |
| 2515 | return false; |
| 2516 | } |
| 2517 | } |
| 2518 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2519 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2520 | { |
| 2521 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2522 | struct net_device *dev = info->user_ptr[1]; |
| 2523 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2524 | struct cfg80211_ap_settings params; |
| 2525 | int err; |
| 2526 | |
| 2527 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2528 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2529 | return -EOPNOTSUPP; |
| 2530 | |
| 2531 | if (!rdev->ops->start_ap) |
| 2532 | return -EOPNOTSUPP; |
| 2533 | |
| 2534 | if (wdev->beacon_interval) |
| 2535 | return -EALREADY; |
| 2536 | |
| 2537 | memset(¶ms, 0, sizeof(params)); |
| 2538 | |
| 2539 | /* these are required for START_AP */ |
| 2540 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2541 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2542 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2543 | return -EINVAL; |
| 2544 | |
| 2545 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2546 | if (err) |
| 2547 | return err; |
| 2548 | |
| 2549 | params.beacon_interval = |
| 2550 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2551 | params.dtim_period = |
| 2552 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2553 | |
| 2554 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2555 | if (err) |
| 2556 | return err; |
| 2557 | |
| 2558 | /* |
| 2559 | * In theory, some of these attributes should be required here |
| 2560 | * but since they were not used when the command was originally |
| 2561 | * added, keep them optional for old user space programs to let |
| 2562 | * them continue to work with drivers that do not need the |
| 2563 | * additional information -- drivers must check! |
| 2564 | */ |
| 2565 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2566 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2567 | params.ssid_len = |
| 2568 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2569 | if (params.ssid_len == 0 || |
| 2570 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2571 | return -EINVAL; |
| 2572 | } |
| 2573 | |
| 2574 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2575 | params.hidden_ssid = nla_get_u32( |
| 2576 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2577 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2578 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2579 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2580 | return -EINVAL; |
| 2581 | } |
| 2582 | |
| 2583 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2584 | |
| 2585 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2586 | params.auth_type = nla_get_u32( |
| 2587 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2588 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 2589 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2590 | return -EINVAL; |
| 2591 | } else |
| 2592 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2593 | |
| 2594 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2595 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2596 | if (err) |
| 2597 | return err; |
| 2598 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2599 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2600 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2601 | return -EOPNOTSUPP; |
| 2602 | params.inactivity_timeout = nla_get_u16( |
| 2603 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2604 | } |
| 2605 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2606 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 2607 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 2608 | |
| 2609 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 2610 | !nl80211_valid_channel_type(info, &channel_type)) |
| 2611 | return -EINVAL; |
| 2612 | |
| 2613 | params.channel = rdev_freq_to_chan(rdev, |
| 2614 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 2615 | channel_type); |
| 2616 | if (!params.channel) |
| 2617 | return -EINVAL; |
| 2618 | params.channel_type = channel_type; |
| 2619 | } else if (wdev->preset_chan) { |
| 2620 | params.channel = wdev->preset_chan; |
| 2621 | params.channel_type = wdev->preset_chantype; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2622 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2623 | return -EINVAL; |
| 2624 | |
| 2625 | if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel, |
| 2626 | params.channel_type)) |
| 2627 | return -EINVAL; |
| 2628 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2629 | mutex_lock(&rdev->devlist_mtx); |
| 2630 | err = cfg80211_can_use_chan(rdev, wdev, params.channel, |
| 2631 | CHAN_MODE_SHARED); |
| 2632 | mutex_unlock(&rdev->devlist_mtx); |
| 2633 | |
| 2634 | if (err) |
| 2635 | return err; |
| 2636 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2637 | err = rdev->ops->start_ap(&rdev->wiphy, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2638 | if (!err) { |
| 2639 | wdev->preset_chan = params.channel; |
| 2640 | wdev->preset_chantype = params.channel_type; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2641 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | f4489eb | 2012-06-29 12:46:58 +0200 | [diff] [blame] | 2642 | wdev->channel = params.channel; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2643 | } |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2644 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2645 | } |
| 2646 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2647 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2648 | { |
| 2649 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2650 | struct net_device *dev = info->user_ptr[1]; |
| 2651 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2652 | struct cfg80211_beacon_data params; |
| 2653 | int err; |
| 2654 | |
| 2655 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2656 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2657 | return -EOPNOTSUPP; |
| 2658 | |
| 2659 | if (!rdev->ops->change_beacon) |
| 2660 | return -EOPNOTSUPP; |
| 2661 | |
| 2662 | if (!wdev->beacon_interval) |
| 2663 | return -EINVAL; |
| 2664 | |
| 2665 | err = nl80211_parse_beacon(info, ¶ms); |
| 2666 | if (err) |
| 2667 | return err; |
| 2668 | |
| 2669 | return rdev->ops->change_beacon(&rdev->wiphy, dev, ¶ms); |
| 2670 | } |
| 2671 | |
| 2672 | 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] | 2673 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2674 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2675 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2676 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2677 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2678 | } |
| 2679 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2680 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2681 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2682 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2683 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2684 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2685 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2686 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2687 | }; |
| 2688 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2689 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2690 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2691 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2692 | { |
| 2693 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2694 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2695 | int flag; |
| 2696 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2697 | /* |
| 2698 | * Try parsing the new attribute first so userspace |
| 2699 | * can specify both for older kernels. |
| 2700 | */ |
| 2701 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2702 | if (nla) { |
| 2703 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2704 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2705 | sta_flags = nla_data(nla); |
| 2706 | params->sta_flags_mask = sta_flags->mask; |
| 2707 | params->sta_flags_set = sta_flags->set; |
| 2708 | if ((params->sta_flags_mask | |
| 2709 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2710 | return -EINVAL; |
| 2711 | return 0; |
| 2712 | } |
| 2713 | |
| 2714 | /* if present, parse the old attribute */ |
| 2715 | |
| 2716 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2717 | if (!nla) |
| 2718 | return 0; |
| 2719 | |
| 2720 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2721 | nla, sta_flags_policy)) |
| 2722 | return -EINVAL; |
| 2723 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2724 | /* |
| 2725 | * Only allow certain flags for interface types so that |
| 2726 | * other attributes are silently ignored. Remember that |
| 2727 | * this is backward compatibility code with old userspace |
| 2728 | * and shouldn't be hit in other cases anyway. |
| 2729 | */ |
| 2730 | switch (iftype) { |
| 2731 | case NL80211_IFTYPE_AP: |
| 2732 | case NL80211_IFTYPE_AP_VLAN: |
| 2733 | case NL80211_IFTYPE_P2P_GO: |
| 2734 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2735 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2736 | BIT(NL80211_STA_FLAG_WME) | |
| 2737 | BIT(NL80211_STA_FLAG_MFP); |
| 2738 | break; |
| 2739 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2740 | case NL80211_IFTYPE_STATION: |
| 2741 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2742 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2743 | break; |
| 2744 | case NL80211_IFTYPE_MESH_POINT: |
| 2745 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2746 | BIT(NL80211_STA_FLAG_MFP) | |
| 2747 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2748 | default: |
| 2749 | return -EINVAL; |
| 2750 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2751 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2752 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 2753 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2754 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2755 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2756 | /* no longer support new API additions in old API */ |
| 2757 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 2758 | return -EINVAL; |
| 2759 | } |
| 2760 | } |
| 2761 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2762 | return 0; |
| 2763 | } |
| 2764 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2765 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2766 | int attr) |
| 2767 | { |
| 2768 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2769 | u32 bitrate; |
| 2770 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2771 | |
| 2772 | rate = nla_nest_start(msg, attr); |
| 2773 | if (!rate) |
| 2774 | goto nla_put_failure; |
| 2775 | |
| 2776 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2777 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2778 | /* report 16-bit bitrate only if we can */ |
| 2779 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2780 | if ((bitrate > 0 && |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2781 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) || |
| 2782 | (bitrate_compat > 0 && |
| 2783 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2784 | ((info->flags & RATE_INFO_FLAGS_MCS) && |
| 2785 | nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) || |
| 2786 | ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) && |
| 2787 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) || |
| 2788 | ((info->flags & RATE_INFO_FLAGS_SHORT_GI) && |
| 2789 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))) |
| 2790 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2791 | |
| 2792 | nla_nest_end(msg, rate); |
| 2793 | return true; |
| 2794 | |
| 2795 | nla_put_failure: |
| 2796 | return false; |
| 2797 | } |
| 2798 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2799 | 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] | 2800 | int flags, |
| 2801 | struct cfg80211_registered_device *rdev, |
| 2802 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2803 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2804 | { |
| 2805 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2806 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2807 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2808 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2809 | if (!hdr) |
| 2810 | return -1; |
| 2811 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2812 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2813 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 2814 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 2815 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2816 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2817 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2818 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2819 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2820 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 2821 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2822 | sinfo->connected_time)) |
| 2823 | goto nla_put_failure; |
| 2824 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 2825 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2826 | sinfo->inactive_time)) |
| 2827 | goto nla_put_failure; |
| 2828 | if ((sinfo->filled & STATION_INFO_RX_BYTES) && |
| 2829 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2830 | sinfo->rx_bytes)) |
| 2831 | goto nla_put_failure; |
| 2832 | if ((sinfo->filled & STATION_INFO_TX_BYTES) && |
| 2833 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2834 | sinfo->tx_bytes)) |
| 2835 | goto nla_put_failure; |
| 2836 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 2837 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 2838 | goto nla_put_failure; |
| 2839 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 2840 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 2841 | goto nla_put_failure; |
| 2842 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 2843 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2844 | sinfo->plink_state)) |
| 2845 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2846 | switch (rdev->wiphy.signal_type) { |
| 2847 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2848 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 2849 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 2850 | sinfo->signal)) |
| 2851 | goto nla_put_failure; |
| 2852 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 2853 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2854 | sinfo->signal_avg)) |
| 2855 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2856 | break; |
| 2857 | default: |
| 2858 | break; |
| 2859 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2860 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2861 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2862 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2863 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2864 | } |
| 2865 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2866 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2867 | NL80211_STA_INFO_RX_BITRATE)) |
| 2868 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2869 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2870 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 2871 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2872 | sinfo->rx_packets)) |
| 2873 | goto nla_put_failure; |
| 2874 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 2875 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2876 | sinfo->tx_packets)) |
| 2877 | goto nla_put_failure; |
| 2878 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 2879 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2880 | sinfo->tx_retries)) |
| 2881 | goto nla_put_failure; |
| 2882 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 2883 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2884 | sinfo->tx_failed)) |
| 2885 | goto nla_put_failure; |
| 2886 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 2887 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 2888 | sinfo->beacon_loss_count)) |
| 2889 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2890 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2891 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2892 | if (!bss_param) |
| 2893 | goto nla_put_failure; |
| 2894 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2895 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 2896 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 2897 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 2898 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 2899 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 2900 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 2901 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2902 | sinfo->bss_param.dtim_period) || |
| 2903 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2904 | sinfo->bss_param.beacon_interval)) |
| 2905 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2906 | |
| 2907 | nla_nest_end(msg, bss_param); |
| 2908 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2909 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 2910 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2911 | sizeof(struct nl80211_sta_flag_update), |
| 2912 | &sinfo->sta_flags)) |
| 2913 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 2914 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 2915 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 2916 | sinfo->t_offset)) |
| 2917 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2918 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2919 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2920 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 2921 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2922 | sinfo->assoc_req_ies)) |
| 2923 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2924 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2925 | return genlmsg_end(msg, hdr); |
| 2926 | |
| 2927 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2928 | genlmsg_cancel(msg, hdr); |
| 2929 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2930 | } |
| 2931 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2932 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2933 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2934 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2935 | struct station_info sinfo; |
| 2936 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2937 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2938 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2939 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2940 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2941 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2942 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2943 | if (err) |
| 2944 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2945 | |
| 2946 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2947 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2948 | goto out_err; |
| 2949 | } |
| 2950 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2951 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2952 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2953 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2954 | mac_addr, &sinfo); |
| 2955 | if (err == -ENOENT) |
| 2956 | break; |
| 2957 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2958 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2959 | |
| 2960 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2961 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2962 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2963 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2964 | &sinfo) < 0) |
| 2965 | goto out; |
| 2966 | |
| 2967 | sta_idx++; |
| 2968 | } |
| 2969 | |
| 2970 | |
| 2971 | out: |
| 2972 | cb->args[1] = sta_idx; |
| 2973 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2974 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2975 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2976 | |
| 2977 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2978 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2979 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2980 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2981 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2982 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2983 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2984 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2985 | struct sk_buff *msg; |
| 2986 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2987 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2988 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2989 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2990 | |
| 2991 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2992 | return -EINVAL; |
| 2993 | |
| 2994 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2995 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2996 | if (!rdev->ops->get_station) |
| 2997 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2998 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2999 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3000 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3001 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3002 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3003 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3004 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3005 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3006 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3007 | 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] | 3008 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3009 | nlmsg_free(msg); |
| 3010 | return -ENOBUFS; |
| 3011 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3012 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3013 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3014 | } |
| 3015 | |
| 3016 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3017 | * 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] | 3018 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3019 | static struct net_device *get_vlan(struct genl_info *info, |
| 3020 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3021 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3022 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3023 | struct net_device *v; |
| 3024 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3025 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3026 | if (!vlanattr) |
| 3027 | return NULL; |
| 3028 | |
| 3029 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3030 | if (!v) |
| 3031 | return ERR_PTR(-ENODEV); |
| 3032 | |
| 3033 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3034 | ret = -EINVAL; |
| 3035 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3036 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3037 | |
| 3038 | if (!netif_running(v)) { |
| 3039 | ret = -ENETDOWN; |
| 3040 | goto error; |
| 3041 | } |
| 3042 | |
| 3043 | return v; |
| 3044 | error: |
| 3045 | dev_put(v); |
| 3046 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3047 | } |
| 3048 | |
| 3049 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3050 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3051 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3052 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3053 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3054 | struct station_parameters params; |
| 3055 | u8 *mac_addr = NULL; |
| 3056 | |
| 3057 | memset(¶ms, 0, sizeof(params)); |
| 3058 | |
| 3059 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 3060 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3061 | |
| 3062 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3063 | return -EINVAL; |
| 3064 | |
| 3065 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3066 | return -EINVAL; |
| 3067 | |
| 3068 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3069 | |
| 3070 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3071 | params.supported_rates = |
| 3072 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3073 | params.supported_rates_len = |
| 3074 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3075 | } |
| 3076 | |
| 3077 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3078 | params.listen_interval = |
| 3079 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 3080 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3081 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3082 | params.ht_capa = |
| 3083 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3084 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3085 | if (!rdev->ops->change_station) |
| 3086 | return -EOPNOTSUPP; |
| 3087 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3088 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3089 | return -EINVAL; |
| 3090 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3091 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3092 | params.plink_action = |
| 3093 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3094 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3095 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3096 | params.plink_state = |
| 3097 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3098 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3099 | switch (dev->ieee80211_ptr->iftype) { |
| 3100 | case NL80211_IFTYPE_AP: |
| 3101 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3102 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3103 | /* disallow mesh-specific things */ |
| 3104 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3105 | return -EINVAL; |
| 3106 | |
| 3107 | /* TDLS can't be set, ... */ |
| 3108 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3109 | return -EINVAL; |
| 3110 | /* |
| 3111 | * ... but don't bother the driver with it. This works around |
| 3112 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3113 | * TLDS_PEER flag in the mask even for AP mode. |
| 3114 | */ |
| 3115 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3116 | |
| 3117 | /* accept only the listed bits */ |
| 3118 | if (params.sta_flags_mask & |
| 3119 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3120 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3121 | BIT(NL80211_STA_FLAG_WME) | |
| 3122 | BIT(NL80211_STA_FLAG_MFP))) |
| 3123 | return -EINVAL; |
| 3124 | |
| 3125 | /* must be last in here for error handling */ |
| 3126 | params.vlan = get_vlan(info, rdev); |
| 3127 | if (IS_ERR(params.vlan)) |
| 3128 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3129 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3130 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3131 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3132 | /* |
| 3133 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3134 | * but silently ignore attempts to change it since we |
| 3135 | * don't have state here to verify that it doesn't try |
| 3136 | * to change the flag. |
| 3137 | */ |
| 3138 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3139 | /* fall through */ |
| 3140 | case NL80211_IFTYPE_ADHOC: |
| 3141 | /* disallow things sta doesn't support */ |
| 3142 | if (params.plink_action) |
| 3143 | return -EINVAL; |
| 3144 | if (params.ht_capa) |
| 3145 | return -EINVAL; |
| 3146 | if (params.listen_interval >= 0) |
| 3147 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3148 | /* reject any changes other than AUTHORIZED */ |
| 3149 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3150 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3151 | break; |
| 3152 | case NL80211_IFTYPE_MESH_POINT: |
| 3153 | /* disallow things mesh doesn't support */ |
| 3154 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3155 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3156 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3157 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3158 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3159 | return -EINVAL; |
| 3160 | /* |
| 3161 | * No special handling for TDLS here -- the userspace |
| 3162 | * mesh code doesn't have this bug. |
| 3163 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3164 | if (params.sta_flags_mask & |
| 3165 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3166 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3167 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3168 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3169 | break; |
| 3170 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3171 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3172 | } |
| 3173 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3174 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3175 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3176 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3177 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3178 | if (params.vlan) |
| 3179 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3180 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3181 | return err; |
| 3182 | } |
| 3183 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3184 | static struct nla_policy |
| 3185 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3186 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3187 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3188 | }; |
| 3189 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3190 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3191 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3192 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3193 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3194 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3195 | struct station_parameters params; |
| 3196 | u8 *mac_addr = NULL; |
| 3197 | |
| 3198 | memset(¶ms, 0, sizeof(params)); |
| 3199 | |
| 3200 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3201 | return -EINVAL; |
| 3202 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3203 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3204 | return -EINVAL; |
| 3205 | |
| 3206 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3207 | return -EINVAL; |
| 3208 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3209 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3210 | return -EINVAL; |
| 3211 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3212 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3213 | params.supported_rates = |
| 3214 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3215 | params.supported_rates_len = |
| 3216 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3217 | params.listen_interval = |
| 3218 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3219 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3220 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3221 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3222 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3223 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3224 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3225 | params.ht_capa = |
| 3226 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3227 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3228 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3229 | params.vht_capa = |
| 3230 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3231 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3232 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3233 | params.plink_action = |
| 3234 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3235 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3236 | if (!rdev->ops->add_station) |
| 3237 | return -EOPNOTSUPP; |
| 3238 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3239 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3240 | return -EINVAL; |
| 3241 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3242 | switch (dev->ieee80211_ptr->iftype) { |
| 3243 | case NL80211_IFTYPE_AP: |
| 3244 | case NL80211_IFTYPE_AP_VLAN: |
| 3245 | case NL80211_IFTYPE_P2P_GO: |
| 3246 | /* parse WME attributes if sta is WME capable */ |
| 3247 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3248 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3249 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3250 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3251 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3252 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3253 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3254 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3255 | nl80211_sta_wme_policy); |
| 3256 | if (err) |
| 3257 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3258 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3259 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3260 | params.uapsd_queues = |
| 3261 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3262 | if (params.uapsd_queues & |
| 3263 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3264 | return -EINVAL; |
| 3265 | |
| 3266 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3267 | params.max_sp = |
| 3268 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3269 | |
| 3270 | if (params.max_sp & |
| 3271 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3272 | return -EINVAL; |
| 3273 | |
| 3274 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3275 | } |
| 3276 | /* TDLS peers cannot be added */ |
| 3277 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3278 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3279 | /* but don't bother the driver with it */ |
| 3280 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3281 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3282 | /* must be last in here for error handling */ |
| 3283 | params.vlan = get_vlan(info, rdev); |
| 3284 | if (IS_ERR(params.vlan)) |
| 3285 | return PTR_ERR(params.vlan); |
| 3286 | break; |
| 3287 | case NL80211_IFTYPE_MESH_POINT: |
| 3288 | /* TDLS peers cannot be added */ |
| 3289 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3290 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3291 | break; |
| 3292 | case NL80211_IFTYPE_STATION: |
| 3293 | /* Only TDLS peers can be added */ |
| 3294 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3295 | return -EINVAL; |
| 3296 | /* Can only add if TDLS ... */ |
| 3297 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3298 | return -EOPNOTSUPP; |
| 3299 | /* ... with external setup is supported */ |
| 3300 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3301 | return -EOPNOTSUPP; |
| 3302 | break; |
| 3303 | default: |
| 3304 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3305 | } |
| 3306 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3307 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3308 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3309 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3310 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3311 | if (params.vlan) |
| 3312 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3313 | return err; |
| 3314 | } |
| 3315 | |
| 3316 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3317 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3318 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3319 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3320 | u8 *mac_addr = NULL; |
| 3321 | |
| 3322 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3323 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3324 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3325 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3326 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3327 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3328 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3329 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3330 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3331 | if (!rdev->ops->del_station) |
| 3332 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3333 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3334 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3335 | } |
| 3336 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3337 | 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] | 3338 | int flags, struct net_device *dev, |
| 3339 | u8 *dst, u8 *next_hop, |
| 3340 | struct mpath_info *pinfo) |
| 3341 | { |
| 3342 | void *hdr; |
| 3343 | struct nlattr *pinfoattr; |
| 3344 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3345 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3346 | if (!hdr) |
| 3347 | return -1; |
| 3348 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3349 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3350 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3351 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3352 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3353 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3354 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3355 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3356 | if (!pinfoattr) |
| 3357 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3358 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3359 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3360 | pinfo->frame_qlen)) |
| 3361 | goto nla_put_failure; |
| 3362 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3363 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3364 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3365 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3366 | pinfo->metric)) || |
| 3367 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3368 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3369 | pinfo->exptime)) || |
| 3370 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3371 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3372 | pinfo->flags)) || |
| 3373 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3374 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3375 | pinfo->discovery_timeout)) || |
| 3376 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3377 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3378 | pinfo->discovery_retries))) |
| 3379 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3380 | |
| 3381 | nla_nest_end(msg, pinfoattr); |
| 3382 | |
| 3383 | return genlmsg_end(msg, hdr); |
| 3384 | |
| 3385 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3386 | genlmsg_cancel(msg, hdr); |
| 3387 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3391 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3392 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3393 | struct mpath_info pinfo; |
| 3394 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3395 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3396 | u8 dst[ETH_ALEN]; |
| 3397 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3398 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3399 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3400 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3401 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3402 | if (err) |
| 3403 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3404 | |
| 3405 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3406 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3407 | goto out_err; |
| 3408 | } |
| 3409 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3410 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3411 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3412 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3413 | } |
| 3414 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3415 | while (1) { |
| 3416 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 3417 | dst, next_hop, &pinfo); |
| 3418 | if (err == -ENOENT) |
| 3419 | break; |
| 3420 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3421 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3422 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3423 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3424 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3425 | netdev, dst, next_hop, |
| 3426 | &pinfo) < 0) |
| 3427 | goto out; |
| 3428 | |
| 3429 | path_idx++; |
| 3430 | } |
| 3431 | |
| 3432 | |
| 3433 | out: |
| 3434 | cb->args[1] = path_idx; |
| 3435 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3436 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3437 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3438 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3442 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3443 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3444 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3445 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3446 | struct mpath_info pinfo; |
| 3447 | struct sk_buff *msg; |
| 3448 | u8 *dst = NULL; |
| 3449 | u8 next_hop[ETH_ALEN]; |
| 3450 | |
| 3451 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3452 | |
| 3453 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3454 | return -EINVAL; |
| 3455 | |
| 3456 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3457 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3458 | if (!rdev->ops->get_mpath) |
| 3459 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3460 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3461 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3462 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3463 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3464 | err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3465 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3466 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3467 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3468 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3469 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3470 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3471 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3472 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3473 | dev, dst, next_hop, &pinfo) < 0) { |
| 3474 | nlmsg_free(msg); |
| 3475 | return -ENOBUFS; |
| 3476 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3477 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3478 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3482 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3483 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3484 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3485 | u8 *dst = NULL; |
| 3486 | u8 *next_hop = NULL; |
| 3487 | |
| 3488 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3489 | return -EINVAL; |
| 3490 | |
| 3491 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3492 | return -EINVAL; |
| 3493 | |
| 3494 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3495 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3496 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3497 | if (!rdev->ops->change_mpath) |
| 3498 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3499 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3500 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3501 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3502 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3503 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3504 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3505 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3506 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3507 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3508 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3509 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3510 | u8 *dst = NULL; |
| 3511 | u8 *next_hop = NULL; |
| 3512 | |
| 3513 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3514 | return -EINVAL; |
| 3515 | |
| 3516 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3517 | return -EINVAL; |
| 3518 | |
| 3519 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3520 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3521 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3522 | if (!rdev->ops->add_mpath) |
| 3523 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3524 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3525 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3526 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3527 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3528 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3532 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3534 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3535 | u8 *dst = NULL; |
| 3536 | |
| 3537 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3538 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3539 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3540 | if (!rdev->ops->del_mpath) |
| 3541 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3542 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3543 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3544 | } |
| 3545 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3546 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3547 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3548 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3549 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3550 | struct bss_parameters params; |
| 3551 | |
| 3552 | memset(¶ms, 0, sizeof(params)); |
| 3553 | /* default to not changing parameters */ |
| 3554 | params.use_cts_prot = -1; |
| 3555 | params.use_short_preamble = -1; |
| 3556 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3557 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3558 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3559 | |
| 3560 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3561 | params.use_cts_prot = |
| 3562 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3563 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3564 | params.use_short_preamble = |
| 3565 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3566 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3567 | params.use_short_slot_time = |
| 3568 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3569 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3570 | params.basic_rates = |
| 3571 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3572 | params.basic_rates_len = |
| 3573 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3574 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3575 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3576 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3577 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3578 | params.ht_opmode = |
| 3579 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3580 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3581 | if (!rdev->ops->change_bss) |
| 3582 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3583 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3584 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3585 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3586 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3587 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3588 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3589 | } |
| 3590 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3591 | 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] | 3592 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3593 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3594 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3595 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3596 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3597 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3598 | }; |
| 3599 | |
| 3600 | static int parse_reg_rule(struct nlattr *tb[], |
| 3601 | struct ieee80211_reg_rule *reg_rule) |
| 3602 | { |
| 3603 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3604 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3605 | |
| 3606 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3607 | return -EINVAL; |
| 3608 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3609 | return -EINVAL; |
| 3610 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3611 | return -EINVAL; |
| 3612 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3613 | return -EINVAL; |
| 3614 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3615 | return -EINVAL; |
| 3616 | |
| 3617 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3618 | |
| 3619 | freq_range->start_freq_khz = |
| 3620 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3621 | freq_range->end_freq_khz = |
| 3622 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3623 | freq_range->max_bandwidth_khz = |
| 3624 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3625 | |
| 3626 | power_rule->max_eirp = |
| 3627 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3628 | |
| 3629 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3630 | power_rule->max_antenna_gain = |
| 3631 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3632 | |
| 3633 | return 0; |
| 3634 | } |
| 3635 | |
| 3636 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3637 | { |
| 3638 | int r; |
| 3639 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3640 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3641 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3642 | /* |
| 3643 | * You should only get this when cfg80211 hasn't yet initialized |
| 3644 | * completely when built-in to the kernel right between the time |
| 3645 | * window between nl80211_init() and regulatory_init(), if that is |
| 3646 | * even possible. |
| 3647 | */ |
| 3648 | mutex_lock(&cfg80211_mutex); |
| 3649 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3650 | mutex_unlock(&cfg80211_mutex); |
| 3651 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3652 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3653 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3654 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3655 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3656 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3657 | |
| 3658 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3659 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3660 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 3661 | user_reg_hint_type = |
| 3662 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 3663 | else |
| 3664 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 3665 | |
| 3666 | switch (user_reg_hint_type) { |
| 3667 | case NL80211_USER_REG_HINT_USER: |
| 3668 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 3669 | break; |
| 3670 | default: |
| 3671 | return -EINVAL; |
| 3672 | } |
| 3673 | |
| 3674 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3675 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3676 | return r; |
| 3677 | } |
| 3678 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3679 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3680 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3681 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3682 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3683 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3684 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3685 | struct mesh_config cur_params; |
| 3686 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3687 | void *hdr; |
| 3688 | struct nlattr *pinfoattr; |
| 3689 | struct sk_buff *msg; |
| 3690 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3691 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3692 | return -EOPNOTSUPP; |
| 3693 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3694 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3695 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3696 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3697 | wdev_lock(wdev); |
| 3698 | /* If not connected, get default parameters */ |
| 3699 | if (!wdev->mesh_id_len) |
| 3700 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3701 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3702 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3703 | &cur_params); |
| 3704 | wdev_unlock(wdev); |
| 3705 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3706 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3707 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3708 | |
| 3709 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3710 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3711 | if (!msg) |
| 3712 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3713 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3714 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3715 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3716 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3717 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3718 | if (!pinfoattr) |
| 3719 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3720 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3721 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3722 | cur_params.dot11MeshRetryTimeout) || |
| 3723 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3724 | cur_params.dot11MeshConfirmTimeout) || |
| 3725 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3726 | cur_params.dot11MeshHoldingTimeout) || |
| 3727 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3728 | cur_params.dot11MeshMaxPeerLinks) || |
| 3729 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3730 | cur_params.dot11MeshMaxRetries) || |
| 3731 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 3732 | cur_params.dot11MeshTTL) || |
| 3733 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3734 | cur_params.element_ttl) || |
| 3735 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3736 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3737 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3738 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3739 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3740 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 3741 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3742 | cur_params.path_refresh_time) || |
| 3743 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3744 | cur_params.min_discovery_timeout) || |
| 3745 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3746 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 3747 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3748 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 3749 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3750 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 3751 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3752 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 3753 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3754 | cur_params.dot11MeshHWMPRootMode) || |
| 3755 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3756 | cur_params.dot11MeshHWMPRannInterval) || |
| 3757 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3758 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 3759 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 3760 | cur_params.dot11MeshForwarding) || |
| 3761 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3762 | cur_params.rssi_threshold) || |
| 3763 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3764 | cur_params.ht_opmode) || |
| 3765 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3766 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 3767 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3768 | cur_params.dot11MeshHWMProotInterval) || |
| 3769 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3770 | cur_params.dot11MeshHWMPconfirmationInterval)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3771 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3772 | nla_nest_end(msg, pinfoattr); |
| 3773 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3774 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3775 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3776 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3777 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3778 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3779 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3780 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3781 | } |
| 3782 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3783 | 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] | 3784 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3785 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3786 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3787 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3788 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3789 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3790 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3791 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3792 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3793 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3794 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3795 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3796 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3797 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3798 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3799 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3800 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3801 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3802 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3803 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3804 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 3805 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3806 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 3807 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3808 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3809 | }; |
| 3810 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3811 | static const struct nla_policy |
| 3812 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3813 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3814 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3815 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3816 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3817 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3818 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3819 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3820 | }; |
| 3821 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3822 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3823 | struct mesh_config *cfg, |
| 3824 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3825 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3826 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3827 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3828 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3829 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3830 | do {\ |
| 3831 | if (table[attr_num]) {\ |
| 3832 | cfg->param = nla_fn(table[attr_num]); \ |
| 3833 | mask |= (1 << (attr_num - 1)); \ |
| 3834 | } \ |
| 3835 | } while (0);\ |
| 3836 | |
| 3837 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3838 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3839 | return -EINVAL; |
| 3840 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3841 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3842 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3843 | return -EINVAL; |
| 3844 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3845 | /* This makes sure that there aren't more than 32 mesh config |
| 3846 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3847 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3848 | |
| 3849 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3850 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3851 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3852 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3853 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3854 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3855 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3856 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3857 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3858 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3859 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3860 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3861 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3862 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3863 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 3864 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3865 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3866 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3867 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3868 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 3869 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3870 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3871 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3872 | nla_get_u8); |
| 3873 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask, |
| 3874 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3875 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3876 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3877 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3878 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3879 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3880 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3881 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3882 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3883 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3884 | nla_get_u16); |
| 3885 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask, |
| 3886 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3887 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3888 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3889 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3890 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3891 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3892 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3893 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3894 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3895 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
| 3896 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3897 | nla_get_u16); |
| 3898 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 3899 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 3900 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 3901 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3902 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3903 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3904 | dot11MeshGateAnnouncementProtocol, mask, |
| 3905 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3906 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3907 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3908 | mask, NL80211_MESHCONF_FORWARDING, |
| 3909 | nla_get_u8); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 3910 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3911 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 3912 | nla_get_u32); |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3913 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3914 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 3915 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3916 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
| 3917 | mask, |
| 3918 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3919 | nla_get_u32); |
| 3920 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, |
| 3921 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 3922 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3923 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3924 | dot11MeshHWMPconfirmationInterval, mask, |
| 3925 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3926 | nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3927 | if (mask_out) |
| 3928 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3929 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3930 | return 0; |
| 3931 | |
| 3932 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3933 | } |
| 3934 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3935 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3936 | struct mesh_setup *setup) |
| 3937 | { |
| 3938 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3939 | |
| 3940 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3941 | return -EINVAL; |
| 3942 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3943 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3944 | nl80211_mesh_setup_params_policy)) |
| 3945 | return -EINVAL; |
| 3946 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3947 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 3948 | setup->sync_method = |
| 3949 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 3950 | IEEE80211_SYNC_METHOD_VENDOR : |
| 3951 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 3952 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3953 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3954 | setup->path_sel_proto = |
| 3955 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3956 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3957 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3958 | |
| 3959 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3960 | setup->path_metric = |
| 3961 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3962 | IEEE80211_PATH_METRIC_VENDOR : |
| 3963 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3964 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3965 | |
| 3966 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3967 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3968 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3969 | if (!is_valid_ie_attr(ieattr)) |
| 3970 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3971 | setup->ie = nla_data(ieattr); |
| 3972 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3973 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3974 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3975 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3976 | |
| 3977 | return 0; |
| 3978 | } |
| 3979 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3980 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3981 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3982 | { |
| 3983 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3984 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3985 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3986 | struct mesh_config cfg; |
| 3987 | u32 mask; |
| 3988 | int err; |
| 3989 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3990 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3991 | return -EOPNOTSUPP; |
| 3992 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3993 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3994 | return -EOPNOTSUPP; |
| 3995 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3996 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3997 | if (err) |
| 3998 | return err; |
| 3999 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4000 | wdev_lock(wdev); |
| 4001 | if (!wdev->mesh_id_len) |
| 4002 | err = -ENOLINK; |
| 4003 | |
| 4004 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4005 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4006 | mask, &cfg); |
| 4007 | |
| 4008 | wdev_unlock(wdev); |
| 4009 | |
| 4010 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4011 | } |
| 4012 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4013 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4014 | { |
| 4015 | struct sk_buff *msg; |
| 4016 | void *hdr = NULL; |
| 4017 | struct nlattr *nl_reg_rules; |
| 4018 | unsigned int i; |
| 4019 | int err = -EINVAL; |
| 4020 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4021 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4022 | |
| 4023 | if (!cfg80211_regdomain) |
| 4024 | goto out; |
| 4025 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4026 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4027 | if (!msg) { |
| 4028 | err = -ENOBUFS; |
| 4029 | goto out; |
| 4030 | } |
| 4031 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4032 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4033 | NL80211_CMD_GET_REG); |
| 4034 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4035 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4036 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4037 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 4038 | cfg80211_regdomain->alpha2) || |
| 4039 | (cfg80211_regdomain->dfs_region && |
| 4040 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, |
| 4041 | cfg80211_regdomain->dfs_region))) |
| 4042 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4043 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4044 | if (reg_last_request_cell_base() && |
| 4045 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4046 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4047 | goto nla_put_failure; |
| 4048 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4049 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4050 | if (!nl_reg_rules) |
| 4051 | goto nla_put_failure; |
| 4052 | |
| 4053 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 4054 | struct nlattr *nl_reg_rule; |
| 4055 | const struct ieee80211_reg_rule *reg_rule; |
| 4056 | const struct ieee80211_freq_range *freq_range; |
| 4057 | const struct ieee80211_power_rule *power_rule; |
| 4058 | |
| 4059 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 4060 | freq_range = ®_rule->freq_range; |
| 4061 | power_rule = ®_rule->power_rule; |
| 4062 | |
| 4063 | nl_reg_rule = nla_nest_start(msg, i); |
| 4064 | if (!nl_reg_rule) |
| 4065 | goto nla_put_failure; |
| 4066 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4067 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4068 | reg_rule->flags) || |
| 4069 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4070 | freq_range->start_freq_khz) || |
| 4071 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4072 | freq_range->end_freq_khz) || |
| 4073 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4074 | freq_range->max_bandwidth_khz) || |
| 4075 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4076 | power_rule->max_antenna_gain) || |
| 4077 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4078 | power_rule->max_eirp)) |
| 4079 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4080 | |
| 4081 | nla_nest_end(msg, nl_reg_rule); |
| 4082 | } |
| 4083 | |
| 4084 | nla_nest_end(msg, nl_reg_rules); |
| 4085 | |
| 4086 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4087 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4088 | goto out; |
| 4089 | |
| 4090 | nla_put_failure: |
| 4091 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4092 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4093 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4094 | err = -EMSGSIZE; |
| 4095 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4096 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4097 | return err; |
| 4098 | } |
| 4099 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4100 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4101 | { |
| 4102 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4103 | struct nlattr *nl_reg_rule; |
| 4104 | char *alpha2 = NULL; |
| 4105 | int rem_reg_rules = 0, r = 0; |
| 4106 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4107 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4108 | struct ieee80211_regdomain *rd = NULL; |
| 4109 | |
| 4110 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4111 | return -EINVAL; |
| 4112 | |
| 4113 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4114 | return -EINVAL; |
| 4115 | |
| 4116 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4117 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4118 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4119 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4120 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4121 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4122 | rem_reg_rules) { |
| 4123 | num_rules++; |
| 4124 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4125 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4126 | } |
| 4127 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4128 | mutex_lock(&cfg80211_mutex); |
| 4129 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4130 | if (!reg_is_valid_request(alpha2)) { |
| 4131 | r = -EINVAL; |
| 4132 | goto bad_reg; |
| 4133 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4134 | |
| 4135 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 4136 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 4137 | |
| 4138 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4139 | if (!rd) { |
| 4140 | r = -ENOMEM; |
| 4141 | goto bad_reg; |
| 4142 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4143 | |
| 4144 | rd->n_reg_rules = num_rules; |
| 4145 | rd->alpha2[0] = alpha2[0]; |
| 4146 | rd->alpha2[1] = alpha2[1]; |
| 4147 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4148 | /* |
| 4149 | * Disable DFS master mode if the DFS region was |
| 4150 | * not supported or known on this kernel. |
| 4151 | */ |
| 4152 | if (reg_supported_dfs_region(dfs_region)) |
| 4153 | rd->dfs_region = dfs_region; |
| 4154 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4155 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4156 | rem_reg_rules) { |
| 4157 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 4158 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4159 | reg_rule_policy); |
| 4160 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4161 | if (r) |
| 4162 | goto bad_reg; |
| 4163 | |
| 4164 | rule_idx++; |
| 4165 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4166 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4167 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4168 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4169 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4170 | } |
| 4171 | |
| 4172 | BUG_ON(rule_idx != num_rules); |
| 4173 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4174 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4175 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4176 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4177 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4178 | return r; |
| 4179 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4180 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4181 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4182 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4183 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4184 | } |
| 4185 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4186 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4187 | { |
| 4188 | struct nlattr *attr1, *attr2; |
| 4189 | int n_channels = 0, tmp1, tmp2; |
| 4190 | |
| 4191 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4192 | n_channels++; |
| 4193 | /* |
| 4194 | * Some hardware has a limited channel list for |
| 4195 | * scanning, and it is pretty much nonsensical |
| 4196 | * to scan for a channel twice, so disallow that |
| 4197 | * and don't require drivers to check that the |
| 4198 | * channel list they get isn't longer than what |
| 4199 | * they can scan, as long as they can scan all |
| 4200 | * the channels they registered at once. |
| 4201 | */ |
| 4202 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4203 | if (attr1 != attr2 && |
| 4204 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4205 | return 0; |
| 4206 | } |
| 4207 | |
| 4208 | return n_channels; |
| 4209 | } |
| 4210 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4211 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4212 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4213 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4214 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4215 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4216 | struct nlattr *attr; |
| 4217 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4218 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4219 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4220 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4221 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4222 | return -EINVAL; |
| 4223 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4224 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4225 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4226 | if (!rdev->ops->scan) |
| 4227 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4228 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4229 | if (rdev->scan_req) |
| 4230 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4231 | |
| 4232 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4233 | n_channels = validate_scan_freqs( |
| 4234 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4235 | if (!n_channels) |
| 4236 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4237 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4238 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4239 | n_channels = 0; |
| 4240 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4241 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4242 | if (wiphy->bands[band]) |
| 4243 | n_channels += wiphy->bands[band]->n_channels; |
| 4244 | } |
| 4245 | |
| 4246 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4247 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4248 | n_ssids++; |
| 4249 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4250 | if (n_ssids > wiphy->max_scan_ssids) |
| 4251 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4252 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4253 | if (info->attrs[NL80211_ATTR_IE]) |
| 4254 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4255 | else |
| 4256 | ie_len = 0; |
| 4257 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4258 | if (ie_len > wiphy->max_scan_ie_len) |
| 4259 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4260 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4261 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4262 | + sizeof(*request->ssids) * n_ssids |
| 4263 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4264 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4265 | if (!request) |
| 4266 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4267 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4268 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4269 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4270 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4271 | if (ie_len) { |
| 4272 | if (request->ssids) |
| 4273 | request->ie = (void *)(request->ssids + n_ssids); |
| 4274 | else |
| 4275 | request->ie = (void *)(request->channels + n_channels); |
| 4276 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4277 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4278 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4279 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4280 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4281 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4282 | struct ieee80211_channel *chan; |
| 4283 | |
| 4284 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4285 | |
| 4286 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4287 | err = -EINVAL; |
| 4288 | goto out_free; |
| 4289 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4290 | |
| 4291 | /* ignore disabled channels */ |
| 4292 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4293 | continue; |
| 4294 | |
| 4295 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4296 | i++; |
| 4297 | } |
| 4298 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4299 | enum ieee80211_band band; |
| 4300 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4301 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4302 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4303 | int j; |
| 4304 | if (!wiphy->bands[band]) |
| 4305 | continue; |
| 4306 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4307 | struct ieee80211_channel *chan; |
| 4308 | |
| 4309 | chan = &wiphy->bands[band]->channels[j]; |
| 4310 | |
| 4311 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4312 | continue; |
| 4313 | |
| 4314 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4315 | i++; |
| 4316 | } |
| 4317 | } |
| 4318 | } |
| 4319 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4320 | if (!i) { |
| 4321 | err = -EINVAL; |
| 4322 | goto out_free; |
| 4323 | } |
| 4324 | |
| 4325 | request->n_channels = i; |
| 4326 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4327 | i = 0; |
| 4328 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4329 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4330 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4331 | err = -EINVAL; |
| 4332 | goto out_free; |
| 4333 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4334 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4335 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4336 | i++; |
| 4337 | } |
| 4338 | } |
| 4339 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4340 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4341 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4342 | memcpy((void *)request->ie, |
| 4343 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4344 | request->ie_len); |
| 4345 | } |
| 4346 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4347 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4348 | if (wiphy->bands[i]) |
| 4349 | request->rates[i] = |
| 4350 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4351 | |
| 4352 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4353 | nla_for_each_nested(attr, |
| 4354 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4355 | tmp) { |
| 4356 | enum ieee80211_band band = nla_type(attr); |
| 4357 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4358 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4359 | err = -EINVAL; |
| 4360 | goto out_free; |
| 4361 | } |
| 4362 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4363 | nla_data(attr), |
| 4364 | nla_len(attr), |
| 4365 | &request->rates[band]); |
| 4366 | if (err) |
| 4367 | goto out_free; |
| 4368 | } |
| 4369 | } |
| 4370 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4371 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4372 | request->flags = nla_get_u32( |
| 4373 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame^] | 4374 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4375 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4376 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4377 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4378 | err = -EOPNOTSUPP; |
| 4379 | goto out_free; |
| 4380 | } |
| 4381 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4382 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4383 | request->no_cck = |
| 4384 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4385 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4386 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4387 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame^] | 4388 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4389 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4390 | rdev->scan_req = request; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4391 | err = rdev->ops->scan(&rdev->wiphy, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4392 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4393 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4394 | nl80211_send_scan_start(rdev, wdev); |
| 4395 | if (wdev->netdev) |
| 4396 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4397 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4398 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4399 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4400 | kfree(request); |
| 4401 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4402 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4403 | return err; |
| 4404 | } |
| 4405 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4406 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4407 | struct genl_info *info) |
| 4408 | { |
| 4409 | struct cfg80211_sched_scan_request *request; |
| 4410 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4411 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4412 | struct nlattr *attr; |
| 4413 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4414 | 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] | 4415 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4416 | enum ieee80211_band band; |
| 4417 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4418 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4419 | |
| 4420 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4421 | !rdev->ops->sched_scan_start) |
| 4422 | return -EOPNOTSUPP; |
| 4423 | |
| 4424 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4425 | return -EINVAL; |
| 4426 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4427 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4428 | return -EINVAL; |
| 4429 | |
| 4430 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4431 | if (interval == 0) |
| 4432 | return -EINVAL; |
| 4433 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4434 | wiphy = &rdev->wiphy; |
| 4435 | |
| 4436 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4437 | n_channels = validate_scan_freqs( |
| 4438 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4439 | if (!n_channels) |
| 4440 | return -EINVAL; |
| 4441 | } else { |
| 4442 | n_channels = 0; |
| 4443 | |
| 4444 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4445 | if (wiphy->bands[band]) |
| 4446 | n_channels += wiphy->bands[band]->n_channels; |
| 4447 | } |
| 4448 | |
| 4449 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4450 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4451 | tmp) |
| 4452 | n_ssids++; |
| 4453 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4454 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4455 | return -EINVAL; |
| 4456 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4457 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4458 | nla_for_each_nested(attr, |
| 4459 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4460 | tmp) |
| 4461 | n_match_sets++; |
| 4462 | |
| 4463 | if (n_match_sets > wiphy->max_match_sets) |
| 4464 | return -EINVAL; |
| 4465 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4466 | if (info->attrs[NL80211_ATTR_IE]) |
| 4467 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4468 | else |
| 4469 | ie_len = 0; |
| 4470 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4471 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4472 | return -EINVAL; |
| 4473 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4474 | mutex_lock(&rdev->sched_scan_mtx); |
| 4475 | |
| 4476 | if (rdev->sched_scan_req) { |
| 4477 | err = -EINPROGRESS; |
| 4478 | goto out; |
| 4479 | } |
| 4480 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4481 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4482 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4483 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4484 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4485 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4486 | if (!request) { |
| 4487 | err = -ENOMEM; |
| 4488 | goto out; |
| 4489 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4490 | |
| 4491 | if (n_ssids) |
| 4492 | request->ssids = (void *)&request->channels[n_channels]; |
| 4493 | request->n_ssids = n_ssids; |
| 4494 | if (ie_len) { |
| 4495 | if (request->ssids) |
| 4496 | request->ie = (void *)(request->ssids + n_ssids); |
| 4497 | else |
| 4498 | request->ie = (void *)(request->channels + n_channels); |
| 4499 | } |
| 4500 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4501 | if (n_match_sets) { |
| 4502 | if (request->ie) |
| 4503 | request->match_sets = (void *)(request->ie + ie_len); |
| 4504 | else if (request->ssids) |
| 4505 | request->match_sets = |
| 4506 | (void *)(request->ssids + n_ssids); |
| 4507 | else |
| 4508 | request->match_sets = |
| 4509 | (void *)(request->channels + n_channels); |
| 4510 | } |
| 4511 | request->n_match_sets = n_match_sets; |
| 4512 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4513 | i = 0; |
| 4514 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4515 | /* user specified, bail out if channel not found */ |
| 4516 | nla_for_each_nested(attr, |
| 4517 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4518 | tmp) { |
| 4519 | struct ieee80211_channel *chan; |
| 4520 | |
| 4521 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4522 | |
| 4523 | if (!chan) { |
| 4524 | err = -EINVAL; |
| 4525 | goto out_free; |
| 4526 | } |
| 4527 | |
| 4528 | /* ignore disabled channels */ |
| 4529 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4530 | continue; |
| 4531 | |
| 4532 | request->channels[i] = chan; |
| 4533 | i++; |
| 4534 | } |
| 4535 | } else { |
| 4536 | /* all channels */ |
| 4537 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4538 | int j; |
| 4539 | if (!wiphy->bands[band]) |
| 4540 | continue; |
| 4541 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4542 | struct ieee80211_channel *chan; |
| 4543 | |
| 4544 | chan = &wiphy->bands[band]->channels[j]; |
| 4545 | |
| 4546 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4547 | continue; |
| 4548 | |
| 4549 | request->channels[i] = chan; |
| 4550 | i++; |
| 4551 | } |
| 4552 | } |
| 4553 | } |
| 4554 | |
| 4555 | if (!i) { |
| 4556 | err = -EINVAL; |
| 4557 | goto out_free; |
| 4558 | } |
| 4559 | |
| 4560 | request->n_channels = i; |
| 4561 | |
| 4562 | i = 0; |
| 4563 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4564 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4565 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4566 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4567 | err = -EINVAL; |
| 4568 | goto out_free; |
| 4569 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4570 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4571 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4572 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4573 | i++; |
| 4574 | } |
| 4575 | } |
| 4576 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4577 | i = 0; |
| 4578 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4579 | nla_for_each_nested(attr, |
| 4580 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4581 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4582 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4583 | |
| 4584 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4585 | nla_data(attr), nla_len(attr), |
| 4586 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 4587 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4588 | if (ssid) { |
| 4589 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4590 | err = -EINVAL; |
| 4591 | goto out_free; |
| 4592 | } |
| 4593 | memcpy(request->match_sets[i].ssid.ssid, |
| 4594 | nla_data(ssid), nla_len(ssid)); |
| 4595 | request->match_sets[i].ssid.ssid_len = |
| 4596 | nla_len(ssid); |
| 4597 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4598 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 4599 | if (rssi) |
| 4600 | request->rssi_thold = nla_get_u32(rssi); |
| 4601 | else |
| 4602 | request->rssi_thold = |
| 4603 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4604 | i++; |
| 4605 | } |
| 4606 | } |
| 4607 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4608 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4609 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4610 | memcpy((void *)request->ie, |
| 4611 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4612 | request->ie_len); |
| 4613 | } |
| 4614 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4615 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4616 | request->flags = nla_get_u32( |
| 4617 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame^] | 4618 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 4619 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 4620 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 4621 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 4622 | err = -EOPNOTSUPP; |
| 4623 | goto out_free; |
| 4624 | } |
| 4625 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 4626 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4627 | request->dev = dev; |
| 4628 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4629 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame^] | 4630 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4631 | |
| 4632 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 4633 | if (!err) { |
| 4634 | rdev->sched_scan_req = request; |
| 4635 | nl80211_send_sched_scan(rdev, dev, |
| 4636 | NL80211_CMD_START_SCHED_SCAN); |
| 4637 | goto out; |
| 4638 | } |
| 4639 | |
| 4640 | out_free: |
| 4641 | kfree(request); |
| 4642 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4643 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4644 | return err; |
| 4645 | } |
| 4646 | |
| 4647 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4648 | struct genl_info *info) |
| 4649 | { |
| 4650 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4651 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4652 | |
| 4653 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4654 | !rdev->ops->sched_scan_stop) |
| 4655 | return -EOPNOTSUPP; |
| 4656 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4657 | mutex_lock(&rdev->sched_scan_mtx); |
| 4658 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4659 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4660 | |
| 4661 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4662 | } |
| 4663 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4664 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4665 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4666 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4667 | struct wireless_dev *wdev, |
| 4668 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4669 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4670 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4671 | void *hdr; |
| 4672 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4673 | |
| 4674 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4675 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4676 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4677 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4678 | if (!hdr) |
| 4679 | return -1; |
| 4680 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4681 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4682 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4683 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 4684 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 4685 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4686 | |
| 4687 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4688 | if (!bss) |
| 4689 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4690 | if ((!is_zero_ether_addr(res->bssid) && |
| 4691 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) || |
| 4692 | (res->information_elements && res->len_information_elements && |
| 4693 | nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4694 | res->len_information_elements, |
| 4695 | res->information_elements)) || |
| 4696 | (res->beacon_ies && res->len_beacon_ies && |
| 4697 | res->beacon_ies != res->information_elements && |
| 4698 | nla_put(msg, NL80211_BSS_BEACON_IES, |
| 4699 | res->len_beacon_ies, res->beacon_ies))) |
| 4700 | goto nla_put_failure; |
| 4701 | if (res->tsf && |
| 4702 | nla_put_u64(msg, NL80211_BSS_TSF, res->tsf)) |
| 4703 | goto nla_put_failure; |
| 4704 | if (res->beacon_interval && |
| 4705 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 4706 | goto nla_put_failure; |
| 4707 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 4708 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 4709 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4710 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 4711 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4712 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4713 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4714 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4715 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 4716 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4717 | break; |
| 4718 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4719 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 4720 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4721 | break; |
| 4722 | default: |
| 4723 | break; |
| 4724 | } |
| 4725 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4726 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4727 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4728 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4729 | if (intbss == wdev->current_bss && |
| 4730 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4731 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 4732 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4733 | break; |
| 4734 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4735 | if (intbss == wdev->current_bss && |
| 4736 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4737 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 4738 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4739 | break; |
| 4740 | default: |
| 4741 | break; |
| 4742 | } |
| 4743 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4744 | nla_nest_end(msg, bss); |
| 4745 | |
| 4746 | return genlmsg_end(msg, hdr); |
| 4747 | |
| 4748 | nla_put_failure: |
| 4749 | genlmsg_cancel(msg, hdr); |
| 4750 | return -EMSGSIZE; |
| 4751 | } |
| 4752 | |
| 4753 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4754 | struct netlink_callback *cb) |
| 4755 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4756 | struct cfg80211_registered_device *rdev; |
| 4757 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4758 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4759 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4760 | int start = cb->args[1], idx = 0; |
| 4761 | int err; |
| 4762 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4763 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4764 | if (err) |
| 4765 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4766 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4767 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4768 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4769 | wdev_lock(wdev); |
| 4770 | spin_lock_bh(&rdev->bss_lock); |
| 4771 | cfg80211_bss_expire(rdev); |
| 4772 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4773 | cb->seq = rdev->bss_generation; |
| 4774 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4775 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4776 | if (++idx <= start) |
| 4777 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4778 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4779 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4780 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4781 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4782 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4783 | } |
| 4784 | } |
| 4785 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4786 | spin_unlock_bh(&rdev->bss_lock); |
| 4787 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4788 | |
| 4789 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4790 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4791 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4792 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4793 | } |
| 4794 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4795 | 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] | 4796 | int flags, struct net_device *dev, |
| 4797 | struct survey_info *survey) |
| 4798 | { |
| 4799 | void *hdr; |
| 4800 | struct nlattr *infoattr; |
| 4801 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4802 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4803 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4804 | if (!hdr) |
| 4805 | return -ENOMEM; |
| 4806 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4807 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 4808 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4809 | |
| 4810 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4811 | if (!infoattr) |
| 4812 | goto nla_put_failure; |
| 4813 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4814 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4815 | survey->channel->center_freq)) |
| 4816 | goto nla_put_failure; |
| 4817 | |
| 4818 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 4819 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 4820 | goto nla_put_failure; |
| 4821 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 4822 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 4823 | goto nla_put_failure; |
| 4824 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 4825 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4826 | survey->channel_time)) |
| 4827 | goto nla_put_failure; |
| 4828 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 4829 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4830 | survey->channel_time_busy)) |
| 4831 | goto nla_put_failure; |
| 4832 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 4833 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4834 | survey->channel_time_ext_busy)) |
| 4835 | goto nla_put_failure; |
| 4836 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 4837 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4838 | survey->channel_time_rx)) |
| 4839 | goto nla_put_failure; |
| 4840 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 4841 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4842 | survey->channel_time_tx)) |
| 4843 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4844 | |
| 4845 | nla_nest_end(msg, infoattr); |
| 4846 | |
| 4847 | return genlmsg_end(msg, hdr); |
| 4848 | |
| 4849 | nla_put_failure: |
| 4850 | genlmsg_cancel(msg, hdr); |
| 4851 | return -EMSGSIZE; |
| 4852 | } |
| 4853 | |
| 4854 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4855 | struct netlink_callback *cb) |
| 4856 | { |
| 4857 | struct survey_info survey; |
| 4858 | struct cfg80211_registered_device *dev; |
| 4859 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4860 | int survey_idx = cb->args[1]; |
| 4861 | int res; |
| 4862 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4863 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4864 | if (res) |
| 4865 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4866 | |
| 4867 | if (!dev->ops->dump_survey) { |
| 4868 | res = -EOPNOTSUPP; |
| 4869 | goto out_err; |
| 4870 | } |
| 4871 | |
| 4872 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4873 | struct ieee80211_channel *chan; |
| 4874 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4875 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4876 | &survey); |
| 4877 | if (res == -ENOENT) |
| 4878 | break; |
| 4879 | if (res) |
| 4880 | goto out_err; |
| 4881 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4882 | /* Survey without a channel doesn't make sense */ |
| 4883 | if (!survey.channel) { |
| 4884 | res = -EINVAL; |
| 4885 | goto out; |
| 4886 | } |
| 4887 | |
| 4888 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4889 | survey.channel->center_freq); |
| 4890 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4891 | survey_idx++; |
| 4892 | continue; |
| 4893 | } |
| 4894 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4895 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4896 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4897 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4898 | netdev, |
| 4899 | &survey) < 0) |
| 4900 | goto out; |
| 4901 | survey_idx++; |
| 4902 | } |
| 4903 | |
| 4904 | out: |
| 4905 | cb->args[1] = survey_idx; |
| 4906 | res = skb->len; |
| 4907 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4908 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4909 | return res; |
| 4910 | } |
| 4911 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4912 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4913 | { |
| 4914 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4915 | NL80211_WPA_VERSION_2)); |
| 4916 | } |
| 4917 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4918 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4919 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4920 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4921 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4922 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4923 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 4924 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4925 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4926 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4927 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4928 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4929 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4930 | return -EINVAL; |
| 4931 | |
| 4932 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4933 | return -EINVAL; |
| 4934 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4935 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4936 | return -EINVAL; |
| 4937 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4938 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4939 | return -EINVAL; |
| 4940 | |
| 4941 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4942 | return -EINVAL; |
| 4943 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4944 | err = nl80211_parse_key(info, &key); |
| 4945 | if (err) |
| 4946 | return err; |
| 4947 | |
| 4948 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4949 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4950 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4951 | if (!key.p.key || !key.p.key_len) |
| 4952 | return -EINVAL; |
| 4953 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4954 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4955 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4956 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4957 | return -EINVAL; |
| 4958 | if (key.idx > 4) |
| 4959 | return -EINVAL; |
| 4960 | } else { |
| 4961 | key.p.key_len = 0; |
| 4962 | key.p.key = NULL; |
| 4963 | } |
| 4964 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4965 | if (key.idx >= 0) { |
| 4966 | int i; |
| 4967 | bool ok = false; |
| 4968 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4969 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4970 | ok = true; |
| 4971 | break; |
| 4972 | } |
| 4973 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4974 | if (!ok) |
| 4975 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4976 | } |
| 4977 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4978 | if (!rdev->ops->auth) |
| 4979 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4980 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4981 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4982 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4983 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4984 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4985 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4986 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4987 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4988 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4989 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4990 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4991 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4992 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4993 | |
| 4994 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4995 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4996 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4997 | } |
| 4998 | |
| 4999 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5000 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5001 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5002 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5003 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5004 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5005 | return -EINVAL; |
| 5006 | |
| 5007 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5008 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5009 | return -EINVAL; |
| 5010 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5011 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5012 | /* need to include at least Auth Transaction and Status Code */ |
| 5013 | if (sae_data_len < 4) |
| 5014 | return -EINVAL; |
| 5015 | } |
| 5016 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5017 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5018 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5019 | /* |
| 5020 | * Since we no longer track auth state, ignore |
| 5021 | * requests to only change local state. |
| 5022 | */ |
| 5023 | if (local_state_change) |
| 5024 | return 0; |
| 5025 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5026 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5027 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5028 | key.p.key, key.p.key_len, key.idx, |
| 5029 | sae_data, sae_data_len); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5030 | } |
| 5031 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5032 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5033 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5034 | struct cfg80211_crypto_settings *settings, |
| 5035 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5036 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5037 | memset(settings, 0, sizeof(*settings)); |
| 5038 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5039 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5040 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5041 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5042 | u16 proto; |
| 5043 | proto = nla_get_u16( |
| 5044 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5045 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5046 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5047 | proto != ETH_P_PAE) |
| 5048 | return -EINVAL; |
| 5049 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5050 | settings->control_port_no_encrypt = true; |
| 5051 | } else |
| 5052 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5053 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5054 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5055 | void *data; |
| 5056 | int len, i; |
| 5057 | |
| 5058 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5059 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5060 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5061 | |
| 5062 | if (len % sizeof(u32)) |
| 5063 | return -EINVAL; |
| 5064 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5065 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5066 | return -EINVAL; |
| 5067 | |
| 5068 | memcpy(settings->ciphers_pairwise, data, len); |
| 5069 | |
| 5070 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5071 | if (!cfg80211_supported_cipher_suite( |
| 5072 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5073 | settings->ciphers_pairwise[i])) |
| 5074 | return -EINVAL; |
| 5075 | } |
| 5076 | |
| 5077 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5078 | settings->cipher_group = |
| 5079 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5080 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5081 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5082 | return -EINVAL; |
| 5083 | } |
| 5084 | |
| 5085 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5086 | settings->wpa_versions = |
| 5087 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5088 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5089 | return -EINVAL; |
| 5090 | } |
| 5091 | |
| 5092 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5093 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5094 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5095 | |
| 5096 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5097 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5098 | settings->n_akm_suites = len / sizeof(u32); |
| 5099 | |
| 5100 | if (len % sizeof(u32)) |
| 5101 | return -EINVAL; |
| 5102 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5103 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5104 | return -EINVAL; |
| 5105 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5106 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5107 | } |
| 5108 | |
| 5109 | return 0; |
| 5110 | } |
| 5111 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5112 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5113 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5114 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5115 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5116 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5117 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5118 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5119 | int err, ssid_len, ie_len = 0; |
| 5120 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5121 | u32 flags = 0; |
| 5122 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5123 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5124 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5125 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5126 | return -EINVAL; |
| 5127 | |
| 5128 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5129 | !info->attrs[NL80211_ATTR_SSID] || |
| 5130 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5131 | return -EINVAL; |
| 5132 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5133 | if (!rdev->ops->assoc) |
| 5134 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5135 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5136 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5137 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5138 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5139 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5140 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5141 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5142 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5143 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5144 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5145 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5146 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5147 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5148 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5149 | |
| 5150 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5151 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5152 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5153 | } |
| 5154 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5155 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5156 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5157 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5158 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5159 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5160 | else if (mfp != NL80211_MFP_NO) |
| 5161 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5162 | } |
| 5163 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5164 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5165 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5166 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5167 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5168 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5169 | |
| 5170 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5171 | ht_capa_mask = |
| 5172 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5173 | |
| 5174 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5175 | if (!ht_capa_mask) |
| 5176 | return -EINVAL; |
| 5177 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5178 | } |
| 5179 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5180 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5181 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5182 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5183 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5184 | &crypto, flags, ht_capa, |
| 5185 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5186 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5187 | return err; |
| 5188 | } |
| 5189 | |
| 5190 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5191 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5192 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5193 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5194 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5195 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5196 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5197 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5198 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5199 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5200 | return -EINVAL; |
| 5201 | |
| 5202 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5203 | return -EINVAL; |
| 5204 | |
| 5205 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5206 | return -EINVAL; |
| 5207 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5208 | if (!rdev->ops->deauth) |
| 5209 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5210 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5211 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5212 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5213 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5214 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5215 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5216 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5217 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5218 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5219 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5220 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5221 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5222 | |
| 5223 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5224 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5225 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5226 | } |
| 5227 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5228 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5229 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5230 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5231 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5232 | } |
| 5233 | |
| 5234 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5235 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5236 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5237 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5238 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5239 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5240 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5241 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5242 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5243 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5244 | return -EINVAL; |
| 5245 | |
| 5246 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5247 | return -EINVAL; |
| 5248 | |
| 5249 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5250 | return -EINVAL; |
| 5251 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5252 | if (!rdev->ops->disassoc) |
| 5253 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5254 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5255 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5256 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5257 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5258 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5259 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5260 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5261 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5262 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5263 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5264 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5265 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5266 | |
| 5267 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5268 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5269 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5270 | } |
| 5271 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5272 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5273 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5274 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5275 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5276 | } |
| 5277 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5278 | static bool |
| 5279 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5280 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5281 | int rateval) |
| 5282 | { |
| 5283 | struct wiphy *wiphy = &rdev->wiphy; |
| 5284 | bool found = false; |
| 5285 | int band, i; |
| 5286 | |
| 5287 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5288 | struct ieee80211_supported_band *sband; |
| 5289 | |
| 5290 | sband = wiphy->bands[band]; |
| 5291 | if (!sband) |
| 5292 | continue; |
| 5293 | |
| 5294 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5295 | if (sband->bitrates[i].bitrate == rateval) { |
| 5296 | mcast_rate[band] = i + 1; |
| 5297 | found = true; |
| 5298 | break; |
| 5299 | } |
| 5300 | } |
| 5301 | } |
| 5302 | |
| 5303 | return found; |
| 5304 | } |
| 5305 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5306 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5307 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5308 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5309 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5310 | struct cfg80211_ibss_params ibss; |
| 5311 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5312 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5313 | int err; |
| 5314 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5315 | memset(&ibss, 0, sizeof(ibss)); |
| 5316 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5317 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5318 | return -EINVAL; |
| 5319 | |
| 5320 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5321 | !info->attrs[NL80211_ATTR_SSID] || |
| 5322 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5323 | return -EINVAL; |
| 5324 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5325 | ibss.beacon_interval = 100; |
| 5326 | |
| 5327 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5328 | ibss.beacon_interval = |
| 5329 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5330 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5331 | return -EINVAL; |
| 5332 | } |
| 5333 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5334 | if (!rdev->ops->join_ibss) |
| 5335 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5336 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5337 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5338 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5339 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5340 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5341 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5342 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5343 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5344 | |
| 5345 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5346 | return -EINVAL; |
| 5347 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5348 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5349 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5350 | |
| 5351 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5352 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5353 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5354 | } |
| 5355 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5356 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5357 | enum nl80211_channel_type channel_type; |
| 5358 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5359 | if (!nl80211_valid_channel_type(info, &channel_type)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5360 | return -EINVAL; |
| 5361 | |
| 5362 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5363 | !(wiphy->features & NL80211_FEATURE_HT_IBSS)) |
| 5364 | return -EINVAL; |
| 5365 | |
| 5366 | ibss.channel_type = channel_type; |
| 5367 | } else { |
| 5368 | ibss.channel_type = NL80211_CHAN_NO_HT; |
| 5369 | } |
| 5370 | |
| 5371 | ibss.channel = rdev_freq_to_chan(rdev, |
| 5372 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 5373 | ibss.channel_type); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5374 | if (!ibss.channel || |
| 5375 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5376 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5377 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5378 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5379 | /* Both channels should be able to initiate communication */ |
| 5380 | if ((ibss.channel_type == NL80211_CHAN_HT40PLUS || |
| 5381 | ibss.channel_type == NL80211_CHAN_HT40MINUS) && |
| 5382 | !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel, |
| 5383 | ibss.channel_type)) |
| 5384 | return -EINVAL; |
| 5385 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5386 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5387 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5388 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5389 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5390 | u8 *rates = |
| 5391 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5392 | int n_rates = |
| 5393 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5394 | struct ieee80211_supported_band *sband = |
| 5395 | wiphy->bands[ibss.channel->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5396 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5397 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5398 | &ibss.basic_rates); |
| 5399 | if (err) |
| 5400 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5401 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5402 | |
| 5403 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5404 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5405 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5406 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5407 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5408 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5409 | connkeys = nl80211_parse_connkeys(rdev, |
| 5410 | info->attrs[NL80211_ATTR_KEYS]); |
| 5411 | if (IS_ERR(connkeys)) |
| 5412 | return PTR_ERR(connkeys); |
| 5413 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5414 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5415 | ibss.control_port = |
| 5416 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5417 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5418 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5419 | if (err) |
| 5420 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5421 | return err; |
| 5422 | } |
| 5423 | |
| 5424 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5425 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5426 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5427 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5428 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5429 | if (!rdev->ops->leave_ibss) |
| 5430 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5431 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5432 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5433 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5434 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5435 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5436 | } |
| 5437 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5438 | #ifdef CONFIG_NL80211_TESTMODE |
| 5439 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5440 | .name = "testmode", |
| 5441 | }; |
| 5442 | |
| 5443 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5444 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5446 | int err; |
| 5447 | |
| 5448 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5449 | return -EINVAL; |
| 5450 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5451 | err = -EOPNOTSUPP; |
| 5452 | if (rdev->ops->testmode_cmd) { |
| 5453 | rdev->testmode_info = info; |
| 5454 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 5455 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5456 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5457 | rdev->testmode_info = NULL; |
| 5458 | } |
| 5459 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5460 | return err; |
| 5461 | } |
| 5462 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5463 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5464 | struct netlink_callback *cb) |
| 5465 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5466 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5467 | int err; |
| 5468 | long phy_idx; |
| 5469 | void *data = NULL; |
| 5470 | int data_len = 0; |
| 5471 | |
| 5472 | if (cb->args[0]) { |
| 5473 | /* |
| 5474 | * 0 is a valid index, but not valid for args[0], |
| 5475 | * so we need to offset by 1. |
| 5476 | */ |
| 5477 | phy_idx = cb->args[0] - 1; |
| 5478 | } else { |
| 5479 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5480 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5481 | nl80211_policy); |
| 5482 | if (err) |
| 5483 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5484 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5485 | mutex_lock(&cfg80211_mutex); |
| 5486 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 5487 | nl80211_fam.attrbuf); |
| 5488 | if (IS_ERR(rdev)) { |
| 5489 | mutex_unlock(&cfg80211_mutex); |
| 5490 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5491 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5492 | phy_idx = rdev->wiphy_idx; |
| 5493 | rdev = NULL; |
| 5494 | mutex_unlock(&cfg80211_mutex); |
| 5495 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5496 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 5497 | cb->args[1] = |
| 5498 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 5499 | } |
| 5500 | |
| 5501 | if (cb->args[1]) { |
| 5502 | data = nla_data((void *)cb->args[1]); |
| 5503 | data_len = nla_len((void *)cb->args[1]); |
| 5504 | } |
| 5505 | |
| 5506 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5507 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 5508 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5509 | mutex_unlock(&cfg80211_mutex); |
| 5510 | return -ENOENT; |
| 5511 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5512 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5513 | mutex_unlock(&cfg80211_mutex); |
| 5514 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5515 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5516 | err = -EOPNOTSUPP; |
| 5517 | goto out_err; |
| 5518 | } |
| 5519 | |
| 5520 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5521 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5522 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5523 | NL80211_CMD_TESTMODE); |
| 5524 | struct nlattr *tmdata; |
| 5525 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5526 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5527 | genlmsg_cancel(skb, hdr); |
| 5528 | break; |
| 5529 | } |
| 5530 | |
| 5531 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5532 | if (!tmdata) { |
| 5533 | genlmsg_cancel(skb, hdr); |
| 5534 | break; |
| 5535 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5536 | err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb, |
| 5537 | data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5538 | nla_nest_end(skb, tmdata); |
| 5539 | |
| 5540 | if (err == -ENOBUFS || err == -ENOENT) { |
| 5541 | genlmsg_cancel(skb, hdr); |
| 5542 | break; |
| 5543 | } else if (err) { |
| 5544 | genlmsg_cancel(skb, hdr); |
| 5545 | goto out_err; |
| 5546 | } |
| 5547 | |
| 5548 | genlmsg_end(skb, hdr); |
| 5549 | } |
| 5550 | |
| 5551 | err = skb->len; |
| 5552 | /* see above */ |
| 5553 | cb->args[0] = phy_idx + 1; |
| 5554 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5555 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5556 | return err; |
| 5557 | } |
| 5558 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5559 | static struct sk_buff * |
| 5560 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5561 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5562 | { |
| 5563 | struct sk_buff *skb; |
| 5564 | void *hdr; |
| 5565 | struct nlattr *data; |
| 5566 | |
| 5567 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5568 | if (!skb) |
| 5569 | return NULL; |
| 5570 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5571 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5572 | if (!hdr) { |
| 5573 | kfree_skb(skb); |
| 5574 | return NULL; |
| 5575 | } |
| 5576 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5577 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 5578 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5579 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5580 | |
| 5581 | ((void **)skb->cb)[0] = rdev; |
| 5582 | ((void **)skb->cb)[1] = hdr; |
| 5583 | ((void **)skb->cb)[2] = data; |
| 5584 | |
| 5585 | return skb; |
| 5586 | |
| 5587 | nla_put_failure: |
| 5588 | kfree_skb(skb); |
| 5589 | return NULL; |
| 5590 | } |
| 5591 | |
| 5592 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5593 | int approxlen) |
| 5594 | { |
| 5595 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5596 | |
| 5597 | if (WARN_ON(!rdev->testmode_info)) |
| 5598 | return NULL; |
| 5599 | |
| 5600 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5601 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5602 | rdev->testmode_info->snd_seq, |
| 5603 | GFP_KERNEL); |
| 5604 | } |
| 5605 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5606 | |
| 5607 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5608 | { |
| 5609 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5610 | void *hdr = ((void **)skb->cb)[1]; |
| 5611 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5612 | |
| 5613 | if (WARN_ON(!rdev->testmode_info)) { |
| 5614 | kfree_skb(skb); |
| 5615 | return -EINVAL; |
| 5616 | } |
| 5617 | |
| 5618 | nla_nest_end(skb, data); |
| 5619 | genlmsg_end(skb, hdr); |
| 5620 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5621 | } |
| 5622 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5623 | |
| 5624 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5625 | int approxlen, gfp_t gfp) |
| 5626 | { |
| 5627 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5628 | |
| 5629 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5630 | } |
| 5631 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5632 | |
| 5633 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5634 | { |
| 5635 | void *hdr = ((void **)skb->cb)[1]; |
| 5636 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5637 | |
| 5638 | nla_nest_end(skb, data); |
| 5639 | genlmsg_end(skb, hdr); |
| 5640 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5641 | } |
| 5642 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5643 | #endif |
| 5644 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5645 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5646 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5647 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5648 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5649 | struct cfg80211_connect_params connect; |
| 5650 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5651 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5652 | int err; |
| 5653 | |
| 5654 | memset(&connect, 0, sizeof(connect)); |
| 5655 | |
| 5656 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5657 | return -EINVAL; |
| 5658 | |
| 5659 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5660 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5661 | return -EINVAL; |
| 5662 | |
| 5663 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5664 | connect.auth_type = |
| 5665 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5666 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 5667 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5668 | return -EINVAL; |
| 5669 | } else |
| 5670 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5671 | |
| 5672 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5673 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5674 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5675 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5676 | if (err) |
| 5677 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5678 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5679 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5680 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5681 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5682 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5683 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5684 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 5685 | connect.bg_scan_period = -1; |
| 5686 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 5687 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 5688 | connect.bg_scan_period = |
| 5689 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 5690 | } |
| 5691 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5692 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5693 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5694 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5695 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5696 | |
| 5697 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5698 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5699 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5700 | } |
| 5701 | |
| 5702 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5703 | connect.channel = |
| 5704 | ieee80211_get_channel(wiphy, |
| 5705 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5706 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5707 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5708 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5709 | } |
| 5710 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5711 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5712 | connkeys = nl80211_parse_connkeys(rdev, |
| 5713 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5714 | if (IS_ERR(connkeys)) |
| 5715 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5716 | } |
| 5717 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5718 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5719 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5720 | |
| 5721 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5722 | memcpy(&connect.ht_capa_mask, |
| 5723 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5724 | sizeof(connect.ht_capa_mask)); |
| 5725 | |
| 5726 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5727 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 5728 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5729 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 5730 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5731 | memcpy(&connect.ht_capa, |
| 5732 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5733 | sizeof(connect.ht_capa)); |
| 5734 | } |
| 5735 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5736 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5737 | if (err) |
| 5738 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5739 | return err; |
| 5740 | } |
| 5741 | |
| 5742 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5743 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5745 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5746 | u16 reason; |
| 5747 | |
| 5748 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5749 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5750 | else |
| 5751 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5752 | |
| 5753 | if (reason == 0) |
| 5754 | return -EINVAL; |
| 5755 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5756 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5757 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5758 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5759 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5760 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5761 | } |
| 5762 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5763 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5764 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5766 | struct net *net; |
| 5767 | int err; |
| 5768 | u32 pid; |
| 5769 | |
| 5770 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5771 | return -EINVAL; |
| 5772 | |
| 5773 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5774 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5775 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5776 | if (IS_ERR(net)) |
| 5777 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5778 | |
| 5779 | err = 0; |
| 5780 | |
| 5781 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5782 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5783 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5784 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5785 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5786 | return err; |
| 5787 | } |
| 5788 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5789 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5790 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5791 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5792 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5793 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5794 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5795 | struct cfg80211_pmksa pmksa; |
| 5796 | |
| 5797 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5798 | |
| 5799 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5800 | return -EINVAL; |
| 5801 | |
| 5802 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5803 | return -EINVAL; |
| 5804 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5805 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5806 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5807 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5808 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5809 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5810 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5811 | |
| 5812 | switch (info->genlhdr->cmd) { |
| 5813 | case NL80211_CMD_SET_PMKSA: |
| 5814 | rdev_ops = rdev->ops->set_pmksa; |
| 5815 | break; |
| 5816 | case NL80211_CMD_DEL_PMKSA: |
| 5817 | rdev_ops = rdev->ops->del_pmksa; |
| 5818 | break; |
| 5819 | default: |
| 5820 | WARN_ON(1); |
| 5821 | break; |
| 5822 | } |
| 5823 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5824 | if (!rdev_ops) |
| 5825 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5826 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5827 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5828 | } |
| 5829 | |
| 5830 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5831 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5833 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5834 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5835 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5836 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5837 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5838 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5839 | if (!rdev->ops->flush_pmksa) |
| 5840 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5841 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5842 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5843 | } |
| 5844 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5845 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5846 | { |
| 5847 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5848 | struct net_device *dev = info->user_ptr[1]; |
| 5849 | u8 action_code, dialog_token; |
| 5850 | u16 status_code; |
| 5851 | u8 *peer; |
| 5852 | |
| 5853 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5854 | !rdev->ops->tdls_mgmt) |
| 5855 | return -EOPNOTSUPP; |
| 5856 | |
| 5857 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5858 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5859 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5860 | !info->attrs[NL80211_ATTR_IE] || |
| 5861 | !info->attrs[NL80211_ATTR_MAC]) |
| 5862 | return -EINVAL; |
| 5863 | |
| 5864 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5865 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5866 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5867 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5868 | |
| 5869 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, |
| 5870 | dialog_token, status_code, |
| 5871 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5872 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 5873 | } |
| 5874 | |
| 5875 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5876 | { |
| 5877 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5878 | struct net_device *dev = info->user_ptr[1]; |
| 5879 | enum nl80211_tdls_operation operation; |
| 5880 | u8 *peer; |
| 5881 | |
| 5882 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5883 | !rdev->ops->tdls_oper) |
| 5884 | return -EOPNOTSUPP; |
| 5885 | |
| 5886 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5887 | !info->attrs[NL80211_ATTR_MAC]) |
| 5888 | return -EINVAL; |
| 5889 | |
| 5890 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5891 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5892 | |
| 5893 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); |
| 5894 | } |
| 5895 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5896 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5897 | struct genl_info *info) |
| 5898 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5899 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 5900 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5901 | struct ieee80211_channel *chan; |
| 5902 | struct sk_buff *msg; |
| 5903 | void *hdr; |
| 5904 | u64 cookie; |
| 5905 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 5906 | u32 freq, duration; |
| 5907 | int err; |
| 5908 | |
| 5909 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5910 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5911 | return -EINVAL; |
| 5912 | |
| 5913 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5914 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5915 | if (!rdev->ops->remain_on_channel || |
| 5916 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5917 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5918 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 5919 | /* |
| 5920 | * We should be on that channel for at least a minimum amount of |
| 5921 | * time (10ms) but no longer than the driver supports. |
| 5922 | */ |
| 5923 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 5924 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 5925 | return -EINVAL; |
| 5926 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5927 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 5928 | !nl80211_valid_channel_type(info, &channel_type)) |
| 5929 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5930 | |
| 5931 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5932 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5933 | if (chan == NULL) |
| 5934 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5935 | |
| 5936 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5937 | if (!msg) |
| 5938 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5939 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5940 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5941 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5942 | |
| 5943 | if (IS_ERR(hdr)) { |
| 5944 | err = PTR_ERR(hdr); |
| 5945 | goto free_msg; |
| 5946 | } |
| 5947 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 5948 | err = rdev->ops->remain_on_channel(&rdev->wiphy, wdev, chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5949 | channel_type, duration, &cookie); |
| 5950 | |
| 5951 | if (err) |
| 5952 | goto free_msg; |
| 5953 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5954 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 5955 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5956 | |
| 5957 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5958 | |
| 5959 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5960 | |
| 5961 | nla_put_failure: |
| 5962 | err = -ENOBUFS; |
| 5963 | free_msg: |
| 5964 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5965 | return err; |
| 5966 | } |
| 5967 | |
| 5968 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5969 | struct genl_info *info) |
| 5970 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5971 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 5972 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5973 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5974 | |
| 5975 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5976 | return -EINVAL; |
| 5977 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5978 | if (!rdev->ops->cancel_remain_on_channel) |
| 5979 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5980 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5981 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5982 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 5983 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5984 | } |
| 5985 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5986 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5987 | u8 *rates, u8 rates_len) |
| 5988 | { |
| 5989 | u8 i; |
| 5990 | u32 mask = 0; |
| 5991 | |
| 5992 | for (i = 0; i < rates_len; i++) { |
| 5993 | int rate = (rates[i] & 0x7f) * 5; |
| 5994 | int ridx; |
| 5995 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5996 | struct ieee80211_rate *srate = |
| 5997 | &sband->bitrates[ridx]; |
| 5998 | if (rate == srate->bitrate) { |
| 5999 | mask |= 1 << ridx; |
| 6000 | break; |
| 6001 | } |
| 6002 | } |
| 6003 | if (ridx == sband->n_bitrates) |
| 6004 | return 0; /* rate not found */ |
| 6005 | } |
| 6006 | |
| 6007 | return mask; |
| 6008 | } |
| 6009 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6010 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6011 | u8 *rates, u8 rates_len, |
| 6012 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6013 | { |
| 6014 | u8 i; |
| 6015 | |
| 6016 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6017 | |
| 6018 | for (i = 0; i < rates_len; i++) { |
| 6019 | int ridx, rbit; |
| 6020 | |
| 6021 | ridx = rates[i] / 8; |
| 6022 | rbit = BIT(rates[i] % 8); |
| 6023 | |
| 6024 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6025 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6026 | return false; |
| 6027 | |
| 6028 | /* check availability */ |
| 6029 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6030 | mcs[ridx] |= rbit; |
| 6031 | else |
| 6032 | return false; |
| 6033 | } |
| 6034 | |
| 6035 | return true; |
| 6036 | } |
| 6037 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6038 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6039 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6040 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6041 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6042 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6043 | }; |
| 6044 | |
| 6045 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6046 | struct genl_info *info) |
| 6047 | { |
| 6048 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6049 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6050 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6051 | int rem, i; |
| 6052 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6053 | struct nlattr *tx_rates; |
| 6054 | struct ieee80211_supported_band *sband; |
| 6055 | |
| 6056 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 6057 | return -EINVAL; |
| 6058 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6059 | if (!rdev->ops->set_bitrate_mask) |
| 6060 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6061 | |
| 6062 | memset(&mask, 0, sizeof(mask)); |
| 6063 | /* Default to all rates enabled */ |
| 6064 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 6065 | sband = rdev->wiphy.bands[i]; |
| 6066 | mask.control[i].legacy = |
| 6067 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6068 | if (sband) |
| 6069 | memcpy(mask.control[i].mcs, |
| 6070 | sband->ht_cap.mcs.rx_mask, |
| 6071 | sizeof(mask.control[i].mcs)); |
| 6072 | else |
| 6073 | memset(mask.control[i].mcs, 0, |
| 6074 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6075 | } |
| 6076 | |
| 6077 | /* |
| 6078 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 6079 | * directly to the enum ieee80211_band values used in cfg80211. |
| 6080 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6081 | 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] | 6082 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 6083 | { |
| 6084 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6085 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 6086 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6087 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6088 | if (sband == NULL) |
| 6089 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6090 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 6091 | nla_len(tx_rates), nl80211_txattr_policy); |
| 6092 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 6093 | mask.control[band].legacy = rateset_to_mask( |
| 6094 | sband, |
| 6095 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 6096 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 6097 | if ((mask.control[band].legacy == 0) && |
| 6098 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 6099 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6100 | } |
| 6101 | if (tb[NL80211_TXRATE_MCS]) { |
| 6102 | if (!ht_rateset_to_mask( |
| 6103 | sband, |
| 6104 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 6105 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 6106 | mask.control[band].mcs)) |
| 6107 | return -EINVAL; |
| 6108 | } |
| 6109 | |
| 6110 | if (mask.control[band].legacy == 0) { |
| 6111 | /* don't allow empty legacy rates if HT |
| 6112 | * is not even supported. */ |
| 6113 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6114 | return -EINVAL; |
| 6115 | |
| 6116 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6117 | if (mask.control[band].mcs[i]) |
| 6118 | break; |
| 6119 | |
| 6120 | /* legacy and mcs rates may not be both empty */ |
| 6121 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6122 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6123 | } |
| 6124 | } |
| 6125 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6126 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6127 | } |
| 6128 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6129 | 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] | 6130 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6131 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6132 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6133 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6134 | |
| 6135 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6136 | return -EINVAL; |
| 6137 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6138 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6139 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6140 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6141 | switch (wdev->iftype) { |
| 6142 | case NL80211_IFTYPE_STATION: |
| 6143 | case NL80211_IFTYPE_ADHOC: |
| 6144 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6145 | case NL80211_IFTYPE_AP: |
| 6146 | case NL80211_IFTYPE_AP_VLAN: |
| 6147 | case NL80211_IFTYPE_MESH_POINT: |
| 6148 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6149 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6150 | break; |
| 6151 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6152 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6153 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6154 | |
| 6155 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6156 | if (!rdev->ops->mgmt_tx) |
| 6157 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6158 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6159 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6160 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6161 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6162 | } |
| 6163 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6164 | 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] | 6165 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6166 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6167 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6168 | struct ieee80211_channel *chan; |
| 6169 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 6170 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6171 | u32 freq; |
| 6172 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6173 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6174 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6175 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6176 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6177 | bool offchan, no_cck, dont_wait_for_ack; |
| 6178 | |
| 6179 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6180 | |
| 6181 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 6182 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6183 | return -EINVAL; |
| 6184 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6185 | if (!rdev->ops->mgmt_tx) |
| 6186 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6187 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6188 | switch (wdev->iftype) { |
| 6189 | case NL80211_IFTYPE_STATION: |
| 6190 | case NL80211_IFTYPE_ADHOC: |
| 6191 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6192 | case NL80211_IFTYPE_AP: |
| 6193 | case NL80211_IFTYPE_AP_VLAN: |
| 6194 | case NL80211_IFTYPE_MESH_POINT: |
| 6195 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6196 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6197 | break; |
| 6198 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6199 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6200 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6201 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6202 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6203 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6204 | return -EINVAL; |
| 6205 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6206 | |
| 6207 | /* |
| 6208 | * We should wait on the channel for at least a minimum amount |
| 6209 | * of time (10ms) but no longer than the driver supports. |
| 6210 | */ |
| 6211 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6212 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6213 | return -EINVAL; |
| 6214 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6215 | } |
| 6216 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6217 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 6218 | if (!nl80211_valid_channel_type(info, &channel_type)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6219 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 6220 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6221 | } |
| 6222 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6223 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6224 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6225 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6226 | return -EINVAL; |
| 6227 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6228 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6229 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6230 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6231 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6232 | if (chan == NULL) |
| 6233 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6234 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6235 | if (!dont_wait_for_ack) { |
| 6236 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6237 | if (!msg) |
| 6238 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6239 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6240 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6241 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6242 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6243 | if (IS_ERR(hdr)) { |
| 6244 | err = PTR_ERR(hdr); |
| 6245 | goto free_msg; |
| 6246 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6247 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6248 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6249 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chan, offchan, channel_type, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6250 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6251 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6252 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6253 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6254 | if (err) |
| 6255 | goto free_msg; |
| 6256 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6257 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6258 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6259 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6260 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6261 | genlmsg_end(msg, hdr); |
| 6262 | return genlmsg_reply(msg, info); |
| 6263 | } |
| 6264 | |
| 6265 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6266 | |
| 6267 | nla_put_failure: |
| 6268 | err = -ENOBUFS; |
| 6269 | free_msg: |
| 6270 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6271 | return err; |
| 6272 | } |
| 6273 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6274 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6275 | { |
| 6276 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6277 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6278 | u64 cookie; |
| 6279 | |
| 6280 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6281 | return -EINVAL; |
| 6282 | |
| 6283 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6284 | return -EOPNOTSUPP; |
| 6285 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6286 | switch (wdev->iftype) { |
| 6287 | case NL80211_IFTYPE_STATION: |
| 6288 | case NL80211_IFTYPE_ADHOC: |
| 6289 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6290 | case NL80211_IFTYPE_AP: |
| 6291 | case NL80211_IFTYPE_AP_VLAN: |
| 6292 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6293 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6294 | break; |
| 6295 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6296 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6297 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6298 | |
| 6299 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6300 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6301 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6302 | } |
| 6303 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6304 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6305 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6307 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6308 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6309 | u8 ps_state; |
| 6310 | bool state; |
| 6311 | int err; |
| 6312 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6313 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6314 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6315 | |
| 6316 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6317 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6318 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6319 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6320 | |
| 6321 | wdev = dev->ieee80211_ptr; |
| 6322 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6323 | if (!rdev->ops->set_power_mgmt) |
| 6324 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6325 | |
| 6326 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6327 | |
| 6328 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6329 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6330 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6331 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 6332 | wdev->ps_timeout); |
| 6333 | if (!err) |
| 6334 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6335 | return err; |
| 6336 | } |
| 6337 | |
| 6338 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6339 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6340 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6341 | enum nl80211_ps_state ps_state; |
| 6342 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6343 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6344 | struct sk_buff *msg; |
| 6345 | void *hdr; |
| 6346 | int err; |
| 6347 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6348 | wdev = dev->ieee80211_ptr; |
| 6349 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6350 | if (!rdev->ops->set_power_mgmt) |
| 6351 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6352 | |
| 6353 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6354 | if (!msg) |
| 6355 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6356 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6357 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6358 | NL80211_CMD_GET_POWER_SAVE); |
| 6359 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6360 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6361 | goto free_msg; |
| 6362 | } |
| 6363 | |
| 6364 | if (wdev->ps) |
| 6365 | ps_state = NL80211_PS_ENABLED; |
| 6366 | else |
| 6367 | ps_state = NL80211_PS_DISABLED; |
| 6368 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6369 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6370 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6371 | |
| 6372 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6373 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6374 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6375 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6376 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6377 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6378 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6379 | return err; |
| 6380 | } |
| 6381 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6382 | static struct nla_policy |
| 6383 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6384 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6385 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6386 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6387 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 6388 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 6389 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6390 | }; |
| 6391 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6392 | static int nl80211_set_cqm_txe(struct genl_info *info, |
| 6393 | u32 rate, u32 pkts, u32 intvl) |
| 6394 | { |
| 6395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6396 | struct wireless_dev *wdev; |
| 6397 | struct net_device *dev = info->user_ptr[1]; |
| 6398 | |
| 6399 | if ((rate < 0 || rate > 100) || |
| 6400 | (intvl < 0 || intvl > NL80211_CQM_TXE_MAX_INTVL)) |
| 6401 | return -EINVAL; |
| 6402 | |
| 6403 | wdev = dev->ieee80211_ptr; |
| 6404 | |
| 6405 | if (!rdev->ops->set_cqm_txe_config) |
| 6406 | return -EOPNOTSUPP; |
| 6407 | |
| 6408 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 6409 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6410 | return -EOPNOTSUPP; |
| 6411 | |
| 6412 | return rdev->ops->set_cqm_txe_config(wdev->wiphy, dev, |
| 6413 | rate, pkts, intvl); |
| 6414 | } |
| 6415 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6416 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6417 | s32 threshold, u32 hysteresis) |
| 6418 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6419 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6420 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6421 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6422 | |
| 6423 | if (threshold > 0) |
| 6424 | return -EINVAL; |
| 6425 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6426 | wdev = dev->ieee80211_ptr; |
| 6427 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6428 | if (!rdev->ops->set_cqm_rssi_config) |
| 6429 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6430 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6431 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6432 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6433 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6434 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6435 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 6436 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6437 | } |
| 6438 | |
| 6439 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6440 | { |
| 6441 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6442 | struct nlattr *cqm; |
| 6443 | int err; |
| 6444 | |
| 6445 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6446 | if (!cqm) { |
| 6447 | err = -EINVAL; |
| 6448 | goto out; |
| 6449 | } |
| 6450 | |
| 6451 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6452 | nl80211_attr_cqm_policy); |
| 6453 | if (err) |
| 6454 | goto out; |
| 6455 | |
| 6456 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6457 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6458 | s32 threshold; |
| 6459 | u32 hysteresis; |
| 6460 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6461 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6462 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 6463 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 6464 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 6465 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 6466 | u32 rate, pkts, intvl; |
| 6467 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 6468 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 6469 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 6470 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6471 | } else |
| 6472 | err = -EINVAL; |
| 6473 | |
| 6474 | out: |
| 6475 | return err; |
| 6476 | } |
| 6477 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6478 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6479 | { |
| 6480 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6481 | struct net_device *dev = info->user_ptr[1]; |
| 6482 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6483 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6484 | int err; |
| 6485 | |
| 6486 | /* start with default */ |
| 6487 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6488 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6489 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6490 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6491 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6492 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6493 | if (err) |
| 6494 | return err; |
| 6495 | } |
| 6496 | |
| 6497 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6498 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 6499 | return -EINVAL; |
| 6500 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6501 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6502 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6503 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 6504 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6505 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 6506 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6507 | return -EINVAL; |
| 6508 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6509 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 6510 | /* parse additional setup parameters if given */ |
| 6511 | err = nl80211_parse_mesh_setup(info, &setup); |
| 6512 | if (err) |
| 6513 | return err; |
| 6514 | } |
| 6515 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6516 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6517 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 6518 | |
| 6519 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 6520 | !nl80211_valid_channel_type(info, &channel_type)) |
| 6521 | return -EINVAL; |
| 6522 | |
| 6523 | setup.channel = rdev_freq_to_chan(rdev, |
| 6524 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 6525 | channel_type); |
| 6526 | if (!setup.channel) |
| 6527 | return -EINVAL; |
| 6528 | setup.channel_type = channel_type; |
| 6529 | } else { |
| 6530 | /* cfg80211_join_mesh() will sort it out */ |
| 6531 | setup.channel = NULL; |
| 6532 | } |
| 6533 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6534 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6535 | } |
| 6536 | |
| 6537 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6538 | { |
| 6539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6540 | struct net_device *dev = info->user_ptr[1]; |
| 6541 | |
| 6542 | return cfg80211_leave_mesh(rdev, dev); |
| 6543 | } |
| 6544 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6545 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6546 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6547 | { |
| 6548 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6549 | struct sk_buff *msg; |
| 6550 | void *hdr; |
| 6551 | |
| 6552 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6553 | return -EOPNOTSUPP; |
| 6554 | |
| 6555 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6556 | if (!msg) |
| 6557 | return -ENOMEM; |
| 6558 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6559 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6560 | NL80211_CMD_GET_WOWLAN); |
| 6561 | if (!hdr) |
| 6562 | goto nla_put_failure; |
| 6563 | |
| 6564 | if (rdev->wowlan) { |
| 6565 | struct nlattr *nl_wowlan; |
| 6566 | |
| 6567 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 6568 | if (!nl_wowlan) |
| 6569 | goto nla_put_failure; |
| 6570 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6571 | if ((rdev->wowlan->any && |
| 6572 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 6573 | (rdev->wowlan->disconnect && |
| 6574 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 6575 | (rdev->wowlan->magic_pkt && |
| 6576 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 6577 | (rdev->wowlan->gtk_rekey_failure && |
| 6578 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 6579 | (rdev->wowlan->eap_identity_req && |
| 6580 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 6581 | (rdev->wowlan->four_way_handshake && |
| 6582 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 6583 | (rdev->wowlan->rfkill_release && |
| 6584 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 6585 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6586 | if (rdev->wowlan->n_patterns) { |
| 6587 | struct nlattr *nl_pats, *nl_pat; |
| 6588 | int i, pat_len; |
| 6589 | |
| 6590 | nl_pats = nla_nest_start(msg, |
| 6591 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 6592 | if (!nl_pats) |
| 6593 | goto nla_put_failure; |
| 6594 | |
| 6595 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 6596 | nl_pat = nla_nest_start(msg, i + 1); |
| 6597 | if (!nl_pat) |
| 6598 | goto nla_put_failure; |
| 6599 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6600 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 6601 | DIV_ROUND_UP(pat_len, 8), |
| 6602 | rdev->wowlan->patterns[i].mask) || |
| 6603 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 6604 | pat_len, |
| 6605 | rdev->wowlan->patterns[i].pattern)) |
| 6606 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6607 | nla_nest_end(msg, nl_pat); |
| 6608 | } |
| 6609 | nla_nest_end(msg, nl_pats); |
| 6610 | } |
| 6611 | |
| 6612 | nla_nest_end(msg, nl_wowlan); |
| 6613 | } |
| 6614 | |
| 6615 | genlmsg_end(msg, hdr); |
| 6616 | return genlmsg_reply(msg, info); |
| 6617 | |
| 6618 | nla_put_failure: |
| 6619 | nlmsg_free(msg); |
| 6620 | return -ENOBUFS; |
| 6621 | } |
| 6622 | |
| 6623 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6624 | { |
| 6625 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6626 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6627 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6628 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6629 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 6630 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6631 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6632 | |
| 6633 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6634 | return -EOPNOTSUPP; |
| 6635 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6636 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 6637 | cfg80211_rdev_free_wowlan(rdev); |
| 6638 | rdev->wowlan = NULL; |
| 6639 | goto set_wakeup; |
| 6640 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6641 | |
| 6642 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 6643 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6644 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6645 | nl80211_wowlan_policy); |
| 6646 | if (err) |
| 6647 | return err; |
| 6648 | |
| 6649 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 6650 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 6651 | return -EINVAL; |
| 6652 | new_triggers.any = true; |
| 6653 | } |
| 6654 | |
| 6655 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 6656 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 6657 | return -EINVAL; |
| 6658 | new_triggers.disconnect = true; |
| 6659 | } |
| 6660 | |
| 6661 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 6662 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 6663 | return -EINVAL; |
| 6664 | new_triggers.magic_pkt = true; |
| 6665 | } |
| 6666 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 6667 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 6668 | return -EINVAL; |
| 6669 | |
| 6670 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 6671 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 6672 | return -EINVAL; |
| 6673 | new_triggers.gtk_rekey_failure = true; |
| 6674 | } |
| 6675 | |
| 6676 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 6677 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 6678 | return -EINVAL; |
| 6679 | new_triggers.eap_identity_req = true; |
| 6680 | } |
| 6681 | |
| 6682 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 6683 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 6684 | return -EINVAL; |
| 6685 | new_triggers.four_way_handshake = true; |
| 6686 | } |
| 6687 | |
| 6688 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 6689 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 6690 | return -EINVAL; |
| 6691 | new_triggers.rfkill_release = true; |
| 6692 | } |
| 6693 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6694 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 6695 | struct nlattr *pat; |
| 6696 | int n_patterns = 0; |
| 6697 | int rem, pat_len, mask_len; |
| 6698 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6699 | |
| 6700 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6701 | rem) |
| 6702 | n_patterns++; |
| 6703 | if (n_patterns > wowlan->n_patterns) |
| 6704 | return -EINVAL; |
| 6705 | |
| 6706 | new_triggers.patterns = kcalloc(n_patterns, |
| 6707 | sizeof(new_triggers.patterns[0]), |
| 6708 | GFP_KERNEL); |
| 6709 | if (!new_triggers.patterns) |
| 6710 | return -ENOMEM; |
| 6711 | |
| 6712 | new_triggers.n_patterns = n_patterns; |
| 6713 | i = 0; |
| 6714 | |
| 6715 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6716 | rem) { |
| 6717 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6718 | nla_data(pat), nla_len(pat), NULL); |
| 6719 | err = -EINVAL; |
| 6720 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6721 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6722 | goto error; |
| 6723 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6724 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6725 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6726 | mask_len) |
| 6727 | goto error; |
| 6728 | if (pat_len > wowlan->pattern_max_len || |
| 6729 | pat_len < wowlan->pattern_min_len) |
| 6730 | goto error; |
| 6731 | |
| 6732 | new_triggers.patterns[i].mask = |
| 6733 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6734 | if (!new_triggers.patterns[i].mask) { |
| 6735 | err = -ENOMEM; |
| 6736 | goto error; |
| 6737 | } |
| 6738 | new_triggers.patterns[i].pattern = |
| 6739 | new_triggers.patterns[i].mask + mask_len; |
| 6740 | memcpy(new_triggers.patterns[i].mask, |
| 6741 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6742 | mask_len); |
| 6743 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6744 | memcpy(new_triggers.patterns[i].pattern, |
| 6745 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6746 | pat_len); |
| 6747 | i++; |
| 6748 | } |
| 6749 | } |
| 6750 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6751 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 6752 | if (!ntrig) { |
| 6753 | err = -ENOMEM; |
| 6754 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6755 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6756 | cfg80211_rdev_free_wowlan(rdev); |
| 6757 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6758 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6759 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6760 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
| 6761 | rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan); |
| 6762 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6763 | return 0; |
| 6764 | error: |
| 6765 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6766 | kfree(new_triggers.patterns[i].mask); |
| 6767 | kfree(new_triggers.patterns); |
| 6768 | return err; |
| 6769 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6770 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6771 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6772 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6773 | { |
| 6774 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6775 | struct net_device *dev = info->user_ptr[1]; |
| 6776 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6777 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6778 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6779 | int err; |
| 6780 | |
| 6781 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6782 | return -EINVAL; |
| 6783 | |
| 6784 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6785 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6786 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6787 | nl80211_rekey_policy); |
| 6788 | if (err) |
| 6789 | return err; |
| 6790 | |
| 6791 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6792 | return -ERANGE; |
| 6793 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6794 | return -ERANGE; |
| 6795 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6796 | return -ERANGE; |
| 6797 | |
| 6798 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6799 | NL80211_KEK_LEN); |
| 6800 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6801 | NL80211_KCK_LEN); |
| 6802 | memcpy(rekey_data.replay_ctr, |
| 6803 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6804 | NL80211_REPLAY_CTR_LEN); |
| 6805 | |
| 6806 | wdev_lock(wdev); |
| 6807 | if (!wdev->current_bss) { |
| 6808 | err = -ENOTCONN; |
| 6809 | goto out; |
| 6810 | } |
| 6811 | |
| 6812 | if (!rdev->ops->set_rekey_data) { |
| 6813 | err = -EOPNOTSUPP; |
| 6814 | goto out; |
| 6815 | } |
| 6816 | |
| 6817 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 6818 | out: |
| 6819 | wdev_unlock(wdev); |
| 6820 | return err; |
| 6821 | } |
| 6822 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6823 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6824 | struct genl_info *info) |
| 6825 | { |
| 6826 | struct net_device *dev = info->user_ptr[1]; |
| 6827 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6828 | |
| 6829 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6830 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6831 | return -EINVAL; |
| 6832 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6833 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6834 | return -EBUSY; |
| 6835 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6836 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6837 | return 0; |
| 6838 | } |
| 6839 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6840 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6841 | struct genl_info *info) |
| 6842 | { |
| 6843 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6844 | struct net_device *dev = info->user_ptr[1]; |
| 6845 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6846 | struct sk_buff *msg; |
| 6847 | void *hdr; |
| 6848 | const u8 *addr; |
| 6849 | u64 cookie; |
| 6850 | int err; |
| 6851 | |
| 6852 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6853 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6854 | return -EOPNOTSUPP; |
| 6855 | |
| 6856 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6857 | return -EINVAL; |
| 6858 | |
| 6859 | if (!rdev->ops->probe_client) |
| 6860 | return -EOPNOTSUPP; |
| 6861 | |
| 6862 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6863 | if (!msg) |
| 6864 | return -ENOMEM; |
| 6865 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6866 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6867 | NL80211_CMD_PROBE_CLIENT); |
| 6868 | |
| 6869 | if (IS_ERR(hdr)) { |
| 6870 | err = PTR_ERR(hdr); |
| 6871 | goto free_msg; |
| 6872 | } |
| 6873 | |
| 6874 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6875 | |
| 6876 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); |
| 6877 | if (err) |
| 6878 | goto free_msg; |
| 6879 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6880 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6881 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6882 | |
| 6883 | genlmsg_end(msg, hdr); |
| 6884 | |
| 6885 | return genlmsg_reply(msg, info); |
| 6886 | |
| 6887 | nla_put_failure: |
| 6888 | err = -ENOBUFS; |
| 6889 | free_msg: |
| 6890 | nlmsg_free(msg); |
| 6891 | return err; |
| 6892 | } |
| 6893 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6894 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 6895 | { |
| 6896 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6897 | |
| 6898 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 6899 | return -EOPNOTSUPP; |
| 6900 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6901 | if (rdev->ap_beacons_nlportid) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6902 | return -EBUSY; |
| 6903 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6904 | rdev->ap_beacons_nlportid = info->snd_portid; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6905 | |
| 6906 | return 0; |
| 6907 | } |
| 6908 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6909 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 6910 | { |
| 6911 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6912 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6913 | int err; |
| 6914 | |
| 6915 | if (!rdev->ops->start_p2p_device) |
| 6916 | return -EOPNOTSUPP; |
| 6917 | |
| 6918 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 6919 | return -EOPNOTSUPP; |
| 6920 | |
| 6921 | if (wdev->p2p_started) |
| 6922 | return 0; |
| 6923 | |
| 6924 | mutex_lock(&rdev->devlist_mtx); |
| 6925 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
| 6926 | mutex_unlock(&rdev->devlist_mtx); |
| 6927 | if (err) |
| 6928 | return err; |
| 6929 | |
| 6930 | err = rdev->ops->start_p2p_device(&rdev->wiphy, wdev); |
| 6931 | if (err) |
| 6932 | return err; |
| 6933 | |
| 6934 | wdev->p2p_started = true; |
| 6935 | mutex_lock(&rdev->devlist_mtx); |
| 6936 | rdev->opencount++; |
| 6937 | mutex_unlock(&rdev->devlist_mtx); |
| 6938 | |
| 6939 | return 0; |
| 6940 | } |
| 6941 | |
| 6942 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 6943 | { |
| 6944 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6945 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6946 | |
| 6947 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 6948 | return -EOPNOTSUPP; |
| 6949 | |
| 6950 | if (!rdev->ops->stop_p2p_device) |
| 6951 | return -EOPNOTSUPP; |
| 6952 | |
| 6953 | if (!wdev->p2p_started) |
| 6954 | return 0; |
| 6955 | |
| 6956 | rdev->ops->stop_p2p_device(&rdev->wiphy, wdev); |
| 6957 | wdev->p2p_started = false; |
| 6958 | |
| 6959 | mutex_lock(&rdev->devlist_mtx); |
| 6960 | rdev->opencount--; |
| 6961 | mutex_unlock(&rdev->devlist_mtx); |
| 6962 | |
| 6963 | if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) { |
| 6964 | rdev->scan_req->aborted = true; |
| 6965 | ___cfg80211_scan_done(rdev, true); |
| 6966 | } |
| 6967 | |
| 6968 | return 0; |
| 6969 | } |
| 6970 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6971 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 6972 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 6973 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6974 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 6975 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 6976 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 6977 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 6978 | /* 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] | 6979 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 6980 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6981 | |
| 6982 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6983 | struct genl_info *info) |
| 6984 | { |
| 6985 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 6986 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6987 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6988 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 6989 | |
| 6990 | if (rtnl) |
| 6991 | rtnl_lock(); |
| 6992 | |
| 6993 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 6994 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6995 | if (IS_ERR(rdev)) { |
| 6996 | if (rtnl) |
| 6997 | rtnl_unlock(); |
| 6998 | return PTR_ERR(rdev); |
| 6999 | } |
| 7000 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7001 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 7002 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7003 | mutex_lock(&cfg80211_mutex); |
| 7004 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 7005 | info->attrs); |
| 7006 | if (IS_ERR(wdev)) { |
| 7007 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7008 | if (rtnl) |
| 7009 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7010 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7011 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7012 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7013 | dev = wdev->netdev; |
| 7014 | rdev = wiphy_to_dev(wdev->wiphy); |
| 7015 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7016 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 7017 | if (!dev) { |
| 7018 | mutex_unlock(&cfg80211_mutex); |
| 7019 | if (rtnl) |
| 7020 | rtnl_unlock(); |
| 7021 | return -EINVAL; |
| 7022 | } |
| 7023 | |
| 7024 | info->user_ptr[1] = dev; |
| 7025 | } else { |
| 7026 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7027 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7028 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7029 | if (dev) { |
| 7030 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 7031 | !netif_running(dev)) { |
| 7032 | mutex_unlock(&cfg80211_mutex); |
| 7033 | if (rtnl) |
| 7034 | rtnl_unlock(); |
| 7035 | return -ENETDOWN; |
| 7036 | } |
| 7037 | |
| 7038 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7039 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 7040 | if (!wdev->p2p_started) { |
| 7041 | mutex_unlock(&cfg80211_mutex); |
| 7042 | if (rtnl) |
| 7043 | rtnl_unlock(); |
| 7044 | return -ENETDOWN; |
| 7045 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7046 | } |
| 7047 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 7048 | cfg80211_lock_rdev(rdev); |
| 7049 | |
| 7050 | mutex_unlock(&cfg80211_mutex); |
| 7051 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7052 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7053 | } |
| 7054 | |
| 7055 | return 0; |
| 7056 | } |
| 7057 | |
| 7058 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 7059 | struct genl_info *info) |
| 7060 | { |
| 7061 | if (info->user_ptr[0]) |
| 7062 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 7063 | if (info->user_ptr[1]) { |
| 7064 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 7065 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 7066 | |
| 7067 | if (wdev->netdev) |
| 7068 | dev_put(wdev->netdev); |
| 7069 | } else { |
| 7070 | dev_put(info->user_ptr[1]); |
| 7071 | } |
| 7072 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7073 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 7074 | rtnl_unlock(); |
| 7075 | } |
| 7076 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7077 | static struct genl_ops nl80211_ops[] = { |
| 7078 | { |
| 7079 | .cmd = NL80211_CMD_GET_WIPHY, |
| 7080 | .doit = nl80211_get_wiphy, |
| 7081 | .dumpit = nl80211_dump_wiphy, |
| 7082 | .policy = nl80211_policy, |
| 7083 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7084 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7085 | }, |
| 7086 | { |
| 7087 | .cmd = NL80211_CMD_SET_WIPHY, |
| 7088 | .doit = nl80211_set_wiphy, |
| 7089 | .policy = nl80211_policy, |
| 7090 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7091 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7092 | }, |
| 7093 | { |
| 7094 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 7095 | .doit = nl80211_get_interface, |
| 7096 | .dumpit = nl80211_dump_interface, |
| 7097 | .policy = nl80211_policy, |
| 7098 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 7099 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7100 | }, |
| 7101 | { |
| 7102 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 7103 | .doit = nl80211_set_interface, |
| 7104 | .policy = nl80211_policy, |
| 7105 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7106 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7107 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7108 | }, |
| 7109 | { |
| 7110 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 7111 | .doit = nl80211_new_interface, |
| 7112 | .policy = nl80211_policy, |
| 7113 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7114 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7115 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7116 | }, |
| 7117 | { |
| 7118 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 7119 | .doit = nl80211_del_interface, |
| 7120 | .policy = nl80211_policy, |
| 7121 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 7122 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7123 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7124 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7125 | { |
| 7126 | .cmd = NL80211_CMD_GET_KEY, |
| 7127 | .doit = nl80211_get_key, |
| 7128 | .policy = nl80211_policy, |
| 7129 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7130 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7131 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7132 | }, |
| 7133 | { |
| 7134 | .cmd = NL80211_CMD_SET_KEY, |
| 7135 | .doit = nl80211_set_key, |
| 7136 | .policy = nl80211_policy, |
| 7137 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7138 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7139 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7140 | }, |
| 7141 | { |
| 7142 | .cmd = NL80211_CMD_NEW_KEY, |
| 7143 | .doit = nl80211_new_key, |
| 7144 | .policy = nl80211_policy, |
| 7145 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7146 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7147 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7148 | }, |
| 7149 | { |
| 7150 | .cmd = NL80211_CMD_DEL_KEY, |
| 7151 | .doit = nl80211_del_key, |
| 7152 | .policy = nl80211_policy, |
| 7153 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7154 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7155 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 7156 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7157 | { |
| 7158 | .cmd = NL80211_CMD_SET_BEACON, |
| 7159 | .policy = nl80211_policy, |
| 7160 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7161 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7162 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7163 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7164 | }, |
| 7165 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7166 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7167 | .policy = nl80211_policy, |
| 7168 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7169 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7170 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7171 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7172 | }, |
| 7173 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7174 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7175 | .policy = nl80211_policy, |
| 7176 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 7177 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7178 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7179 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 7180 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7181 | { |
| 7182 | .cmd = NL80211_CMD_GET_STATION, |
| 7183 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7184 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7185 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7186 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7187 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7188 | }, |
| 7189 | { |
| 7190 | .cmd = NL80211_CMD_SET_STATION, |
| 7191 | .doit = nl80211_set_station, |
| 7192 | .policy = nl80211_policy, |
| 7193 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7194 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7195 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7196 | }, |
| 7197 | { |
| 7198 | .cmd = NL80211_CMD_NEW_STATION, |
| 7199 | .doit = nl80211_new_station, |
| 7200 | .policy = nl80211_policy, |
| 7201 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7202 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7203 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7204 | }, |
| 7205 | { |
| 7206 | .cmd = NL80211_CMD_DEL_STATION, |
| 7207 | .doit = nl80211_del_station, |
| 7208 | .policy = nl80211_policy, |
| 7209 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7210 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7211 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7212 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7213 | { |
| 7214 | .cmd = NL80211_CMD_GET_MPATH, |
| 7215 | .doit = nl80211_get_mpath, |
| 7216 | .dumpit = nl80211_dump_mpath, |
| 7217 | .policy = nl80211_policy, |
| 7218 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7219 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7220 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7221 | }, |
| 7222 | { |
| 7223 | .cmd = NL80211_CMD_SET_MPATH, |
| 7224 | .doit = nl80211_set_mpath, |
| 7225 | .policy = nl80211_policy, |
| 7226 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7227 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7228 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7229 | }, |
| 7230 | { |
| 7231 | .cmd = NL80211_CMD_NEW_MPATH, |
| 7232 | .doit = nl80211_new_mpath, |
| 7233 | .policy = nl80211_policy, |
| 7234 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7235 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7236 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7237 | }, |
| 7238 | { |
| 7239 | .cmd = NL80211_CMD_DEL_MPATH, |
| 7240 | .doit = nl80211_del_mpath, |
| 7241 | .policy = nl80211_policy, |
| 7242 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7243 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7244 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7245 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7246 | { |
| 7247 | .cmd = NL80211_CMD_SET_BSS, |
| 7248 | .doit = nl80211_set_bss, |
| 7249 | .policy = nl80211_policy, |
| 7250 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7251 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7252 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7253 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7254 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7255 | .cmd = NL80211_CMD_GET_REG, |
| 7256 | .doit = nl80211_get_reg, |
| 7257 | .policy = nl80211_policy, |
| 7258 | /* can be retrieved by unprivileged users */ |
| 7259 | }, |
| 7260 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7261 | .cmd = NL80211_CMD_SET_REG, |
| 7262 | .doit = nl80211_set_reg, |
| 7263 | .policy = nl80211_policy, |
| 7264 | .flags = GENL_ADMIN_PERM, |
| 7265 | }, |
| 7266 | { |
| 7267 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 7268 | .doit = nl80211_req_set_reg, |
| 7269 | .policy = nl80211_policy, |
| 7270 | .flags = GENL_ADMIN_PERM, |
| 7271 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7272 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7273 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 7274 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7275 | .policy = nl80211_policy, |
| 7276 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7277 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7278 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7279 | }, |
| 7280 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7281 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 7282 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7283 | .policy = nl80211_policy, |
| 7284 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7285 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7286 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7287 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 7288 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7289 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 7290 | .doit = nl80211_trigger_scan, |
| 7291 | .policy = nl80211_policy, |
| 7292 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7293 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7294 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7295 | }, |
| 7296 | { |
| 7297 | .cmd = NL80211_CMD_GET_SCAN, |
| 7298 | .policy = nl80211_policy, |
| 7299 | .dumpit = nl80211_dump_scan, |
| 7300 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7301 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7302 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 7303 | .doit = nl80211_start_sched_scan, |
| 7304 | .policy = nl80211_policy, |
| 7305 | .flags = GENL_ADMIN_PERM, |
| 7306 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7307 | NL80211_FLAG_NEED_RTNL, |
| 7308 | }, |
| 7309 | { |
| 7310 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 7311 | .doit = nl80211_stop_sched_scan, |
| 7312 | .policy = nl80211_policy, |
| 7313 | .flags = GENL_ADMIN_PERM, |
| 7314 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7315 | NL80211_FLAG_NEED_RTNL, |
| 7316 | }, |
| 7317 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7318 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 7319 | .doit = nl80211_authenticate, |
| 7320 | .policy = nl80211_policy, |
| 7321 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7322 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7323 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7324 | }, |
| 7325 | { |
| 7326 | .cmd = NL80211_CMD_ASSOCIATE, |
| 7327 | .doit = nl80211_associate, |
| 7328 | .policy = nl80211_policy, |
| 7329 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7330 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7331 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7332 | }, |
| 7333 | { |
| 7334 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 7335 | .doit = nl80211_deauthenticate, |
| 7336 | .policy = nl80211_policy, |
| 7337 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7338 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7339 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7340 | }, |
| 7341 | { |
| 7342 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 7343 | .doit = nl80211_disassociate, |
| 7344 | .policy = nl80211_policy, |
| 7345 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7346 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7347 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7348 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7349 | { |
| 7350 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 7351 | .doit = nl80211_join_ibss, |
| 7352 | .policy = nl80211_policy, |
| 7353 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7354 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7355 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7356 | }, |
| 7357 | { |
| 7358 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 7359 | .doit = nl80211_leave_ibss, |
| 7360 | .policy = nl80211_policy, |
| 7361 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7362 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7363 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7364 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7365 | #ifdef CONFIG_NL80211_TESTMODE |
| 7366 | { |
| 7367 | .cmd = NL80211_CMD_TESTMODE, |
| 7368 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7369 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7370 | .policy = nl80211_policy, |
| 7371 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7372 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7373 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7374 | }, |
| 7375 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7376 | { |
| 7377 | .cmd = NL80211_CMD_CONNECT, |
| 7378 | .doit = nl80211_connect, |
| 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, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7383 | }, |
| 7384 | { |
| 7385 | .cmd = NL80211_CMD_DISCONNECT, |
| 7386 | .doit = nl80211_disconnect, |
| 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, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7391 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7392 | { |
| 7393 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 7394 | .doit = nl80211_wiphy_netns, |
| 7395 | .policy = nl80211_policy, |
| 7396 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7397 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7398 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7399 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7400 | { |
| 7401 | .cmd = NL80211_CMD_GET_SURVEY, |
| 7402 | .policy = nl80211_policy, |
| 7403 | .dumpit = nl80211_dump_survey, |
| 7404 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7405 | { |
| 7406 | .cmd = NL80211_CMD_SET_PMKSA, |
| 7407 | .doit = nl80211_setdel_pmksa, |
| 7408 | .policy = nl80211_policy, |
| 7409 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7410 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7411 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7412 | }, |
| 7413 | { |
| 7414 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 7415 | .doit = nl80211_setdel_pmksa, |
| 7416 | .policy = nl80211_policy, |
| 7417 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7418 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7419 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7420 | }, |
| 7421 | { |
| 7422 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 7423 | .doit = nl80211_flush_pmksa, |
| 7424 | .policy = nl80211_policy, |
| 7425 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7426 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7427 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7428 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7429 | { |
| 7430 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7431 | .doit = nl80211_remain_on_channel, |
| 7432 | .policy = nl80211_policy, |
| 7433 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7434 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7435 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7436 | }, |
| 7437 | { |
| 7438 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7439 | .doit = nl80211_cancel_remain_on_channel, |
| 7440 | .policy = nl80211_policy, |
| 7441 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7442 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7443 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7444 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7445 | { |
| 7446 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 7447 | .doit = nl80211_set_tx_bitrate_mask, |
| 7448 | .policy = nl80211_policy, |
| 7449 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7450 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7451 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7452 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7453 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7454 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 7455 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7456 | .policy = nl80211_policy, |
| 7457 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7458 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7459 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7460 | }, |
| 7461 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7462 | .cmd = NL80211_CMD_FRAME, |
| 7463 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7464 | .policy = nl80211_policy, |
| 7465 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7466 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7467 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7468 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7469 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7470 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 7471 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 7472 | .policy = nl80211_policy, |
| 7473 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7474 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7475 | NL80211_FLAG_NEED_RTNL, |
| 7476 | }, |
| 7477 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7478 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 7479 | .doit = nl80211_set_power_save, |
| 7480 | .policy = nl80211_policy, |
| 7481 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7482 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7483 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7484 | }, |
| 7485 | { |
| 7486 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 7487 | .doit = nl80211_get_power_save, |
| 7488 | .policy = nl80211_policy, |
| 7489 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7490 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7491 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7492 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7493 | { |
| 7494 | .cmd = NL80211_CMD_SET_CQM, |
| 7495 | .doit = nl80211_set_cqm, |
| 7496 | .policy = nl80211_policy, |
| 7497 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7498 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7499 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7500 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7501 | { |
| 7502 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 7503 | .doit = nl80211_set_channel, |
| 7504 | .policy = nl80211_policy, |
| 7505 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7506 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7507 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7508 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7509 | { |
| 7510 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 7511 | .doit = nl80211_set_wds_peer, |
| 7512 | .policy = nl80211_policy, |
| 7513 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 7514 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7515 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7516 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7517 | { |
| 7518 | .cmd = NL80211_CMD_JOIN_MESH, |
| 7519 | .doit = nl80211_join_mesh, |
| 7520 | .policy = nl80211_policy, |
| 7521 | .flags = GENL_ADMIN_PERM, |
| 7522 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7523 | NL80211_FLAG_NEED_RTNL, |
| 7524 | }, |
| 7525 | { |
| 7526 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 7527 | .doit = nl80211_leave_mesh, |
| 7528 | .policy = nl80211_policy, |
| 7529 | .flags = GENL_ADMIN_PERM, |
| 7530 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7531 | NL80211_FLAG_NEED_RTNL, |
| 7532 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7533 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7534 | { |
| 7535 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 7536 | .doit = nl80211_get_wowlan, |
| 7537 | .policy = nl80211_policy, |
| 7538 | /* can be retrieved by unprivileged users */ |
| 7539 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7540 | NL80211_FLAG_NEED_RTNL, |
| 7541 | }, |
| 7542 | { |
| 7543 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 7544 | .doit = nl80211_set_wowlan, |
| 7545 | .policy = nl80211_policy, |
| 7546 | .flags = GENL_ADMIN_PERM, |
| 7547 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7548 | NL80211_FLAG_NEED_RTNL, |
| 7549 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7550 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7551 | { |
| 7552 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 7553 | .doit = nl80211_set_rekey_data, |
| 7554 | .policy = nl80211_policy, |
| 7555 | .flags = GENL_ADMIN_PERM, |
| 7556 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7557 | NL80211_FLAG_NEED_RTNL, |
| 7558 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7559 | { |
| 7560 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 7561 | .doit = nl80211_tdls_mgmt, |
| 7562 | .policy = nl80211_policy, |
| 7563 | .flags = GENL_ADMIN_PERM, |
| 7564 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7565 | NL80211_FLAG_NEED_RTNL, |
| 7566 | }, |
| 7567 | { |
| 7568 | .cmd = NL80211_CMD_TDLS_OPER, |
| 7569 | .doit = nl80211_tdls_oper, |
| 7570 | .policy = nl80211_policy, |
| 7571 | .flags = GENL_ADMIN_PERM, |
| 7572 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7573 | NL80211_FLAG_NEED_RTNL, |
| 7574 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7575 | { |
| 7576 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 7577 | .doit = nl80211_register_unexpected_frame, |
| 7578 | .policy = nl80211_policy, |
| 7579 | .flags = GENL_ADMIN_PERM, |
| 7580 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7581 | NL80211_FLAG_NEED_RTNL, |
| 7582 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7583 | { |
| 7584 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 7585 | .doit = nl80211_probe_client, |
| 7586 | .policy = nl80211_policy, |
| 7587 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7588 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7589 | NL80211_FLAG_NEED_RTNL, |
| 7590 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7591 | { |
| 7592 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 7593 | .doit = nl80211_register_beacons, |
| 7594 | .policy = nl80211_policy, |
| 7595 | .flags = GENL_ADMIN_PERM, |
| 7596 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7597 | NL80211_FLAG_NEED_RTNL, |
| 7598 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 7599 | { |
| 7600 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 7601 | .doit = nl80211_set_noack_map, |
| 7602 | .policy = nl80211_policy, |
| 7603 | .flags = GENL_ADMIN_PERM, |
| 7604 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7605 | NL80211_FLAG_NEED_RTNL, |
| 7606 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7607 | { |
| 7608 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 7609 | .doit = nl80211_start_p2p_device, |
| 7610 | .policy = nl80211_policy, |
| 7611 | .flags = GENL_ADMIN_PERM, |
| 7612 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 7613 | NL80211_FLAG_NEED_RTNL, |
| 7614 | }, |
| 7615 | { |
| 7616 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 7617 | .doit = nl80211_stop_p2p_device, |
| 7618 | .policy = nl80211_policy, |
| 7619 | .flags = GENL_ADMIN_PERM, |
| 7620 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 7621 | NL80211_FLAG_NEED_RTNL, |
| 7622 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7623 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7624 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7625 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 7626 | .name = "mlme", |
| 7627 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7628 | |
| 7629 | /* multicast groups */ |
| 7630 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 7631 | .name = "config", |
| 7632 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7633 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 7634 | .name = "scan", |
| 7635 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7636 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 7637 | .name = "regulatory", |
| 7638 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7639 | |
| 7640 | /* notification functions */ |
| 7641 | |
| 7642 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 7643 | { |
| 7644 | struct sk_buff *msg; |
| 7645 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7646 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7647 | if (!msg) |
| 7648 | return; |
| 7649 | |
| 7650 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 7651 | nlmsg_free(msg); |
| 7652 | return; |
| 7653 | } |
| 7654 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7655 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7656 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7657 | } |
| 7658 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7659 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 7660 | struct cfg80211_registered_device *rdev) |
| 7661 | { |
| 7662 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 7663 | struct nlattr *nest; |
| 7664 | int i; |
| 7665 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7666 | ASSERT_RDEV_LOCK(rdev); |
| 7667 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7668 | if (WARN_ON(!req)) |
| 7669 | return 0; |
| 7670 | |
| 7671 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 7672 | if (!nest) |
| 7673 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7674 | for (i = 0; i < req->n_ssids; i++) { |
| 7675 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 7676 | goto nla_put_failure; |
| 7677 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7678 | nla_nest_end(msg, nest); |
| 7679 | |
| 7680 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 7681 | if (!nest) |
| 7682 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7683 | for (i = 0; i < req->n_channels; i++) { |
| 7684 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 7685 | goto nla_put_failure; |
| 7686 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7687 | nla_nest_end(msg, nest); |
| 7688 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7689 | if (req->ie && |
| 7690 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 7691 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7692 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7693 | if (req->flags) |
| 7694 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 7695 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7696 | return 0; |
| 7697 | nla_put_failure: |
| 7698 | return -ENOBUFS; |
| 7699 | } |
| 7700 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7701 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 7702 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7703 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7704 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7705 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7706 | { |
| 7707 | void *hdr; |
| 7708 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7709 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7710 | if (!hdr) |
| 7711 | return -1; |
| 7712 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7713 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7714 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 7715 | wdev->netdev->ifindex)) || |
| 7716 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7717 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7718 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7719 | /* ignore errors and send incomplete event anyway */ |
| 7720 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7721 | |
| 7722 | return genlmsg_end(msg, hdr); |
| 7723 | |
| 7724 | nla_put_failure: |
| 7725 | genlmsg_cancel(msg, hdr); |
| 7726 | return -EMSGSIZE; |
| 7727 | } |
| 7728 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7729 | static int |
| 7730 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 7731 | struct cfg80211_registered_device *rdev, |
| 7732 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7733 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7734 | { |
| 7735 | void *hdr; |
| 7736 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7737 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7738 | if (!hdr) |
| 7739 | return -1; |
| 7740 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7741 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7742 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7743 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7744 | |
| 7745 | return genlmsg_end(msg, hdr); |
| 7746 | |
| 7747 | nla_put_failure: |
| 7748 | genlmsg_cancel(msg, hdr); |
| 7749 | return -EMSGSIZE; |
| 7750 | } |
| 7751 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7752 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7753 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7754 | { |
| 7755 | struct sk_buff *msg; |
| 7756 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 7757 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7758 | if (!msg) |
| 7759 | return; |
| 7760 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7761 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7762 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 7763 | nlmsg_free(msg); |
| 7764 | return; |
| 7765 | } |
| 7766 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7767 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7768 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7769 | } |
| 7770 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7771 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7772 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7773 | { |
| 7774 | struct sk_buff *msg; |
| 7775 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7776 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7777 | if (!msg) |
| 7778 | return; |
| 7779 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7780 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7781 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7782 | nlmsg_free(msg); |
| 7783 | return; |
| 7784 | } |
| 7785 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7786 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7787 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7788 | } |
| 7789 | |
| 7790 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7791 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7792 | { |
| 7793 | struct sk_buff *msg; |
| 7794 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7795 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7796 | if (!msg) |
| 7797 | return; |
| 7798 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7799 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7800 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7801 | nlmsg_free(msg); |
| 7802 | return; |
| 7803 | } |
| 7804 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7805 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7806 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7807 | } |
| 7808 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7809 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 7810 | struct net_device *netdev) |
| 7811 | { |
| 7812 | struct sk_buff *msg; |
| 7813 | |
| 7814 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7815 | if (!msg) |
| 7816 | return; |
| 7817 | |
| 7818 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7819 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 7820 | nlmsg_free(msg); |
| 7821 | return; |
| 7822 | } |
| 7823 | |
| 7824 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7825 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7826 | } |
| 7827 | |
| 7828 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 7829 | struct net_device *netdev, u32 cmd) |
| 7830 | { |
| 7831 | struct sk_buff *msg; |
| 7832 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 7833 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7834 | if (!msg) |
| 7835 | return; |
| 7836 | |
| 7837 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 7838 | nlmsg_free(msg); |
| 7839 | return; |
| 7840 | } |
| 7841 | |
| 7842 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7843 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7844 | } |
| 7845 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7846 | /* |
| 7847 | * This can happen on global regulatory changes or device specific settings |
| 7848 | * based on custom world regulatory domains. |
| 7849 | */ |
| 7850 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 7851 | { |
| 7852 | struct sk_buff *msg; |
| 7853 | void *hdr; |
| 7854 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7855 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7856 | if (!msg) |
| 7857 | return; |
| 7858 | |
| 7859 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 7860 | if (!hdr) { |
| 7861 | nlmsg_free(msg); |
| 7862 | return; |
| 7863 | } |
| 7864 | |
| 7865 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7866 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 7867 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7868 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7869 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 7870 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7871 | NL80211_REGDOM_TYPE_WORLD)) |
| 7872 | goto nla_put_failure; |
| 7873 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 7874 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7875 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 7876 | goto nla_put_failure; |
| 7877 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 7878 | request->intersect) { |
| 7879 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7880 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 7881 | goto nla_put_failure; |
| 7882 | } else { |
| 7883 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7884 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 7885 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 7886 | request->alpha2)) |
| 7887 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7888 | } |
| 7889 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7890 | if (wiphy_idx_valid(request->wiphy_idx) && |
| 7891 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 7892 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7893 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7894 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7895 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7896 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7897 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7898 | GFP_ATOMIC); |
| 7899 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7900 | |
| 7901 | return; |
| 7902 | |
| 7903 | nla_put_failure: |
| 7904 | genlmsg_cancel(msg, hdr); |
| 7905 | nlmsg_free(msg); |
| 7906 | } |
| 7907 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7908 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 7909 | struct net_device *netdev, |
| 7910 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7911 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7912 | { |
| 7913 | struct sk_buff *msg; |
| 7914 | void *hdr; |
| 7915 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7916 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7917 | if (!msg) |
| 7918 | return; |
| 7919 | |
| 7920 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7921 | if (!hdr) { |
| 7922 | nlmsg_free(msg); |
| 7923 | return; |
| 7924 | } |
| 7925 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7926 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7927 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7928 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 7929 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7930 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7931 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7932 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7933 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7934 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7935 | return; |
| 7936 | |
| 7937 | nla_put_failure: |
| 7938 | genlmsg_cancel(msg, hdr); |
| 7939 | nlmsg_free(msg); |
| 7940 | } |
| 7941 | |
| 7942 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7943 | struct net_device *netdev, const u8 *buf, |
| 7944 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7945 | { |
| 7946 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7947 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7948 | } |
| 7949 | |
| 7950 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 7951 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7952 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7953 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7954 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7955 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7956 | } |
| 7957 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7958 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7959 | struct net_device *netdev, const u8 *buf, |
| 7960 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7961 | { |
| 7962 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7963 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7964 | } |
| 7965 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7966 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 7967 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7968 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7969 | { |
| 7970 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7971 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7972 | } |
| 7973 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 7974 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 7975 | struct net_device *netdev, const u8 *buf, |
| 7976 | size_t len, gfp_t gfp) |
| 7977 | { |
| 7978 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7979 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 7980 | } |
| 7981 | |
| 7982 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 7983 | struct net_device *netdev, const u8 *buf, |
| 7984 | size_t len, gfp_t gfp) |
| 7985 | { |
| 7986 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7987 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 7988 | } |
| 7989 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 7990 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 7991 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7992 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7993 | { |
| 7994 | struct sk_buff *msg; |
| 7995 | void *hdr; |
| 7996 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7997 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7998 | if (!msg) |
| 7999 | return; |
| 8000 | |
| 8001 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8002 | if (!hdr) { |
| 8003 | nlmsg_free(msg); |
| 8004 | return; |
| 8005 | } |
| 8006 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8007 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8008 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8009 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 8010 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8011 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8012 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8013 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8014 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8015 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8016 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8017 | return; |
| 8018 | |
| 8019 | nla_put_failure: |
| 8020 | genlmsg_cancel(msg, hdr); |
| 8021 | nlmsg_free(msg); |
| 8022 | } |
| 8023 | |
| 8024 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8025 | struct net_device *netdev, const u8 *addr, |
| 8026 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8027 | { |
| 8028 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8029 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8030 | } |
| 8031 | |
| 8032 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8033 | struct net_device *netdev, const u8 *addr, |
| 8034 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8035 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8036 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 8037 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 8038 | } |
| 8039 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8040 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 8041 | struct net_device *netdev, const u8 *bssid, |
| 8042 | const u8 *req_ie, size_t req_ie_len, |
| 8043 | const u8 *resp_ie, size_t resp_ie_len, |
| 8044 | u16 status, gfp_t gfp) |
| 8045 | { |
| 8046 | struct sk_buff *msg; |
| 8047 | void *hdr; |
| 8048 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8049 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8050 | if (!msg) |
| 8051 | return; |
| 8052 | |
| 8053 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 8054 | if (!hdr) { |
| 8055 | nlmsg_free(msg); |
| 8056 | return; |
| 8057 | } |
| 8058 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8059 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8060 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8061 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 8062 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 8063 | (req_ie && |
| 8064 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8065 | (resp_ie && |
| 8066 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8067 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8068 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8069 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8070 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8071 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8072 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8073 | return; |
| 8074 | |
| 8075 | nla_put_failure: |
| 8076 | genlmsg_cancel(msg, hdr); |
| 8077 | nlmsg_free(msg); |
| 8078 | |
| 8079 | } |
| 8080 | |
| 8081 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 8082 | struct net_device *netdev, const u8 *bssid, |
| 8083 | const u8 *req_ie, size_t req_ie_len, |
| 8084 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 8085 | { |
| 8086 | struct sk_buff *msg; |
| 8087 | void *hdr; |
| 8088 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8089 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8090 | if (!msg) |
| 8091 | return; |
| 8092 | |
| 8093 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 8094 | if (!hdr) { |
| 8095 | nlmsg_free(msg); |
| 8096 | return; |
| 8097 | } |
| 8098 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8099 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8100 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8101 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 8102 | (req_ie && |
| 8103 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 8104 | (resp_ie && |
| 8105 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 8106 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8107 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8108 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8109 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8110 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8111 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8112 | return; |
| 8113 | |
| 8114 | nla_put_failure: |
| 8115 | genlmsg_cancel(msg, hdr); |
| 8116 | nlmsg_free(msg); |
| 8117 | |
| 8118 | } |
| 8119 | |
| 8120 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 8121 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 8122 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8123 | { |
| 8124 | struct sk_buff *msg; |
| 8125 | void *hdr; |
| 8126 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8127 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8128 | if (!msg) |
| 8129 | return; |
| 8130 | |
| 8131 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 8132 | if (!hdr) { |
| 8133 | nlmsg_free(msg); |
| 8134 | return; |
| 8135 | } |
| 8136 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8137 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8138 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8139 | (from_ap && reason && |
| 8140 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 8141 | (from_ap && |
| 8142 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 8143 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 8144 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8145 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8146 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8147 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8148 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8149 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8150 | return; |
| 8151 | |
| 8152 | nla_put_failure: |
| 8153 | genlmsg_cancel(msg, hdr); |
| 8154 | nlmsg_free(msg); |
| 8155 | |
| 8156 | } |
| 8157 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8158 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 8159 | struct net_device *netdev, const u8 *bssid, |
| 8160 | gfp_t gfp) |
| 8161 | { |
| 8162 | struct sk_buff *msg; |
| 8163 | void *hdr; |
| 8164 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8165 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8166 | if (!msg) |
| 8167 | return; |
| 8168 | |
| 8169 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 8170 | if (!hdr) { |
| 8171 | nlmsg_free(msg); |
| 8172 | return; |
| 8173 | } |
| 8174 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8175 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8176 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8177 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8178 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8179 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8180 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8181 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8182 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8183 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8184 | return; |
| 8185 | |
| 8186 | nla_put_failure: |
| 8187 | genlmsg_cancel(msg, hdr); |
| 8188 | nlmsg_free(msg); |
| 8189 | } |
| 8190 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8191 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 8192 | struct net_device *netdev, |
| 8193 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 8194 | gfp_t gfp) |
| 8195 | { |
| 8196 | struct sk_buff *msg; |
| 8197 | void *hdr; |
| 8198 | |
| 8199 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8200 | if (!msg) |
| 8201 | return; |
| 8202 | |
| 8203 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 8204 | if (!hdr) { |
| 8205 | nlmsg_free(msg); |
| 8206 | return; |
| 8207 | } |
| 8208 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8209 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8210 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8211 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 8212 | (ie_len && ie && |
| 8213 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 8214 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8215 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8216 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 8217 | |
| 8218 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8219 | nl80211_mlme_mcgrp.id, gfp); |
| 8220 | return; |
| 8221 | |
| 8222 | nla_put_failure: |
| 8223 | genlmsg_cancel(msg, hdr); |
| 8224 | nlmsg_free(msg); |
| 8225 | } |
| 8226 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8227 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 8228 | struct net_device *netdev, const u8 *addr, |
| 8229 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8230 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8231 | { |
| 8232 | struct sk_buff *msg; |
| 8233 | void *hdr; |
| 8234 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 8235 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8236 | if (!msg) |
| 8237 | return; |
| 8238 | |
| 8239 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 8240 | if (!hdr) { |
| 8241 | nlmsg_free(msg); |
| 8242 | return; |
| 8243 | } |
| 8244 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8245 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8246 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8247 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 8248 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 8249 | (key_id != -1 && |
| 8250 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 8251 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 8252 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8253 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8254 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8255 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8256 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8257 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8258 | return; |
| 8259 | |
| 8260 | nla_put_failure: |
| 8261 | genlmsg_cancel(msg, hdr); |
| 8262 | nlmsg_free(msg); |
| 8263 | } |
| 8264 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8265 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 8266 | struct ieee80211_channel *channel_before, |
| 8267 | struct ieee80211_channel *channel_after) |
| 8268 | { |
| 8269 | struct sk_buff *msg; |
| 8270 | void *hdr; |
| 8271 | struct nlattr *nl_freq; |
| 8272 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8273 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8274 | if (!msg) |
| 8275 | return; |
| 8276 | |
| 8277 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 8278 | if (!hdr) { |
| 8279 | nlmsg_free(msg); |
| 8280 | return; |
| 8281 | } |
| 8282 | |
| 8283 | /* |
| 8284 | * Since we are applying the beacon hint to a wiphy we know its |
| 8285 | * wiphy_idx is valid |
| 8286 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8287 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 8288 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8289 | |
| 8290 | /* Before */ |
| 8291 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 8292 | if (!nl_freq) |
| 8293 | goto nla_put_failure; |
| 8294 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 8295 | goto nla_put_failure; |
| 8296 | nla_nest_end(msg, nl_freq); |
| 8297 | |
| 8298 | /* After */ |
| 8299 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 8300 | if (!nl_freq) |
| 8301 | goto nla_put_failure; |
| 8302 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 8303 | goto nla_put_failure; |
| 8304 | nla_nest_end(msg, nl_freq); |
| 8305 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8306 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8307 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8308 | rcu_read_lock(); |
| 8309 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 8310 | GFP_ATOMIC); |
| 8311 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8312 | |
| 8313 | return; |
| 8314 | |
| 8315 | nla_put_failure: |
| 8316 | genlmsg_cancel(msg, hdr); |
| 8317 | nlmsg_free(msg); |
| 8318 | } |
| 8319 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8320 | static void nl80211_send_remain_on_chan_event( |
| 8321 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8322 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8323 | struct ieee80211_channel *chan, |
| 8324 | enum nl80211_channel_type channel_type, |
| 8325 | unsigned int duration, gfp_t gfp) |
| 8326 | { |
| 8327 | struct sk_buff *msg; |
| 8328 | void *hdr; |
| 8329 | |
| 8330 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8331 | if (!msg) |
| 8332 | return; |
| 8333 | |
| 8334 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8335 | if (!hdr) { |
| 8336 | nlmsg_free(msg); |
| 8337 | return; |
| 8338 | } |
| 8339 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8340 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8341 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8342 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 8343 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8344 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
| 8345 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) || |
| 8346 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8347 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8348 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8349 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 8350 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 8351 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8352 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8353 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8354 | |
| 8355 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8356 | nl80211_mlme_mcgrp.id, gfp); |
| 8357 | return; |
| 8358 | |
| 8359 | nla_put_failure: |
| 8360 | genlmsg_cancel(msg, hdr); |
| 8361 | nlmsg_free(msg); |
| 8362 | } |
| 8363 | |
| 8364 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8365 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8366 | struct ieee80211_channel *chan, |
| 8367 | enum nl80211_channel_type channel_type, |
| 8368 | unsigned int duration, gfp_t gfp) |
| 8369 | { |
| 8370 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8371 | rdev, wdev, cookie, chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8372 | channel_type, duration, gfp); |
| 8373 | } |
| 8374 | |
| 8375 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8376 | struct cfg80211_registered_device *rdev, |
| 8377 | struct wireless_dev *wdev, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8378 | u64 cookie, struct ieee80211_channel *chan, |
| 8379 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 8380 | { |
| 8381 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8382 | rdev, wdev, cookie, chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8383 | channel_type, 0, gfp); |
| 8384 | } |
| 8385 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8386 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 8387 | struct net_device *dev, const u8 *mac_addr, |
| 8388 | struct station_info *sinfo, gfp_t gfp) |
| 8389 | { |
| 8390 | struct sk_buff *msg; |
| 8391 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8392 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8393 | if (!msg) |
| 8394 | return; |
| 8395 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 8396 | if (nl80211_send_station(msg, 0, 0, 0, |
| 8397 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8398 | nlmsg_free(msg); |
| 8399 | return; |
| 8400 | } |
| 8401 | |
| 8402 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8403 | nl80211_mlme_mcgrp.id, gfp); |
| 8404 | } |
| 8405 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8406 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 8407 | struct net_device *dev, const u8 *mac_addr, |
| 8408 | gfp_t gfp) |
| 8409 | { |
| 8410 | struct sk_buff *msg; |
| 8411 | void *hdr; |
| 8412 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8413 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8414 | if (!msg) |
| 8415 | return; |
| 8416 | |
| 8417 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 8418 | if (!hdr) { |
| 8419 | nlmsg_free(msg); |
| 8420 | return; |
| 8421 | } |
| 8422 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8423 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8424 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 8425 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8426 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8427 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8428 | |
| 8429 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8430 | nl80211_mlme_mcgrp.id, gfp); |
| 8431 | return; |
| 8432 | |
| 8433 | nla_put_failure: |
| 8434 | genlmsg_cancel(msg, hdr); |
| 8435 | nlmsg_free(msg); |
| 8436 | } |
| 8437 | |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 8438 | void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev, |
| 8439 | struct net_device *dev, const u8 *mac_addr, |
| 8440 | enum nl80211_connect_failed_reason reason, |
| 8441 | gfp_t gfp) |
| 8442 | { |
| 8443 | struct sk_buff *msg; |
| 8444 | void *hdr; |
| 8445 | |
| 8446 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8447 | if (!msg) |
| 8448 | return; |
| 8449 | |
| 8450 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 8451 | if (!hdr) { |
| 8452 | nlmsg_free(msg); |
| 8453 | return; |
| 8454 | } |
| 8455 | |
| 8456 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8457 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 8458 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 8459 | goto nla_put_failure; |
| 8460 | |
| 8461 | genlmsg_end(msg, hdr); |
| 8462 | |
| 8463 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8464 | nl80211_mlme_mcgrp.id, gfp); |
| 8465 | return; |
| 8466 | |
| 8467 | nla_put_failure: |
| 8468 | genlmsg_cancel(msg, hdr); |
| 8469 | nlmsg_free(msg); |
| 8470 | } |
| 8471 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8472 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 8473 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8474 | { |
| 8475 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8476 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8477 | struct sk_buff *msg; |
| 8478 | void *hdr; |
| 8479 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8480 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8481 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8482 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8483 | return false; |
| 8484 | |
| 8485 | msg = nlmsg_new(100, gfp); |
| 8486 | if (!msg) |
| 8487 | return true; |
| 8488 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8489 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8490 | if (!hdr) { |
| 8491 | nlmsg_free(msg); |
| 8492 | return true; |
| 8493 | } |
| 8494 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8495 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8496 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8497 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8498 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8499 | |
| 8500 | err = genlmsg_end(msg, hdr); |
| 8501 | if (err < 0) { |
| 8502 | nlmsg_free(msg); |
| 8503 | return true; |
| 8504 | } |
| 8505 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8506 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8507 | return true; |
| 8508 | |
| 8509 | nla_put_failure: |
| 8510 | genlmsg_cancel(msg, hdr); |
| 8511 | nlmsg_free(msg); |
| 8512 | return true; |
| 8513 | } |
| 8514 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8515 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 8516 | { |
| 8517 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 8518 | addr, gfp); |
| 8519 | } |
| 8520 | |
| 8521 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 8522 | const u8 *addr, gfp_t gfp) |
| 8523 | { |
| 8524 | return __nl80211_unexpected_frame(dev, |
| 8525 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 8526 | addr, gfp); |
| 8527 | } |
| 8528 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8529 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8530 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8531 | int freq, int sig_dbm, |
| 8532 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8533 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8534 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8535 | struct sk_buff *msg; |
| 8536 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8537 | |
| 8538 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8539 | if (!msg) |
| 8540 | return -ENOMEM; |
| 8541 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8542 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8543 | if (!hdr) { |
| 8544 | nlmsg_free(msg); |
| 8545 | return -ENOMEM; |
| 8546 | } |
| 8547 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8548 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8549 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8550 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8551 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8552 | (sig_dbm && |
| 8553 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8554 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8555 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8556 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8557 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8558 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8559 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8560 | |
| 8561 | nla_put_failure: |
| 8562 | genlmsg_cancel(msg, hdr); |
| 8563 | nlmsg_free(msg); |
| 8564 | return -ENOBUFS; |
| 8565 | } |
| 8566 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8567 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8568 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8569 | const u8 *buf, size_t len, bool ack, |
| 8570 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8571 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8572 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8573 | struct sk_buff *msg; |
| 8574 | void *hdr; |
| 8575 | |
| 8576 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8577 | if (!msg) |
| 8578 | return; |
| 8579 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8580 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8581 | if (!hdr) { |
| 8582 | nlmsg_free(msg); |
| 8583 | return; |
| 8584 | } |
| 8585 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8586 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8587 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8588 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8589 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 8590 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8591 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8592 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8593 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8594 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8595 | |
| 8596 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 8597 | return; |
| 8598 | |
| 8599 | nla_put_failure: |
| 8600 | genlmsg_cancel(msg, hdr); |
| 8601 | nlmsg_free(msg); |
| 8602 | } |
| 8603 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8604 | void |
| 8605 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 8606 | struct net_device *netdev, |
| 8607 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 8608 | gfp_t gfp) |
| 8609 | { |
| 8610 | struct sk_buff *msg; |
| 8611 | struct nlattr *pinfoattr; |
| 8612 | void *hdr; |
| 8613 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8614 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8615 | if (!msg) |
| 8616 | return; |
| 8617 | |
| 8618 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8619 | if (!hdr) { |
| 8620 | nlmsg_free(msg); |
| 8621 | return; |
| 8622 | } |
| 8623 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8624 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8625 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8626 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8627 | |
| 8628 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8629 | if (!pinfoattr) |
| 8630 | goto nla_put_failure; |
| 8631 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8632 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 8633 | rssi_event)) |
| 8634 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8635 | |
| 8636 | nla_nest_end(msg, pinfoattr); |
| 8637 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8638 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8639 | |
| 8640 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8641 | nl80211_mlme_mcgrp.id, gfp); |
| 8642 | return; |
| 8643 | |
| 8644 | nla_put_failure: |
| 8645 | genlmsg_cancel(msg, hdr); |
| 8646 | nlmsg_free(msg); |
| 8647 | } |
| 8648 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8649 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 8650 | struct net_device *netdev, const u8 *bssid, |
| 8651 | const u8 *replay_ctr, gfp_t gfp) |
| 8652 | { |
| 8653 | struct sk_buff *msg; |
| 8654 | struct nlattr *rekey_attr; |
| 8655 | void *hdr; |
| 8656 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8657 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8658 | if (!msg) |
| 8659 | return; |
| 8660 | |
| 8661 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 8662 | if (!hdr) { |
| 8663 | nlmsg_free(msg); |
| 8664 | return; |
| 8665 | } |
| 8666 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8667 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8668 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8669 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8670 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8671 | |
| 8672 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 8673 | if (!rekey_attr) |
| 8674 | goto nla_put_failure; |
| 8675 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8676 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 8677 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 8678 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8679 | |
| 8680 | nla_nest_end(msg, rekey_attr); |
| 8681 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8682 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8683 | |
| 8684 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8685 | nl80211_mlme_mcgrp.id, gfp); |
| 8686 | return; |
| 8687 | |
| 8688 | nla_put_failure: |
| 8689 | genlmsg_cancel(msg, hdr); |
| 8690 | nlmsg_free(msg); |
| 8691 | } |
| 8692 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8693 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 8694 | struct net_device *netdev, int index, |
| 8695 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 8696 | { |
| 8697 | struct sk_buff *msg; |
| 8698 | struct nlattr *attr; |
| 8699 | void *hdr; |
| 8700 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8701 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8702 | if (!msg) |
| 8703 | return; |
| 8704 | |
| 8705 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 8706 | if (!hdr) { |
| 8707 | nlmsg_free(msg); |
| 8708 | return; |
| 8709 | } |
| 8710 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8711 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8712 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8713 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8714 | |
| 8715 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 8716 | if (!attr) |
| 8717 | goto nla_put_failure; |
| 8718 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8719 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 8720 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 8721 | (preauth && |
| 8722 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 8723 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8724 | |
| 8725 | nla_nest_end(msg, attr); |
| 8726 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8727 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8728 | |
| 8729 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8730 | nl80211_mlme_mcgrp.id, gfp); |
| 8731 | return; |
| 8732 | |
| 8733 | nla_put_failure: |
| 8734 | genlmsg_cancel(msg, hdr); |
| 8735 | nlmsg_free(msg); |
| 8736 | } |
| 8737 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8738 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 8739 | struct net_device *netdev, int freq, |
| 8740 | enum nl80211_channel_type type, gfp_t gfp) |
| 8741 | { |
| 8742 | struct sk_buff *msg; |
| 8743 | void *hdr; |
| 8744 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8745 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8746 | if (!msg) |
| 8747 | return; |
| 8748 | |
| 8749 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 8750 | if (!hdr) { |
| 8751 | nlmsg_free(msg); |
| 8752 | return; |
| 8753 | } |
| 8754 | |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 8755 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8756 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8757 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type)) |
| 8758 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8759 | |
| 8760 | genlmsg_end(msg, hdr); |
| 8761 | |
| 8762 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8763 | nl80211_mlme_mcgrp.id, gfp); |
| 8764 | return; |
| 8765 | |
| 8766 | nla_put_failure: |
| 8767 | genlmsg_cancel(msg, hdr); |
| 8768 | nlmsg_free(msg); |
| 8769 | } |
| 8770 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8771 | void |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8772 | nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev, |
| 8773 | struct net_device *netdev, const u8 *peer, |
| 8774 | u32 num_packets, u32 rate, u32 intvl, gfp_t gfp) |
| 8775 | { |
| 8776 | struct sk_buff *msg; |
| 8777 | struct nlattr *pinfoattr; |
| 8778 | void *hdr; |
| 8779 | |
| 8780 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8781 | if (!msg) |
| 8782 | return; |
| 8783 | |
| 8784 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8785 | if (!hdr) { |
| 8786 | nlmsg_free(msg); |
| 8787 | return; |
| 8788 | } |
| 8789 | |
| 8790 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8791 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8792 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8793 | goto nla_put_failure; |
| 8794 | |
| 8795 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8796 | if (!pinfoattr) |
| 8797 | goto nla_put_failure; |
| 8798 | |
| 8799 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 8800 | goto nla_put_failure; |
| 8801 | |
| 8802 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 8803 | goto nla_put_failure; |
| 8804 | |
| 8805 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 8806 | goto nla_put_failure; |
| 8807 | |
| 8808 | nla_nest_end(msg, pinfoattr); |
| 8809 | |
| 8810 | genlmsg_end(msg, hdr); |
| 8811 | |
| 8812 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8813 | nl80211_mlme_mcgrp.id, gfp); |
| 8814 | return; |
| 8815 | |
| 8816 | nla_put_failure: |
| 8817 | genlmsg_cancel(msg, hdr); |
| 8818 | nlmsg_free(msg); |
| 8819 | } |
| 8820 | |
| 8821 | void |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8822 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 8823 | struct net_device *netdev, const u8 *peer, |
| 8824 | u32 num_packets, gfp_t gfp) |
| 8825 | { |
| 8826 | struct sk_buff *msg; |
| 8827 | struct nlattr *pinfoattr; |
| 8828 | void *hdr; |
| 8829 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8830 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8831 | if (!msg) |
| 8832 | return; |
| 8833 | |
| 8834 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8835 | if (!hdr) { |
| 8836 | nlmsg_free(msg); |
| 8837 | return; |
| 8838 | } |
| 8839 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8840 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8841 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8842 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8843 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8844 | |
| 8845 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8846 | if (!pinfoattr) |
| 8847 | goto nla_put_failure; |
| 8848 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8849 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 8850 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8851 | |
| 8852 | nla_nest_end(msg, pinfoattr); |
| 8853 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8854 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8855 | |
| 8856 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8857 | nl80211_mlme_mcgrp.id, gfp); |
| 8858 | return; |
| 8859 | |
| 8860 | nla_put_failure: |
| 8861 | genlmsg_cancel(msg, hdr); |
| 8862 | nlmsg_free(msg); |
| 8863 | } |
| 8864 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8865 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 8866 | u64 cookie, bool acked, gfp_t gfp) |
| 8867 | { |
| 8868 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8869 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8870 | struct sk_buff *msg; |
| 8871 | void *hdr; |
| 8872 | int err; |
| 8873 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 8874 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8875 | if (!msg) |
| 8876 | return; |
| 8877 | |
| 8878 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 8879 | if (!hdr) { |
| 8880 | nlmsg_free(msg); |
| 8881 | return; |
| 8882 | } |
| 8883 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8884 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8885 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8886 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8887 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8888 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8889 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8890 | |
| 8891 | err = genlmsg_end(msg, hdr); |
| 8892 | if (err < 0) { |
| 8893 | nlmsg_free(msg); |
| 8894 | return; |
| 8895 | } |
| 8896 | |
| 8897 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8898 | nl80211_mlme_mcgrp.id, gfp); |
| 8899 | return; |
| 8900 | |
| 8901 | nla_put_failure: |
| 8902 | genlmsg_cancel(msg, hdr); |
| 8903 | nlmsg_free(msg); |
| 8904 | } |
| 8905 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 8906 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8907 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 8908 | const u8 *frame, size_t len, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8909 | int freq, int sig_dbm, gfp_t gfp) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8910 | { |
| 8911 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 8912 | struct sk_buff *msg; |
| 8913 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8914 | u32 nlportid = ACCESS_ONCE(rdev->ap_beacons_nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8915 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8916 | if (!nlportid) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8917 | return; |
| 8918 | |
| 8919 | msg = nlmsg_new(len + 100, gfp); |
| 8920 | if (!msg) |
| 8921 | return; |
| 8922 | |
| 8923 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 8924 | if (!hdr) { |
| 8925 | nlmsg_free(msg); |
| 8926 | return; |
| 8927 | } |
| 8928 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8929 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8930 | (freq && |
| 8931 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 8932 | (sig_dbm && |
| 8933 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8934 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 8935 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8936 | |
| 8937 | genlmsg_end(msg, hdr); |
| 8938 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8939 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8940 | return; |
| 8941 | |
| 8942 | nla_put_failure: |
| 8943 | genlmsg_cancel(msg, hdr); |
| 8944 | nlmsg_free(msg); |
| 8945 | } |
| 8946 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 8947 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8948 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 8949 | unsigned long state, |
| 8950 | void *_notify) |
| 8951 | { |
| 8952 | struct netlink_notify *notify = _notify; |
| 8953 | struct cfg80211_registered_device *rdev; |
| 8954 | struct wireless_dev *wdev; |
| 8955 | |
| 8956 | if (state != NETLINK_URELEASE) |
| 8957 | return NOTIFY_DONE; |
| 8958 | |
| 8959 | rcu_read_lock(); |
| 8960 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8961 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8962 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8963 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
| 8964 | if (rdev->ap_beacons_nlportid == notify->portid) |
| 8965 | rdev->ap_beacons_nlportid = 0; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8966 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8967 | |
| 8968 | rcu_read_unlock(); |
| 8969 | |
| 8970 | return NOTIFY_DONE; |
| 8971 | } |
| 8972 | |
| 8973 | static struct notifier_block nl80211_netlink_notifier = { |
| 8974 | .notifier_call = nl80211_netlink_notify, |
| 8975 | }; |
| 8976 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8977 | /* initialisation/exit functions */ |
| 8978 | |
| 8979 | int nl80211_init(void) |
| 8980 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8981 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8982 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8983 | err = genl_register_family_with_ops(&nl80211_fam, |
| 8984 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8985 | if (err) |
| 8986 | return err; |
| 8987 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8988 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 8989 | if (err) |
| 8990 | goto err_out; |
| 8991 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8992 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 8993 | if (err) |
| 8994 | goto err_out; |
| 8995 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8996 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 8997 | if (err) |
| 8998 | goto err_out; |
| 8999 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9000 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 9001 | if (err) |
| 9002 | goto err_out; |
| 9003 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9004 | #ifdef CONFIG_NL80211_TESTMODE |
| 9005 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 9006 | if (err) |
| 9007 | goto err_out; |
| 9008 | #endif |
| 9009 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9010 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 9011 | if (err) |
| 9012 | goto err_out; |
| 9013 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9014 | return 0; |
| 9015 | err_out: |
| 9016 | genl_unregister_family(&nl80211_fam); |
| 9017 | return err; |
| 9018 | } |
| 9019 | |
| 9020 | void nl80211_exit(void) |
| 9021 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9022 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9023 | genl_unregister_family(&nl80211_fam); |
| 9024 | } |