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 bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type); |
| 27 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 28 | struct genl_info *info, |
| 29 | struct cfg80211_crypto_settings *settings, |
| 30 | int cipher_limit); |
| 31 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 32 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 33 | struct genl_info *info); |
| 34 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 35 | struct genl_info *info); |
| 36 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | /* the netlink family */ |
| 38 | static struct genl_family nl80211_fam = { |
| 39 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 40 | .name = "nl80211", /* have users key off the name instead */ |
| 41 | .hdrsize = 0, /* no private header */ |
| 42 | .version = 1, /* no particular meaning now */ |
| 43 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 44 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 45 | .pre_doit = nl80211_pre_doit, |
| 46 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 49 | /* returns ERR_PTR values */ |
| 50 | static struct wireless_dev * |
| 51 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 52 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 53 | struct cfg80211_registered_device *rdev; |
| 54 | struct wireless_dev *result = NULL; |
| 55 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 56 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 57 | u64 wdev_id; |
| 58 | int wiphy_idx = -1; |
| 59 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 60 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 61 | assert_cfg80211_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 62 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 63 | if (!have_ifidx && !have_wdev_id) |
| 64 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 65 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 66 | if (have_ifidx) |
| 67 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 68 | if (have_wdev_id) { |
| 69 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 70 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 73 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 74 | struct wireless_dev *wdev; |
| 75 | |
| 76 | if (wiphy_net(&rdev->wiphy) != netns) |
| 77 | continue; |
| 78 | |
| 79 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 80 | continue; |
| 81 | |
| 82 | mutex_lock(&rdev->devlist_mtx); |
| 83 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 84 | if (have_ifidx && wdev->netdev && |
| 85 | wdev->netdev->ifindex == ifidx) { |
| 86 | result = wdev; |
| 87 | break; |
| 88 | } |
| 89 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 90 | result = wdev; |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | mutex_unlock(&rdev->devlist_mtx); |
| 95 | |
| 96 | if (result) |
| 97 | break; |
| 98 | } |
| 99 | |
| 100 | if (result) |
| 101 | return result; |
| 102 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 103 | } |
| 104 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 105 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 106 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 107 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 108 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 109 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 110 | |
| 111 | assert_cfg80211_lock(); |
| 112 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 113 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 114 | !attrs[NL80211_ATTR_IFINDEX] && |
| 115 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 116 | return ERR_PTR(-EINVAL); |
| 117 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 118 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 119 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 120 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 121 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 122 | if (attrs[NL80211_ATTR_WDEV]) { |
| 123 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 124 | struct wireless_dev *wdev; |
| 125 | bool found = false; |
| 126 | |
| 127 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 128 | if (tmp) { |
| 129 | /* make sure wdev exists */ |
| 130 | mutex_lock(&tmp->devlist_mtx); |
| 131 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 132 | if (wdev->identifier != (u32)wdev_id) |
| 133 | continue; |
| 134 | found = true; |
| 135 | break; |
| 136 | } |
| 137 | mutex_unlock(&tmp->devlist_mtx); |
| 138 | |
| 139 | if (!found) |
| 140 | tmp = NULL; |
| 141 | |
| 142 | if (rdev && tmp != rdev) |
| 143 | return ERR_PTR(-EINVAL); |
| 144 | rdev = tmp; |
| 145 | } |
| 146 | } |
| 147 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 148 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 149 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 150 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 151 | if (netdev) { |
| 152 | if (netdev->ieee80211_ptr) |
| 153 | tmp = wiphy_to_dev( |
| 154 | netdev->ieee80211_ptr->wiphy); |
| 155 | else |
| 156 | tmp = NULL; |
| 157 | |
| 158 | dev_put(netdev); |
| 159 | |
| 160 | /* not wireless device -- return error */ |
| 161 | if (!tmp) |
| 162 | return ERR_PTR(-EINVAL); |
| 163 | |
| 164 | /* mismatch -- return error */ |
| 165 | if (rdev && tmp != rdev) |
| 166 | return ERR_PTR(-EINVAL); |
| 167 | |
| 168 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 169 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 170 | } |
| 171 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 172 | if (!rdev) |
| 173 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 174 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 175 | if (netns != wiphy_net(&rdev->wiphy)) |
| 176 | return ERR_PTR(-ENODEV); |
| 177 | |
| 178 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* |
| 182 | * This function returns a pointer to the driver |
| 183 | * that the genl_info item that is passed refers to. |
| 184 | * If successful, it returns non-NULL and also locks |
| 185 | * the driver's mutex! |
| 186 | * |
| 187 | * This means that you need to call cfg80211_unlock_rdev() |
| 188 | * before being allowed to acquire &cfg80211_mutex! |
| 189 | * |
| 190 | * This is necessary because we need to lock the global |
| 191 | * mutex to get an item off the list safely, and then |
| 192 | * we lock the rdev mutex so it doesn't go away under us. |
| 193 | * |
| 194 | * We don't want to keep cfg80211_mutex locked |
| 195 | * for all the time in order to allow requests on |
| 196 | * other interfaces to go through at the same time. |
| 197 | * |
| 198 | * The result of this can be a PTR_ERR and hence must |
| 199 | * be checked with IS_ERR() for errors. |
| 200 | */ |
| 201 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 202 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 203 | { |
| 204 | struct cfg80211_registered_device *rdev; |
| 205 | |
| 206 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 207 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 208 | |
| 209 | /* if it is not an error we grab the lock on |
| 210 | * it to assure it won't be going away while |
| 211 | * we operate on it */ |
| 212 | if (!IS_ERR(rdev)) |
| 213 | mutex_lock(&rdev->mtx); |
| 214 | |
| 215 | mutex_unlock(&cfg80211_mutex); |
| 216 | |
| 217 | return rdev; |
| 218 | } |
| 219 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 220 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 221 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 222 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 223 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 224 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 225 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 226 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 227 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 229 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 230 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 232 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 233 | |
| 234 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 235 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 236 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 237 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 238 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 239 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 240 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 241 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 242 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 243 | .len = WLAN_MAX_KEY_LEN }, |
| 244 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 245 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 246 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 247 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 248 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 249 | |
| 250 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 251 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 252 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 253 | .len = IEEE80211_MAX_DATA_LEN }, |
| 254 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 255 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 256 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 257 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 258 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 259 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 260 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 263 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 264 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 265 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 266 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 267 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 268 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 269 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 270 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 271 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 272 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 273 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 274 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 275 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 276 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 277 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 278 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 279 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 280 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 281 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 282 | |
| 283 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 284 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 285 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 286 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 287 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 288 | |
| 289 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 290 | .len = IEEE80211_MAX_SSID_LEN }, |
| 291 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 292 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 293 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 296 | [NL80211_ATTR_STA_FLAGS2] = { |
| 297 | .len = sizeof(struct nl80211_sta_flag_update), |
| 298 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 299 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 301 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 302 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 303 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 304 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 305 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 306 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 307 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 308 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 309 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 310 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 312 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 313 | .len = IEEE80211_MAX_DATA_LEN }, |
| 314 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 315 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 317 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 319 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 320 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 321 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 322 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 323 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 324 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 325 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 326 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 328 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 329 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 330 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 331 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 332 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 333 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 334 | .len = IEEE80211_MAX_DATA_LEN }, |
| 335 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 336 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 337 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 339 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 340 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 341 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 342 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 343 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 344 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 345 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 346 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 347 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 348 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 349 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 350 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 351 | .len = NL80211_HT_CAPABILITY_LEN |
| 352 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 353 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 354 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 355 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 356 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 357 | }; |
| 358 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 359 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 360 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 361 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 362 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 363 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 364 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 365 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 366 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 367 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 368 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 369 | }; |
| 370 | |
| 371 | /* policy for the key default flags */ |
| 372 | static const struct nla_policy |
| 373 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 374 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 375 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 376 | }; |
| 377 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 378 | /* policy for WoWLAN attributes */ |
| 379 | static const struct nla_policy |
| 380 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 381 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 382 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 383 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 384 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 385 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 386 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 387 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 388 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 389 | }; |
| 390 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 391 | /* policy for GTK rekey offload attributes */ |
| 392 | static const struct nla_policy |
| 393 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 394 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 395 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 396 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 397 | }; |
| 398 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 399 | static const struct nla_policy |
| 400 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 401 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 402 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 403 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 404 | }; |
| 405 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 406 | /* ifidx get helper */ |
| 407 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 408 | { |
| 409 | int res; |
| 410 | |
| 411 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 412 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 413 | nl80211_policy); |
| 414 | if (res) |
| 415 | return res; |
| 416 | |
| 417 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 418 | return -EINVAL; |
| 419 | |
| 420 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 421 | if (!res) |
| 422 | return -EINVAL; |
| 423 | return res; |
| 424 | } |
| 425 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 426 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 427 | struct netlink_callback *cb, |
| 428 | struct cfg80211_registered_device **rdev, |
| 429 | struct net_device **dev) |
| 430 | { |
| 431 | int ifidx = cb->args[0]; |
| 432 | int err; |
| 433 | |
| 434 | if (!ifidx) |
| 435 | ifidx = nl80211_get_ifidx(cb); |
| 436 | if (ifidx < 0) |
| 437 | return ifidx; |
| 438 | |
| 439 | cb->args[0] = ifidx; |
| 440 | |
| 441 | rtnl_lock(); |
| 442 | |
| 443 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 444 | if (!*dev) { |
| 445 | err = -ENODEV; |
| 446 | goto out_rtnl; |
| 447 | } |
| 448 | |
| 449 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 450 | if (IS_ERR(*rdev)) { |
| 451 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 452 | goto out_rtnl; |
| 453 | } |
| 454 | |
| 455 | return 0; |
| 456 | out_rtnl: |
| 457 | rtnl_unlock(); |
| 458 | return err; |
| 459 | } |
| 460 | |
| 461 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 462 | { |
| 463 | cfg80211_unlock_rdev(rdev); |
| 464 | rtnl_unlock(); |
| 465 | } |
| 466 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 467 | /* IE validation */ |
| 468 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 469 | { |
| 470 | const u8 *pos; |
| 471 | int len; |
| 472 | |
| 473 | if (!attr) |
| 474 | return true; |
| 475 | |
| 476 | pos = nla_data(attr); |
| 477 | len = nla_len(attr); |
| 478 | |
| 479 | while (len) { |
| 480 | u8 elemlen; |
| 481 | |
| 482 | if (len < 2) |
| 483 | return false; |
| 484 | len -= 2; |
| 485 | |
| 486 | elemlen = pos[1]; |
| 487 | if (elemlen > len) |
| 488 | return false; |
| 489 | |
| 490 | len -= elemlen; |
| 491 | pos += 2 + elemlen; |
| 492 | } |
| 493 | |
| 494 | return true; |
| 495 | } |
| 496 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 497 | /* message building helper */ |
| 498 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 499 | int flags, u8 cmd) |
| 500 | { |
| 501 | /* since there is no private header just add the generic one */ |
| 502 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 503 | } |
| 504 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 505 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 506 | struct ieee80211_channel *chan) |
| 507 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 508 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 509 | chan->center_freq)) |
| 510 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 511 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 512 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 513 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 514 | goto nla_put_failure; |
| 515 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 516 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 517 | goto nla_put_failure; |
| 518 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 519 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 520 | goto nla_put_failure; |
| 521 | if ((chan->flags & IEEE80211_CHAN_RADAR) && |
| 522 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 523 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 524 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 525 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 526 | DBM_TO_MBM(chan->max_power))) |
| 527 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 528 | |
| 529 | return 0; |
| 530 | |
| 531 | nla_put_failure: |
| 532 | return -ENOBUFS; |
| 533 | } |
| 534 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 535 | /* netlink command implementations */ |
| 536 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 537 | struct key_parse { |
| 538 | struct key_params p; |
| 539 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 540 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 541 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 542 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 543 | }; |
| 544 | |
| 545 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 546 | { |
| 547 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 548 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 549 | nl80211_key_policy); |
| 550 | if (err) |
| 551 | return err; |
| 552 | |
| 553 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 554 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 555 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 556 | if (k->def) { |
| 557 | k->def_uni = true; |
| 558 | k->def_multi = true; |
| 559 | } |
| 560 | if (k->defmgmt) |
| 561 | k->def_multi = true; |
| 562 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 563 | if (tb[NL80211_KEY_IDX]) |
| 564 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 565 | |
| 566 | if (tb[NL80211_KEY_DATA]) { |
| 567 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 568 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 569 | } |
| 570 | |
| 571 | if (tb[NL80211_KEY_SEQ]) { |
| 572 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 573 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 574 | } |
| 575 | |
| 576 | if (tb[NL80211_KEY_CIPHER]) |
| 577 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 578 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 579 | if (tb[NL80211_KEY_TYPE]) { |
| 580 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 581 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 582 | return -EINVAL; |
| 583 | } |
| 584 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 585 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 586 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 587 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 588 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 589 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 590 | if (err) |
| 591 | return err; |
| 592 | |
| 593 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 594 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 595 | } |
| 596 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 601 | { |
| 602 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 603 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 604 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 605 | } |
| 606 | |
| 607 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 608 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 609 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 610 | } |
| 611 | |
| 612 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 613 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 614 | |
| 615 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 616 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 617 | |
| 618 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 619 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 620 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 621 | if (k->def) { |
| 622 | k->def_uni = true; |
| 623 | k->def_multi = true; |
| 624 | } |
| 625 | if (k->defmgmt) |
| 626 | k->def_multi = true; |
| 627 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 628 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 629 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 630 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 631 | return -EINVAL; |
| 632 | } |
| 633 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 634 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 635 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 636 | int err = nla_parse_nested( |
| 637 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 638 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 639 | nl80211_key_default_policy); |
| 640 | if (err) |
| 641 | return err; |
| 642 | |
| 643 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 644 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 645 | } |
| 646 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 647 | return 0; |
| 648 | } |
| 649 | |
| 650 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 651 | { |
| 652 | int err; |
| 653 | |
| 654 | memset(k, 0, sizeof(*k)); |
| 655 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 656 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 657 | |
| 658 | if (info->attrs[NL80211_ATTR_KEY]) |
| 659 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 660 | else |
| 661 | err = nl80211_parse_key_old(info, k); |
| 662 | |
| 663 | if (err) |
| 664 | return err; |
| 665 | |
| 666 | if (k->def && k->defmgmt) |
| 667 | return -EINVAL; |
| 668 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 669 | if (k->defmgmt) { |
| 670 | if (k->def_uni || !k->def_multi) |
| 671 | return -EINVAL; |
| 672 | } |
| 673 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 674 | if (k->idx != -1) { |
| 675 | if (k->defmgmt) { |
| 676 | if (k->idx < 4 || k->idx > 5) |
| 677 | return -EINVAL; |
| 678 | } else if (k->def) { |
| 679 | if (k->idx < 0 || k->idx > 3) |
| 680 | return -EINVAL; |
| 681 | } else { |
| 682 | if (k->idx < 0 || k->idx > 5) |
| 683 | return -EINVAL; |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | return 0; |
| 688 | } |
| 689 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 690 | static struct cfg80211_cached_keys * |
| 691 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 692 | struct nlattr *keys) |
| 693 | { |
| 694 | struct key_parse parse; |
| 695 | struct nlattr *key; |
| 696 | struct cfg80211_cached_keys *result; |
| 697 | int rem, err, def = 0; |
| 698 | |
| 699 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 700 | if (!result) |
| 701 | return ERR_PTR(-ENOMEM); |
| 702 | |
| 703 | result->def = -1; |
| 704 | result->defmgmt = -1; |
| 705 | |
| 706 | nla_for_each_nested(key, keys, rem) { |
| 707 | memset(&parse, 0, sizeof(parse)); |
| 708 | parse.idx = -1; |
| 709 | |
| 710 | err = nl80211_parse_key_new(key, &parse); |
| 711 | if (err) |
| 712 | goto error; |
| 713 | err = -EINVAL; |
| 714 | if (!parse.p.key) |
| 715 | goto error; |
| 716 | if (parse.idx < 0 || parse.idx > 4) |
| 717 | goto error; |
| 718 | if (parse.def) { |
| 719 | if (def) |
| 720 | goto error; |
| 721 | def = 1; |
| 722 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 723 | if (!parse.def_uni || !parse.def_multi) |
| 724 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 725 | } else if (parse.defmgmt) |
| 726 | goto error; |
| 727 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 728 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 729 | if (err) |
| 730 | goto error; |
| 731 | result->params[parse.idx].cipher = parse.p.cipher; |
| 732 | result->params[parse.idx].key_len = parse.p.key_len; |
| 733 | result->params[parse.idx].key = result->data[parse.idx]; |
| 734 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 735 | } |
| 736 | |
| 737 | return result; |
| 738 | error: |
| 739 | kfree(result); |
| 740 | return ERR_PTR(err); |
| 741 | } |
| 742 | |
| 743 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 744 | { |
| 745 | ASSERT_WDEV_LOCK(wdev); |
| 746 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 747 | switch (wdev->iftype) { |
| 748 | case NL80211_IFTYPE_AP: |
| 749 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 750 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 751 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 752 | break; |
| 753 | case NL80211_IFTYPE_ADHOC: |
| 754 | if (!wdev->current_bss) |
| 755 | return -ENOLINK; |
| 756 | break; |
| 757 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 758 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 759 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 760 | return -ENOLINK; |
| 761 | break; |
| 762 | default: |
| 763 | return -EINVAL; |
| 764 | } |
| 765 | |
| 766 | return 0; |
| 767 | } |
| 768 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 769 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 770 | { |
| 771 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 772 | int i; |
| 773 | |
| 774 | if (!nl_modes) |
| 775 | goto nla_put_failure; |
| 776 | |
| 777 | i = 0; |
| 778 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 779 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 780 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 781 | ifmodes >>= 1; |
| 782 | i++; |
| 783 | } |
| 784 | |
| 785 | nla_nest_end(msg, nl_modes); |
| 786 | return 0; |
| 787 | |
| 788 | nla_put_failure: |
| 789 | return -ENOBUFS; |
| 790 | } |
| 791 | |
| 792 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 793 | struct sk_buff *msg) |
| 794 | { |
| 795 | struct nlattr *nl_combis; |
| 796 | int i, j; |
| 797 | |
| 798 | nl_combis = nla_nest_start(msg, |
| 799 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 800 | if (!nl_combis) |
| 801 | goto nla_put_failure; |
| 802 | |
| 803 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 804 | const struct ieee80211_iface_combination *c; |
| 805 | struct nlattr *nl_combi, *nl_limits; |
| 806 | |
| 807 | c = &wiphy->iface_combinations[i]; |
| 808 | |
| 809 | nl_combi = nla_nest_start(msg, i + 1); |
| 810 | if (!nl_combi) |
| 811 | goto nla_put_failure; |
| 812 | |
| 813 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 814 | if (!nl_limits) |
| 815 | goto nla_put_failure; |
| 816 | |
| 817 | for (j = 0; j < c->n_limits; j++) { |
| 818 | struct nlattr *nl_limit; |
| 819 | |
| 820 | nl_limit = nla_nest_start(msg, j + 1); |
| 821 | if (!nl_limit) |
| 822 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 823 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 824 | c->limits[j].max)) |
| 825 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 826 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 827 | c->limits[j].types)) |
| 828 | goto nla_put_failure; |
| 829 | nla_nest_end(msg, nl_limit); |
| 830 | } |
| 831 | |
| 832 | nla_nest_end(msg, nl_limits); |
| 833 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 834 | if (c->beacon_int_infra_match && |
| 835 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 836 | goto nla_put_failure; |
| 837 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 838 | c->num_different_channels) || |
| 839 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 840 | c->max_interfaces)) |
| 841 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 842 | |
| 843 | nla_nest_end(msg, nl_combi); |
| 844 | } |
| 845 | |
| 846 | nla_nest_end(msg, nl_combis); |
| 847 | |
| 848 | return 0; |
| 849 | nla_put_failure: |
| 850 | return -ENOBUFS; |
| 851 | } |
| 852 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 853 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 854 | struct cfg80211_registered_device *dev) |
| 855 | { |
| 856 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 857 | struct nlattr *nl_bands, *nl_band; |
| 858 | struct nlattr *nl_freqs, *nl_freq; |
| 859 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 860 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 861 | enum ieee80211_band band; |
| 862 | struct ieee80211_channel *chan; |
| 863 | struct ieee80211_rate *rate; |
| 864 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 865 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 866 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 867 | |
| 868 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 869 | if (!hdr) |
| 870 | return -1; |
| 871 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 872 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
| 873 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || |
| 874 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 875 | cfg80211_rdev_list_generation) || |
| 876 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 877 | dev->wiphy.retry_short) || |
| 878 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 879 | dev->wiphy.retry_long) || |
| 880 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 881 | dev->wiphy.frag_threshold) || |
| 882 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 883 | dev->wiphy.rts_threshold) || |
| 884 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 885 | dev->wiphy.coverage_class) || |
| 886 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 887 | dev->wiphy.max_scan_ssids) || |
| 888 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 889 | dev->wiphy.max_sched_scan_ssids) || |
| 890 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 891 | dev->wiphy.max_scan_ie_len) || |
| 892 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 893 | dev->wiphy.max_sched_scan_ie_len) || |
| 894 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 895 | dev->wiphy.max_match_sets)) |
| 896 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 897 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 898 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 899 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 900 | goto nla_put_failure; |
| 901 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 902 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 903 | goto nla_put_failure; |
| 904 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 905 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 906 | goto nla_put_failure; |
| 907 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 908 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 909 | goto nla_put_failure; |
| 910 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 911 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 912 | goto nla_put_failure; |
| 913 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 914 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 915 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 916 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 917 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 918 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 919 | dev->wiphy.cipher_suites)) |
| 920 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 921 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 922 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 923 | dev->wiphy.max_num_pmkids)) |
| 924 | goto nla_put_failure; |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 925 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 926 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 927 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 928 | goto nla_put_failure; |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 929 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 930 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 931 | dev->wiphy.available_antennas_tx) || |
| 932 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 933 | dev->wiphy.available_antennas_rx)) |
| 934 | goto nla_put_failure; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 935 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 936 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 937 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 938 | dev->wiphy.probe_resp_offload)) |
| 939 | goto nla_put_failure; |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 940 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 941 | if ((dev->wiphy.available_antennas_tx || |
| 942 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 943 | u32 tx_ant = 0, rx_ant = 0; |
| 944 | int res; |
| 945 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 946 | if (!res) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 947 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 948 | tx_ant) || |
| 949 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 950 | rx_ant)) |
| 951 | goto nla_put_failure; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 955 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 956 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 957 | goto nla_put_failure; |
| 958 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 959 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 960 | if (!nl_bands) |
| 961 | goto nla_put_failure; |
| 962 | |
| 963 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 964 | if (!dev->wiphy.bands[band]) |
| 965 | continue; |
| 966 | |
| 967 | nl_band = nla_nest_start(msg, band); |
| 968 | if (!nl_band) |
| 969 | goto nla_put_failure; |
| 970 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 971 | /* add HT info */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 972 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
| 973 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 974 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 975 | &dev->wiphy.bands[band]->ht_cap.mcs) || |
| 976 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 977 | dev->wiphy.bands[band]->ht_cap.cap) || |
| 978 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 979 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || |
| 980 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 981 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) |
| 982 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 983 | |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 984 | /* add VHT info */ |
| 985 | if (dev->wiphy.bands[band]->vht_cap.vht_supported && |
| 986 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 987 | sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs), |
| 988 | &dev->wiphy.bands[band]->vht_cap.vht_mcs) || |
| 989 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 990 | dev->wiphy.bands[band]->vht_cap.cap))) |
| 991 | goto nla_put_failure; |
| 992 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 993 | /* add frequencies */ |
| 994 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 995 | if (!nl_freqs) |
| 996 | goto nla_put_failure; |
| 997 | |
| 998 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 999 | nl_freq = nla_nest_start(msg, i); |
| 1000 | if (!nl_freq) |
| 1001 | goto nla_put_failure; |
| 1002 | |
| 1003 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1004 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1005 | if (nl80211_msg_put_channel(msg, chan)) |
| 1006 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1007 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1008 | nla_nest_end(msg, nl_freq); |
| 1009 | } |
| 1010 | |
| 1011 | nla_nest_end(msg, nl_freqs); |
| 1012 | |
| 1013 | /* add bitrates */ |
| 1014 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1015 | if (!nl_rates) |
| 1016 | goto nla_put_failure; |
| 1017 | |
| 1018 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 1019 | nl_rate = nla_nest_start(msg, i); |
| 1020 | if (!nl_rate) |
| 1021 | goto nla_put_failure; |
| 1022 | |
| 1023 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1024 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1025 | rate->bitrate)) |
| 1026 | goto nla_put_failure; |
| 1027 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1028 | nla_put_flag(msg, |
| 1029 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1030 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1031 | |
| 1032 | nla_nest_end(msg, nl_rate); |
| 1033 | } |
| 1034 | |
| 1035 | nla_nest_end(msg, nl_rates); |
| 1036 | |
| 1037 | nla_nest_end(msg, nl_band); |
| 1038 | } |
| 1039 | nla_nest_end(msg, nl_bands); |
| 1040 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1041 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1042 | if (!nl_cmds) |
| 1043 | goto nla_put_failure; |
| 1044 | |
| 1045 | i = 0; |
| 1046 | #define CMD(op, n) \ |
| 1047 | do { \ |
| 1048 | if (dev->ops->op) { \ |
| 1049 | i++; \ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1050 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1051 | goto nla_put_failure; \ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1052 | } \ |
| 1053 | } while (0) |
| 1054 | |
| 1055 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1056 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1057 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1058 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1059 | CMD(add_station, NEW_STATION); |
| 1060 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 1061 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1062 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1063 | CMD(auth, AUTHENTICATE); |
| 1064 | CMD(assoc, ASSOCIATE); |
| 1065 | CMD(deauth, DEAUTHENTICATE); |
| 1066 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1067 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1068 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 1069 | CMD(set_pmksa, SET_PMKSA); |
| 1070 | CMD(del_pmksa, DEL_PMKSA); |
| 1071 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1072 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1073 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 1074 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1075 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1076 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 1077 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1078 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1079 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1080 | goto nla_put_failure; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1081 | } |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1082 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1083 | dev->ops->join_mesh) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1084 | i++; |
| 1085 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1086 | goto nla_put_failure; |
| 1087 | } |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1088 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 1089 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1090 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1091 | CMD(tdls_oper, TDLS_OPER); |
| 1092 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 1093 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1094 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 1095 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1096 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1097 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1098 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1099 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1100 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1101 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1102 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1103 | #ifdef CONFIG_NL80211_TESTMODE |
| 1104 | CMD(testmode_cmd, TESTMODE); |
| 1105 | #endif |
| 1106 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1107 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1108 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1109 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1110 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1111 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1112 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1113 | } |
| 1114 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1115 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1116 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1117 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1118 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1119 | } |
| 1120 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1121 | nla_nest_end(msg, nl_cmds); |
| 1122 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1123 | if (dev->ops->remain_on_channel && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1124 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1125 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1126 | dev->wiphy.max_remain_on_channel_duration)) |
| 1127 | goto nla_put_failure; |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 1128 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1129 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1130 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1131 | goto nla_put_failure; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1132 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1133 | if (mgmt_stypes) { |
| 1134 | u16 stypes; |
| 1135 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1136 | enum nl80211_iftype ift; |
| 1137 | |
| 1138 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1139 | if (!nl_ifs) |
| 1140 | goto nla_put_failure; |
| 1141 | |
| 1142 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1143 | nl_ftypes = nla_nest_start(msg, ift); |
| 1144 | if (!nl_ftypes) |
| 1145 | goto nla_put_failure; |
| 1146 | i = 0; |
| 1147 | stypes = mgmt_stypes[ift].tx; |
| 1148 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1149 | if ((stypes & 1) && |
| 1150 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1151 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1152 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1153 | stypes >>= 1; |
| 1154 | i++; |
| 1155 | } |
| 1156 | nla_nest_end(msg, nl_ftypes); |
| 1157 | } |
| 1158 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1159 | nla_nest_end(msg, nl_ifs); |
| 1160 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1161 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1162 | if (!nl_ifs) |
| 1163 | goto nla_put_failure; |
| 1164 | |
| 1165 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1166 | nl_ftypes = nla_nest_start(msg, ift); |
| 1167 | if (!nl_ftypes) |
| 1168 | goto nla_put_failure; |
| 1169 | i = 0; |
| 1170 | stypes = mgmt_stypes[ift].rx; |
| 1171 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1172 | if ((stypes & 1) && |
| 1173 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1174 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1175 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1176 | stypes >>= 1; |
| 1177 | i++; |
| 1178 | } |
| 1179 | nla_nest_end(msg, nl_ftypes); |
| 1180 | } |
| 1181 | nla_nest_end(msg, nl_ifs); |
| 1182 | } |
| 1183 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1184 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1185 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 1186 | struct nlattr *nl_wowlan; |
| 1187 | |
| 1188 | nl_wowlan = nla_nest_start(msg, |
| 1189 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1190 | if (!nl_wowlan) |
| 1191 | goto nla_put_failure; |
| 1192 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1193 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 1194 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1195 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1196 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1197 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1198 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1199 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1200 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1201 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1202 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1203 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1204 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1205 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1206 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1207 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1208 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1209 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1210 | if (dev->wiphy.wowlan.n_patterns) { |
| 1211 | struct nl80211_wowlan_pattern_support pat = { |
| 1212 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1213 | .min_pattern_len = |
| 1214 | dev->wiphy.wowlan.pattern_min_len, |
| 1215 | .max_pattern_len = |
| 1216 | dev->wiphy.wowlan.pattern_max_len, |
| 1217 | }; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1218 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1219 | sizeof(pat), &pat)) |
| 1220 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | nla_nest_end(msg, nl_wowlan); |
| 1224 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1225 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1226 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1227 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1228 | dev->wiphy.software_iftypes)) |
| 1229 | goto nla_put_failure; |
| 1230 | |
| 1231 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1232 | goto nla_put_failure; |
| 1233 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1234 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1235 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1236 | dev->wiphy.ap_sme_capa)) |
| 1237 | goto nla_put_failure; |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1238 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1239 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
| 1240 | dev->wiphy.features)) |
| 1241 | goto nla_put_failure; |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1242 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1243 | if (dev->wiphy.ht_capa_mod_mask && |
| 1244 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1245 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1246 | dev->wiphy.ht_capa_mod_mask)) |
| 1247 | goto nla_put_failure; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1248 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1249 | return genlmsg_end(msg, hdr); |
| 1250 | |
| 1251 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1252 | genlmsg_cancel(msg, hdr); |
| 1253 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1257 | { |
| 1258 | int idx = 0; |
| 1259 | int start = cb->args[0]; |
| 1260 | struct cfg80211_registered_device *dev; |
| 1261 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1262 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1263 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1264 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1265 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1266 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1267 | continue; |
| 1268 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1269 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1270 | dev) < 0) { |
| 1271 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1272 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1273 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1274 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1275 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1276 | |
| 1277 | cb->args[0] = idx; |
| 1278 | |
| 1279 | return skb->len; |
| 1280 | } |
| 1281 | |
| 1282 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1283 | { |
| 1284 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1285 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1286 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1287 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1288 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1289 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1290 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1291 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1292 | nlmsg_free(msg); |
| 1293 | return -ENOBUFS; |
| 1294 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1295 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1296 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1297 | } |
| 1298 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1299 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1300 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1301 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1302 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1303 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1304 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1305 | }; |
| 1306 | |
| 1307 | static int parse_txq_params(struct nlattr *tb[], |
| 1308 | struct ieee80211_txq_params *txq_params) |
| 1309 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1310 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1311 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1312 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1313 | return -EINVAL; |
| 1314 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1315 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1316 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1317 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1318 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1319 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1320 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1321 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1322 | return -EINVAL; |
| 1323 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1324 | return 0; |
| 1325 | } |
| 1326 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1327 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1328 | { |
| 1329 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1330 | * You can only set the channel explicitly for WDS interfaces, |
| 1331 | * all others have their channel managed via their respective |
| 1332 | * "establish a connection" command (connect, join, ...) |
| 1333 | * |
| 1334 | * For AP/GO and mesh mode, the channel can be set with the |
| 1335 | * channel userspace API, but is only stored and passed to the |
| 1336 | * low-level driver when the AP starts or the mesh is joined. |
| 1337 | * This is for backward compatibility, userspace can also give |
| 1338 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1339 | * |
| 1340 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1341 | * whatever else is going on, so they have their own special |
| 1342 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1343 | */ |
| 1344 | return !wdev || |
| 1345 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1346 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1347 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1348 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1349 | } |
| 1350 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 1351 | static bool nl80211_valid_channel_type(struct genl_info *info, |
| 1352 | enum nl80211_channel_type *channel_type) |
| 1353 | { |
| 1354 | enum nl80211_channel_type tmp; |
| 1355 | |
| 1356 | if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) |
| 1357 | return false; |
| 1358 | |
| 1359 | tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1360 | if (tmp != NL80211_CHAN_NO_HT && |
| 1361 | tmp != NL80211_CHAN_HT20 && |
| 1362 | tmp != NL80211_CHAN_HT40PLUS && |
| 1363 | tmp != NL80211_CHAN_HT40MINUS) |
| 1364 | return false; |
| 1365 | |
| 1366 | if (channel_type) |
| 1367 | *channel_type = tmp; |
| 1368 | |
| 1369 | return true; |
| 1370 | } |
| 1371 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1372 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1373 | struct wireless_dev *wdev, |
| 1374 | struct genl_info *info) |
| 1375 | { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1376 | struct ieee80211_channel *channel; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1377 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1378 | u32 freq; |
| 1379 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1380 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1381 | |
| 1382 | if (wdev) |
| 1383 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1384 | |
| 1385 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1386 | return -EINVAL; |
| 1387 | |
| 1388 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1389 | return -EOPNOTSUPP; |
| 1390 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 1391 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 1392 | !nl80211_valid_channel_type(info, &channel_type)) |
| 1393 | return -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1394 | |
| 1395 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1396 | |
| 1397 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1398 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1399 | case NL80211_IFTYPE_AP: |
| 1400 | case NL80211_IFTYPE_P2P_GO: |
| 1401 | if (wdev->beacon_interval) { |
| 1402 | result = -EBUSY; |
| 1403 | break; |
| 1404 | } |
| 1405 | channel = rdev_freq_to_chan(rdev, freq, channel_type); |
| 1406 | if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy, |
| 1407 | channel, |
| 1408 | channel_type)) { |
| 1409 | result = -EINVAL; |
| 1410 | break; |
| 1411 | } |
| 1412 | wdev->preset_chan = channel; |
| 1413 | wdev->preset_chantype = channel_type; |
| 1414 | result = 0; |
| 1415 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1416 | case NL80211_IFTYPE_MESH_POINT: |
| 1417 | result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type); |
| 1418 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1419 | case NL80211_IFTYPE_MONITOR: |
| 1420 | result = cfg80211_set_monitor_channel(rdev, freq, channel_type); |
| 1421 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1422 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1423 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1424 | } |
| 1425 | mutex_unlock(&rdev->devlist_mtx); |
| 1426 | |
| 1427 | return result; |
| 1428 | } |
| 1429 | |
| 1430 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1431 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1432 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1433 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1434 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1435 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1436 | } |
| 1437 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1438 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1439 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1440 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1441 | struct net_device *dev = info->user_ptr[1]; |
| 1442 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1443 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1444 | |
| 1445 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1446 | return -EINVAL; |
| 1447 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1448 | if (netif_running(dev)) |
| 1449 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1450 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1451 | if (!rdev->ops->set_wds_peer) |
| 1452 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1453 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1454 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1455 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1456 | |
| 1457 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1458 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1462 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1463 | { |
| 1464 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1465 | struct net_device *netdev = NULL; |
| 1466 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1467 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1468 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1469 | u32 changed; |
| 1470 | u8 retry_short = 0, retry_long = 0; |
| 1471 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1472 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1473 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1474 | /* |
| 1475 | * Try to find the wiphy and netdev. Normally this |
| 1476 | * function shouldn't need the netdev, but this is |
| 1477 | * done for backward compatibility -- previously |
| 1478 | * setting the channel was done per wiphy, but now |
| 1479 | * it is per netdev. Previous userland like hostapd |
| 1480 | * also passed a netdev to set_wiphy, so that it is |
| 1481 | * possible to let that go to the right netdev! |
| 1482 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1483 | mutex_lock(&cfg80211_mutex); |
| 1484 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1485 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1486 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1487 | |
| 1488 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1489 | if (netdev && netdev->ieee80211_ptr) { |
| 1490 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1491 | mutex_lock(&rdev->mtx); |
| 1492 | } else |
| 1493 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1494 | } |
| 1495 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1496 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1497 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1498 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1499 | if (IS_ERR(rdev)) { |
| 1500 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1501 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1502 | } |
| 1503 | wdev = NULL; |
| 1504 | netdev = NULL; |
| 1505 | result = 0; |
| 1506 | |
| 1507 | mutex_lock(&rdev->mtx); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1508 | } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1509 | wdev = netdev->ieee80211_ptr; |
| 1510 | else |
| 1511 | wdev = NULL; |
| 1512 | |
| 1513 | /* |
| 1514 | * end workaround code, by now the rdev is available |
| 1515 | * and locked, and wdev may or may not be NULL. |
| 1516 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1517 | |
| 1518 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1519 | result = cfg80211_dev_rename( |
| 1520 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1521 | |
| 1522 | mutex_unlock(&cfg80211_mutex); |
| 1523 | |
| 1524 | if (result) |
| 1525 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1526 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1527 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1528 | struct ieee80211_txq_params txq_params; |
| 1529 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1530 | |
| 1531 | if (!rdev->ops->set_txq_params) { |
| 1532 | result = -EOPNOTSUPP; |
| 1533 | goto bad_res; |
| 1534 | } |
| 1535 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1536 | if (!netdev) { |
| 1537 | result = -EINVAL; |
| 1538 | goto bad_res; |
| 1539 | } |
| 1540 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1541 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1542 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1543 | result = -EINVAL; |
| 1544 | goto bad_res; |
| 1545 | } |
| 1546 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1547 | if (!netif_running(netdev)) { |
| 1548 | result = -ENETDOWN; |
| 1549 | goto bad_res; |
| 1550 | } |
| 1551 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1552 | nla_for_each_nested(nl_txq_params, |
| 1553 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1554 | rem_txq_params) { |
| 1555 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1556 | nla_data(nl_txq_params), |
| 1557 | nla_len(nl_txq_params), |
| 1558 | txq_params_policy); |
| 1559 | result = parse_txq_params(tb, &txq_params); |
| 1560 | if (result) |
| 1561 | goto bad_res; |
| 1562 | |
| 1563 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1564 | netdev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1565 | &txq_params); |
| 1566 | if (result) |
| 1567 | goto bad_res; |
| 1568 | } |
| 1569 | } |
| 1570 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1571 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1572 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1573 | if (result) |
| 1574 | goto bad_res; |
| 1575 | } |
| 1576 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1577 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1578 | enum nl80211_tx_power_setting type; |
| 1579 | int idx, mbm = 0; |
| 1580 | |
| 1581 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1582 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1583 | goto bad_res; |
| 1584 | } |
| 1585 | |
| 1586 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1587 | type = nla_get_u32(info->attrs[idx]); |
| 1588 | |
| 1589 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1590 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1591 | result = -EINVAL; |
| 1592 | goto bad_res; |
| 1593 | } |
| 1594 | |
| 1595 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1596 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1597 | mbm = nla_get_u32(info->attrs[idx]); |
| 1598 | } |
| 1599 | |
| 1600 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1601 | if (result) |
| 1602 | goto bad_res; |
| 1603 | } |
| 1604 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1605 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1606 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1607 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1608 | if ((!rdev->wiphy.available_antennas_tx && |
| 1609 | !rdev->wiphy.available_antennas_rx) || |
| 1610 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1611 | result = -EOPNOTSUPP; |
| 1612 | goto bad_res; |
| 1613 | } |
| 1614 | |
| 1615 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1616 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1617 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1618 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1619 | * available antenna masks, except for the "all" mask */ |
| 1620 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1621 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1622 | result = -EINVAL; |
| 1623 | goto bad_res; |
| 1624 | } |
| 1625 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1626 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1627 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1628 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1629 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1630 | if (result) |
| 1631 | goto bad_res; |
| 1632 | } |
| 1633 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1634 | changed = 0; |
| 1635 | |
| 1636 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1637 | retry_short = nla_get_u8( |
| 1638 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1639 | if (retry_short == 0) { |
| 1640 | result = -EINVAL; |
| 1641 | goto bad_res; |
| 1642 | } |
| 1643 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1644 | } |
| 1645 | |
| 1646 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1647 | retry_long = nla_get_u8( |
| 1648 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1649 | if (retry_long == 0) { |
| 1650 | result = -EINVAL; |
| 1651 | goto bad_res; |
| 1652 | } |
| 1653 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1654 | } |
| 1655 | |
| 1656 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1657 | frag_threshold = nla_get_u32( |
| 1658 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1659 | if (frag_threshold < 256) { |
| 1660 | result = -EINVAL; |
| 1661 | goto bad_res; |
| 1662 | } |
| 1663 | if (frag_threshold != (u32) -1) { |
| 1664 | /* |
| 1665 | * Fragments (apart from the last one) are required to |
| 1666 | * have even length. Make the fragmentation code |
| 1667 | * simpler by stripping LSB should someone try to use |
| 1668 | * odd threshold value. |
| 1669 | */ |
| 1670 | frag_threshold &= ~0x1; |
| 1671 | } |
| 1672 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1673 | } |
| 1674 | |
| 1675 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1676 | rts_threshold = nla_get_u32( |
| 1677 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1678 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1679 | } |
| 1680 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1681 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1682 | coverage_class = nla_get_u8( |
| 1683 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1684 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1685 | } |
| 1686 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1687 | if (changed) { |
| 1688 | u8 old_retry_short, old_retry_long; |
| 1689 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1690 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1691 | |
| 1692 | if (!rdev->ops->set_wiphy_params) { |
| 1693 | result = -EOPNOTSUPP; |
| 1694 | goto bad_res; |
| 1695 | } |
| 1696 | |
| 1697 | old_retry_short = rdev->wiphy.retry_short; |
| 1698 | old_retry_long = rdev->wiphy.retry_long; |
| 1699 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1700 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1701 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1702 | |
| 1703 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1704 | rdev->wiphy.retry_short = retry_short; |
| 1705 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1706 | rdev->wiphy.retry_long = retry_long; |
| 1707 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1708 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1709 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1710 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1711 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1712 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1713 | |
| 1714 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1715 | if (result) { |
| 1716 | rdev->wiphy.retry_short = old_retry_short; |
| 1717 | rdev->wiphy.retry_long = old_retry_long; |
| 1718 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1719 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1720 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1721 | } |
| 1722 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1723 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1724 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1725 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1726 | if (netdev) |
| 1727 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1728 | return result; |
| 1729 | } |
| 1730 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1731 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 1732 | { |
| 1733 | return (u64)wdev->identifier | |
| 1734 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 1735 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1736 | |
| 1737 | static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1738 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1739 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1740 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1741 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1742 | void *hdr; |
| 1743 | |
| 1744 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1745 | if (!hdr) |
| 1746 | return -1; |
| 1747 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1748 | if (dev && |
| 1749 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 1750 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) || |
| 1751 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dev->dev_addr))) |
| 1752 | goto nla_put_failure; |
| 1753 | |
| 1754 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1755 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 1756 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1757 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1758 | rdev->devlist_generation ^ |
| 1759 | (cfg80211_rdev_list_generation << 2))) |
| 1760 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1761 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 1762 | if (rdev->ops->get_channel) { |
| 1763 | struct ieee80211_channel *chan; |
| 1764 | enum nl80211_channel_type channel_type; |
| 1765 | |
| 1766 | chan = rdev->ops->get_channel(&rdev->wiphy, wdev, |
| 1767 | &channel_type); |
| 1768 | if (chan && |
| 1769 | (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1770 | chan->center_freq) || |
| 1771 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1772 | channel_type))) |
John W. Linville | 59ef43e | 2012-04-18 14:17:13 -0400 | [diff] [blame] | 1773 | goto nla_put_failure; |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1774 | } |
| 1775 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1776 | return genlmsg_end(msg, hdr); |
| 1777 | |
| 1778 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1779 | genlmsg_cancel(msg, hdr); |
| 1780 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1784 | { |
| 1785 | int wp_idx = 0; |
| 1786 | int if_idx = 0; |
| 1787 | int wp_start = cb->args[0]; |
| 1788 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1789 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1790 | struct wireless_dev *wdev; |
| 1791 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1792 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1793 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1794 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1795 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1796 | if (wp_idx < wp_start) { |
| 1797 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1798 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1799 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1800 | if_idx = 0; |
| 1801 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1802 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1803 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1804 | if (if_idx < if_start) { |
| 1805 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1806 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1807 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1808 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1809 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1810 | rdev, wdev) < 0) { |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1811 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1812 | goto out; |
| 1813 | } |
| 1814 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1815 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1816 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1817 | |
| 1818 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1819 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1820 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1821 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1822 | |
| 1823 | cb->args[0] = wp_idx; |
| 1824 | cb->args[1] = if_idx; |
| 1825 | |
| 1826 | return skb->len; |
| 1827 | } |
| 1828 | |
| 1829 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1830 | { |
| 1831 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1832 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1833 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1834 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1835 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1836 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1837 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1838 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1839 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 1840 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1841 | nlmsg_free(msg); |
| 1842 | return -ENOBUFS; |
| 1843 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1844 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1845 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1846 | } |
| 1847 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1848 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1849 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1850 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1851 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1852 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1853 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1854 | }; |
| 1855 | |
| 1856 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1857 | { |
| 1858 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1859 | int flag; |
| 1860 | |
| 1861 | *mntrflags = 0; |
| 1862 | |
| 1863 | if (!nla) |
| 1864 | return -EINVAL; |
| 1865 | |
| 1866 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1867 | nla, mntr_flags_policy)) |
| 1868 | return -EINVAL; |
| 1869 | |
| 1870 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1871 | if (flags[flag]) |
| 1872 | *mntrflags |= (1<<flag); |
| 1873 | |
| 1874 | return 0; |
| 1875 | } |
| 1876 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1877 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1878 | struct net_device *netdev, u8 use_4addr, |
| 1879 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1880 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1881 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1882 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1883 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1884 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1885 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1886 | |
| 1887 | switch (iftype) { |
| 1888 | case NL80211_IFTYPE_AP_VLAN: |
| 1889 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1890 | return 0; |
| 1891 | break; |
| 1892 | case NL80211_IFTYPE_STATION: |
| 1893 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1894 | return 0; |
| 1895 | break; |
| 1896 | default: |
| 1897 | break; |
| 1898 | } |
| 1899 | |
| 1900 | return -EOPNOTSUPP; |
| 1901 | } |
| 1902 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1903 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1904 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1905 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1906 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1907 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1908 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1909 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1910 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1911 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1912 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1913 | memset(¶ms, 0, sizeof(params)); |
| 1914 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1915 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1916 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1917 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1918 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1919 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1920 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1921 | if (ntype > NL80211_IFTYPE_MAX) |
| 1922 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1923 | } |
| 1924 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1925 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1926 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1927 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1928 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1929 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1930 | if (netif_running(dev)) |
| 1931 | return -EBUSY; |
| 1932 | |
| 1933 | wdev_lock(wdev); |
| 1934 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1935 | IEEE80211_MAX_MESH_ID_LEN); |
| 1936 | wdev->mesh_id_up_len = |
| 1937 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1938 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1939 | wdev->mesh_id_up_len); |
| 1940 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1941 | } |
| 1942 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1943 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1944 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1945 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1946 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1947 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1948 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1949 | } else { |
| 1950 | params.use_4addr = -1; |
| 1951 | } |
| 1952 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1953 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1954 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1955 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1956 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1957 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1958 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1959 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1960 | |
| 1961 | flags = &_flags; |
| 1962 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1963 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1964 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1965 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1966 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1967 | else |
| 1968 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1969 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1970 | if (!err && params.use_4addr != -1) |
| 1971 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1972 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1973 | return err; |
| 1974 | } |
| 1975 | |
| 1976 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1977 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1978 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1979 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 1980 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 1981 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1982 | int err; |
| 1983 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1984 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1985 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1986 | memset(¶ms, 0, sizeof(params)); |
| 1987 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1988 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1989 | return -EINVAL; |
| 1990 | |
| 1991 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1992 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1993 | if (type > NL80211_IFTYPE_MAX) |
| 1994 | return -EINVAL; |
| 1995 | } |
| 1996 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1997 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1998 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1999 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2000 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2001 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2002 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2003 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2004 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2005 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2006 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2007 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2008 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2009 | if (!msg) |
| 2010 | return -ENOMEM; |
| 2011 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2012 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2013 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2014 | &flags); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2015 | wdev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2016 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2017 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2018 | if (IS_ERR(wdev)) { |
| 2019 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2020 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2021 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2022 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2023 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 2024 | info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2025 | wdev_lock(wdev); |
| 2026 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2027 | IEEE80211_MAX_MESH_ID_LEN); |
| 2028 | wdev->mesh_id_up_len = |
| 2029 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2030 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2031 | wdev->mesh_id_up_len); |
| 2032 | wdev_unlock(wdev); |
| 2033 | } |
| 2034 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2035 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
| 2036 | rdev, wdev) < 0) { |
| 2037 | nlmsg_free(msg); |
| 2038 | return -ENOBUFS; |
| 2039 | } |
| 2040 | |
| 2041 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2045 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2046 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2047 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2048 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2049 | if (!rdev->ops->del_virtual_intf) |
| 2050 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2051 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2052 | /* |
| 2053 | * If we remove a wireless device without a netdev then clear |
| 2054 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2055 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2056 | * since the wdev has been freed, unlike with a netdev where |
| 2057 | * we need the dev_put() for the netdev to really be freed. |
| 2058 | */ |
| 2059 | if (!wdev->netdev) |
| 2060 | info->user_ptr[1] = NULL; |
| 2061 | |
| 2062 | return rdev->ops->del_virtual_intf(&rdev->wiphy, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2063 | } |
| 2064 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2065 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2066 | { |
| 2067 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2068 | struct net_device *dev = info->user_ptr[1]; |
| 2069 | u16 noack_map; |
| 2070 | |
| 2071 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2072 | return -EINVAL; |
| 2073 | |
| 2074 | if (!rdev->ops->set_noack_map) |
| 2075 | return -EOPNOTSUPP; |
| 2076 | |
| 2077 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2078 | |
| 2079 | return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map); |
| 2080 | } |
| 2081 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2082 | struct get_key_cookie { |
| 2083 | struct sk_buff *msg; |
| 2084 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2085 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2086 | }; |
| 2087 | |
| 2088 | static void get_key_callback(void *c, struct key_params *params) |
| 2089 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2090 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2091 | struct get_key_cookie *cookie = c; |
| 2092 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2093 | if ((params->key && |
| 2094 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2095 | params->key_len, params->key)) || |
| 2096 | (params->seq && |
| 2097 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2098 | params->seq_len, params->seq)) || |
| 2099 | (params->cipher && |
| 2100 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2101 | params->cipher))) |
| 2102 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2103 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2104 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2105 | if (!key) |
| 2106 | goto nla_put_failure; |
| 2107 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2108 | if ((params->key && |
| 2109 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2110 | params->key_len, params->key)) || |
| 2111 | (params->seq && |
| 2112 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2113 | params->seq_len, params->seq)) || |
| 2114 | (params->cipher && |
| 2115 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2116 | params->cipher))) |
| 2117 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2118 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2119 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2120 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2121 | |
| 2122 | nla_nest_end(cookie->msg, key); |
| 2123 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2124 | return; |
| 2125 | nla_put_failure: |
| 2126 | cookie->error = 1; |
| 2127 | } |
| 2128 | |
| 2129 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2130 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2131 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2132 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2133 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2134 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2135 | const u8 *mac_addr = NULL; |
| 2136 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2137 | struct get_key_cookie cookie = { |
| 2138 | .error = 0, |
| 2139 | }; |
| 2140 | void *hdr; |
| 2141 | struct sk_buff *msg; |
| 2142 | |
| 2143 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2144 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2145 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2146 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2147 | return -EINVAL; |
| 2148 | |
| 2149 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2150 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2151 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2152 | pairwise = !!mac_addr; |
| 2153 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2154 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2155 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2156 | return -EINVAL; |
| 2157 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2158 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2159 | return -EINVAL; |
| 2160 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2161 | } |
| 2162 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2163 | if (!rdev->ops->get_key) |
| 2164 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2165 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2166 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2167 | if (!msg) |
| 2168 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2169 | |
| 2170 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2171 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2172 | if (IS_ERR(hdr)) |
| 2173 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2174 | |
| 2175 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2176 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2177 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2178 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2179 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2180 | goto nla_put_failure; |
| 2181 | if (mac_addr && |
| 2182 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2183 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2184 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2185 | if (pairwise && mac_addr && |
| 2186 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2187 | return -ENOENT; |
| 2188 | |
| 2189 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 2190 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2191 | |
| 2192 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2193 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2194 | |
| 2195 | if (cookie.error) |
| 2196 | goto nla_put_failure; |
| 2197 | |
| 2198 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2199 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2200 | |
| 2201 | nla_put_failure: |
| 2202 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2203 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2204 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2205 | return err; |
| 2206 | } |
| 2207 | |
| 2208 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2209 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2210 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2211 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2212 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2213 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2214 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2215 | err = nl80211_parse_key(info, &key); |
| 2216 | if (err) |
| 2217 | return err; |
| 2218 | |
| 2219 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2220 | return -EINVAL; |
| 2221 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2222 | /* only support setting default key */ |
| 2223 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2224 | return -EINVAL; |
| 2225 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2226 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2227 | |
| 2228 | if (key.def) { |
| 2229 | if (!rdev->ops->set_default_key) { |
| 2230 | err = -EOPNOTSUPP; |
| 2231 | goto out; |
| 2232 | } |
| 2233 | |
| 2234 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2235 | if (err) |
| 2236 | goto out; |
| 2237 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2238 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 2239 | key.def_uni, key.def_multi); |
| 2240 | |
| 2241 | if (err) |
| 2242 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2243 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2244 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2245 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2246 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2247 | } else { |
| 2248 | if (key.def_uni || !key.def_multi) { |
| 2249 | err = -EINVAL; |
| 2250 | goto out; |
| 2251 | } |
| 2252 | |
| 2253 | if (!rdev->ops->set_default_mgmt_key) { |
| 2254 | err = -EOPNOTSUPP; |
| 2255 | goto out; |
| 2256 | } |
| 2257 | |
| 2258 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2259 | if (err) |
| 2260 | goto out; |
| 2261 | |
| 2262 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 2263 | dev, key.idx); |
| 2264 | if (err) |
| 2265 | goto out; |
| 2266 | |
| 2267 | #ifdef CONFIG_CFG80211_WEXT |
| 2268 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2269 | #endif |
| 2270 | } |
| 2271 | |
| 2272 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2273 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2274 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2275 | return err; |
| 2276 | } |
| 2277 | |
| 2278 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2279 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2280 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2281 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2282 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2283 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2284 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2285 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2286 | err = nl80211_parse_key(info, &key); |
| 2287 | if (err) |
| 2288 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2289 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2290 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2291 | return -EINVAL; |
| 2292 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2293 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2294 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2295 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2296 | if (key.type == -1) { |
| 2297 | if (mac_addr) |
| 2298 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2299 | else |
| 2300 | key.type = NL80211_KEYTYPE_GROUP; |
| 2301 | } |
| 2302 | |
| 2303 | /* for now */ |
| 2304 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2305 | key.type != NL80211_KEYTYPE_GROUP) |
| 2306 | return -EINVAL; |
| 2307 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2308 | if (!rdev->ops->add_key) |
| 2309 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2310 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2311 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2312 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2313 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2314 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2315 | |
| 2316 | wdev_lock(dev->ieee80211_ptr); |
| 2317 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2318 | if (!err) |
| 2319 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2320 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2321 | mac_addr, &key.p); |
| 2322 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2323 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2324 | return err; |
| 2325 | } |
| 2326 | |
| 2327 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2328 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2330 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2331 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2332 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2333 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2334 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2335 | err = nl80211_parse_key(info, &key); |
| 2336 | if (err) |
| 2337 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2338 | |
| 2339 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2340 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2341 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2342 | if (key.type == -1) { |
| 2343 | if (mac_addr) |
| 2344 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2345 | else |
| 2346 | key.type = NL80211_KEYTYPE_GROUP; |
| 2347 | } |
| 2348 | |
| 2349 | /* for now */ |
| 2350 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2351 | key.type != NL80211_KEYTYPE_GROUP) |
| 2352 | return -EINVAL; |
| 2353 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2354 | if (!rdev->ops->del_key) |
| 2355 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2356 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2357 | wdev_lock(dev->ieee80211_ptr); |
| 2358 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2359 | |
| 2360 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2361 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2362 | err = -ENOENT; |
| 2363 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2364 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2365 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 2366 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2367 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2368 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2369 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2370 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2371 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2372 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2373 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2374 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2375 | } |
| 2376 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2377 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2378 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2379 | return err; |
| 2380 | } |
| 2381 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2382 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2383 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2384 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2385 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2386 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2387 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2388 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2389 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2390 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2391 | return -EINVAL; |
| 2392 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2393 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2394 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2395 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2396 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2397 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2398 | if (!bcn->head_len) |
| 2399 | return -EINVAL; |
| 2400 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2404 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2405 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2406 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2407 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2408 | } |
| 2409 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2410 | if (!haveinfo) |
| 2411 | return -EINVAL; |
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 (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2414 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2415 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2419 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2420 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2421 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2422 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2423 | } |
| 2424 | |
| 2425 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2426 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2427 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2428 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2429 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2430 | } |
| 2431 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2432 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2433 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2434 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2435 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2436 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2437 | } |
| 2438 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2439 | return 0; |
| 2440 | } |
| 2441 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2442 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2443 | struct cfg80211_ap_settings *params) |
| 2444 | { |
| 2445 | struct wireless_dev *wdev; |
| 2446 | bool ret = false; |
| 2447 | |
| 2448 | mutex_lock(&rdev->devlist_mtx); |
| 2449 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2450 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2451 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2452 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2453 | continue; |
| 2454 | |
| 2455 | if (!wdev->preset_chan) |
| 2456 | continue; |
| 2457 | |
| 2458 | params->channel = wdev->preset_chan; |
| 2459 | params->channel_type = wdev->preset_chantype; |
| 2460 | ret = true; |
| 2461 | break; |
| 2462 | } |
| 2463 | |
| 2464 | mutex_unlock(&rdev->devlist_mtx); |
| 2465 | |
| 2466 | return ret; |
| 2467 | } |
| 2468 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2469 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2470 | { |
| 2471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2472 | struct net_device *dev = info->user_ptr[1]; |
| 2473 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2474 | struct cfg80211_ap_settings params; |
| 2475 | int err; |
| 2476 | |
| 2477 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2478 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2479 | return -EOPNOTSUPP; |
| 2480 | |
| 2481 | if (!rdev->ops->start_ap) |
| 2482 | return -EOPNOTSUPP; |
| 2483 | |
| 2484 | if (wdev->beacon_interval) |
| 2485 | return -EALREADY; |
| 2486 | |
| 2487 | memset(¶ms, 0, sizeof(params)); |
| 2488 | |
| 2489 | /* these are required for START_AP */ |
| 2490 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2491 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2492 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2493 | return -EINVAL; |
| 2494 | |
| 2495 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2496 | if (err) |
| 2497 | return err; |
| 2498 | |
| 2499 | params.beacon_interval = |
| 2500 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2501 | params.dtim_period = |
| 2502 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2503 | |
| 2504 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2505 | if (err) |
| 2506 | return err; |
| 2507 | |
| 2508 | /* |
| 2509 | * In theory, some of these attributes should be required here |
| 2510 | * but since they were not used when the command was originally |
| 2511 | * added, keep them optional for old user space programs to let |
| 2512 | * them continue to work with drivers that do not need the |
| 2513 | * additional information -- drivers must check! |
| 2514 | */ |
| 2515 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2516 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2517 | params.ssid_len = |
| 2518 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2519 | if (params.ssid_len == 0 || |
| 2520 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2521 | return -EINVAL; |
| 2522 | } |
| 2523 | |
| 2524 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2525 | params.hidden_ssid = nla_get_u32( |
| 2526 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2527 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2528 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2529 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2530 | return -EINVAL; |
| 2531 | } |
| 2532 | |
| 2533 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2534 | |
| 2535 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2536 | params.auth_type = nla_get_u32( |
| 2537 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2538 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2539 | return -EINVAL; |
| 2540 | } else |
| 2541 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2542 | |
| 2543 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2544 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2545 | if (err) |
| 2546 | return err; |
| 2547 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2548 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2549 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2550 | return -EOPNOTSUPP; |
| 2551 | params.inactivity_timeout = nla_get_u16( |
| 2552 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2553 | } |
| 2554 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2555 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 2556 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 2557 | |
| 2558 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 2559 | !nl80211_valid_channel_type(info, &channel_type)) |
| 2560 | return -EINVAL; |
| 2561 | |
| 2562 | params.channel = rdev_freq_to_chan(rdev, |
| 2563 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 2564 | channel_type); |
| 2565 | if (!params.channel) |
| 2566 | return -EINVAL; |
| 2567 | params.channel_type = channel_type; |
| 2568 | } else if (wdev->preset_chan) { |
| 2569 | params.channel = wdev->preset_chan; |
| 2570 | params.channel_type = wdev->preset_chantype; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2571 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2572 | return -EINVAL; |
| 2573 | |
| 2574 | if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel, |
| 2575 | params.channel_type)) |
| 2576 | return -EINVAL; |
| 2577 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2578 | mutex_lock(&rdev->devlist_mtx); |
| 2579 | err = cfg80211_can_use_chan(rdev, wdev, params.channel, |
| 2580 | CHAN_MODE_SHARED); |
| 2581 | mutex_unlock(&rdev->devlist_mtx); |
| 2582 | |
| 2583 | if (err) |
| 2584 | return err; |
| 2585 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2586 | err = rdev->ops->start_ap(&rdev->wiphy, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2587 | if (!err) { |
| 2588 | wdev->preset_chan = params.channel; |
| 2589 | wdev->preset_chantype = params.channel_type; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2590 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | f4489eb | 2012-06-29 12:46:58 +0200 | [diff] [blame] | 2591 | wdev->channel = params.channel; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2592 | } |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2593 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2594 | } |
| 2595 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2596 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2597 | { |
| 2598 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2599 | struct net_device *dev = info->user_ptr[1]; |
| 2600 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2601 | struct cfg80211_beacon_data params; |
| 2602 | int err; |
| 2603 | |
| 2604 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2605 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2606 | return -EOPNOTSUPP; |
| 2607 | |
| 2608 | if (!rdev->ops->change_beacon) |
| 2609 | return -EOPNOTSUPP; |
| 2610 | |
| 2611 | if (!wdev->beacon_interval) |
| 2612 | return -EINVAL; |
| 2613 | |
| 2614 | err = nl80211_parse_beacon(info, ¶ms); |
| 2615 | if (err) |
| 2616 | return err; |
| 2617 | |
| 2618 | return rdev->ops->change_beacon(&rdev->wiphy, dev, ¶ms); |
| 2619 | } |
| 2620 | |
| 2621 | 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] | 2622 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2623 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2624 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2625 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2626 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2627 | } |
| 2628 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2629 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2630 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2631 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2632 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2633 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2634 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2635 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2636 | }; |
| 2637 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2638 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2639 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2640 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2641 | { |
| 2642 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2643 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2644 | int flag; |
| 2645 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2646 | /* |
| 2647 | * Try parsing the new attribute first so userspace |
| 2648 | * can specify both for older kernels. |
| 2649 | */ |
| 2650 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2651 | if (nla) { |
| 2652 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2653 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2654 | sta_flags = nla_data(nla); |
| 2655 | params->sta_flags_mask = sta_flags->mask; |
| 2656 | params->sta_flags_set = sta_flags->set; |
| 2657 | if ((params->sta_flags_mask | |
| 2658 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2659 | return -EINVAL; |
| 2660 | return 0; |
| 2661 | } |
| 2662 | |
| 2663 | /* if present, parse the old attribute */ |
| 2664 | |
| 2665 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2666 | if (!nla) |
| 2667 | return 0; |
| 2668 | |
| 2669 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2670 | nla, sta_flags_policy)) |
| 2671 | return -EINVAL; |
| 2672 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2673 | /* |
| 2674 | * Only allow certain flags for interface types so that |
| 2675 | * other attributes are silently ignored. Remember that |
| 2676 | * this is backward compatibility code with old userspace |
| 2677 | * and shouldn't be hit in other cases anyway. |
| 2678 | */ |
| 2679 | switch (iftype) { |
| 2680 | case NL80211_IFTYPE_AP: |
| 2681 | case NL80211_IFTYPE_AP_VLAN: |
| 2682 | case NL80211_IFTYPE_P2P_GO: |
| 2683 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2684 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2685 | BIT(NL80211_STA_FLAG_WME) | |
| 2686 | BIT(NL80211_STA_FLAG_MFP); |
| 2687 | break; |
| 2688 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2689 | case NL80211_IFTYPE_STATION: |
| 2690 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2691 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2692 | break; |
| 2693 | case NL80211_IFTYPE_MESH_POINT: |
| 2694 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2695 | BIT(NL80211_STA_FLAG_MFP) | |
| 2696 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2697 | default: |
| 2698 | return -EINVAL; |
| 2699 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2700 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2701 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 2702 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2703 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2704 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2705 | /* no longer support new API additions in old API */ |
| 2706 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 2707 | return -EINVAL; |
| 2708 | } |
| 2709 | } |
| 2710 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2711 | return 0; |
| 2712 | } |
| 2713 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2714 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2715 | int attr) |
| 2716 | { |
| 2717 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2718 | u32 bitrate; |
| 2719 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2720 | |
| 2721 | rate = nla_nest_start(msg, attr); |
| 2722 | if (!rate) |
| 2723 | goto nla_put_failure; |
| 2724 | |
| 2725 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2726 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2727 | /* report 16-bit bitrate only if we can */ |
| 2728 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2729 | if ((bitrate > 0 && |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2730 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) || |
| 2731 | (bitrate_compat > 0 && |
| 2732 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2733 | ((info->flags & RATE_INFO_FLAGS_MCS) && |
| 2734 | nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) || |
| 2735 | ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) && |
| 2736 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) || |
| 2737 | ((info->flags & RATE_INFO_FLAGS_SHORT_GI) && |
| 2738 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))) |
| 2739 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2740 | |
| 2741 | nla_nest_end(msg, rate); |
| 2742 | return true; |
| 2743 | |
| 2744 | nla_put_failure: |
| 2745 | return false; |
| 2746 | } |
| 2747 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2748 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2749 | int flags, |
| 2750 | struct cfg80211_registered_device *rdev, |
| 2751 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2752 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2753 | { |
| 2754 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2755 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2756 | |
| 2757 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2758 | if (!hdr) |
| 2759 | return -1; |
| 2760 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2761 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2762 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 2763 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 2764 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2765 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2766 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2767 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2768 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2769 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 2770 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2771 | sinfo->connected_time)) |
| 2772 | goto nla_put_failure; |
| 2773 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 2774 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2775 | sinfo->inactive_time)) |
| 2776 | goto nla_put_failure; |
| 2777 | if ((sinfo->filled & STATION_INFO_RX_BYTES) && |
| 2778 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2779 | sinfo->rx_bytes)) |
| 2780 | goto nla_put_failure; |
| 2781 | if ((sinfo->filled & STATION_INFO_TX_BYTES) && |
| 2782 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2783 | sinfo->tx_bytes)) |
| 2784 | goto nla_put_failure; |
| 2785 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 2786 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 2787 | goto nla_put_failure; |
| 2788 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 2789 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 2790 | goto nla_put_failure; |
| 2791 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 2792 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2793 | sinfo->plink_state)) |
| 2794 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2795 | switch (rdev->wiphy.signal_type) { |
| 2796 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2797 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 2798 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 2799 | sinfo->signal)) |
| 2800 | goto nla_put_failure; |
| 2801 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 2802 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2803 | sinfo->signal_avg)) |
| 2804 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2805 | break; |
| 2806 | default: |
| 2807 | break; |
| 2808 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2809 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2810 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2811 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2812 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2813 | } |
| 2814 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2815 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2816 | NL80211_STA_INFO_RX_BITRATE)) |
| 2817 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2818 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2819 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 2820 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2821 | sinfo->rx_packets)) |
| 2822 | goto nla_put_failure; |
| 2823 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 2824 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2825 | sinfo->tx_packets)) |
| 2826 | goto nla_put_failure; |
| 2827 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 2828 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2829 | sinfo->tx_retries)) |
| 2830 | goto nla_put_failure; |
| 2831 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 2832 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2833 | sinfo->tx_failed)) |
| 2834 | goto nla_put_failure; |
| 2835 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 2836 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 2837 | sinfo->beacon_loss_count)) |
| 2838 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2839 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2840 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2841 | if (!bss_param) |
| 2842 | goto nla_put_failure; |
| 2843 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2844 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 2845 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 2846 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 2847 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 2848 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 2849 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 2850 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2851 | sinfo->bss_param.dtim_period) || |
| 2852 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2853 | sinfo->bss_param.beacon_interval)) |
| 2854 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2855 | |
| 2856 | nla_nest_end(msg, bss_param); |
| 2857 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2858 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 2859 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2860 | sizeof(struct nl80211_sta_flag_update), |
| 2861 | &sinfo->sta_flags)) |
| 2862 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 2863 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 2864 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 2865 | sinfo->t_offset)) |
| 2866 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2867 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2868 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2869 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 2870 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2871 | sinfo->assoc_req_ies)) |
| 2872 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2873 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2874 | return genlmsg_end(msg, hdr); |
| 2875 | |
| 2876 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2877 | genlmsg_cancel(msg, hdr); |
| 2878 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2879 | } |
| 2880 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2881 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2882 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2883 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2884 | struct station_info sinfo; |
| 2885 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2886 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2887 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2888 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2889 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2890 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2891 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2892 | if (err) |
| 2893 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2894 | |
| 2895 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2896 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2897 | goto out_err; |
| 2898 | } |
| 2899 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2900 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2901 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2902 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2903 | mac_addr, &sinfo); |
| 2904 | if (err == -ENOENT) |
| 2905 | break; |
| 2906 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2907 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2908 | |
| 2909 | if (nl80211_send_station(skb, |
| 2910 | NETLINK_CB(cb->skb).pid, |
| 2911 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2912 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2913 | &sinfo) < 0) |
| 2914 | goto out; |
| 2915 | |
| 2916 | sta_idx++; |
| 2917 | } |
| 2918 | |
| 2919 | |
| 2920 | out: |
| 2921 | cb->args[1] = sta_idx; |
| 2922 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2923 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2924 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2925 | |
| 2926 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2927 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2928 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2929 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2930 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2932 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2933 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2934 | struct sk_buff *msg; |
| 2935 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2936 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2937 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2938 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2939 | |
| 2940 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2941 | return -EINVAL; |
| 2942 | |
| 2943 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2944 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2945 | if (!rdev->ops->get_station) |
| 2946 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2947 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2948 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2949 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2950 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2951 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2952 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2953 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2954 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2955 | |
| 2956 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2957 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2958 | nlmsg_free(msg); |
| 2959 | return -ENOBUFS; |
| 2960 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2961 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2962 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2966 | * 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] | 2967 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2968 | static struct net_device *get_vlan(struct genl_info *info, |
| 2969 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2970 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2971 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2972 | struct net_device *v; |
| 2973 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2974 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2975 | if (!vlanattr) |
| 2976 | return NULL; |
| 2977 | |
| 2978 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 2979 | if (!v) |
| 2980 | return ERR_PTR(-ENODEV); |
| 2981 | |
| 2982 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 2983 | ret = -EINVAL; |
| 2984 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2985 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2986 | |
| 2987 | if (!netif_running(v)) { |
| 2988 | ret = -ENETDOWN; |
| 2989 | goto error; |
| 2990 | } |
| 2991 | |
| 2992 | return v; |
| 2993 | error: |
| 2994 | dev_put(v); |
| 2995 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2996 | } |
| 2997 | |
| 2998 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2999 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3000 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3001 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3002 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3003 | struct station_parameters params; |
| 3004 | u8 *mac_addr = NULL; |
| 3005 | |
| 3006 | memset(¶ms, 0, sizeof(params)); |
| 3007 | |
| 3008 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 3009 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3010 | |
| 3011 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3012 | return -EINVAL; |
| 3013 | |
| 3014 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3015 | return -EINVAL; |
| 3016 | |
| 3017 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3018 | |
| 3019 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3020 | params.supported_rates = |
| 3021 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3022 | params.supported_rates_len = |
| 3023 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3024 | } |
| 3025 | |
| 3026 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3027 | params.listen_interval = |
| 3028 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 3029 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3030 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3031 | params.ht_capa = |
| 3032 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3033 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3034 | if (!rdev->ops->change_station) |
| 3035 | return -EOPNOTSUPP; |
| 3036 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3037 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3038 | return -EINVAL; |
| 3039 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3040 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3041 | params.plink_action = |
| 3042 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3043 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3044 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3045 | params.plink_state = |
| 3046 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3047 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3048 | switch (dev->ieee80211_ptr->iftype) { |
| 3049 | case NL80211_IFTYPE_AP: |
| 3050 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3051 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3052 | /* disallow mesh-specific things */ |
| 3053 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3054 | return -EINVAL; |
| 3055 | |
| 3056 | /* TDLS can't be set, ... */ |
| 3057 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3058 | return -EINVAL; |
| 3059 | /* |
| 3060 | * ... but don't bother the driver with it. This works around |
| 3061 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3062 | * TLDS_PEER flag in the mask even for AP mode. |
| 3063 | */ |
| 3064 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3065 | |
| 3066 | /* accept only the listed bits */ |
| 3067 | if (params.sta_flags_mask & |
| 3068 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3069 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3070 | BIT(NL80211_STA_FLAG_WME) | |
| 3071 | BIT(NL80211_STA_FLAG_MFP))) |
| 3072 | return -EINVAL; |
| 3073 | |
| 3074 | /* must be last in here for error handling */ |
| 3075 | params.vlan = get_vlan(info, rdev); |
| 3076 | if (IS_ERR(params.vlan)) |
| 3077 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3078 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3079 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3080 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3081 | /* |
| 3082 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3083 | * but silently ignore attempts to change it since we |
| 3084 | * don't have state here to verify that it doesn't try |
| 3085 | * to change the flag. |
| 3086 | */ |
| 3087 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3088 | /* fall through */ |
| 3089 | case NL80211_IFTYPE_ADHOC: |
| 3090 | /* disallow things sta doesn't support */ |
| 3091 | if (params.plink_action) |
| 3092 | return -EINVAL; |
| 3093 | if (params.ht_capa) |
| 3094 | return -EINVAL; |
| 3095 | if (params.listen_interval >= 0) |
| 3096 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3097 | /* reject any changes other than AUTHORIZED */ |
| 3098 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3099 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3100 | break; |
| 3101 | case NL80211_IFTYPE_MESH_POINT: |
| 3102 | /* disallow things mesh doesn't support */ |
| 3103 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3104 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3105 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3106 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3107 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3108 | return -EINVAL; |
| 3109 | /* |
| 3110 | * No special handling for TDLS here -- the userspace |
| 3111 | * mesh code doesn't have this bug. |
| 3112 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3113 | if (params.sta_flags_mask & |
| 3114 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3115 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3116 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3117 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3118 | break; |
| 3119 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3120 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3121 | } |
| 3122 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3123 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3124 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3125 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3126 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3127 | if (params.vlan) |
| 3128 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3129 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3130 | return err; |
| 3131 | } |
| 3132 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3133 | static struct nla_policy |
| 3134 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3135 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3136 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3137 | }; |
| 3138 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3139 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3140 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3141 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3142 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3143 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3144 | struct station_parameters params; |
| 3145 | u8 *mac_addr = NULL; |
| 3146 | |
| 3147 | memset(¶ms, 0, sizeof(params)); |
| 3148 | |
| 3149 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3150 | return -EINVAL; |
| 3151 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3152 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3153 | return -EINVAL; |
| 3154 | |
| 3155 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3156 | return -EINVAL; |
| 3157 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3158 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3159 | return -EINVAL; |
| 3160 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3161 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3162 | params.supported_rates = |
| 3163 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3164 | params.supported_rates_len = |
| 3165 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3166 | params.listen_interval = |
| 3167 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3168 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3169 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3170 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3171 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3172 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3173 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3174 | params.ht_capa = |
| 3175 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3176 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3177 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3178 | params.plink_action = |
| 3179 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3180 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3181 | if (!rdev->ops->add_station) |
| 3182 | return -EOPNOTSUPP; |
| 3183 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3184 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3185 | return -EINVAL; |
| 3186 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3187 | switch (dev->ieee80211_ptr->iftype) { |
| 3188 | case NL80211_IFTYPE_AP: |
| 3189 | case NL80211_IFTYPE_AP_VLAN: |
| 3190 | case NL80211_IFTYPE_P2P_GO: |
| 3191 | /* parse WME attributes if sta is WME capable */ |
| 3192 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3193 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3194 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3195 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3196 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3197 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3198 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3199 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3200 | nl80211_sta_wme_policy); |
| 3201 | if (err) |
| 3202 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3203 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3204 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3205 | params.uapsd_queues = |
| 3206 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3207 | if (params.uapsd_queues & |
| 3208 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3209 | return -EINVAL; |
| 3210 | |
| 3211 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3212 | params.max_sp = |
| 3213 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3214 | |
| 3215 | if (params.max_sp & |
| 3216 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3217 | return -EINVAL; |
| 3218 | |
| 3219 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3220 | } |
| 3221 | /* TDLS peers cannot be added */ |
| 3222 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3223 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3224 | /* but don't bother the driver with it */ |
| 3225 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3226 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3227 | /* must be last in here for error handling */ |
| 3228 | params.vlan = get_vlan(info, rdev); |
| 3229 | if (IS_ERR(params.vlan)) |
| 3230 | return PTR_ERR(params.vlan); |
| 3231 | break; |
| 3232 | case NL80211_IFTYPE_MESH_POINT: |
| 3233 | /* TDLS peers cannot be added */ |
| 3234 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3235 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3236 | break; |
| 3237 | case NL80211_IFTYPE_STATION: |
| 3238 | /* Only TDLS peers can be added */ |
| 3239 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3240 | return -EINVAL; |
| 3241 | /* Can only add if TDLS ... */ |
| 3242 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3243 | return -EOPNOTSUPP; |
| 3244 | /* ... with external setup is supported */ |
| 3245 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3246 | return -EOPNOTSUPP; |
| 3247 | break; |
| 3248 | default: |
| 3249 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3250 | } |
| 3251 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3252 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3253 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3254 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3255 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3256 | if (params.vlan) |
| 3257 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3258 | return err; |
| 3259 | } |
| 3260 | |
| 3261 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3262 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3263 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3264 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3265 | u8 *mac_addr = NULL; |
| 3266 | |
| 3267 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3268 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3269 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3270 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3271 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3272 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3273 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3274 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3275 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3276 | if (!rdev->ops->del_station) |
| 3277 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3278 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3279 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3280 | } |
| 3281 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3282 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 3283 | int flags, struct net_device *dev, |
| 3284 | u8 *dst, u8 *next_hop, |
| 3285 | struct mpath_info *pinfo) |
| 3286 | { |
| 3287 | void *hdr; |
| 3288 | struct nlattr *pinfoattr; |
| 3289 | |
| 3290 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 3291 | if (!hdr) |
| 3292 | return -1; |
| 3293 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3294 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3295 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3296 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3297 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3298 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3299 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3300 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3301 | if (!pinfoattr) |
| 3302 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3303 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3304 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3305 | pinfo->frame_qlen)) |
| 3306 | goto nla_put_failure; |
| 3307 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3308 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3309 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3310 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3311 | pinfo->metric)) || |
| 3312 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3313 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3314 | pinfo->exptime)) || |
| 3315 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3316 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3317 | pinfo->flags)) || |
| 3318 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3319 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3320 | pinfo->discovery_timeout)) || |
| 3321 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3322 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3323 | pinfo->discovery_retries))) |
| 3324 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3325 | |
| 3326 | nla_nest_end(msg, pinfoattr); |
| 3327 | |
| 3328 | return genlmsg_end(msg, hdr); |
| 3329 | |
| 3330 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3331 | genlmsg_cancel(msg, hdr); |
| 3332 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3336 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3337 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3338 | struct mpath_info pinfo; |
| 3339 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3340 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3341 | u8 dst[ETH_ALEN]; |
| 3342 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3343 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3344 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3345 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3346 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3347 | if (err) |
| 3348 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3349 | |
| 3350 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3351 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3352 | goto out_err; |
| 3353 | } |
| 3354 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3355 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3356 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3357 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3358 | } |
| 3359 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3360 | while (1) { |
| 3361 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 3362 | dst, next_hop, &pinfo); |
| 3363 | if (err == -ENOENT) |
| 3364 | break; |
| 3365 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3366 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3367 | |
| 3368 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 3369 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3370 | netdev, dst, next_hop, |
| 3371 | &pinfo) < 0) |
| 3372 | goto out; |
| 3373 | |
| 3374 | path_idx++; |
| 3375 | } |
| 3376 | |
| 3377 | |
| 3378 | out: |
| 3379 | cb->args[1] = path_idx; |
| 3380 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3381 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3382 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3383 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3387 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3388 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3389 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3390 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3391 | struct mpath_info pinfo; |
| 3392 | struct sk_buff *msg; |
| 3393 | u8 *dst = NULL; |
| 3394 | u8 next_hop[ETH_ALEN]; |
| 3395 | |
| 3396 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3397 | |
| 3398 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3399 | return -EINVAL; |
| 3400 | |
| 3401 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3402 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3403 | if (!rdev->ops->get_mpath) |
| 3404 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3405 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3406 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3407 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3408 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3409 | 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] | 3410 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3411 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3412 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3413 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3414 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3415 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3416 | |
| 3417 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3418 | dev, dst, next_hop, &pinfo) < 0) { |
| 3419 | nlmsg_free(msg); |
| 3420 | return -ENOBUFS; |
| 3421 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3422 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3423 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3427 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3428 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3429 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3430 | u8 *dst = NULL; |
| 3431 | u8 *next_hop = NULL; |
| 3432 | |
| 3433 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3434 | return -EINVAL; |
| 3435 | |
| 3436 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3437 | return -EINVAL; |
| 3438 | |
| 3439 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3440 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3441 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3442 | if (!rdev->ops->change_mpath) |
| 3443 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3444 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3445 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3446 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3447 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3448 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3449 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3450 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3451 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3452 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3453 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3454 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3455 | u8 *dst = NULL; |
| 3456 | u8 *next_hop = NULL; |
| 3457 | |
| 3458 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3459 | return -EINVAL; |
| 3460 | |
| 3461 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3462 | return -EINVAL; |
| 3463 | |
| 3464 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3465 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3466 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3467 | if (!rdev->ops->add_mpath) |
| 3468 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3469 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3470 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3471 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3472 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3473 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3477 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3478 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3479 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3480 | u8 *dst = NULL; |
| 3481 | |
| 3482 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3483 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3484 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3485 | if (!rdev->ops->del_mpath) |
| 3486 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3487 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3488 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3489 | } |
| 3490 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3491 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3492 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3494 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3495 | struct bss_parameters params; |
| 3496 | |
| 3497 | memset(¶ms, 0, sizeof(params)); |
| 3498 | /* default to not changing parameters */ |
| 3499 | params.use_cts_prot = -1; |
| 3500 | params.use_short_preamble = -1; |
| 3501 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3502 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3503 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3504 | |
| 3505 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3506 | params.use_cts_prot = |
| 3507 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3508 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3509 | params.use_short_preamble = |
| 3510 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3511 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3512 | params.use_short_slot_time = |
| 3513 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3514 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3515 | params.basic_rates = |
| 3516 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3517 | params.basic_rates_len = |
| 3518 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3519 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3520 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3521 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3522 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3523 | params.ht_opmode = |
| 3524 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3525 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3526 | if (!rdev->ops->change_bss) |
| 3527 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3528 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3529 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3530 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3531 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3532 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3533 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3534 | } |
| 3535 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3536 | 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] | 3537 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3538 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3539 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3540 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3541 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3542 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3543 | }; |
| 3544 | |
| 3545 | static int parse_reg_rule(struct nlattr *tb[], |
| 3546 | struct ieee80211_reg_rule *reg_rule) |
| 3547 | { |
| 3548 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3549 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3550 | |
| 3551 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3552 | return -EINVAL; |
| 3553 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3554 | return -EINVAL; |
| 3555 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3556 | return -EINVAL; |
| 3557 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3558 | return -EINVAL; |
| 3559 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3560 | return -EINVAL; |
| 3561 | |
| 3562 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3563 | |
| 3564 | freq_range->start_freq_khz = |
| 3565 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3566 | freq_range->end_freq_khz = |
| 3567 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3568 | freq_range->max_bandwidth_khz = |
| 3569 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3570 | |
| 3571 | power_rule->max_eirp = |
| 3572 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3573 | |
| 3574 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3575 | power_rule->max_antenna_gain = |
| 3576 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3577 | |
| 3578 | return 0; |
| 3579 | } |
| 3580 | |
| 3581 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3582 | { |
| 3583 | int r; |
| 3584 | char *data = NULL; |
| 3585 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3586 | /* |
| 3587 | * You should only get this when cfg80211 hasn't yet initialized |
| 3588 | * completely when built-in to the kernel right between the time |
| 3589 | * window between nl80211_init() and regulatory_init(), if that is |
| 3590 | * even possible. |
| 3591 | */ |
| 3592 | mutex_lock(&cfg80211_mutex); |
| 3593 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3594 | mutex_unlock(&cfg80211_mutex); |
| 3595 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3596 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3597 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3598 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3599 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3600 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3601 | |
| 3602 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3603 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3604 | r = regulatory_hint_user(data); |
| 3605 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3606 | return r; |
| 3607 | } |
| 3608 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3609 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3610 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3611 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3612 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3613 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3614 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3615 | struct mesh_config cur_params; |
| 3616 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3617 | void *hdr; |
| 3618 | struct nlattr *pinfoattr; |
| 3619 | struct sk_buff *msg; |
| 3620 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3621 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3622 | return -EOPNOTSUPP; |
| 3623 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3624 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3625 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3626 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3627 | wdev_lock(wdev); |
| 3628 | /* If not connected, get default parameters */ |
| 3629 | if (!wdev->mesh_id_len) |
| 3630 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3631 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3632 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3633 | &cur_params); |
| 3634 | wdev_unlock(wdev); |
| 3635 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3636 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3637 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3638 | |
| 3639 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3640 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3641 | if (!msg) |
| 3642 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3643 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3644 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3645 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3646 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3647 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3648 | if (!pinfoattr) |
| 3649 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3650 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3651 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3652 | cur_params.dot11MeshRetryTimeout) || |
| 3653 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3654 | cur_params.dot11MeshConfirmTimeout) || |
| 3655 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3656 | cur_params.dot11MeshHoldingTimeout) || |
| 3657 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3658 | cur_params.dot11MeshMaxPeerLinks) || |
| 3659 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3660 | cur_params.dot11MeshMaxRetries) || |
| 3661 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 3662 | cur_params.dot11MeshTTL) || |
| 3663 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3664 | cur_params.element_ttl) || |
| 3665 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3666 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3667 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3668 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3669 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3670 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 3671 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3672 | cur_params.path_refresh_time) || |
| 3673 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3674 | cur_params.min_discovery_timeout) || |
| 3675 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3676 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 3677 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3678 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 3679 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3680 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 3681 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3682 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 3683 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3684 | cur_params.dot11MeshHWMPRootMode) || |
| 3685 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3686 | cur_params.dot11MeshHWMPRannInterval) || |
| 3687 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3688 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 3689 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 3690 | cur_params.dot11MeshForwarding) || |
| 3691 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3692 | cur_params.rssi_threshold) || |
| 3693 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3694 | cur_params.ht_opmode) || |
| 3695 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3696 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 3697 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3698 | cur_params.dot11MeshHWMProotInterval) || |
| 3699 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3700 | cur_params.dot11MeshHWMPconfirmationInterval)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3701 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3702 | nla_nest_end(msg, pinfoattr); |
| 3703 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3704 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3705 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3706 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3707 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3708 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3709 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3710 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3711 | } |
| 3712 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3713 | 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] | 3714 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3715 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3716 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3717 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3718 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3719 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3720 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3721 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3722 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3723 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3724 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3725 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3726 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3727 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3728 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3729 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3730 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3731 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3732 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3733 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3734 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 3735 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3736 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 3737 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3738 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3739 | }; |
| 3740 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3741 | static const struct nla_policy |
| 3742 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3743 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3744 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3745 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3746 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3747 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3748 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3749 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3750 | }; |
| 3751 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3752 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3753 | struct mesh_config *cfg, |
| 3754 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3755 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3756 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3757 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3758 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3759 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3760 | do {\ |
| 3761 | if (table[attr_num]) {\ |
| 3762 | cfg->param = nla_fn(table[attr_num]); \ |
| 3763 | mask |= (1 << (attr_num - 1)); \ |
| 3764 | } \ |
| 3765 | } while (0);\ |
| 3766 | |
| 3767 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3768 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3769 | return -EINVAL; |
| 3770 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3771 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3772 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3773 | return -EINVAL; |
| 3774 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3775 | /* This makes sure that there aren't more than 32 mesh config |
| 3776 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3777 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3778 | |
| 3779 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3780 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3781 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3782 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3783 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3784 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3785 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3786 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3787 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3788 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3789 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3790 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3791 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3792 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3793 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 3794 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3795 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3796 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3797 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3798 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 3799 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3800 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3801 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3802 | nla_get_u8); |
| 3803 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask, |
| 3804 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3805 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3806 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3807 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3808 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3809 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3810 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3811 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3812 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3813 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3814 | nla_get_u16); |
| 3815 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask, |
| 3816 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3817 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3818 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3819 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3820 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3821 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3822 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3823 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3824 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3825 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
| 3826 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3827 | nla_get_u16); |
| 3828 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 3829 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 3830 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 3831 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3832 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3833 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3834 | dot11MeshGateAnnouncementProtocol, mask, |
| 3835 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3836 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3837 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3838 | mask, NL80211_MESHCONF_FORWARDING, |
| 3839 | nla_get_u8); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 3840 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3841 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 3842 | nla_get_u32); |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3843 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3844 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 3845 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3846 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
| 3847 | mask, |
| 3848 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3849 | nla_get_u32); |
| 3850 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, |
| 3851 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 3852 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3853 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3854 | dot11MeshHWMPconfirmationInterval, mask, |
| 3855 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3856 | nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3857 | if (mask_out) |
| 3858 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3859 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3860 | return 0; |
| 3861 | |
| 3862 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3863 | } |
| 3864 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3865 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3866 | struct mesh_setup *setup) |
| 3867 | { |
| 3868 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3869 | |
| 3870 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3871 | return -EINVAL; |
| 3872 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3873 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3874 | nl80211_mesh_setup_params_policy)) |
| 3875 | return -EINVAL; |
| 3876 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3877 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 3878 | setup->sync_method = |
| 3879 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 3880 | IEEE80211_SYNC_METHOD_VENDOR : |
| 3881 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 3882 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3883 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3884 | setup->path_sel_proto = |
| 3885 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3886 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3887 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3888 | |
| 3889 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3890 | setup->path_metric = |
| 3891 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3892 | IEEE80211_PATH_METRIC_VENDOR : |
| 3893 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3894 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3895 | |
| 3896 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3897 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3898 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3899 | if (!is_valid_ie_attr(ieattr)) |
| 3900 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3901 | setup->ie = nla_data(ieattr); |
| 3902 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3903 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3904 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3905 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3906 | |
| 3907 | return 0; |
| 3908 | } |
| 3909 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3910 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3911 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3912 | { |
| 3913 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3914 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3915 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3916 | struct mesh_config cfg; |
| 3917 | u32 mask; |
| 3918 | int err; |
| 3919 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3920 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3921 | return -EOPNOTSUPP; |
| 3922 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3923 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3924 | return -EOPNOTSUPP; |
| 3925 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3926 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3927 | if (err) |
| 3928 | return err; |
| 3929 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3930 | wdev_lock(wdev); |
| 3931 | if (!wdev->mesh_id_len) |
| 3932 | err = -ENOLINK; |
| 3933 | |
| 3934 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3935 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3936 | mask, &cfg); |
| 3937 | |
| 3938 | wdev_unlock(wdev); |
| 3939 | |
| 3940 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3941 | } |
| 3942 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3943 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3944 | { |
| 3945 | struct sk_buff *msg; |
| 3946 | void *hdr = NULL; |
| 3947 | struct nlattr *nl_reg_rules; |
| 3948 | unsigned int i; |
| 3949 | int err = -EINVAL; |
| 3950 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3951 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3952 | |
| 3953 | if (!cfg80211_regdomain) |
| 3954 | goto out; |
| 3955 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3956 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3957 | if (!msg) { |
| 3958 | err = -ENOBUFS; |
| 3959 | goto out; |
| 3960 | } |
| 3961 | |
| 3962 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3963 | NL80211_CMD_GET_REG); |
| 3964 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3965 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3966 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3967 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 3968 | cfg80211_regdomain->alpha2) || |
| 3969 | (cfg80211_regdomain->dfs_region && |
| 3970 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, |
| 3971 | cfg80211_regdomain->dfs_region))) |
| 3972 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3973 | |
| 3974 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3975 | if (!nl_reg_rules) |
| 3976 | goto nla_put_failure; |
| 3977 | |
| 3978 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3979 | struct nlattr *nl_reg_rule; |
| 3980 | const struct ieee80211_reg_rule *reg_rule; |
| 3981 | const struct ieee80211_freq_range *freq_range; |
| 3982 | const struct ieee80211_power_rule *power_rule; |
| 3983 | |
| 3984 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3985 | freq_range = ®_rule->freq_range; |
| 3986 | power_rule = ®_rule->power_rule; |
| 3987 | |
| 3988 | nl_reg_rule = nla_nest_start(msg, i); |
| 3989 | if (!nl_reg_rule) |
| 3990 | goto nla_put_failure; |
| 3991 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3992 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3993 | reg_rule->flags) || |
| 3994 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3995 | freq_range->start_freq_khz) || |
| 3996 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3997 | freq_range->end_freq_khz) || |
| 3998 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3999 | freq_range->max_bandwidth_khz) || |
| 4000 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4001 | power_rule->max_antenna_gain) || |
| 4002 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4003 | power_rule->max_eirp)) |
| 4004 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4005 | |
| 4006 | nla_nest_end(msg, nl_reg_rule); |
| 4007 | } |
| 4008 | |
| 4009 | nla_nest_end(msg, nl_reg_rules); |
| 4010 | |
| 4011 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 4012 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4013 | goto out; |
| 4014 | |
| 4015 | nla_put_failure: |
| 4016 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4017 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4018 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4019 | err = -EMSGSIZE; |
| 4020 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4021 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4022 | return err; |
| 4023 | } |
| 4024 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4025 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4026 | { |
| 4027 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4028 | struct nlattr *nl_reg_rule; |
| 4029 | char *alpha2 = NULL; |
| 4030 | int rem_reg_rules = 0, r = 0; |
| 4031 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4032 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4033 | struct ieee80211_regdomain *rd = NULL; |
| 4034 | |
| 4035 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4036 | return -EINVAL; |
| 4037 | |
| 4038 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4039 | return -EINVAL; |
| 4040 | |
| 4041 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4042 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4043 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4044 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4045 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4046 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4047 | rem_reg_rules) { |
| 4048 | num_rules++; |
| 4049 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4050 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4051 | } |
| 4052 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4053 | mutex_lock(&cfg80211_mutex); |
| 4054 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4055 | if (!reg_is_valid_request(alpha2)) { |
| 4056 | r = -EINVAL; |
| 4057 | goto bad_reg; |
| 4058 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4059 | |
| 4060 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 4061 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 4062 | |
| 4063 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4064 | if (!rd) { |
| 4065 | r = -ENOMEM; |
| 4066 | goto bad_reg; |
| 4067 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4068 | |
| 4069 | rd->n_reg_rules = num_rules; |
| 4070 | rd->alpha2[0] = alpha2[0]; |
| 4071 | rd->alpha2[1] = alpha2[1]; |
| 4072 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4073 | /* |
| 4074 | * Disable DFS master mode if the DFS region was |
| 4075 | * not supported or known on this kernel. |
| 4076 | */ |
| 4077 | if (reg_supported_dfs_region(dfs_region)) |
| 4078 | rd->dfs_region = dfs_region; |
| 4079 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4080 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4081 | rem_reg_rules) { |
| 4082 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 4083 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4084 | reg_rule_policy); |
| 4085 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4086 | if (r) |
| 4087 | goto bad_reg; |
| 4088 | |
| 4089 | rule_idx++; |
| 4090 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4091 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4092 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4093 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4094 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | BUG_ON(rule_idx != num_rules); |
| 4098 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4099 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4100 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4101 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4102 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4103 | return r; |
| 4104 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4105 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4106 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4107 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4108 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4109 | } |
| 4110 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4111 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4112 | { |
| 4113 | struct nlattr *attr1, *attr2; |
| 4114 | int n_channels = 0, tmp1, tmp2; |
| 4115 | |
| 4116 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4117 | n_channels++; |
| 4118 | /* |
| 4119 | * Some hardware has a limited channel list for |
| 4120 | * scanning, and it is pretty much nonsensical |
| 4121 | * to scan for a channel twice, so disallow that |
| 4122 | * and don't require drivers to check that the |
| 4123 | * channel list they get isn't longer than what |
| 4124 | * they can scan, as long as they can scan all |
| 4125 | * the channels they registered at once. |
| 4126 | */ |
| 4127 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4128 | if (attr1 != attr2 && |
| 4129 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4130 | return 0; |
| 4131 | } |
| 4132 | |
| 4133 | return n_channels; |
| 4134 | } |
| 4135 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4136 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4137 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4138 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4139 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4140 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4141 | struct nlattr *attr; |
| 4142 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4143 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4144 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4145 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4146 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4147 | return -EINVAL; |
| 4148 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4149 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4150 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4151 | if (!rdev->ops->scan) |
| 4152 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4153 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4154 | if (rdev->scan_req) |
| 4155 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4156 | |
| 4157 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4158 | n_channels = validate_scan_freqs( |
| 4159 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4160 | if (!n_channels) |
| 4161 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4162 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4163 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4164 | n_channels = 0; |
| 4165 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4166 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4167 | if (wiphy->bands[band]) |
| 4168 | n_channels += wiphy->bands[band]->n_channels; |
| 4169 | } |
| 4170 | |
| 4171 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4172 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4173 | n_ssids++; |
| 4174 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4175 | if (n_ssids > wiphy->max_scan_ssids) |
| 4176 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4177 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4178 | if (info->attrs[NL80211_ATTR_IE]) |
| 4179 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4180 | else |
| 4181 | ie_len = 0; |
| 4182 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4183 | if (ie_len > wiphy->max_scan_ie_len) |
| 4184 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4185 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4186 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4187 | + sizeof(*request->ssids) * n_ssids |
| 4188 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4189 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4190 | if (!request) |
| 4191 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4192 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4193 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4194 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4195 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4196 | if (ie_len) { |
| 4197 | if (request->ssids) |
| 4198 | request->ie = (void *)(request->ssids + n_ssids); |
| 4199 | else |
| 4200 | request->ie = (void *)(request->channels + n_channels); |
| 4201 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4202 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4203 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4204 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4205 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4206 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4207 | struct ieee80211_channel *chan; |
| 4208 | |
| 4209 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4210 | |
| 4211 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4212 | err = -EINVAL; |
| 4213 | goto out_free; |
| 4214 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4215 | |
| 4216 | /* ignore disabled channels */ |
| 4217 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4218 | continue; |
| 4219 | |
| 4220 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4221 | i++; |
| 4222 | } |
| 4223 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4224 | enum ieee80211_band band; |
| 4225 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4226 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4227 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4228 | int j; |
| 4229 | if (!wiphy->bands[band]) |
| 4230 | continue; |
| 4231 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4232 | struct ieee80211_channel *chan; |
| 4233 | |
| 4234 | chan = &wiphy->bands[band]->channels[j]; |
| 4235 | |
| 4236 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4237 | continue; |
| 4238 | |
| 4239 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4240 | i++; |
| 4241 | } |
| 4242 | } |
| 4243 | } |
| 4244 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4245 | if (!i) { |
| 4246 | err = -EINVAL; |
| 4247 | goto out_free; |
| 4248 | } |
| 4249 | |
| 4250 | request->n_channels = i; |
| 4251 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4252 | i = 0; |
| 4253 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4254 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4255 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4256 | err = -EINVAL; |
| 4257 | goto out_free; |
| 4258 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4259 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4260 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4261 | i++; |
| 4262 | } |
| 4263 | } |
| 4264 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4265 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4266 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4267 | memcpy((void *)request->ie, |
| 4268 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4269 | request->ie_len); |
| 4270 | } |
| 4271 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4272 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4273 | if (wiphy->bands[i]) |
| 4274 | request->rates[i] = |
| 4275 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4276 | |
| 4277 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4278 | nla_for_each_nested(attr, |
| 4279 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4280 | tmp) { |
| 4281 | enum ieee80211_band band = nla_type(attr); |
| 4282 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4283 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4284 | err = -EINVAL; |
| 4285 | goto out_free; |
| 4286 | } |
| 4287 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4288 | nla_data(attr), |
| 4289 | nla_len(attr), |
| 4290 | &request->rates[band]); |
| 4291 | if (err) |
| 4292 | goto out_free; |
| 4293 | } |
| 4294 | } |
| 4295 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4296 | request->no_cck = |
| 4297 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4298 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4299 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4300 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4301 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4302 | rdev->scan_req = request; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4303 | err = rdev->ops->scan(&rdev->wiphy, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4304 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4305 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 4306 | nl80211_send_scan_start(rdev, wdev); |
| 4307 | if (wdev->netdev) |
| 4308 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4309 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4310 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4311 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4312 | kfree(request); |
| 4313 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4314 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4315 | return err; |
| 4316 | } |
| 4317 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4318 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4319 | struct genl_info *info) |
| 4320 | { |
| 4321 | struct cfg80211_sched_scan_request *request; |
| 4322 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4323 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4324 | struct nlattr *attr; |
| 4325 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4326 | 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] | 4327 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4328 | enum ieee80211_band band; |
| 4329 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4330 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4331 | |
| 4332 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4333 | !rdev->ops->sched_scan_start) |
| 4334 | return -EOPNOTSUPP; |
| 4335 | |
| 4336 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4337 | return -EINVAL; |
| 4338 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4339 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4340 | return -EINVAL; |
| 4341 | |
| 4342 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4343 | if (interval == 0) |
| 4344 | return -EINVAL; |
| 4345 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4346 | wiphy = &rdev->wiphy; |
| 4347 | |
| 4348 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4349 | n_channels = validate_scan_freqs( |
| 4350 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4351 | if (!n_channels) |
| 4352 | return -EINVAL; |
| 4353 | } else { |
| 4354 | n_channels = 0; |
| 4355 | |
| 4356 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4357 | if (wiphy->bands[band]) |
| 4358 | n_channels += wiphy->bands[band]->n_channels; |
| 4359 | } |
| 4360 | |
| 4361 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4362 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4363 | tmp) |
| 4364 | n_ssids++; |
| 4365 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4366 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4367 | return -EINVAL; |
| 4368 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4369 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4370 | nla_for_each_nested(attr, |
| 4371 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4372 | tmp) |
| 4373 | n_match_sets++; |
| 4374 | |
| 4375 | if (n_match_sets > wiphy->max_match_sets) |
| 4376 | return -EINVAL; |
| 4377 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4378 | if (info->attrs[NL80211_ATTR_IE]) |
| 4379 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4380 | else |
| 4381 | ie_len = 0; |
| 4382 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4383 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4384 | return -EINVAL; |
| 4385 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4386 | mutex_lock(&rdev->sched_scan_mtx); |
| 4387 | |
| 4388 | if (rdev->sched_scan_req) { |
| 4389 | err = -EINPROGRESS; |
| 4390 | goto out; |
| 4391 | } |
| 4392 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4393 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4394 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4395 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4396 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4397 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4398 | if (!request) { |
| 4399 | err = -ENOMEM; |
| 4400 | goto out; |
| 4401 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4402 | |
| 4403 | if (n_ssids) |
| 4404 | request->ssids = (void *)&request->channels[n_channels]; |
| 4405 | request->n_ssids = n_ssids; |
| 4406 | if (ie_len) { |
| 4407 | if (request->ssids) |
| 4408 | request->ie = (void *)(request->ssids + n_ssids); |
| 4409 | else |
| 4410 | request->ie = (void *)(request->channels + n_channels); |
| 4411 | } |
| 4412 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4413 | if (n_match_sets) { |
| 4414 | if (request->ie) |
| 4415 | request->match_sets = (void *)(request->ie + ie_len); |
| 4416 | else if (request->ssids) |
| 4417 | request->match_sets = |
| 4418 | (void *)(request->ssids + n_ssids); |
| 4419 | else |
| 4420 | request->match_sets = |
| 4421 | (void *)(request->channels + n_channels); |
| 4422 | } |
| 4423 | request->n_match_sets = n_match_sets; |
| 4424 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4425 | i = 0; |
| 4426 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4427 | /* user specified, bail out if channel not found */ |
| 4428 | nla_for_each_nested(attr, |
| 4429 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4430 | tmp) { |
| 4431 | struct ieee80211_channel *chan; |
| 4432 | |
| 4433 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4434 | |
| 4435 | if (!chan) { |
| 4436 | err = -EINVAL; |
| 4437 | goto out_free; |
| 4438 | } |
| 4439 | |
| 4440 | /* ignore disabled channels */ |
| 4441 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4442 | continue; |
| 4443 | |
| 4444 | request->channels[i] = chan; |
| 4445 | i++; |
| 4446 | } |
| 4447 | } else { |
| 4448 | /* all channels */ |
| 4449 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4450 | int j; |
| 4451 | if (!wiphy->bands[band]) |
| 4452 | continue; |
| 4453 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4454 | struct ieee80211_channel *chan; |
| 4455 | |
| 4456 | chan = &wiphy->bands[band]->channels[j]; |
| 4457 | |
| 4458 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4459 | continue; |
| 4460 | |
| 4461 | request->channels[i] = chan; |
| 4462 | i++; |
| 4463 | } |
| 4464 | } |
| 4465 | } |
| 4466 | |
| 4467 | if (!i) { |
| 4468 | err = -EINVAL; |
| 4469 | goto out_free; |
| 4470 | } |
| 4471 | |
| 4472 | request->n_channels = i; |
| 4473 | |
| 4474 | i = 0; |
| 4475 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4476 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4477 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4478 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4479 | err = -EINVAL; |
| 4480 | goto out_free; |
| 4481 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4482 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4483 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4484 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4485 | i++; |
| 4486 | } |
| 4487 | } |
| 4488 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4489 | i = 0; |
| 4490 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4491 | nla_for_each_nested(attr, |
| 4492 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4493 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4494 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4495 | |
| 4496 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4497 | nla_data(attr), nla_len(attr), |
| 4498 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 4499 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4500 | if (ssid) { |
| 4501 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4502 | err = -EINVAL; |
| 4503 | goto out_free; |
| 4504 | } |
| 4505 | memcpy(request->match_sets[i].ssid.ssid, |
| 4506 | nla_data(ssid), nla_len(ssid)); |
| 4507 | request->match_sets[i].ssid.ssid_len = |
| 4508 | nla_len(ssid); |
| 4509 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4510 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 4511 | if (rssi) |
| 4512 | request->rssi_thold = nla_get_u32(rssi); |
| 4513 | else |
| 4514 | request->rssi_thold = |
| 4515 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4516 | i++; |
| 4517 | } |
| 4518 | } |
| 4519 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4520 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4521 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4522 | memcpy((void *)request->ie, |
| 4523 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4524 | request->ie_len); |
| 4525 | } |
| 4526 | |
| 4527 | request->dev = dev; |
| 4528 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4529 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4530 | |
| 4531 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 4532 | if (!err) { |
| 4533 | rdev->sched_scan_req = request; |
| 4534 | nl80211_send_sched_scan(rdev, dev, |
| 4535 | NL80211_CMD_START_SCHED_SCAN); |
| 4536 | goto out; |
| 4537 | } |
| 4538 | |
| 4539 | out_free: |
| 4540 | kfree(request); |
| 4541 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4542 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4543 | return err; |
| 4544 | } |
| 4545 | |
| 4546 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4547 | struct genl_info *info) |
| 4548 | { |
| 4549 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4550 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4551 | |
| 4552 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4553 | !rdev->ops->sched_scan_stop) |
| 4554 | return -EOPNOTSUPP; |
| 4555 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4556 | mutex_lock(&rdev->sched_scan_mtx); |
| 4557 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4558 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4559 | |
| 4560 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4561 | } |
| 4562 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4563 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4564 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4565 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4566 | struct wireless_dev *wdev, |
| 4567 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4568 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4569 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4570 | void *hdr; |
| 4571 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4572 | |
| 4573 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4574 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4575 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4576 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4577 | if (!hdr) |
| 4578 | return -1; |
| 4579 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4580 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4581 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4582 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 4583 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 4584 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4585 | |
| 4586 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4587 | if (!bss) |
| 4588 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4589 | if ((!is_zero_ether_addr(res->bssid) && |
| 4590 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) || |
| 4591 | (res->information_elements && res->len_information_elements && |
| 4592 | nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4593 | res->len_information_elements, |
| 4594 | res->information_elements)) || |
| 4595 | (res->beacon_ies && res->len_beacon_ies && |
| 4596 | res->beacon_ies != res->information_elements && |
| 4597 | nla_put(msg, NL80211_BSS_BEACON_IES, |
| 4598 | res->len_beacon_ies, res->beacon_ies))) |
| 4599 | goto nla_put_failure; |
| 4600 | if (res->tsf && |
| 4601 | nla_put_u64(msg, NL80211_BSS_TSF, res->tsf)) |
| 4602 | goto nla_put_failure; |
| 4603 | if (res->beacon_interval && |
| 4604 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 4605 | goto nla_put_failure; |
| 4606 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 4607 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 4608 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4609 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 4610 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4611 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4612 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4613 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4614 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 4615 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4616 | break; |
| 4617 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4618 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 4619 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4620 | break; |
| 4621 | default: |
| 4622 | break; |
| 4623 | } |
| 4624 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4625 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4626 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4627 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4628 | if (intbss == wdev->current_bss && |
| 4629 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4630 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 4631 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4632 | break; |
| 4633 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4634 | if (intbss == wdev->current_bss && |
| 4635 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4636 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 4637 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4638 | break; |
| 4639 | default: |
| 4640 | break; |
| 4641 | } |
| 4642 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4643 | nla_nest_end(msg, bss); |
| 4644 | |
| 4645 | return genlmsg_end(msg, hdr); |
| 4646 | |
| 4647 | nla_put_failure: |
| 4648 | genlmsg_cancel(msg, hdr); |
| 4649 | return -EMSGSIZE; |
| 4650 | } |
| 4651 | |
| 4652 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4653 | struct netlink_callback *cb) |
| 4654 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4655 | struct cfg80211_registered_device *rdev; |
| 4656 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4657 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4658 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4659 | int start = cb->args[1], idx = 0; |
| 4660 | int err; |
| 4661 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4662 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4663 | if (err) |
| 4664 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4665 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4666 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4667 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4668 | wdev_lock(wdev); |
| 4669 | spin_lock_bh(&rdev->bss_lock); |
| 4670 | cfg80211_bss_expire(rdev); |
| 4671 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4672 | cb->seq = rdev->bss_generation; |
| 4673 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4674 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4675 | if (++idx <= start) |
| 4676 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4677 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4678 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4679 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4680 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4681 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4682 | } |
| 4683 | } |
| 4684 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4685 | spin_unlock_bh(&rdev->bss_lock); |
| 4686 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4687 | |
| 4688 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4689 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4690 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4691 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4692 | } |
| 4693 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4694 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4695 | int flags, struct net_device *dev, |
| 4696 | struct survey_info *survey) |
| 4697 | { |
| 4698 | void *hdr; |
| 4699 | struct nlattr *infoattr; |
| 4700 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4701 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4702 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4703 | if (!hdr) |
| 4704 | return -ENOMEM; |
| 4705 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4706 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 4707 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4708 | |
| 4709 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4710 | if (!infoattr) |
| 4711 | goto nla_put_failure; |
| 4712 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4713 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4714 | survey->channel->center_freq)) |
| 4715 | goto nla_put_failure; |
| 4716 | |
| 4717 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 4718 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 4719 | goto nla_put_failure; |
| 4720 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 4721 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 4722 | goto nla_put_failure; |
| 4723 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 4724 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4725 | survey->channel_time)) |
| 4726 | goto nla_put_failure; |
| 4727 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 4728 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4729 | survey->channel_time_busy)) |
| 4730 | goto nla_put_failure; |
| 4731 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 4732 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4733 | survey->channel_time_ext_busy)) |
| 4734 | goto nla_put_failure; |
| 4735 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 4736 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4737 | survey->channel_time_rx)) |
| 4738 | goto nla_put_failure; |
| 4739 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 4740 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4741 | survey->channel_time_tx)) |
| 4742 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4743 | |
| 4744 | nla_nest_end(msg, infoattr); |
| 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_survey(struct sk_buff *skb, |
| 4754 | struct netlink_callback *cb) |
| 4755 | { |
| 4756 | struct survey_info survey; |
| 4757 | struct cfg80211_registered_device *dev; |
| 4758 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4759 | int survey_idx = cb->args[1]; |
| 4760 | int res; |
| 4761 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4762 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4763 | if (res) |
| 4764 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4765 | |
| 4766 | if (!dev->ops->dump_survey) { |
| 4767 | res = -EOPNOTSUPP; |
| 4768 | goto out_err; |
| 4769 | } |
| 4770 | |
| 4771 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4772 | struct ieee80211_channel *chan; |
| 4773 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4774 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4775 | &survey); |
| 4776 | if (res == -ENOENT) |
| 4777 | break; |
| 4778 | if (res) |
| 4779 | goto out_err; |
| 4780 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4781 | /* Survey without a channel doesn't make sense */ |
| 4782 | if (!survey.channel) { |
| 4783 | res = -EINVAL; |
| 4784 | goto out; |
| 4785 | } |
| 4786 | |
| 4787 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4788 | survey.channel->center_freq); |
| 4789 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4790 | survey_idx++; |
| 4791 | continue; |
| 4792 | } |
| 4793 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4794 | if (nl80211_send_survey(skb, |
| 4795 | NETLINK_CB(cb->skb).pid, |
| 4796 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4797 | netdev, |
| 4798 | &survey) < 0) |
| 4799 | goto out; |
| 4800 | survey_idx++; |
| 4801 | } |
| 4802 | |
| 4803 | out: |
| 4804 | cb->args[1] = survey_idx; |
| 4805 | res = skb->len; |
| 4806 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4807 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4808 | return res; |
| 4809 | } |
| 4810 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4811 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4812 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4813 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4814 | } |
| 4815 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4816 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4817 | { |
| 4818 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4819 | NL80211_WPA_VERSION_2)); |
| 4820 | } |
| 4821 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4822 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4823 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4824 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4825 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4826 | struct ieee80211_channel *chan; |
| 4827 | const u8 *bssid, *ssid, *ie = NULL; |
| 4828 | int err, ssid_len, ie_len = 0; |
| 4829 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4830 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4831 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4832 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4833 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4834 | return -EINVAL; |
| 4835 | |
| 4836 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4837 | return -EINVAL; |
| 4838 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4839 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4840 | return -EINVAL; |
| 4841 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4842 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4843 | return -EINVAL; |
| 4844 | |
| 4845 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4846 | return -EINVAL; |
| 4847 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4848 | err = nl80211_parse_key(info, &key); |
| 4849 | if (err) |
| 4850 | return err; |
| 4851 | |
| 4852 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4853 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4854 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4855 | if (!key.p.key || !key.p.key_len) |
| 4856 | return -EINVAL; |
| 4857 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4858 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4859 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4860 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4861 | return -EINVAL; |
| 4862 | if (key.idx > 4) |
| 4863 | return -EINVAL; |
| 4864 | } else { |
| 4865 | key.p.key_len = 0; |
| 4866 | key.p.key = NULL; |
| 4867 | } |
| 4868 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4869 | if (key.idx >= 0) { |
| 4870 | int i; |
| 4871 | bool ok = false; |
| 4872 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4873 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4874 | ok = true; |
| 4875 | break; |
| 4876 | } |
| 4877 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4878 | if (!ok) |
| 4879 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4880 | } |
| 4881 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4882 | if (!rdev->ops->auth) |
| 4883 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4884 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4885 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4886 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4887 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4888 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4889 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4890 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4891 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4892 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4893 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4894 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4895 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4896 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4897 | |
| 4898 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4899 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4900 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4901 | } |
| 4902 | |
| 4903 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4904 | if (!nl80211_valid_auth_type(auth_type)) |
| 4905 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4906 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4907 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4908 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 4909 | /* |
| 4910 | * Since we no longer track auth state, ignore |
| 4911 | * requests to only change local state. |
| 4912 | */ |
| 4913 | if (local_state_change) |
| 4914 | return 0; |
| 4915 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4916 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4917 | ssid, ssid_len, ie, ie_len, |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 4918 | key.p.key, key.p.key_len, key.idx); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4919 | } |
| 4920 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4921 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4922 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4923 | struct cfg80211_crypto_settings *settings, |
| 4924 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4925 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4926 | memset(settings, 0, sizeof(*settings)); |
| 4927 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4928 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4929 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4930 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4931 | u16 proto; |
| 4932 | proto = nla_get_u16( |
| 4933 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4934 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4935 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4936 | proto != ETH_P_PAE) |
| 4937 | return -EINVAL; |
| 4938 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4939 | settings->control_port_no_encrypt = true; |
| 4940 | } else |
| 4941 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4942 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4943 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4944 | void *data; |
| 4945 | int len, i; |
| 4946 | |
| 4947 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4948 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4949 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4950 | |
| 4951 | if (len % sizeof(u32)) |
| 4952 | return -EINVAL; |
| 4953 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4954 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4955 | return -EINVAL; |
| 4956 | |
| 4957 | memcpy(settings->ciphers_pairwise, data, len); |
| 4958 | |
| 4959 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4960 | if (!cfg80211_supported_cipher_suite( |
| 4961 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4962 | settings->ciphers_pairwise[i])) |
| 4963 | return -EINVAL; |
| 4964 | } |
| 4965 | |
| 4966 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4967 | settings->cipher_group = |
| 4968 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4969 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 4970 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4971 | return -EINVAL; |
| 4972 | } |
| 4973 | |
| 4974 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4975 | settings->wpa_versions = |
| 4976 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4977 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4978 | return -EINVAL; |
| 4979 | } |
| 4980 | |
| 4981 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4982 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 4983 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4984 | |
| 4985 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4986 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4987 | settings->n_akm_suites = len / sizeof(u32); |
| 4988 | |
| 4989 | if (len % sizeof(u32)) |
| 4990 | return -EINVAL; |
| 4991 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 4992 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4993 | return -EINVAL; |
| 4994 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4995 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | return 0; |
| 4999 | } |
| 5000 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5001 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5002 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5003 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5004 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5005 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5006 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5007 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5008 | int err, ssid_len, ie_len = 0; |
| 5009 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5010 | u32 flags = 0; |
| 5011 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 5012 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5013 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5014 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5015 | return -EINVAL; |
| 5016 | |
| 5017 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5018 | !info->attrs[NL80211_ATTR_SSID] || |
| 5019 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5020 | return -EINVAL; |
| 5021 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5022 | if (!rdev->ops->assoc) |
| 5023 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5024 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5025 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5026 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5027 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5028 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5029 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5030 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5031 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 5032 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5033 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5034 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5035 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5036 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5037 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5038 | |
| 5039 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5040 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5041 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5042 | } |
| 5043 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5044 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5045 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5046 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5047 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5048 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5049 | else if (mfp != NL80211_MFP_NO) |
| 5050 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5051 | } |
| 5052 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5053 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5054 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5055 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5056 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5057 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5058 | |
| 5059 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5060 | ht_capa_mask = |
| 5061 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5062 | |
| 5063 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5064 | if (!ht_capa_mask) |
| 5065 | return -EINVAL; |
| 5066 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5067 | } |
| 5068 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5069 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5070 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5071 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5072 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5073 | &crypto, flags, ht_capa, |
| 5074 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5075 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5076 | return err; |
| 5077 | } |
| 5078 | |
| 5079 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5080 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5082 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5083 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5084 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5085 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5086 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5087 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5088 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5089 | return -EINVAL; |
| 5090 | |
| 5091 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5092 | return -EINVAL; |
| 5093 | |
| 5094 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5095 | return -EINVAL; |
| 5096 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5097 | if (!rdev->ops->deauth) |
| 5098 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5099 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5100 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5101 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5102 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5103 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5104 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5105 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5106 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5107 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5108 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5109 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5110 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5111 | |
| 5112 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5113 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5114 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5115 | } |
| 5116 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5117 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5118 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5119 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5120 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5124 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5125 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5126 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5127 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5128 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5129 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5130 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5131 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5132 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5133 | return -EINVAL; |
| 5134 | |
| 5135 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5136 | return -EINVAL; |
| 5137 | |
| 5138 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5139 | return -EINVAL; |
| 5140 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5141 | if (!rdev->ops->disassoc) |
| 5142 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5143 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5144 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5145 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5146 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5147 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5148 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5149 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5150 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5151 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5152 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5153 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5154 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5155 | |
| 5156 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5157 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5158 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5159 | } |
| 5160 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5161 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5162 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5163 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5164 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5165 | } |
| 5166 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5167 | static bool |
| 5168 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5169 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5170 | int rateval) |
| 5171 | { |
| 5172 | struct wiphy *wiphy = &rdev->wiphy; |
| 5173 | bool found = false; |
| 5174 | int band, i; |
| 5175 | |
| 5176 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5177 | struct ieee80211_supported_band *sband; |
| 5178 | |
| 5179 | sband = wiphy->bands[band]; |
| 5180 | if (!sband) |
| 5181 | continue; |
| 5182 | |
| 5183 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5184 | if (sband->bitrates[i].bitrate == rateval) { |
| 5185 | mcast_rate[band] = i + 1; |
| 5186 | found = true; |
| 5187 | break; |
| 5188 | } |
| 5189 | } |
| 5190 | } |
| 5191 | |
| 5192 | return found; |
| 5193 | } |
| 5194 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5195 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5196 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5197 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5198 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5199 | struct cfg80211_ibss_params ibss; |
| 5200 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5201 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5202 | int err; |
| 5203 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5204 | memset(&ibss, 0, sizeof(ibss)); |
| 5205 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5206 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5207 | return -EINVAL; |
| 5208 | |
| 5209 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5210 | !info->attrs[NL80211_ATTR_SSID] || |
| 5211 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5212 | return -EINVAL; |
| 5213 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5214 | ibss.beacon_interval = 100; |
| 5215 | |
| 5216 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5217 | ibss.beacon_interval = |
| 5218 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5219 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5220 | return -EINVAL; |
| 5221 | } |
| 5222 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5223 | if (!rdev->ops->join_ibss) |
| 5224 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5225 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5226 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5227 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5228 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5229 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5230 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5231 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5232 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5233 | |
| 5234 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5235 | return -EINVAL; |
| 5236 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5237 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5238 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5239 | |
| 5240 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5241 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5242 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5243 | } |
| 5244 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5245 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5246 | enum nl80211_channel_type channel_type; |
| 5247 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5248 | if (!nl80211_valid_channel_type(info, &channel_type)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5249 | return -EINVAL; |
| 5250 | |
| 5251 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5252 | !(wiphy->features & NL80211_FEATURE_HT_IBSS)) |
| 5253 | return -EINVAL; |
| 5254 | |
| 5255 | ibss.channel_type = channel_type; |
| 5256 | } else { |
| 5257 | ibss.channel_type = NL80211_CHAN_NO_HT; |
| 5258 | } |
| 5259 | |
| 5260 | ibss.channel = rdev_freq_to_chan(rdev, |
| 5261 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 5262 | ibss.channel_type); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5263 | if (!ibss.channel || |
| 5264 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5265 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5266 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5267 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5268 | /* Both channels should be able to initiate communication */ |
| 5269 | if ((ibss.channel_type == NL80211_CHAN_HT40PLUS || |
| 5270 | ibss.channel_type == NL80211_CHAN_HT40MINUS) && |
| 5271 | !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel, |
| 5272 | ibss.channel_type)) |
| 5273 | return -EINVAL; |
| 5274 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5275 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5276 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5277 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5278 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5279 | u8 *rates = |
| 5280 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5281 | int n_rates = |
| 5282 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5283 | struct ieee80211_supported_band *sband = |
| 5284 | wiphy->bands[ibss.channel->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5285 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5286 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5287 | &ibss.basic_rates); |
| 5288 | if (err) |
| 5289 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5290 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5291 | |
| 5292 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5293 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5294 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5295 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5296 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5297 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5298 | connkeys = nl80211_parse_connkeys(rdev, |
| 5299 | info->attrs[NL80211_ATTR_KEYS]); |
| 5300 | if (IS_ERR(connkeys)) |
| 5301 | return PTR_ERR(connkeys); |
| 5302 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5303 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5304 | ibss.control_port = |
| 5305 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5306 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5307 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5308 | if (err) |
| 5309 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5310 | return err; |
| 5311 | } |
| 5312 | |
| 5313 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5314 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5315 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5316 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5317 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5318 | if (!rdev->ops->leave_ibss) |
| 5319 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5320 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5321 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5322 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5323 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5324 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5325 | } |
| 5326 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5327 | #ifdef CONFIG_NL80211_TESTMODE |
| 5328 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5329 | .name = "testmode", |
| 5330 | }; |
| 5331 | |
| 5332 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5333 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5334 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5335 | int err; |
| 5336 | |
| 5337 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5338 | return -EINVAL; |
| 5339 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5340 | err = -EOPNOTSUPP; |
| 5341 | if (rdev->ops->testmode_cmd) { |
| 5342 | rdev->testmode_info = info; |
| 5343 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 5344 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5345 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5346 | rdev->testmode_info = NULL; |
| 5347 | } |
| 5348 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5349 | return err; |
| 5350 | } |
| 5351 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5352 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5353 | struct netlink_callback *cb) |
| 5354 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5355 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5356 | int err; |
| 5357 | long phy_idx; |
| 5358 | void *data = NULL; |
| 5359 | int data_len = 0; |
| 5360 | |
| 5361 | if (cb->args[0]) { |
| 5362 | /* |
| 5363 | * 0 is a valid index, but not valid for args[0], |
| 5364 | * so we need to offset by 1. |
| 5365 | */ |
| 5366 | phy_idx = cb->args[0] - 1; |
| 5367 | } else { |
| 5368 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5369 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5370 | nl80211_policy); |
| 5371 | if (err) |
| 5372 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5373 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5374 | mutex_lock(&cfg80211_mutex); |
| 5375 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 5376 | nl80211_fam.attrbuf); |
| 5377 | if (IS_ERR(rdev)) { |
| 5378 | mutex_unlock(&cfg80211_mutex); |
| 5379 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5380 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5381 | phy_idx = rdev->wiphy_idx; |
| 5382 | rdev = NULL; |
| 5383 | mutex_unlock(&cfg80211_mutex); |
| 5384 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5385 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 5386 | cb->args[1] = |
| 5387 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 5388 | } |
| 5389 | |
| 5390 | if (cb->args[1]) { |
| 5391 | data = nla_data((void *)cb->args[1]); |
| 5392 | data_len = nla_len((void *)cb->args[1]); |
| 5393 | } |
| 5394 | |
| 5395 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5396 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 5397 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5398 | mutex_unlock(&cfg80211_mutex); |
| 5399 | return -ENOENT; |
| 5400 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5401 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5402 | mutex_unlock(&cfg80211_mutex); |
| 5403 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5404 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5405 | err = -EOPNOTSUPP; |
| 5406 | goto out_err; |
| 5407 | } |
| 5408 | |
| 5409 | while (1) { |
| 5410 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 5411 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5412 | NL80211_CMD_TESTMODE); |
| 5413 | struct nlattr *tmdata; |
| 5414 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5415 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5416 | genlmsg_cancel(skb, hdr); |
| 5417 | break; |
| 5418 | } |
| 5419 | |
| 5420 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5421 | if (!tmdata) { |
| 5422 | genlmsg_cancel(skb, hdr); |
| 5423 | break; |
| 5424 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5425 | err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb, |
| 5426 | data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5427 | nla_nest_end(skb, tmdata); |
| 5428 | |
| 5429 | if (err == -ENOBUFS || err == -ENOENT) { |
| 5430 | genlmsg_cancel(skb, hdr); |
| 5431 | break; |
| 5432 | } else if (err) { |
| 5433 | genlmsg_cancel(skb, hdr); |
| 5434 | goto out_err; |
| 5435 | } |
| 5436 | |
| 5437 | genlmsg_end(skb, hdr); |
| 5438 | } |
| 5439 | |
| 5440 | err = skb->len; |
| 5441 | /* see above */ |
| 5442 | cb->args[0] = phy_idx + 1; |
| 5443 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5444 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5445 | return err; |
| 5446 | } |
| 5447 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5448 | static struct sk_buff * |
| 5449 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 5450 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 5451 | { |
| 5452 | struct sk_buff *skb; |
| 5453 | void *hdr; |
| 5454 | struct nlattr *data; |
| 5455 | |
| 5456 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5457 | if (!skb) |
| 5458 | return NULL; |
| 5459 | |
| 5460 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 5461 | if (!hdr) { |
| 5462 | kfree_skb(skb); |
| 5463 | return NULL; |
| 5464 | } |
| 5465 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5466 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 5467 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5468 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5469 | |
| 5470 | ((void **)skb->cb)[0] = rdev; |
| 5471 | ((void **)skb->cb)[1] = hdr; |
| 5472 | ((void **)skb->cb)[2] = data; |
| 5473 | |
| 5474 | return skb; |
| 5475 | |
| 5476 | nla_put_failure: |
| 5477 | kfree_skb(skb); |
| 5478 | return NULL; |
| 5479 | } |
| 5480 | |
| 5481 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5482 | int approxlen) |
| 5483 | { |
| 5484 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5485 | |
| 5486 | if (WARN_ON(!rdev->testmode_info)) |
| 5487 | return NULL; |
| 5488 | |
| 5489 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 5490 | rdev->testmode_info->snd_pid, |
| 5491 | rdev->testmode_info->snd_seq, |
| 5492 | GFP_KERNEL); |
| 5493 | } |
| 5494 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5495 | |
| 5496 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5497 | { |
| 5498 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5499 | void *hdr = ((void **)skb->cb)[1]; |
| 5500 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5501 | |
| 5502 | if (WARN_ON(!rdev->testmode_info)) { |
| 5503 | kfree_skb(skb); |
| 5504 | return -EINVAL; |
| 5505 | } |
| 5506 | |
| 5507 | nla_nest_end(skb, data); |
| 5508 | genlmsg_end(skb, hdr); |
| 5509 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5510 | } |
| 5511 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5512 | |
| 5513 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5514 | int approxlen, gfp_t gfp) |
| 5515 | { |
| 5516 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5517 | |
| 5518 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5519 | } |
| 5520 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5521 | |
| 5522 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5523 | { |
| 5524 | void *hdr = ((void **)skb->cb)[1]; |
| 5525 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5526 | |
| 5527 | nla_nest_end(skb, data); |
| 5528 | genlmsg_end(skb, hdr); |
| 5529 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5530 | } |
| 5531 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5532 | #endif |
| 5533 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5534 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5535 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5536 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5537 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5538 | struct cfg80211_connect_params connect; |
| 5539 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5540 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5541 | int err; |
| 5542 | |
| 5543 | memset(&connect, 0, sizeof(connect)); |
| 5544 | |
| 5545 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5546 | return -EINVAL; |
| 5547 | |
| 5548 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5549 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5550 | return -EINVAL; |
| 5551 | |
| 5552 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5553 | connect.auth_type = |
| 5554 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 5555 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 5556 | return -EINVAL; |
| 5557 | } else |
| 5558 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5559 | |
| 5560 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5561 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5562 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5563 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5564 | if (err) |
| 5565 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5566 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5567 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5568 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5569 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5570 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5571 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5572 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 5573 | connect.bg_scan_period = -1; |
| 5574 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 5575 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 5576 | connect.bg_scan_period = |
| 5577 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 5578 | } |
| 5579 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5580 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5581 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5582 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5583 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5584 | |
| 5585 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5586 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5587 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5588 | } |
| 5589 | |
| 5590 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5591 | connect.channel = |
| 5592 | ieee80211_get_channel(wiphy, |
| 5593 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5594 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5595 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5596 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5597 | } |
| 5598 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5599 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5600 | connkeys = nl80211_parse_connkeys(rdev, |
| 5601 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5602 | if (IS_ERR(connkeys)) |
| 5603 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5604 | } |
| 5605 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5606 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5607 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5608 | |
| 5609 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5610 | memcpy(&connect.ht_capa_mask, |
| 5611 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5612 | sizeof(connect.ht_capa_mask)); |
| 5613 | |
| 5614 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5615 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5616 | return -EINVAL; |
| 5617 | memcpy(&connect.ht_capa, |
| 5618 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5619 | sizeof(connect.ht_capa)); |
| 5620 | } |
| 5621 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5622 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5623 | if (err) |
| 5624 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5625 | return err; |
| 5626 | } |
| 5627 | |
| 5628 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5629 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5630 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5631 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5632 | u16 reason; |
| 5633 | |
| 5634 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5635 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5636 | else |
| 5637 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5638 | |
| 5639 | if (reason == 0) |
| 5640 | return -EINVAL; |
| 5641 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5642 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5643 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5644 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5645 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5646 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5647 | } |
| 5648 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5649 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5650 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5651 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5652 | struct net *net; |
| 5653 | int err; |
| 5654 | u32 pid; |
| 5655 | |
| 5656 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5657 | return -EINVAL; |
| 5658 | |
| 5659 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5660 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5661 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5662 | if (IS_ERR(net)) |
| 5663 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5664 | |
| 5665 | err = 0; |
| 5666 | |
| 5667 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5668 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5669 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5670 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5671 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5672 | return err; |
| 5673 | } |
| 5674 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5675 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5676 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5678 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5679 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5680 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5681 | struct cfg80211_pmksa pmksa; |
| 5682 | |
| 5683 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5684 | |
| 5685 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5686 | return -EINVAL; |
| 5687 | |
| 5688 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5689 | return -EINVAL; |
| 5690 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5691 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5692 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5693 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5694 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5695 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5696 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5697 | |
| 5698 | switch (info->genlhdr->cmd) { |
| 5699 | case NL80211_CMD_SET_PMKSA: |
| 5700 | rdev_ops = rdev->ops->set_pmksa; |
| 5701 | break; |
| 5702 | case NL80211_CMD_DEL_PMKSA: |
| 5703 | rdev_ops = rdev->ops->del_pmksa; |
| 5704 | break; |
| 5705 | default: |
| 5706 | WARN_ON(1); |
| 5707 | break; |
| 5708 | } |
| 5709 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5710 | if (!rdev_ops) |
| 5711 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5712 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5713 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5714 | } |
| 5715 | |
| 5716 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5717 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5718 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5719 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5720 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5721 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5722 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5723 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5724 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5725 | if (!rdev->ops->flush_pmksa) |
| 5726 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5727 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5728 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5729 | } |
| 5730 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5731 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5732 | { |
| 5733 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5734 | struct net_device *dev = info->user_ptr[1]; |
| 5735 | u8 action_code, dialog_token; |
| 5736 | u16 status_code; |
| 5737 | u8 *peer; |
| 5738 | |
| 5739 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5740 | !rdev->ops->tdls_mgmt) |
| 5741 | return -EOPNOTSUPP; |
| 5742 | |
| 5743 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5744 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5745 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5746 | !info->attrs[NL80211_ATTR_IE] || |
| 5747 | !info->attrs[NL80211_ATTR_MAC]) |
| 5748 | return -EINVAL; |
| 5749 | |
| 5750 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5751 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5752 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5753 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5754 | |
| 5755 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, |
| 5756 | dialog_token, status_code, |
| 5757 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5758 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 5759 | } |
| 5760 | |
| 5761 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5762 | { |
| 5763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5764 | struct net_device *dev = info->user_ptr[1]; |
| 5765 | enum nl80211_tdls_operation operation; |
| 5766 | u8 *peer; |
| 5767 | |
| 5768 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5769 | !rdev->ops->tdls_oper) |
| 5770 | return -EOPNOTSUPP; |
| 5771 | |
| 5772 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5773 | !info->attrs[NL80211_ATTR_MAC]) |
| 5774 | return -EINVAL; |
| 5775 | |
| 5776 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5777 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5778 | |
| 5779 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); |
| 5780 | } |
| 5781 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5782 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5783 | struct genl_info *info) |
| 5784 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5785 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 5786 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5787 | struct ieee80211_channel *chan; |
| 5788 | struct sk_buff *msg; |
| 5789 | void *hdr; |
| 5790 | u64 cookie; |
| 5791 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 5792 | u32 freq, duration; |
| 5793 | int err; |
| 5794 | |
| 5795 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5796 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5797 | return -EINVAL; |
| 5798 | |
| 5799 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5800 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5801 | if (!rdev->ops->remain_on_channel || |
| 5802 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5803 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5804 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 5805 | /* |
| 5806 | * We should be on that channel for at least a minimum amount of |
| 5807 | * time (10ms) but no longer than the driver supports. |
| 5808 | */ |
| 5809 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 5810 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 5811 | return -EINVAL; |
| 5812 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5813 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 5814 | !nl80211_valid_channel_type(info, &channel_type)) |
| 5815 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5816 | |
| 5817 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5818 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5819 | if (chan == NULL) |
| 5820 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5821 | |
| 5822 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5823 | if (!msg) |
| 5824 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5825 | |
| 5826 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5827 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5828 | |
| 5829 | if (IS_ERR(hdr)) { |
| 5830 | err = PTR_ERR(hdr); |
| 5831 | goto free_msg; |
| 5832 | } |
| 5833 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 5834 | err = rdev->ops->remain_on_channel(&rdev->wiphy, wdev, chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5835 | channel_type, duration, &cookie); |
| 5836 | |
| 5837 | if (err) |
| 5838 | goto free_msg; |
| 5839 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5840 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 5841 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5842 | |
| 5843 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5844 | |
| 5845 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5846 | |
| 5847 | nla_put_failure: |
| 5848 | err = -ENOBUFS; |
| 5849 | free_msg: |
| 5850 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5851 | return err; |
| 5852 | } |
| 5853 | |
| 5854 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5855 | struct genl_info *info) |
| 5856 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5857 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 5858 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5859 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5860 | |
| 5861 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5862 | return -EINVAL; |
| 5863 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5864 | if (!rdev->ops->cancel_remain_on_channel) |
| 5865 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5866 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5867 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5868 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 5869 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5870 | } |
| 5871 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5872 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5873 | u8 *rates, u8 rates_len) |
| 5874 | { |
| 5875 | u8 i; |
| 5876 | u32 mask = 0; |
| 5877 | |
| 5878 | for (i = 0; i < rates_len; i++) { |
| 5879 | int rate = (rates[i] & 0x7f) * 5; |
| 5880 | int ridx; |
| 5881 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5882 | struct ieee80211_rate *srate = |
| 5883 | &sband->bitrates[ridx]; |
| 5884 | if (rate == srate->bitrate) { |
| 5885 | mask |= 1 << ridx; |
| 5886 | break; |
| 5887 | } |
| 5888 | } |
| 5889 | if (ridx == sband->n_bitrates) |
| 5890 | return 0; /* rate not found */ |
| 5891 | } |
| 5892 | |
| 5893 | return mask; |
| 5894 | } |
| 5895 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5896 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5897 | u8 *rates, u8 rates_len, |
| 5898 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 5899 | { |
| 5900 | u8 i; |
| 5901 | |
| 5902 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 5903 | |
| 5904 | for (i = 0; i < rates_len; i++) { |
| 5905 | int ridx, rbit; |
| 5906 | |
| 5907 | ridx = rates[i] / 8; |
| 5908 | rbit = BIT(rates[i] % 8); |
| 5909 | |
| 5910 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 5911 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5912 | return false; |
| 5913 | |
| 5914 | /* check availability */ |
| 5915 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 5916 | mcs[ridx] |= rbit; |
| 5917 | else |
| 5918 | return false; |
| 5919 | } |
| 5920 | |
| 5921 | return true; |
| 5922 | } |
| 5923 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5924 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5925 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5926 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5927 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 5928 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5929 | }; |
| 5930 | |
| 5931 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5932 | struct genl_info *info) |
| 5933 | { |
| 5934 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5935 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5936 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5937 | int rem, i; |
| 5938 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5939 | struct nlattr *tx_rates; |
| 5940 | struct ieee80211_supported_band *sband; |
| 5941 | |
| 5942 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5943 | return -EINVAL; |
| 5944 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5945 | if (!rdev->ops->set_bitrate_mask) |
| 5946 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5947 | |
| 5948 | memset(&mask, 0, sizeof(mask)); |
| 5949 | /* Default to all rates enabled */ |
| 5950 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5951 | sband = rdev->wiphy.bands[i]; |
| 5952 | mask.control[i].legacy = |
| 5953 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5954 | if (sband) |
| 5955 | memcpy(mask.control[i].mcs, |
| 5956 | sband->ht_cap.mcs.rx_mask, |
| 5957 | sizeof(mask.control[i].mcs)); |
| 5958 | else |
| 5959 | memset(mask.control[i].mcs, 0, |
| 5960 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5961 | } |
| 5962 | |
| 5963 | /* |
| 5964 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5965 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5966 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5967 | 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] | 5968 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5969 | { |
| 5970 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5971 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5972 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5973 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5974 | if (sband == NULL) |
| 5975 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5976 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5977 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5978 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5979 | mask.control[band].legacy = rateset_to_mask( |
| 5980 | sband, |
| 5981 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5982 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 5983 | if ((mask.control[band].legacy == 0) && |
| 5984 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 5985 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5986 | } |
| 5987 | if (tb[NL80211_TXRATE_MCS]) { |
| 5988 | if (!ht_rateset_to_mask( |
| 5989 | sband, |
| 5990 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 5991 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 5992 | mask.control[band].mcs)) |
| 5993 | return -EINVAL; |
| 5994 | } |
| 5995 | |
| 5996 | if (mask.control[band].legacy == 0) { |
| 5997 | /* don't allow empty legacy rates if HT |
| 5998 | * is not even supported. */ |
| 5999 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 6000 | return -EINVAL; |
| 6001 | |
| 6002 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 6003 | if (mask.control[band].mcs[i]) |
| 6004 | break; |
| 6005 | |
| 6006 | /* legacy and mcs rates may not be both empty */ |
| 6007 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6008 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6009 | } |
| 6010 | } |
| 6011 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6012 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6013 | } |
| 6014 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6015 | 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] | 6016 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6017 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6018 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6019 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6020 | |
| 6021 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 6022 | return -EINVAL; |
| 6023 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6024 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 6025 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6026 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6027 | switch (wdev->iftype) { |
| 6028 | case NL80211_IFTYPE_STATION: |
| 6029 | case NL80211_IFTYPE_ADHOC: |
| 6030 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6031 | case NL80211_IFTYPE_AP: |
| 6032 | case NL80211_IFTYPE_AP_VLAN: |
| 6033 | case NL80211_IFTYPE_MESH_POINT: |
| 6034 | case NL80211_IFTYPE_P2P_GO: |
| 6035 | break; |
| 6036 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6037 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6038 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6039 | |
| 6040 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6041 | if (!rdev->ops->mgmt_tx) |
| 6042 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6043 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6044 | return cfg80211_mlme_register_mgmt(wdev, info->snd_pid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6045 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6046 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6047 | } |
| 6048 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6049 | 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] | 6050 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6051 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6052 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6053 | struct ieee80211_channel *chan; |
| 6054 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 6055 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6056 | u32 freq; |
| 6057 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6058 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6059 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6060 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6061 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6062 | bool offchan, no_cck, dont_wait_for_ack; |
| 6063 | |
| 6064 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6065 | |
| 6066 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 6067 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6068 | return -EINVAL; |
| 6069 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6070 | if (!rdev->ops->mgmt_tx) |
| 6071 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6072 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6073 | switch (wdev->iftype) { |
| 6074 | case NL80211_IFTYPE_STATION: |
| 6075 | case NL80211_IFTYPE_ADHOC: |
| 6076 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6077 | case NL80211_IFTYPE_AP: |
| 6078 | case NL80211_IFTYPE_AP_VLAN: |
| 6079 | case NL80211_IFTYPE_MESH_POINT: |
| 6080 | case NL80211_IFTYPE_P2P_GO: |
| 6081 | break; |
| 6082 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6083 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6084 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6085 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6086 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6087 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6088 | return -EINVAL; |
| 6089 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6090 | |
| 6091 | /* |
| 6092 | * We should wait on the channel for at least a minimum amount |
| 6093 | * of time (10ms) but no longer than the driver supports. |
| 6094 | */ |
| 6095 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6096 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6097 | return -EINVAL; |
| 6098 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6099 | } |
| 6100 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6101 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 6102 | if (!nl80211_valid_channel_type(info, &channel_type)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6103 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 6104 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6105 | } |
| 6106 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6107 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6108 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6109 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6110 | return -EINVAL; |
| 6111 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6112 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6113 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6114 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6115 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6116 | if (chan == NULL) |
| 6117 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6118 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6119 | if (!dont_wait_for_ack) { |
| 6120 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6121 | if (!msg) |
| 6122 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6123 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6124 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6125 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6126 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6127 | if (IS_ERR(hdr)) { |
| 6128 | err = PTR_ERR(hdr); |
| 6129 | goto free_msg; |
| 6130 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6131 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6132 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6133 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chan, offchan, channel_type, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6134 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6135 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6136 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6137 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6138 | if (err) |
| 6139 | goto free_msg; |
| 6140 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6141 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6142 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6143 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6144 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6145 | genlmsg_end(msg, hdr); |
| 6146 | return genlmsg_reply(msg, info); |
| 6147 | } |
| 6148 | |
| 6149 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6150 | |
| 6151 | nla_put_failure: |
| 6152 | err = -ENOBUFS; |
| 6153 | free_msg: |
| 6154 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6155 | return err; |
| 6156 | } |
| 6157 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6158 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6159 | { |
| 6160 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6161 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6162 | u64 cookie; |
| 6163 | |
| 6164 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6165 | return -EINVAL; |
| 6166 | |
| 6167 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6168 | return -EOPNOTSUPP; |
| 6169 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6170 | switch (wdev->iftype) { |
| 6171 | case NL80211_IFTYPE_STATION: |
| 6172 | case NL80211_IFTYPE_ADHOC: |
| 6173 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6174 | case NL80211_IFTYPE_AP: |
| 6175 | case NL80211_IFTYPE_AP_VLAN: |
| 6176 | case NL80211_IFTYPE_P2P_GO: |
| 6177 | break; |
| 6178 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6179 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6180 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6181 | |
| 6182 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6183 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6184 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6185 | } |
| 6186 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6187 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6188 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6189 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6190 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6191 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6192 | u8 ps_state; |
| 6193 | bool state; |
| 6194 | int err; |
| 6195 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6196 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6197 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6198 | |
| 6199 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6200 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6201 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6202 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6203 | |
| 6204 | wdev = dev->ieee80211_ptr; |
| 6205 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6206 | if (!rdev->ops->set_power_mgmt) |
| 6207 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6208 | |
| 6209 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6210 | |
| 6211 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6212 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6213 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6214 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 6215 | wdev->ps_timeout); |
| 6216 | if (!err) |
| 6217 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6218 | return err; |
| 6219 | } |
| 6220 | |
| 6221 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6222 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6223 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6224 | enum nl80211_ps_state ps_state; |
| 6225 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6226 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6227 | struct sk_buff *msg; |
| 6228 | void *hdr; |
| 6229 | int err; |
| 6230 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6231 | wdev = dev->ieee80211_ptr; |
| 6232 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6233 | if (!rdev->ops->set_power_mgmt) |
| 6234 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6235 | |
| 6236 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6237 | if (!msg) |
| 6238 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6239 | |
| 6240 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6241 | NL80211_CMD_GET_POWER_SAVE); |
| 6242 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6243 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6244 | goto free_msg; |
| 6245 | } |
| 6246 | |
| 6247 | if (wdev->ps) |
| 6248 | ps_state = NL80211_PS_ENABLED; |
| 6249 | else |
| 6250 | ps_state = NL80211_PS_DISABLED; |
| 6251 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6252 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6253 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6254 | |
| 6255 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6256 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6257 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6258 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6259 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6260 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6261 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6262 | return err; |
| 6263 | } |
| 6264 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6265 | static struct nla_policy |
| 6266 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6267 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6268 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6269 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 6270 | }; |
| 6271 | |
| 6272 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6273 | s32 threshold, u32 hysteresis) |
| 6274 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6275 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6276 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6277 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6278 | |
| 6279 | if (threshold > 0) |
| 6280 | return -EINVAL; |
| 6281 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6282 | wdev = dev->ieee80211_ptr; |
| 6283 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6284 | if (!rdev->ops->set_cqm_rssi_config) |
| 6285 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6286 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6287 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6288 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6289 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6290 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6291 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 6292 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6296 | { |
| 6297 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6298 | struct nlattr *cqm; |
| 6299 | int err; |
| 6300 | |
| 6301 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6302 | if (!cqm) { |
| 6303 | err = -EINVAL; |
| 6304 | goto out; |
| 6305 | } |
| 6306 | |
| 6307 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6308 | nl80211_attr_cqm_policy); |
| 6309 | if (err) |
| 6310 | goto out; |
| 6311 | |
| 6312 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6313 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6314 | s32 threshold; |
| 6315 | u32 hysteresis; |
| 6316 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6317 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6318 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 6319 | } else |
| 6320 | err = -EINVAL; |
| 6321 | |
| 6322 | out: |
| 6323 | return err; |
| 6324 | } |
| 6325 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6326 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6327 | { |
| 6328 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6329 | struct net_device *dev = info->user_ptr[1]; |
| 6330 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6331 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6332 | int err; |
| 6333 | |
| 6334 | /* start with default */ |
| 6335 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6336 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6337 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6338 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6339 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6340 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6341 | if (err) |
| 6342 | return err; |
| 6343 | } |
| 6344 | |
| 6345 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6346 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 6347 | return -EINVAL; |
| 6348 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6349 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6350 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6351 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 6352 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6353 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 6354 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6355 | return -EINVAL; |
| 6356 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6357 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 6358 | /* parse additional setup parameters if given */ |
| 6359 | err = nl80211_parse_mesh_setup(info, &setup); |
| 6360 | if (err) |
| 6361 | return err; |
| 6362 | } |
| 6363 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6364 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6365 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 6366 | |
| 6367 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 6368 | !nl80211_valid_channel_type(info, &channel_type)) |
| 6369 | return -EINVAL; |
| 6370 | |
| 6371 | setup.channel = rdev_freq_to_chan(rdev, |
| 6372 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 6373 | channel_type); |
| 6374 | if (!setup.channel) |
| 6375 | return -EINVAL; |
| 6376 | setup.channel_type = channel_type; |
| 6377 | } else { |
| 6378 | /* cfg80211_join_mesh() will sort it out */ |
| 6379 | setup.channel = NULL; |
| 6380 | } |
| 6381 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6382 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6383 | } |
| 6384 | |
| 6385 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6386 | { |
| 6387 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6388 | struct net_device *dev = info->user_ptr[1]; |
| 6389 | |
| 6390 | return cfg80211_leave_mesh(rdev, dev); |
| 6391 | } |
| 6392 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6393 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6394 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6395 | { |
| 6396 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6397 | struct sk_buff *msg; |
| 6398 | void *hdr; |
| 6399 | |
| 6400 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6401 | return -EOPNOTSUPP; |
| 6402 | |
| 6403 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6404 | if (!msg) |
| 6405 | return -ENOMEM; |
| 6406 | |
| 6407 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6408 | NL80211_CMD_GET_WOWLAN); |
| 6409 | if (!hdr) |
| 6410 | goto nla_put_failure; |
| 6411 | |
| 6412 | if (rdev->wowlan) { |
| 6413 | struct nlattr *nl_wowlan; |
| 6414 | |
| 6415 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 6416 | if (!nl_wowlan) |
| 6417 | goto nla_put_failure; |
| 6418 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6419 | if ((rdev->wowlan->any && |
| 6420 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 6421 | (rdev->wowlan->disconnect && |
| 6422 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 6423 | (rdev->wowlan->magic_pkt && |
| 6424 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 6425 | (rdev->wowlan->gtk_rekey_failure && |
| 6426 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 6427 | (rdev->wowlan->eap_identity_req && |
| 6428 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 6429 | (rdev->wowlan->four_way_handshake && |
| 6430 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 6431 | (rdev->wowlan->rfkill_release && |
| 6432 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 6433 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6434 | if (rdev->wowlan->n_patterns) { |
| 6435 | struct nlattr *nl_pats, *nl_pat; |
| 6436 | int i, pat_len; |
| 6437 | |
| 6438 | nl_pats = nla_nest_start(msg, |
| 6439 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 6440 | if (!nl_pats) |
| 6441 | goto nla_put_failure; |
| 6442 | |
| 6443 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 6444 | nl_pat = nla_nest_start(msg, i + 1); |
| 6445 | if (!nl_pat) |
| 6446 | goto nla_put_failure; |
| 6447 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6448 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 6449 | DIV_ROUND_UP(pat_len, 8), |
| 6450 | rdev->wowlan->patterns[i].mask) || |
| 6451 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 6452 | pat_len, |
| 6453 | rdev->wowlan->patterns[i].pattern)) |
| 6454 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6455 | nla_nest_end(msg, nl_pat); |
| 6456 | } |
| 6457 | nla_nest_end(msg, nl_pats); |
| 6458 | } |
| 6459 | |
| 6460 | nla_nest_end(msg, nl_wowlan); |
| 6461 | } |
| 6462 | |
| 6463 | genlmsg_end(msg, hdr); |
| 6464 | return genlmsg_reply(msg, info); |
| 6465 | |
| 6466 | nla_put_failure: |
| 6467 | nlmsg_free(msg); |
| 6468 | return -ENOBUFS; |
| 6469 | } |
| 6470 | |
| 6471 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6472 | { |
| 6473 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6474 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6475 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6476 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6477 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 6478 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6479 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6480 | |
| 6481 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6482 | return -EOPNOTSUPP; |
| 6483 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6484 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 6485 | cfg80211_rdev_free_wowlan(rdev); |
| 6486 | rdev->wowlan = NULL; |
| 6487 | goto set_wakeup; |
| 6488 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6489 | |
| 6490 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 6491 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6492 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6493 | nl80211_wowlan_policy); |
| 6494 | if (err) |
| 6495 | return err; |
| 6496 | |
| 6497 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 6498 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 6499 | return -EINVAL; |
| 6500 | new_triggers.any = true; |
| 6501 | } |
| 6502 | |
| 6503 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 6504 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 6505 | return -EINVAL; |
| 6506 | new_triggers.disconnect = true; |
| 6507 | } |
| 6508 | |
| 6509 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 6510 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 6511 | return -EINVAL; |
| 6512 | new_triggers.magic_pkt = true; |
| 6513 | } |
| 6514 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 6515 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 6516 | return -EINVAL; |
| 6517 | |
| 6518 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 6519 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 6520 | return -EINVAL; |
| 6521 | new_triggers.gtk_rekey_failure = true; |
| 6522 | } |
| 6523 | |
| 6524 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 6525 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 6526 | return -EINVAL; |
| 6527 | new_triggers.eap_identity_req = true; |
| 6528 | } |
| 6529 | |
| 6530 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 6531 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 6532 | return -EINVAL; |
| 6533 | new_triggers.four_way_handshake = true; |
| 6534 | } |
| 6535 | |
| 6536 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 6537 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 6538 | return -EINVAL; |
| 6539 | new_triggers.rfkill_release = true; |
| 6540 | } |
| 6541 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6542 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 6543 | struct nlattr *pat; |
| 6544 | int n_patterns = 0; |
| 6545 | int rem, pat_len, mask_len; |
| 6546 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6547 | |
| 6548 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6549 | rem) |
| 6550 | n_patterns++; |
| 6551 | if (n_patterns > wowlan->n_patterns) |
| 6552 | return -EINVAL; |
| 6553 | |
| 6554 | new_triggers.patterns = kcalloc(n_patterns, |
| 6555 | sizeof(new_triggers.patterns[0]), |
| 6556 | GFP_KERNEL); |
| 6557 | if (!new_triggers.patterns) |
| 6558 | return -ENOMEM; |
| 6559 | |
| 6560 | new_triggers.n_patterns = n_patterns; |
| 6561 | i = 0; |
| 6562 | |
| 6563 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6564 | rem) { |
| 6565 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6566 | nla_data(pat), nla_len(pat), NULL); |
| 6567 | err = -EINVAL; |
| 6568 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6569 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6570 | goto error; |
| 6571 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6572 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6573 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6574 | mask_len) |
| 6575 | goto error; |
| 6576 | if (pat_len > wowlan->pattern_max_len || |
| 6577 | pat_len < wowlan->pattern_min_len) |
| 6578 | goto error; |
| 6579 | |
| 6580 | new_triggers.patterns[i].mask = |
| 6581 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6582 | if (!new_triggers.patterns[i].mask) { |
| 6583 | err = -ENOMEM; |
| 6584 | goto error; |
| 6585 | } |
| 6586 | new_triggers.patterns[i].pattern = |
| 6587 | new_triggers.patterns[i].mask + mask_len; |
| 6588 | memcpy(new_triggers.patterns[i].mask, |
| 6589 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6590 | mask_len); |
| 6591 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6592 | memcpy(new_triggers.patterns[i].pattern, |
| 6593 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6594 | pat_len); |
| 6595 | i++; |
| 6596 | } |
| 6597 | } |
| 6598 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6599 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 6600 | if (!ntrig) { |
| 6601 | err = -ENOMEM; |
| 6602 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6603 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6604 | cfg80211_rdev_free_wowlan(rdev); |
| 6605 | rdev->wowlan = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6606 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 6607 | set_wakeup: |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6608 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
| 6609 | rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan); |
| 6610 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6611 | return 0; |
| 6612 | error: |
| 6613 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6614 | kfree(new_triggers.patterns[i].mask); |
| 6615 | kfree(new_triggers.patterns); |
| 6616 | return err; |
| 6617 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6618 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6619 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6620 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6621 | { |
| 6622 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6623 | struct net_device *dev = info->user_ptr[1]; |
| 6624 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6625 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6626 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6627 | int err; |
| 6628 | |
| 6629 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6630 | return -EINVAL; |
| 6631 | |
| 6632 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6633 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6634 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6635 | nl80211_rekey_policy); |
| 6636 | if (err) |
| 6637 | return err; |
| 6638 | |
| 6639 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6640 | return -ERANGE; |
| 6641 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6642 | return -ERANGE; |
| 6643 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6644 | return -ERANGE; |
| 6645 | |
| 6646 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6647 | NL80211_KEK_LEN); |
| 6648 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6649 | NL80211_KCK_LEN); |
| 6650 | memcpy(rekey_data.replay_ctr, |
| 6651 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6652 | NL80211_REPLAY_CTR_LEN); |
| 6653 | |
| 6654 | wdev_lock(wdev); |
| 6655 | if (!wdev->current_bss) { |
| 6656 | err = -ENOTCONN; |
| 6657 | goto out; |
| 6658 | } |
| 6659 | |
| 6660 | if (!rdev->ops->set_rekey_data) { |
| 6661 | err = -EOPNOTSUPP; |
| 6662 | goto out; |
| 6663 | } |
| 6664 | |
| 6665 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 6666 | out: |
| 6667 | wdev_unlock(wdev); |
| 6668 | return err; |
| 6669 | } |
| 6670 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6671 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6672 | struct genl_info *info) |
| 6673 | { |
| 6674 | struct net_device *dev = info->user_ptr[1]; |
| 6675 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6676 | |
| 6677 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6678 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6679 | return -EINVAL; |
| 6680 | |
| 6681 | if (wdev->ap_unexpected_nlpid) |
| 6682 | return -EBUSY; |
| 6683 | |
| 6684 | wdev->ap_unexpected_nlpid = info->snd_pid; |
| 6685 | return 0; |
| 6686 | } |
| 6687 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6688 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6689 | struct genl_info *info) |
| 6690 | { |
| 6691 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6692 | struct net_device *dev = info->user_ptr[1]; |
| 6693 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6694 | struct sk_buff *msg; |
| 6695 | void *hdr; |
| 6696 | const u8 *addr; |
| 6697 | u64 cookie; |
| 6698 | int err; |
| 6699 | |
| 6700 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6701 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6702 | return -EOPNOTSUPP; |
| 6703 | |
| 6704 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6705 | return -EINVAL; |
| 6706 | |
| 6707 | if (!rdev->ops->probe_client) |
| 6708 | return -EOPNOTSUPP; |
| 6709 | |
| 6710 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6711 | if (!msg) |
| 6712 | return -ENOMEM; |
| 6713 | |
| 6714 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6715 | NL80211_CMD_PROBE_CLIENT); |
| 6716 | |
| 6717 | if (IS_ERR(hdr)) { |
| 6718 | err = PTR_ERR(hdr); |
| 6719 | goto free_msg; |
| 6720 | } |
| 6721 | |
| 6722 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6723 | |
| 6724 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); |
| 6725 | if (err) |
| 6726 | goto free_msg; |
| 6727 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6728 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6729 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6730 | |
| 6731 | genlmsg_end(msg, hdr); |
| 6732 | |
| 6733 | return genlmsg_reply(msg, info); |
| 6734 | |
| 6735 | nla_put_failure: |
| 6736 | err = -ENOBUFS; |
| 6737 | free_msg: |
| 6738 | nlmsg_free(msg); |
| 6739 | return err; |
| 6740 | } |
| 6741 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6742 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 6743 | { |
| 6744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6745 | |
| 6746 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 6747 | return -EOPNOTSUPP; |
| 6748 | |
| 6749 | if (rdev->ap_beacons_nlpid) |
| 6750 | return -EBUSY; |
| 6751 | |
| 6752 | rdev->ap_beacons_nlpid = info->snd_pid; |
| 6753 | |
| 6754 | return 0; |
| 6755 | } |
| 6756 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6757 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 6758 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 6759 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6760 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 6761 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 6762 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 6763 | #define NL80211_FLAG_NEED_WDEV 0x10 |
| 6764 | /* If a netdev is associated, it must be UP */ |
| 6765 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 6766 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6767 | |
| 6768 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6769 | struct genl_info *info) |
| 6770 | { |
| 6771 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 6772 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6773 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6774 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 6775 | |
| 6776 | if (rtnl) |
| 6777 | rtnl_lock(); |
| 6778 | |
| 6779 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 6780 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6781 | if (IS_ERR(rdev)) { |
| 6782 | if (rtnl) |
| 6783 | rtnl_unlock(); |
| 6784 | return PTR_ERR(rdev); |
| 6785 | } |
| 6786 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 6787 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 6788 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 6789 | mutex_lock(&cfg80211_mutex); |
| 6790 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 6791 | info->attrs); |
| 6792 | if (IS_ERR(wdev)) { |
| 6793 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6794 | if (rtnl) |
| 6795 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 6796 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6797 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 6798 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 6799 | dev = wdev->netdev; |
| 6800 | rdev = wiphy_to_dev(wdev->wiphy); |
| 6801 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 6802 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 6803 | if (!dev) { |
| 6804 | mutex_unlock(&cfg80211_mutex); |
| 6805 | if (rtnl) |
| 6806 | rtnl_unlock(); |
| 6807 | return -EINVAL; |
| 6808 | } |
| 6809 | |
| 6810 | info->user_ptr[1] = dev; |
| 6811 | } else { |
| 6812 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6813 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 6814 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 6815 | if (dev) { |
| 6816 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 6817 | !netif_running(dev)) { |
| 6818 | mutex_unlock(&cfg80211_mutex); |
| 6819 | if (rtnl) |
| 6820 | rtnl_unlock(); |
| 6821 | return -ENETDOWN; |
| 6822 | } |
| 6823 | |
| 6824 | dev_hold(dev); |
| 6825 | } |
| 6826 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 6827 | cfg80211_lock_rdev(rdev); |
| 6828 | |
| 6829 | mutex_unlock(&cfg80211_mutex); |
| 6830 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6831 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6832 | } |
| 6833 | |
| 6834 | return 0; |
| 6835 | } |
| 6836 | |
| 6837 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6838 | struct genl_info *info) |
| 6839 | { |
| 6840 | if (info->user_ptr[0]) |
| 6841 | cfg80211_unlock_rdev(info->user_ptr[0]); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 6842 | if (info->user_ptr[1]) { |
| 6843 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 6844 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6845 | |
| 6846 | if (wdev->netdev) |
| 6847 | dev_put(wdev->netdev); |
| 6848 | } else { |
| 6849 | dev_put(info->user_ptr[1]); |
| 6850 | } |
| 6851 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6852 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 6853 | rtnl_unlock(); |
| 6854 | } |
| 6855 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6856 | static struct genl_ops nl80211_ops[] = { |
| 6857 | { |
| 6858 | .cmd = NL80211_CMD_GET_WIPHY, |
| 6859 | .doit = nl80211_get_wiphy, |
| 6860 | .dumpit = nl80211_dump_wiphy, |
| 6861 | .policy = nl80211_policy, |
| 6862 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6863 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6864 | }, |
| 6865 | { |
| 6866 | .cmd = NL80211_CMD_SET_WIPHY, |
| 6867 | .doit = nl80211_set_wiphy, |
| 6868 | .policy = nl80211_policy, |
| 6869 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6870 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6871 | }, |
| 6872 | { |
| 6873 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 6874 | .doit = nl80211_get_interface, |
| 6875 | .dumpit = nl80211_dump_interface, |
| 6876 | .policy = nl80211_policy, |
| 6877 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 6878 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6879 | }, |
| 6880 | { |
| 6881 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 6882 | .doit = nl80211_set_interface, |
| 6883 | .policy = nl80211_policy, |
| 6884 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6885 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6886 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6887 | }, |
| 6888 | { |
| 6889 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 6890 | .doit = nl80211_new_interface, |
| 6891 | .policy = nl80211_policy, |
| 6892 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6893 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6894 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6895 | }, |
| 6896 | { |
| 6897 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 6898 | .doit = nl80211_del_interface, |
| 6899 | .policy = nl80211_policy, |
| 6900 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 6901 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6902 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6903 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6904 | { |
| 6905 | .cmd = NL80211_CMD_GET_KEY, |
| 6906 | .doit = nl80211_get_key, |
| 6907 | .policy = nl80211_policy, |
| 6908 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6909 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6910 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6911 | }, |
| 6912 | { |
| 6913 | .cmd = NL80211_CMD_SET_KEY, |
| 6914 | .doit = nl80211_set_key, |
| 6915 | .policy = nl80211_policy, |
| 6916 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6917 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6918 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6919 | }, |
| 6920 | { |
| 6921 | .cmd = NL80211_CMD_NEW_KEY, |
| 6922 | .doit = nl80211_new_key, |
| 6923 | .policy = nl80211_policy, |
| 6924 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6925 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6926 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6927 | }, |
| 6928 | { |
| 6929 | .cmd = NL80211_CMD_DEL_KEY, |
| 6930 | .doit = nl80211_del_key, |
| 6931 | .policy = nl80211_policy, |
| 6932 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6933 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6934 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6935 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6936 | { |
| 6937 | .cmd = NL80211_CMD_SET_BEACON, |
| 6938 | .policy = nl80211_policy, |
| 6939 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6940 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6941 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6942 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6943 | }, |
| 6944 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6945 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6946 | .policy = nl80211_policy, |
| 6947 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6948 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6949 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6950 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6951 | }, |
| 6952 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6953 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6954 | .policy = nl80211_policy, |
| 6955 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6956 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6957 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6958 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6959 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6960 | { |
| 6961 | .cmd = NL80211_CMD_GET_STATION, |
| 6962 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6963 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6964 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6965 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6966 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6967 | }, |
| 6968 | { |
| 6969 | .cmd = NL80211_CMD_SET_STATION, |
| 6970 | .doit = nl80211_set_station, |
| 6971 | .policy = nl80211_policy, |
| 6972 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6973 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6974 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6975 | }, |
| 6976 | { |
| 6977 | .cmd = NL80211_CMD_NEW_STATION, |
| 6978 | .doit = nl80211_new_station, |
| 6979 | .policy = nl80211_policy, |
| 6980 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6981 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6982 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6983 | }, |
| 6984 | { |
| 6985 | .cmd = NL80211_CMD_DEL_STATION, |
| 6986 | .doit = nl80211_del_station, |
| 6987 | .policy = nl80211_policy, |
| 6988 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6989 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6990 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6991 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6992 | { |
| 6993 | .cmd = NL80211_CMD_GET_MPATH, |
| 6994 | .doit = nl80211_get_mpath, |
| 6995 | .dumpit = nl80211_dump_mpath, |
| 6996 | .policy = nl80211_policy, |
| 6997 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6998 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6999 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7000 | }, |
| 7001 | { |
| 7002 | .cmd = NL80211_CMD_SET_MPATH, |
| 7003 | .doit = nl80211_set_mpath, |
| 7004 | .policy = nl80211_policy, |
| 7005 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7006 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7007 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7008 | }, |
| 7009 | { |
| 7010 | .cmd = NL80211_CMD_NEW_MPATH, |
| 7011 | .doit = nl80211_new_mpath, |
| 7012 | .policy = nl80211_policy, |
| 7013 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7014 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7015 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7016 | }, |
| 7017 | { |
| 7018 | .cmd = NL80211_CMD_DEL_MPATH, |
| 7019 | .doit = nl80211_del_mpath, |
| 7020 | .policy = nl80211_policy, |
| 7021 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7022 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7023 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7024 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7025 | { |
| 7026 | .cmd = NL80211_CMD_SET_BSS, |
| 7027 | .doit = nl80211_set_bss, |
| 7028 | .policy = nl80211_policy, |
| 7029 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7030 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7031 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7032 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7033 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7034 | .cmd = NL80211_CMD_GET_REG, |
| 7035 | .doit = nl80211_get_reg, |
| 7036 | .policy = nl80211_policy, |
| 7037 | /* can be retrieved by unprivileged users */ |
| 7038 | }, |
| 7039 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7040 | .cmd = NL80211_CMD_SET_REG, |
| 7041 | .doit = nl80211_set_reg, |
| 7042 | .policy = nl80211_policy, |
| 7043 | .flags = GENL_ADMIN_PERM, |
| 7044 | }, |
| 7045 | { |
| 7046 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 7047 | .doit = nl80211_req_set_reg, |
| 7048 | .policy = nl80211_policy, |
| 7049 | .flags = GENL_ADMIN_PERM, |
| 7050 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7051 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7052 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 7053 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7054 | .policy = nl80211_policy, |
| 7055 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7056 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7057 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7058 | }, |
| 7059 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7060 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 7061 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7062 | .policy = nl80211_policy, |
| 7063 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7064 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7065 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7066 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 7067 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7068 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 7069 | .doit = nl80211_trigger_scan, |
| 7070 | .policy = nl80211_policy, |
| 7071 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7072 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7073 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7074 | }, |
| 7075 | { |
| 7076 | .cmd = NL80211_CMD_GET_SCAN, |
| 7077 | .policy = nl80211_policy, |
| 7078 | .dumpit = nl80211_dump_scan, |
| 7079 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7080 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7081 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 7082 | .doit = nl80211_start_sched_scan, |
| 7083 | .policy = nl80211_policy, |
| 7084 | .flags = GENL_ADMIN_PERM, |
| 7085 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7086 | NL80211_FLAG_NEED_RTNL, |
| 7087 | }, |
| 7088 | { |
| 7089 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 7090 | .doit = nl80211_stop_sched_scan, |
| 7091 | .policy = nl80211_policy, |
| 7092 | .flags = GENL_ADMIN_PERM, |
| 7093 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7094 | NL80211_FLAG_NEED_RTNL, |
| 7095 | }, |
| 7096 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7097 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 7098 | .doit = nl80211_authenticate, |
| 7099 | .policy = nl80211_policy, |
| 7100 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7101 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7102 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7103 | }, |
| 7104 | { |
| 7105 | .cmd = NL80211_CMD_ASSOCIATE, |
| 7106 | .doit = nl80211_associate, |
| 7107 | .policy = nl80211_policy, |
| 7108 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7109 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7110 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7111 | }, |
| 7112 | { |
| 7113 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 7114 | .doit = nl80211_deauthenticate, |
| 7115 | .policy = nl80211_policy, |
| 7116 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7117 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7118 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7119 | }, |
| 7120 | { |
| 7121 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 7122 | .doit = nl80211_disassociate, |
| 7123 | .policy = nl80211_policy, |
| 7124 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7125 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7126 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7127 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7128 | { |
| 7129 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 7130 | .doit = nl80211_join_ibss, |
| 7131 | .policy = nl80211_policy, |
| 7132 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7133 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7134 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7135 | }, |
| 7136 | { |
| 7137 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 7138 | .doit = nl80211_leave_ibss, |
| 7139 | .policy = nl80211_policy, |
| 7140 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7141 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7142 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7143 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7144 | #ifdef CONFIG_NL80211_TESTMODE |
| 7145 | { |
| 7146 | .cmd = NL80211_CMD_TESTMODE, |
| 7147 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7148 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7149 | .policy = nl80211_policy, |
| 7150 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7151 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7152 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7153 | }, |
| 7154 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7155 | { |
| 7156 | .cmd = NL80211_CMD_CONNECT, |
| 7157 | .doit = nl80211_connect, |
| 7158 | .policy = nl80211_policy, |
| 7159 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7160 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7161 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7162 | }, |
| 7163 | { |
| 7164 | .cmd = NL80211_CMD_DISCONNECT, |
| 7165 | .doit = nl80211_disconnect, |
| 7166 | .policy = nl80211_policy, |
| 7167 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7168 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7169 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7170 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7171 | { |
| 7172 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 7173 | .doit = nl80211_wiphy_netns, |
| 7174 | .policy = nl80211_policy, |
| 7175 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7176 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7177 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7178 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7179 | { |
| 7180 | .cmd = NL80211_CMD_GET_SURVEY, |
| 7181 | .policy = nl80211_policy, |
| 7182 | .dumpit = nl80211_dump_survey, |
| 7183 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7184 | { |
| 7185 | .cmd = NL80211_CMD_SET_PMKSA, |
| 7186 | .doit = nl80211_setdel_pmksa, |
| 7187 | .policy = nl80211_policy, |
| 7188 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7189 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7190 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7191 | }, |
| 7192 | { |
| 7193 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 7194 | .doit = nl80211_setdel_pmksa, |
| 7195 | .policy = nl80211_policy, |
| 7196 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7197 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7198 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7199 | }, |
| 7200 | { |
| 7201 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 7202 | .doit = nl80211_flush_pmksa, |
| 7203 | .policy = nl80211_policy, |
| 7204 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7205 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7206 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7207 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7208 | { |
| 7209 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7210 | .doit = nl80211_remain_on_channel, |
| 7211 | .policy = nl80211_policy, |
| 7212 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7213 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7214 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7215 | }, |
| 7216 | { |
| 7217 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7218 | .doit = nl80211_cancel_remain_on_channel, |
| 7219 | .policy = nl80211_policy, |
| 7220 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7221 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7222 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7223 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7224 | { |
| 7225 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 7226 | .doit = nl80211_set_tx_bitrate_mask, |
| 7227 | .policy = nl80211_policy, |
| 7228 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7229 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7230 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7231 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7232 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7233 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 7234 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7235 | .policy = nl80211_policy, |
| 7236 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7237 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7238 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7239 | }, |
| 7240 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7241 | .cmd = NL80211_CMD_FRAME, |
| 7242 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7243 | .policy = nl80211_policy, |
| 7244 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7245 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7246 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7247 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7248 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7249 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 7250 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 7251 | .policy = nl80211_policy, |
| 7252 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7253 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7254 | NL80211_FLAG_NEED_RTNL, |
| 7255 | }, |
| 7256 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7257 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 7258 | .doit = nl80211_set_power_save, |
| 7259 | .policy = nl80211_policy, |
| 7260 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7261 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7262 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7263 | }, |
| 7264 | { |
| 7265 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 7266 | .doit = nl80211_get_power_save, |
| 7267 | .policy = nl80211_policy, |
| 7268 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7269 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7270 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7271 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7272 | { |
| 7273 | .cmd = NL80211_CMD_SET_CQM, |
| 7274 | .doit = nl80211_set_cqm, |
| 7275 | .policy = nl80211_policy, |
| 7276 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7277 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7278 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7279 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7280 | { |
| 7281 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 7282 | .doit = nl80211_set_channel, |
| 7283 | .policy = nl80211_policy, |
| 7284 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7285 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7286 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7287 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7288 | { |
| 7289 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 7290 | .doit = nl80211_set_wds_peer, |
| 7291 | .policy = nl80211_policy, |
| 7292 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 7293 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7294 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7295 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7296 | { |
| 7297 | .cmd = NL80211_CMD_JOIN_MESH, |
| 7298 | .doit = nl80211_join_mesh, |
| 7299 | .policy = nl80211_policy, |
| 7300 | .flags = GENL_ADMIN_PERM, |
| 7301 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7302 | NL80211_FLAG_NEED_RTNL, |
| 7303 | }, |
| 7304 | { |
| 7305 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 7306 | .doit = nl80211_leave_mesh, |
| 7307 | .policy = nl80211_policy, |
| 7308 | .flags = GENL_ADMIN_PERM, |
| 7309 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7310 | NL80211_FLAG_NEED_RTNL, |
| 7311 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7312 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7313 | { |
| 7314 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 7315 | .doit = nl80211_get_wowlan, |
| 7316 | .policy = nl80211_policy, |
| 7317 | /* can be retrieved by unprivileged users */ |
| 7318 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7319 | NL80211_FLAG_NEED_RTNL, |
| 7320 | }, |
| 7321 | { |
| 7322 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 7323 | .doit = nl80211_set_wowlan, |
| 7324 | .policy = nl80211_policy, |
| 7325 | .flags = GENL_ADMIN_PERM, |
| 7326 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7327 | NL80211_FLAG_NEED_RTNL, |
| 7328 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7329 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7330 | { |
| 7331 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 7332 | .doit = nl80211_set_rekey_data, |
| 7333 | .policy = nl80211_policy, |
| 7334 | .flags = GENL_ADMIN_PERM, |
| 7335 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7336 | NL80211_FLAG_NEED_RTNL, |
| 7337 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7338 | { |
| 7339 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 7340 | .doit = nl80211_tdls_mgmt, |
| 7341 | .policy = nl80211_policy, |
| 7342 | .flags = GENL_ADMIN_PERM, |
| 7343 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7344 | NL80211_FLAG_NEED_RTNL, |
| 7345 | }, |
| 7346 | { |
| 7347 | .cmd = NL80211_CMD_TDLS_OPER, |
| 7348 | .doit = nl80211_tdls_oper, |
| 7349 | .policy = nl80211_policy, |
| 7350 | .flags = GENL_ADMIN_PERM, |
| 7351 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7352 | NL80211_FLAG_NEED_RTNL, |
| 7353 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7354 | { |
| 7355 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 7356 | .doit = nl80211_register_unexpected_frame, |
| 7357 | .policy = nl80211_policy, |
| 7358 | .flags = GENL_ADMIN_PERM, |
| 7359 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7360 | NL80211_FLAG_NEED_RTNL, |
| 7361 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7362 | { |
| 7363 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 7364 | .doit = nl80211_probe_client, |
| 7365 | .policy = nl80211_policy, |
| 7366 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7367 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7368 | NL80211_FLAG_NEED_RTNL, |
| 7369 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7370 | { |
| 7371 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 7372 | .doit = nl80211_register_beacons, |
| 7373 | .policy = nl80211_policy, |
| 7374 | .flags = GENL_ADMIN_PERM, |
| 7375 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7376 | NL80211_FLAG_NEED_RTNL, |
| 7377 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 7378 | { |
| 7379 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 7380 | .doit = nl80211_set_noack_map, |
| 7381 | .policy = nl80211_policy, |
| 7382 | .flags = GENL_ADMIN_PERM, |
| 7383 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7384 | NL80211_FLAG_NEED_RTNL, |
| 7385 | }, |
| 7386 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7387 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7388 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7389 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 7390 | .name = "mlme", |
| 7391 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7392 | |
| 7393 | /* multicast groups */ |
| 7394 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 7395 | .name = "config", |
| 7396 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7397 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 7398 | .name = "scan", |
| 7399 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7400 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 7401 | .name = "regulatory", |
| 7402 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7403 | |
| 7404 | /* notification functions */ |
| 7405 | |
| 7406 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 7407 | { |
| 7408 | struct sk_buff *msg; |
| 7409 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7410 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7411 | if (!msg) |
| 7412 | return; |
| 7413 | |
| 7414 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 7415 | nlmsg_free(msg); |
| 7416 | return; |
| 7417 | } |
| 7418 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7419 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7420 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7421 | } |
| 7422 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7423 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 7424 | struct cfg80211_registered_device *rdev) |
| 7425 | { |
| 7426 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 7427 | struct nlattr *nest; |
| 7428 | int i; |
| 7429 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7430 | ASSERT_RDEV_LOCK(rdev); |
| 7431 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7432 | if (WARN_ON(!req)) |
| 7433 | return 0; |
| 7434 | |
| 7435 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 7436 | if (!nest) |
| 7437 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7438 | for (i = 0; i < req->n_ssids; i++) { |
| 7439 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 7440 | goto nla_put_failure; |
| 7441 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7442 | nla_nest_end(msg, nest); |
| 7443 | |
| 7444 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 7445 | if (!nest) |
| 7446 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7447 | for (i = 0; i < req->n_channels; i++) { |
| 7448 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 7449 | goto nla_put_failure; |
| 7450 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7451 | nla_nest_end(msg, nest); |
| 7452 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7453 | if (req->ie && |
| 7454 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 7455 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7456 | |
| 7457 | return 0; |
| 7458 | nla_put_failure: |
| 7459 | return -ENOBUFS; |
| 7460 | } |
| 7461 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7462 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 7463 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7464 | struct wireless_dev *wdev, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7465 | u32 pid, u32 seq, int flags, |
| 7466 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7467 | { |
| 7468 | void *hdr; |
| 7469 | |
| 7470 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 7471 | if (!hdr) |
| 7472 | return -1; |
| 7473 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7474 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7475 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 7476 | wdev->netdev->ifindex)) || |
| 7477 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7478 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7479 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7480 | /* ignore errors and send incomplete event anyway */ |
| 7481 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7482 | |
| 7483 | return genlmsg_end(msg, hdr); |
| 7484 | |
| 7485 | nla_put_failure: |
| 7486 | genlmsg_cancel(msg, hdr); |
| 7487 | return -EMSGSIZE; |
| 7488 | } |
| 7489 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7490 | static int |
| 7491 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 7492 | struct cfg80211_registered_device *rdev, |
| 7493 | struct net_device *netdev, |
| 7494 | u32 pid, u32 seq, int flags, u32 cmd) |
| 7495 | { |
| 7496 | void *hdr; |
| 7497 | |
| 7498 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 7499 | if (!hdr) |
| 7500 | return -1; |
| 7501 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7502 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7503 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7504 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7505 | |
| 7506 | return genlmsg_end(msg, hdr); |
| 7507 | |
| 7508 | nla_put_failure: |
| 7509 | genlmsg_cancel(msg, hdr); |
| 7510 | return -EMSGSIZE; |
| 7511 | } |
| 7512 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7513 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7514 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7515 | { |
| 7516 | struct sk_buff *msg; |
| 7517 | |
| 7518 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 7519 | if (!msg) |
| 7520 | return; |
| 7521 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7522 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7523 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 7524 | nlmsg_free(msg); |
| 7525 | return; |
| 7526 | } |
| 7527 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7528 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7529 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7530 | } |
| 7531 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7532 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7533 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7534 | { |
| 7535 | struct sk_buff *msg; |
| 7536 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7537 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7538 | if (!msg) |
| 7539 | return; |
| 7540 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7541 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7542 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7543 | nlmsg_free(msg); |
| 7544 | return; |
| 7545 | } |
| 7546 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7547 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7548 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7549 | } |
| 7550 | |
| 7551 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7552 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7553 | { |
| 7554 | struct sk_buff *msg; |
| 7555 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7556 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7557 | if (!msg) |
| 7558 | return; |
| 7559 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7560 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7561 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7562 | nlmsg_free(msg); |
| 7563 | return; |
| 7564 | } |
| 7565 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7566 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7567 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7568 | } |
| 7569 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7570 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 7571 | struct net_device *netdev) |
| 7572 | { |
| 7573 | struct sk_buff *msg; |
| 7574 | |
| 7575 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7576 | if (!msg) |
| 7577 | return; |
| 7578 | |
| 7579 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7580 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 7581 | nlmsg_free(msg); |
| 7582 | return; |
| 7583 | } |
| 7584 | |
| 7585 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7586 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7587 | } |
| 7588 | |
| 7589 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 7590 | struct net_device *netdev, u32 cmd) |
| 7591 | { |
| 7592 | struct sk_buff *msg; |
| 7593 | |
| 7594 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 7595 | if (!msg) |
| 7596 | return; |
| 7597 | |
| 7598 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 7599 | nlmsg_free(msg); |
| 7600 | return; |
| 7601 | } |
| 7602 | |
| 7603 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7604 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7605 | } |
| 7606 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7607 | /* |
| 7608 | * This can happen on global regulatory changes or device specific settings |
| 7609 | * based on custom world regulatory domains. |
| 7610 | */ |
| 7611 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 7612 | { |
| 7613 | struct sk_buff *msg; |
| 7614 | void *hdr; |
| 7615 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7616 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7617 | if (!msg) |
| 7618 | return; |
| 7619 | |
| 7620 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 7621 | if (!hdr) { |
| 7622 | nlmsg_free(msg); |
| 7623 | return; |
| 7624 | } |
| 7625 | |
| 7626 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7627 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 7628 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7629 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7630 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 7631 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7632 | NL80211_REGDOM_TYPE_WORLD)) |
| 7633 | goto nla_put_failure; |
| 7634 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 7635 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7636 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 7637 | goto nla_put_failure; |
| 7638 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 7639 | request->intersect) { |
| 7640 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7641 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 7642 | goto nla_put_failure; |
| 7643 | } else { |
| 7644 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7645 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 7646 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 7647 | request->alpha2)) |
| 7648 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7649 | } |
| 7650 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7651 | if (wiphy_idx_valid(request->wiphy_idx) && |
| 7652 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 7653 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7654 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7655 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7656 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7657 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7658 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7659 | GFP_ATOMIC); |
| 7660 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7661 | |
| 7662 | return; |
| 7663 | |
| 7664 | nla_put_failure: |
| 7665 | genlmsg_cancel(msg, hdr); |
| 7666 | nlmsg_free(msg); |
| 7667 | } |
| 7668 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7669 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 7670 | struct net_device *netdev, |
| 7671 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7672 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7673 | { |
| 7674 | struct sk_buff *msg; |
| 7675 | void *hdr; |
| 7676 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7677 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7678 | if (!msg) |
| 7679 | return; |
| 7680 | |
| 7681 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7682 | if (!hdr) { |
| 7683 | nlmsg_free(msg); |
| 7684 | return; |
| 7685 | } |
| 7686 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7687 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7688 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7689 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 7690 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7691 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7692 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7693 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7694 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7695 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7696 | return; |
| 7697 | |
| 7698 | nla_put_failure: |
| 7699 | genlmsg_cancel(msg, hdr); |
| 7700 | nlmsg_free(msg); |
| 7701 | } |
| 7702 | |
| 7703 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7704 | struct net_device *netdev, const u8 *buf, |
| 7705 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7706 | { |
| 7707 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7708 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7709 | } |
| 7710 | |
| 7711 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 7712 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7713 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7714 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7715 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7716 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7717 | } |
| 7718 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7719 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7720 | struct net_device *netdev, const u8 *buf, |
| 7721 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7722 | { |
| 7723 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7724 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7725 | } |
| 7726 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7727 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 7728 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7729 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7730 | { |
| 7731 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7732 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7733 | } |
| 7734 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 7735 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 7736 | struct net_device *netdev, const u8 *buf, |
| 7737 | size_t len, gfp_t gfp) |
| 7738 | { |
| 7739 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7740 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 7741 | } |
| 7742 | |
| 7743 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 7744 | struct net_device *netdev, const u8 *buf, |
| 7745 | size_t len, gfp_t gfp) |
| 7746 | { |
| 7747 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7748 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 7749 | } |
| 7750 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 7751 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 7752 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7753 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7754 | { |
| 7755 | struct sk_buff *msg; |
| 7756 | void *hdr; |
| 7757 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7758 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7759 | if (!msg) |
| 7760 | return; |
| 7761 | |
| 7762 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7763 | if (!hdr) { |
| 7764 | nlmsg_free(msg); |
| 7765 | return; |
| 7766 | } |
| 7767 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7768 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7769 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7770 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 7771 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 7772 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7773 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7774 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7775 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7776 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7777 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7778 | return; |
| 7779 | |
| 7780 | nla_put_failure: |
| 7781 | genlmsg_cancel(msg, hdr); |
| 7782 | nlmsg_free(msg); |
| 7783 | } |
| 7784 | |
| 7785 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7786 | struct net_device *netdev, const u8 *addr, |
| 7787 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7788 | { |
| 7789 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7790 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7791 | } |
| 7792 | |
| 7793 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7794 | struct net_device *netdev, const u8 *addr, |
| 7795 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7796 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7797 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 7798 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7799 | } |
| 7800 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7801 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 7802 | struct net_device *netdev, const u8 *bssid, |
| 7803 | const u8 *req_ie, size_t req_ie_len, |
| 7804 | const u8 *resp_ie, size_t resp_ie_len, |
| 7805 | u16 status, gfp_t gfp) |
| 7806 | { |
| 7807 | struct sk_buff *msg; |
| 7808 | void *hdr; |
| 7809 | |
| 7810 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7811 | if (!msg) |
| 7812 | return; |
| 7813 | |
| 7814 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 7815 | if (!hdr) { |
| 7816 | nlmsg_free(msg); |
| 7817 | return; |
| 7818 | } |
| 7819 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7820 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7821 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7822 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 7823 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 7824 | (req_ie && |
| 7825 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 7826 | (resp_ie && |
| 7827 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 7828 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7829 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7830 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7831 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7832 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7833 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7834 | return; |
| 7835 | |
| 7836 | nla_put_failure: |
| 7837 | genlmsg_cancel(msg, hdr); |
| 7838 | nlmsg_free(msg); |
| 7839 | |
| 7840 | } |
| 7841 | |
| 7842 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 7843 | struct net_device *netdev, const u8 *bssid, |
| 7844 | const u8 *req_ie, size_t req_ie_len, |
| 7845 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 7846 | { |
| 7847 | struct sk_buff *msg; |
| 7848 | void *hdr; |
| 7849 | |
| 7850 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7851 | if (!msg) |
| 7852 | return; |
| 7853 | |
| 7854 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 7855 | if (!hdr) { |
| 7856 | nlmsg_free(msg); |
| 7857 | return; |
| 7858 | } |
| 7859 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7860 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7861 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7862 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 7863 | (req_ie && |
| 7864 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 7865 | (resp_ie && |
| 7866 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 7867 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7868 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7869 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7870 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7871 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7872 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7873 | return; |
| 7874 | |
| 7875 | nla_put_failure: |
| 7876 | genlmsg_cancel(msg, hdr); |
| 7877 | nlmsg_free(msg); |
| 7878 | |
| 7879 | } |
| 7880 | |
| 7881 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 7882 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7883 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7884 | { |
| 7885 | struct sk_buff *msg; |
| 7886 | void *hdr; |
| 7887 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7888 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7889 | if (!msg) |
| 7890 | return; |
| 7891 | |
| 7892 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 7893 | if (!hdr) { |
| 7894 | nlmsg_free(msg); |
| 7895 | return; |
| 7896 | } |
| 7897 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7898 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7899 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7900 | (from_ap && reason && |
| 7901 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 7902 | (from_ap && |
| 7903 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 7904 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 7905 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7906 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7907 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7908 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7909 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7910 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7911 | return; |
| 7912 | |
| 7913 | nla_put_failure: |
| 7914 | genlmsg_cancel(msg, hdr); |
| 7915 | nlmsg_free(msg); |
| 7916 | |
| 7917 | } |
| 7918 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7919 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 7920 | struct net_device *netdev, const u8 *bssid, |
| 7921 | gfp_t gfp) |
| 7922 | { |
| 7923 | struct sk_buff *msg; |
| 7924 | void *hdr; |
| 7925 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7926 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7927 | if (!msg) |
| 7928 | return; |
| 7929 | |
| 7930 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 7931 | if (!hdr) { |
| 7932 | nlmsg_free(msg); |
| 7933 | return; |
| 7934 | } |
| 7935 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7936 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7937 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7938 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 7939 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7940 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7941 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7942 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7943 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7944 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7945 | return; |
| 7946 | |
| 7947 | nla_put_failure: |
| 7948 | genlmsg_cancel(msg, hdr); |
| 7949 | nlmsg_free(msg); |
| 7950 | } |
| 7951 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7952 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 7953 | struct net_device *netdev, |
| 7954 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 7955 | gfp_t gfp) |
| 7956 | { |
| 7957 | struct sk_buff *msg; |
| 7958 | void *hdr; |
| 7959 | |
| 7960 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7961 | if (!msg) |
| 7962 | return; |
| 7963 | |
| 7964 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 7965 | if (!hdr) { |
| 7966 | nlmsg_free(msg); |
| 7967 | return; |
| 7968 | } |
| 7969 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7970 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7971 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7972 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 7973 | (ie_len && ie && |
| 7974 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 7975 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7976 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7977 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7978 | |
| 7979 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7980 | nl80211_mlme_mcgrp.id, gfp); |
| 7981 | return; |
| 7982 | |
| 7983 | nla_put_failure: |
| 7984 | genlmsg_cancel(msg, hdr); |
| 7985 | nlmsg_free(msg); |
| 7986 | } |
| 7987 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7988 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 7989 | struct net_device *netdev, const u8 *addr, |
| 7990 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7991 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7992 | { |
| 7993 | struct sk_buff *msg; |
| 7994 | void *hdr; |
| 7995 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7996 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7997 | if (!msg) |
| 7998 | return; |
| 7999 | |
| 8000 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 8001 | if (!hdr) { |
| 8002 | nlmsg_free(msg); |
| 8003 | return; |
| 8004 | } |
| 8005 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8006 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8007 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8008 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 8009 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 8010 | (key_id != -1 && |
| 8011 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 8012 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 8013 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8014 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8015 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8016 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8017 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8018 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 8019 | return; |
| 8020 | |
| 8021 | nla_put_failure: |
| 8022 | genlmsg_cancel(msg, hdr); |
| 8023 | nlmsg_free(msg); |
| 8024 | } |
| 8025 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8026 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 8027 | struct ieee80211_channel *channel_before, |
| 8028 | struct ieee80211_channel *channel_after) |
| 8029 | { |
| 8030 | struct sk_buff *msg; |
| 8031 | void *hdr; |
| 8032 | struct nlattr *nl_freq; |
| 8033 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8034 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8035 | if (!msg) |
| 8036 | return; |
| 8037 | |
| 8038 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 8039 | if (!hdr) { |
| 8040 | nlmsg_free(msg); |
| 8041 | return; |
| 8042 | } |
| 8043 | |
| 8044 | /* |
| 8045 | * Since we are applying the beacon hint to a wiphy we know its |
| 8046 | * wiphy_idx is valid |
| 8047 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8048 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 8049 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8050 | |
| 8051 | /* Before */ |
| 8052 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 8053 | if (!nl_freq) |
| 8054 | goto nla_put_failure; |
| 8055 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 8056 | goto nla_put_failure; |
| 8057 | nla_nest_end(msg, nl_freq); |
| 8058 | |
| 8059 | /* After */ |
| 8060 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 8061 | if (!nl_freq) |
| 8062 | goto nla_put_failure; |
| 8063 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 8064 | goto nla_put_failure; |
| 8065 | nla_nest_end(msg, nl_freq); |
| 8066 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8067 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8068 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8069 | rcu_read_lock(); |
| 8070 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 8071 | GFP_ATOMIC); |
| 8072 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8073 | |
| 8074 | return; |
| 8075 | |
| 8076 | nla_put_failure: |
| 8077 | genlmsg_cancel(msg, hdr); |
| 8078 | nlmsg_free(msg); |
| 8079 | } |
| 8080 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8081 | static void nl80211_send_remain_on_chan_event( |
| 8082 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8083 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8084 | struct ieee80211_channel *chan, |
| 8085 | enum nl80211_channel_type channel_type, |
| 8086 | unsigned int duration, gfp_t gfp) |
| 8087 | { |
| 8088 | struct sk_buff *msg; |
| 8089 | void *hdr; |
| 8090 | |
| 8091 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8092 | if (!msg) |
| 8093 | return; |
| 8094 | |
| 8095 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8096 | if (!hdr) { |
| 8097 | nlmsg_free(msg); |
| 8098 | return; |
| 8099 | } |
| 8100 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8101 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8102 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8103 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame^] | 8104 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8105 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
| 8106 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) || |
| 8107 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8108 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8109 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8110 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 8111 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 8112 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8113 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8114 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8115 | |
| 8116 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8117 | nl80211_mlme_mcgrp.id, gfp); |
| 8118 | return; |
| 8119 | |
| 8120 | nla_put_failure: |
| 8121 | genlmsg_cancel(msg, hdr); |
| 8122 | nlmsg_free(msg); |
| 8123 | } |
| 8124 | |
| 8125 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8126 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8127 | struct ieee80211_channel *chan, |
| 8128 | enum nl80211_channel_type channel_type, |
| 8129 | unsigned int duration, gfp_t gfp) |
| 8130 | { |
| 8131 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8132 | rdev, wdev, cookie, chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8133 | channel_type, duration, gfp); |
| 8134 | } |
| 8135 | |
| 8136 | void nl80211_send_remain_on_channel_cancel( |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8137 | struct cfg80211_registered_device *rdev, |
| 8138 | struct wireless_dev *wdev, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8139 | u64 cookie, struct ieee80211_channel *chan, |
| 8140 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 8141 | { |
| 8142 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8143 | rdev, wdev, cookie, chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8144 | channel_type, 0, gfp); |
| 8145 | } |
| 8146 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8147 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 8148 | struct net_device *dev, const u8 *mac_addr, |
| 8149 | struct station_info *sinfo, gfp_t gfp) |
| 8150 | { |
| 8151 | struct sk_buff *msg; |
| 8152 | |
| 8153 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8154 | if (!msg) |
| 8155 | return; |
| 8156 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 8157 | if (nl80211_send_station(msg, 0, 0, 0, |
| 8158 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8159 | nlmsg_free(msg); |
| 8160 | return; |
| 8161 | } |
| 8162 | |
| 8163 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8164 | nl80211_mlme_mcgrp.id, gfp); |
| 8165 | } |
| 8166 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8167 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 8168 | struct net_device *dev, const u8 *mac_addr, |
| 8169 | gfp_t gfp) |
| 8170 | { |
| 8171 | struct sk_buff *msg; |
| 8172 | void *hdr; |
| 8173 | |
| 8174 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8175 | if (!msg) |
| 8176 | return; |
| 8177 | |
| 8178 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 8179 | if (!hdr) { |
| 8180 | nlmsg_free(msg); |
| 8181 | return; |
| 8182 | } |
| 8183 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8184 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8185 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 8186 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8187 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8188 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8189 | |
| 8190 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8191 | nl80211_mlme_mcgrp.id, gfp); |
| 8192 | return; |
| 8193 | |
| 8194 | nla_put_failure: |
| 8195 | genlmsg_cancel(msg, hdr); |
| 8196 | nlmsg_free(msg); |
| 8197 | } |
| 8198 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8199 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 8200 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8201 | { |
| 8202 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8203 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8204 | struct sk_buff *msg; |
| 8205 | void *hdr; |
| 8206 | int err; |
| 8207 | u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid); |
| 8208 | |
| 8209 | if (!nlpid) |
| 8210 | return false; |
| 8211 | |
| 8212 | msg = nlmsg_new(100, gfp); |
| 8213 | if (!msg) |
| 8214 | return true; |
| 8215 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8216 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8217 | if (!hdr) { |
| 8218 | nlmsg_free(msg); |
| 8219 | return true; |
| 8220 | } |
| 8221 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8222 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8223 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8224 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8225 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8226 | |
| 8227 | err = genlmsg_end(msg, hdr); |
| 8228 | if (err < 0) { |
| 8229 | nlmsg_free(msg); |
| 8230 | return true; |
| 8231 | } |
| 8232 | |
| 8233 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 8234 | return true; |
| 8235 | |
| 8236 | nla_put_failure: |
| 8237 | genlmsg_cancel(msg, hdr); |
| 8238 | nlmsg_free(msg); |
| 8239 | return true; |
| 8240 | } |
| 8241 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8242 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 8243 | { |
| 8244 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 8245 | addr, gfp); |
| 8246 | } |
| 8247 | |
| 8248 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 8249 | const u8 *addr, gfp_t gfp) |
| 8250 | { |
| 8251 | return __nl80211_unexpected_frame(dev, |
| 8252 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 8253 | addr, gfp); |
| 8254 | } |
| 8255 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8256 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8257 | struct wireless_dev *wdev, u32 nlpid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8258 | int freq, int sig_dbm, |
| 8259 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8260 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8261 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8262 | struct sk_buff *msg; |
| 8263 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8264 | |
| 8265 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8266 | if (!msg) |
| 8267 | return -ENOMEM; |
| 8268 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8269 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8270 | if (!hdr) { |
| 8271 | nlmsg_free(msg); |
| 8272 | return -ENOMEM; |
| 8273 | } |
| 8274 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8275 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8276 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8277 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8278 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8279 | (sig_dbm && |
| 8280 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8281 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8282 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8283 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8284 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8285 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8286 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8287 | |
| 8288 | nla_put_failure: |
| 8289 | genlmsg_cancel(msg, hdr); |
| 8290 | nlmsg_free(msg); |
| 8291 | return -ENOBUFS; |
| 8292 | } |
| 8293 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8294 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8295 | struct wireless_dev *wdev, u64 cookie, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8296 | const u8 *buf, size_t len, bool ack, |
| 8297 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8298 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8299 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8300 | struct sk_buff *msg; |
| 8301 | void *hdr; |
| 8302 | |
| 8303 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8304 | if (!msg) |
| 8305 | return; |
| 8306 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8307 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8308 | if (!hdr) { |
| 8309 | nlmsg_free(msg); |
| 8310 | return; |
| 8311 | } |
| 8312 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8313 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8314 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 8315 | netdev->ifindex)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8316 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 8317 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8318 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8319 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8320 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8321 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8322 | |
| 8323 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 8324 | return; |
| 8325 | |
| 8326 | nla_put_failure: |
| 8327 | genlmsg_cancel(msg, hdr); |
| 8328 | nlmsg_free(msg); |
| 8329 | } |
| 8330 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8331 | void |
| 8332 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 8333 | struct net_device *netdev, |
| 8334 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 8335 | gfp_t gfp) |
| 8336 | { |
| 8337 | struct sk_buff *msg; |
| 8338 | struct nlattr *pinfoattr; |
| 8339 | void *hdr; |
| 8340 | |
| 8341 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8342 | if (!msg) |
| 8343 | return; |
| 8344 | |
| 8345 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8346 | if (!hdr) { |
| 8347 | nlmsg_free(msg); |
| 8348 | return; |
| 8349 | } |
| 8350 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8351 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8352 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8353 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8354 | |
| 8355 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8356 | if (!pinfoattr) |
| 8357 | goto nla_put_failure; |
| 8358 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8359 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 8360 | rssi_event)) |
| 8361 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8362 | |
| 8363 | nla_nest_end(msg, pinfoattr); |
| 8364 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8365 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8366 | |
| 8367 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8368 | nl80211_mlme_mcgrp.id, gfp); |
| 8369 | return; |
| 8370 | |
| 8371 | nla_put_failure: |
| 8372 | genlmsg_cancel(msg, hdr); |
| 8373 | nlmsg_free(msg); |
| 8374 | } |
| 8375 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8376 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 8377 | struct net_device *netdev, const u8 *bssid, |
| 8378 | const u8 *replay_ctr, gfp_t gfp) |
| 8379 | { |
| 8380 | struct sk_buff *msg; |
| 8381 | struct nlattr *rekey_attr; |
| 8382 | void *hdr; |
| 8383 | |
| 8384 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8385 | if (!msg) |
| 8386 | return; |
| 8387 | |
| 8388 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 8389 | if (!hdr) { |
| 8390 | nlmsg_free(msg); |
| 8391 | return; |
| 8392 | } |
| 8393 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8394 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8395 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8396 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8397 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8398 | |
| 8399 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 8400 | if (!rekey_attr) |
| 8401 | goto nla_put_failure; |
| 8402 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8403 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 8404 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 8405 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8406 | |
| 8407 | nla_nest_end(msg, rekey_attr); |
| 8408 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8409 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8410 | |
| 8411 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8412 | nl80211_mlme_mcgrp.id, gfp); |
| 8413 | return; |
| 8414 | |
| 8415 | nla_put_failure: |
| 8416 | genlmsg_cancel(msg, hdr); |
| 8417 | nlmsg_free(msg); |
| 8418 | } |
| 8419 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8420 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 8421 | struct net_device *netdev, int index, |
| 8422 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 8423 | { |
| 8424 | struct sk_buff *msg; |
| 8425 | struct nlattr *attr; |
| 8426 | void *hdr; |
| 8427 | |
| 8428 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8429 | if (!msg) |
| 8430 | return; |
| 8431 | |
| 8432 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 8433 | if (!hdr) { |
| 8434 | nlmsg_free(msg); |
| 8435 | return; |
| 8436 | } |
| 8437 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8438 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8439 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8440 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8441 | |
| 8442 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 8443 | if (!attr) |
| 8444 | goto nla_put_failure; |
| 8445 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8446 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 8447 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 8448 | (preauth && |
| 8449 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 8450 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8451 | |
| 8452 | nla_nest_end(msg, attr); |
| 8453 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8454 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8455 | |
| 8456 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8457 | nl80211_mlme_mcgrp.id, gfp); |
| 8458 | return; |
| 8459 | |
| 8460 | nla_put_failure: |
| 8461 | genlmsg_cancel(msg, hdr); |
| 8462 | nlmsg_free(msg); |
| 8463 | } |
| 8464 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8465 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 8466 | struct net_device *netdev, int freq, |
| 8467 | enum nl80211_channel_type type, gfp_t gfp) |
| 8468 | { |
| 8469 | struct sk_buff *msg; |
| 8470 | void *hdr; |
| 8471 | |
| 8472 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8473 | if (!msg) |
| 8474 | return; |
| 8475 | |
| 8476 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 8477 | if (!hdr) { |
| 8478 | nlmsg_free(msg); |
| 8479 | return; |
| 8480 | } |
| 8481 | |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 8482 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8483 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8484 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type)) |
| 8485 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8486 | |
| 8487 | genlmsg_end(msg, hdr); |
| 8488 | |
| 8489 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8490 | nl80211_mlme_mcgrp.id, gfp); |
| 8491 | return; |
| 8492 | |
| 8493 | nla_put_failure: |
| 8494 | genlmsg_cancel(msg, hdr); |
| 8495 | nlmsg_free(msg); |
| 8496 | } |
| 8497 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8498 | void |
| 8499 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 8500 | struct net_device *netdev, const u8 *peer, |
| 8501 | u32 num_packets, gfp_t gfp) |
| 8502 | { |
| 8503 | struct sk_buff *msg; |
| 8504 | struct nlattr *pinfoattr; |
| 8505 | void *hdr; |
| 8506 | |
| 8507 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8508 | if (!msg) |
| 8509 | return; |
| 8510 | |
| 8511 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8512 | if (!hdr) { |
| 8513 | nlmsg_free(msg); |
| 8514 | return; |
| 8515 | } |
| 8516 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8517 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8518 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8519 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8520 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8521 | |
| 8522 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8523 | if (!pinfoattr) |
| 8524 | goto nla_put_failure; |
| 8525 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8526 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 8527 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8528 | |
| 8529 | nla_nest_end(msg, pinfoattr); |
| 8530 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8531 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8532 | |
| 8533 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8534 | nl80211_mlme_mcgrp.id, gfp); |
| 8535 | return; |
| 8536 | |
| 8537 | nla_put_failure: |
| 8538 | genlmsg_cancel(msg, hdr); |
| 8539 | nlmsg_free(msg); |
| 8540 | } |
| 8541 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8542 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 8543 | u64 cookie, bool acked, gfp_t gfp) |
| 8544 | { |
| 8545 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8546 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8547 | struct sk_buff *msg; |
| 8548 | void *hdr; |
| 8549 | int err; |
| 8550 | |
| 8551 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8552 | if (!msg) |
| 8553 | return; |
| 8554 | |
| 8555 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 8556 | if (!hdr) { |
| 8557 | nlmsg_free(msg); |
| 8558 | return; |
| 8559 | } |
| 8560 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8561 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8562 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8563 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8564 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8565 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8566 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8567 | |
| 8568 | err = genlmsg_end(msg, hdr); |
| 8569 | if (err < 0) { |
| 8570 | nlmsg_free(msg); |
| 8571 | return; |
| 8572 | } |
| 8573 | |
| 8574 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8575 | nl80211_mlme_mcgrp.id, gfp); |
| 8576 | return; |
| 8577 | |
| 8578 | nla_put_failure: |
| 8579 | genlmsg_cancel(msg, hdr); |
| 8580 | nlmsg_free(msg); |
| 8581 | } |
| 8582 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 8583 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8584 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 8585 | const u8 *frame, size_t len, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8586 | int freq, int sig_dbm, gfp_t gfp) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8587 | { |
| 8588 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 8589 | struct sk_buff *msg; |
| 8590 | void *hdr; |
| 8591 | u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid); |
| 8592 | |
| 8593 | if (!nlpid) |
| 8594 | return; |
| 8595 | |
| 8596 | msg = nlmsg_new(len + 100, gfp); |
| 8597 | if (!msg) |
| 8598 | return; |
| 8599 | |
| 8600 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 8601 | if (!hdr) { |
| 8602 | nlmsg_free(msg); |
| 8603 | return; |
| 8604 | } |
| 8605 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8606 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8607 | (freq && |
| 8608 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 8609 | (sig_dbm && |
| 8610 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8611 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 8612 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8613 | |
| 8614 | genlmsg_end(msg, hdr); |
| 8615 | |
| 8616 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 8617 | return; |
| 8618 | |
| 8619 | nla_put_failure: |
| 8620 | genlmsg_cancel(msg, hdr); |
| 8621 | nlmsg_free(msg); |
| 8622 | } |
| 8623 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 8624 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8625 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 8626 | unsigned long state, |
| 8627 | void *_notify) |
| 8628 | { |
| 8629 | struct netlink_notify *notify = _notify; |
| 8630 | struct cfg80211_registered_device *rdev; |
| 8631 | struct wireless_dev *wdev; |
| 8632 | |
| 8633 | if (state != NETLINK_URELEASE) |
| 8634 | return NOTIFY_DONE; |
| 8635 | |
| 8636 | rcu_read_lock(); |
| 8637 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8638 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8639 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8640 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8641 | if (rdev->ap_beacons_nlpid == notify->pid) |
| 8642 | rdev->ap_beacons_nlpid = 0; |
| 8643 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8644 | |
| 8645 | rcu_read_unlock(); |
| 8646 | |
| 8647 | return NOTIFY_DONE; |
| 8648 | } |
| 8649 | |
| 8650 | static struct notifier_block nl80211_netlink_notifier = { |
| 8651 | .notifier_call = nl80211_netlink_notify, |
| 8652 | }; |
| 8653 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8654 | /* initialisation/exit functions */ |
| 8655 | |
| 8656 | int nl80211_init(void) |
| 8657 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8658 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8659 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8660 | err = genl_register_family_with_ops(&nl80211_fam, |
| 8661 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8662 | if (err) |
| 8663 | return err; |
| 8664 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8665 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 8666 | if (err) |
| 8667 | goto err_out; |
| 8668 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8669 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 8670 | if (err) |
| 8671 | goto err_out; |
| 8672 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8673 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 8674 | if (err) |
| 8675 | goto err_out; |
| 8676 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8677 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 8678 | if (err) |
| 8679 | goto err_out; |
| 8680 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8681 | #ifdef CONFIG_NL80211_TESTMODE |
| 8682 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 8683 | if (err) |
| 8684 | goto err_out; |
| 8685 | #endif |
| 8686 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8687 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 8688 | if (err) |
| 8689 | goto err_out; |
| 8690 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8691 | return 0; |
| 8692 | err_out: |
| 8693 | genl_unregister_family(&nl80211_fam); |
| 8694 | return err; |
| 8695 | } |
| 8696 | |
| 8697 | void nl80211_exit(void) |
| 8698 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8699 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8700 | genl_unregister_family(&nl80211_fam); |
| 8701 | } |