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 | dc6382c | 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 | 25e47c1 | 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 | 6829c87 | 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 | 6829c87 | 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 | |
| 1731 | |
| 1732 | 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] | 1733 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1734 | struct net_device *dev) |
| 1735 | { |
| 1736 | void *hdr; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame^] | 1737 | u64 wdev_id = (u64)dev->ieee80211_ptr->identifier | |
| 1738 | ((u64)rdev->wiphy_idx << 32); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1739 | |
| 1740 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1741 | if (!hdr) |
| 1742 | return -1; |
| 1743 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1744 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 1745 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1746 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) || |
| 1747 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 1748 | dev->ieee80211_ptr->iftype) || |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame^] | 1749 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1750 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1751 | rdev->devlist_generation ^ |
| 1752 | (cfg80211_rdev_list_generation << 2))) |
| 1753 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1754 | |
Michal Kazior | 2e165b8 | 2012-06-29 12:47:06 +0200 | [diff] [blame] | 1755 | if (rdev->monitor_channel) { |
| 1756 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1757 | rdev->monitor_channel->center_freq) || |
| 1758 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1759 | rdev->monitor_channel_type)) |
John W. Linville | 59ef43e | 2012-04-18 14:17:13 -0400 | [diff] [blame] | 1760 | goto nla_put_failure; |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1761 | } |
| 1762 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1763 | return genlmsg_end(msg, hdr); |
| 1764 | |
| 1765 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1766 | genlmsg_cancel(msg, hdr); |
| 1767 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1771 | { |
| 1772 | int wp_idx = 0; |
| 1773 | int if_idx = 0; |
| 1774 | int wp_start = cb->args[0]; |
| 1775 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1776 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1777 | struct wireless_dev *wdev; |
| 1778 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1779 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1780 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1781 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1782 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1783 | if (wp_idx < wp_start) { |
| 1784 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1785 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1786 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1787 | if_idx = 0; |
| 1788 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1789 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame^] | 1790 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1791 | if (if_idx < if_start) { |
| 1792 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1793 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1794 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1795 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1796 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1797 | rdev, wdev->netdev) < 0) { |
| 1798 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1799 | goto out; |
| 1800 | } |
| 1801 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1802 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1803 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1804 | |
| 1805 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1806 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1807 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1808 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1809 | |
| 1810 | cb->args[0] = wp_idx; |
| 1811 | cb->args[1] = if_idx; |
| 1812 | |
| 1813 | return skb->len; |
| 1814 | } |
| 1815 | |
| 1816 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1817 | { |
| 1818 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1819 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1820 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1821 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1822 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1823 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1824 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1825 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1826 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1827 | dev, netdev) < 0) { |
| 1828 | nlmsg_free(msg); |
| 1829 | return -ENOBUFS; |
| 1830 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1831 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1832 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1833 | } |
| 1834 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1835 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1836 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1837 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1838 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1839 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1840 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1841 | }; |
| 1842 | |
| 1843 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1844 | { |
| 1845 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1846 | int flag; |
| 1847 | |
| 1848 | *mntrflags = 0; |
| 1849 | |
| 1850 | if (!nla) |
| 1851 | return -EINVAL; |
| 1852 | |
| 1853 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1854 | nla, mntr_flags_policy)) |
| 1855 | return -EINVAL; |
| 1856 | |
| 1857 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1858 | if (flags[flag]) |
| 1859 | *mntrflags |= (1<<flag); |
| 1860 | |
| 1861 | return 0; |
| 1862 | } |
| 1863 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1864 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1865 | struct net_device *netdev, u8 use_4addr, |
| 1866 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1867 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1868 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1869 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1870 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1871 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1872 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1873 | |
| 1874 | switch (iftype) { |
| 1875 | case NL80211_IFTYPE_AP_VLAN: |
| 1876 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1877 | return 0; |
| 1878 | break; |
| 1879 | case NL80211_IFTYPE_STATION: |
| 1880 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1881 | return 0; |
| 1882 | break; |
| 1883 | default: |
| 1884 | break; |
| 1885 | } |
| 1886 | |
| 1887 | return -EOPNOTSUPP; |
| 1888 | } |
| 1889 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1890 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1891 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1893 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1894 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1895 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1896 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1897 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1898 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1899 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1900 | memset(¶ms, 0, sizeof(params)); |
| 1901 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1902 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1903 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1904 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1905 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1906 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1907 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1908 | if (ntype > NL80211_IFTYPE_MAX) |
| 1909 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1910 | } |
| 1911 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1912 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1913 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1914 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1915 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1916 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1917 | if (netif_running(dev)) |
| 1918 | return -EBUSY; |
| 1919 | |
| 1920 | wdev_lock(wdev); |
| 1921 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1922 | IEEE80211_MAX_MESH_ID_LEN); |
| 1923 | wdev->mesh_id_up_len = |
| 1924 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1925 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1926 | wdev->mesh_id_up_len); |
| 1927 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1928 | } |
| 1929 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1930 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1931 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1932 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1933 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1934 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1935 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1936 | } else { |
| 1937 | params.use_4addr = -1; |
| 1938 | } |
| 1939 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1940 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1941 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1942 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1943 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1944 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1945 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1946 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1947 | |
| 1948 | flags = &_flags; |
| 1949 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1950 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1951 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1952 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1953 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1954 | else |
| 1955 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1956 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1957 | if (!err && params.use_4addr != -1) |
| 1958 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1959 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1960 | return err; |
| 1961 | } |
| 1962 | |
| 1963 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1964 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1965 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1966 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1967 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1968 | int err; |
| 1969 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1970 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1971 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1972 | memset(¶ms, 0, sizeof(params)); |
| 1973 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1974 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1975 | return -EINVAL; |
| 1976 | |
| 1977 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1978 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1979 | if (type > NL80211_IFTYPE_MAX) |
| 1980 | return -EINVAL; |
| 1981 | } |
| 1982 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1983 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1984 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1985 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1986 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1987 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1988 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1989 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1990 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1991 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1992 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1993 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1994 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1995 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1996 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1997 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1998 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1999 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 2000 | if (IS_ERR(dev)) |
| 2001 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2002 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2003 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 2004 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 2005 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2006 | |
| 2007 | wdev_lock(wdev); |
| 2008 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2009 | IEEE80211_MAX_MESH_ID_LEN); |
| 2010 | wdev->mesh_id_up_len = |
| 2011 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2012 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2013 | wdev->mesh_id_up_len); |
| 2014 | wdev_unlock(wdev); |
| 2015 | } |
| 2016 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 2017 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2021 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2022 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2023 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2024 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2025 | if (!rdev->ops->del_virtual_intf) |
| 2026 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2027 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2028 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2029 | } |
| 2030 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2031 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2032 | { |
| 2033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2034 | struct net_device *dev = info->user_ptr[1]; |
| 2035 | u16 noack_map; |
| 2036 | |
| 2037 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2038 | return -EINVAL; |
| 2039 | |
| 2040 | if (!rdev->ops->set_noack_map) |
| 2041 | return -EOPNOTSUPP; |
| 2042 | |
| 2043 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2044 | |
| 2045 | return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map); |
| 2046 | } |
| 2047 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2048 | struct get_key_cookie { |
| 2049 | struct sk_buff *msg; |
| 2050 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2051 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2052 | }; |
| 2053 | |
| 2054 | static void get_key_callback(void *c, struct key_params *params) |
| 2055 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2056 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2057 | struct get_key_cookie *cookie = c; |
| 2058 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2059 | if ((params->key && |
| 2060 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2061 | params->key_len, params->key)) || |
| 2062 | (params->seq && |
| 2063 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2064 | params->seq_len, params->seq)) || |
| 2065 | (params->cipher && |
| 2066 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2067 | params->cipher))) |
| 2068 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2069 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2070 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2071 | if (!key) |
| 2072 | goto nla_put_failure; |
| 2073 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2074 | if ((params->key && |
| 2075 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2076 | params->key_len, params->key)) || |
| 2077 | (params->seq && |
| 2078 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2079 | params->seq_len, params->seq)) || |
| 2080 | (params->cipher && |
| 2081 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2082 | params->cipher))) |
| 2083 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2084 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2085 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2086 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2087 | |
| 2088 | nla_nest_end(cookie->msg, key); |
| 2089 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2090 | return; |
| 2091 | nla_put_failure: |
| 2092 | cookie->error = 1; |
| 2093 | } |
| 2094 | |
| 2095 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2096 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2098 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2099 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2100 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2101 | const u8 *mac_addr = NULL; |
| 2102 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2103 | struct get_key_cookie cookie = { |
| 2104 | .error = 0, |
| 2105 | }; |
| 2106 | void *hdr; |
| 2107 | struct sk_buff *msg; |
| 2108 | |
| 2109 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2110 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2111 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2112 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2113 | return -EINVAL; |
| 2114 | |
| 2115 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2116 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2117 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2118 | pairwise = !!mac_addr; |
| 2119 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2120 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2121 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2122 | return -EINVAL; |
| 2123 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2124 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2125 | return -EINVAL; |
| 2126 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2127 | } |
| 2128 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2129 | if (!rdev->ops->get_key) |
| 2130 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2131 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2132 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2133 | if (!msg) |
| 2134 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2135 | |
| 2136 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2137 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2138 | if (IS_ERR(hdr)) |
| 2139 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2140 | |
| 2141 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2142 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2143 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2144 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2145 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2146 | goto nla_put_failure; |
| 2147 | if (mac_addr && |
| 2148 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2149 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2150 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2151 | if (pairwise && mac_addr && |
| 2152 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2153 | return -ENOENT; |
| 2154 | |
| 2155 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 2156 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2157 | |
| 2158 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2159 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2160 | |
| 2161 | if (cookie.error) |
| 2162 | goto nla_put_failure; |
| 2163 | |
| 2164 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2165 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2166 | |
| 2167 | nla_put_failure: |
| 2168 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2169 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2170 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2171 | return err; |
| 2172 | } |
| 2173 | |
| 2174 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2175 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2176 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2177 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2178 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2179 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2180 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2181 | err = nl80211_parse_key(info, &key); |
| 2182 | if (err) |
| 2183 | return err; |
| 2184 | |
| 2185 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2186 | return -EINVAL; |
| 2187 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2188 | /* only support setting default key */ |
| 2189 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2190 | return -EINVAL; |
| 2191 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2192 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2193 | |
| 2194 | if (key.def) { |
| 2195 | if (!rdev->ops->set_default_key) { |
| 2196 | err = -EOPNOTSUPP; |
| 2197 | goto out; |
| 2198 | } |
| 2199 | |
| 2200 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2201 | if (err) |
| 2202 | goto out; |
| 2203 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2204 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 2205 | key.def_uni, key.def_multi); |
| 2206 | |
| 2207 | if (err) |
| 2208 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2209 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2210 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2211 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2212 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2213 | } else { |
| 2214 | if (key.def_uni || !key.def_multi) { |
| 2215 | err = -EINVAL; |
| 2216 | goto out; |
| 2217 | } |
| 2218 | |
| 2219 | if (!rdev->ops->set_default_mgmt_key) { |
| 2220 | err = -EOPNOTSUPP; |
| 2221 | goto out; |
| 2222 | } |
| 2223 | |
| 2224 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2225 | if (err) |
| 2226 | goto out; |
| 2227 | |
| 2228 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 2229 | dev, key.idx); |
| 2230 | if (err) |
| 2231 | goto out; |
| 2232 | |
| 2233 | #ifdef CONFIG_CFG80211_WEXT |
| 2234 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2235 | #endif |
| 2236 | } |
| 2237 | |
| 2238 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2239 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2240 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2241 | return err; |
| 2242 | } |
| 2243 | |
| 2244 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2245 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2246 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2247 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2248 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2249 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2250 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2251 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2252 | err = nl80211_parse_key(info, &key); |
| 2253 | if (err) |
| 2254 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2255 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2256 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2257 | return -EINVAL; |
| 2258 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2259 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2260 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2261 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2262 | if (key.type == -1) { |
| 2263 | if (mac_addr) |
| 2264 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2265 | else |
| 2266 | key.type = NL80211_KEYTYPE_GROUP; |
| 2267 | } |
| 2268 | |
| 2269 | /* for now */ |
| 2270 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2271 | key.type != NL80211_KEYTYPE_GROUP) |
| 2272 | return -EINVAL; |
| 2273 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2274 | if (!rdev->ops->add_key) |
| 2275 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2276 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2277 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2278 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2279 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2280 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2281 | |
| 2282 | wdev_lock(dev->ieee80211_ptr); |
| 2283 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2284 | if (!err) |
| 2285 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2286 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2287 | mac_addr, &key.p); |
| 2288 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2289 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2290 | return err; |
| 2291 | } |
| 2292 | |
| 2293 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2294 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2295 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2296 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2297 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2298 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2299 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2300 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2301 | err = nl80211_parse_key(info, &key); |
| 2302 | if (err) |
| 2303 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2304 | |
| 2305 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2306 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2307 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2308 | if (key.type == -1) { |
| 2309 | if (mac_addr) |
| 2310 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2311 | else |
| 2312 | key.type = NL80211_KEYTYPE_GROUP; |
| 2313 | } |
| 2314 | |
| 2315 | /* for now */ |
| 2316 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2317 | key.type != NL80211_KEYTYPE_GROUP) |
| 2318 | return -EINVAL; |
| 2319 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2320 | if (!rdev->ops->del_key) |
| 2321 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2322 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2323 | wdev_lock(dev->ieee80211_ptr); |
| 2324 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2325 | |
| 2326 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2327 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2328 | err = -ENOENT; |
| 2329 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2330 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2331 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 2332 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2333 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2334 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2335 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2336 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2337 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2338 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2339 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2340 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2341 | } |
| 2342 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2343 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2344 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2345 | return err; |
| 2346 | } |
| 2347 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2348 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2349 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2350 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2351 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2352 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2353 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2354 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2355 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2356 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2357 | return -EINVAL; |
| 2358 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2359 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2360 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2361 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2362 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2363 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2364 | if (!bcn->head_len) |
| 2365 | return -EINVAL; |
| 2366 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2370 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2371 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2372 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2373 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2374 | } |
| 2375 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2376 | if (!haveinfo) |
| 2377 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2378 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2379 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2380 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2381 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2385 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2386 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2387 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2388 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2389 | } |
| 2390 | |
| 2391 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2392 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2393 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2394 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2395 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2396 | } |
| 2397 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2398 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2399 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2400 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2401 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2402 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2403 | } |
| 2404 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2405 | return 0; |
| 2406 | } |
| 2407 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2408 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2409 | struct cfg80211_ap_settings *params) |
| 2410 | { |
| 2411 | struct wireless_dev *wdev; |
| 2412 | bool ret = false; |
| 2413 | |
| 2414 | mutex_lock(&rdev->devlist_mtx); |
| 2415 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame^] | 2416 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2417 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2418 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2419 | continue; |
| 2420 | |
| 2421 | if (!wdev->preset_chan) |
| 2422 | continue; |
| 2423 | |
| 2424 | params->channel = wdev->preset_chan; |
| 2425 | params->channel_type = wdev->preset_chantype; |
| 2426 | ret = true; |
| 2427 | break; |
| 2428 | } |
| 2429 | |
| 2430 | mutex_unlock(&rdev->devlist_mtx); |
| 2431 | |
| 2432 | return ret; |
| 2433 | } |
| 2434 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2435 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2436 | { |
| 2437 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2438 | struct net_device *dev = info->user_ptr[1]; |
| 2439 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2440 | struct cfg80211_ap_settings params; |
| 2441 | int err; |
| 2442 | |
| 2443 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2444 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2445 | return -EOPNOTSUPP; |
| 2446 | |
| 2447 | if (!rdev->ops->start_ap) |
| 2448 | return -EOPNOTSUPP; |
| 2449 | |
| 2450 | if (wdev->beacon_interval) |
| 2451 | return -EALREADY; |
| 2452 | |
| 2453 | memset(¶ms, 0, sizeof(params)); |
| 2454 | |
| 2455 | /* these are required for START_AP */ |
| 2456 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2457 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2458 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2459 | return -EINVAL; |
| 2460 | |
| 2461 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2462 | if (err) |
| 2463 | return err; |
| 2464 | |
| 2465 | params.beacon_interval = |
| 2466 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2467 | params.dtim_period = |
| 2468 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2469 | |
| 2470 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2471 | if (err) |
| 2472 | return err; |
| 2473 | |
| 2474 | /* |
| 2475 | * In theory, some of these attributes should be required here |
| 2476 | * but since they were not used when the command was originally |
| 2477 | * added, keep them optional for old user space programs to let |
| 2478 | * them continue to work with drivers that do not need the |
| 2479 | * additional information -- drivers must check! |
| 2480 | */ |
| 2481 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2482 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2483 | params.ssid_len = |
| 2484 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2485 | if (params.ssid_len == 0 || |
| 2486 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2487 | return -EINVAL; |
| 2488 | } |
| 2489 | |
| 2490 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2491 | params.hidden_ssid = nla_get_u32( |
| 2492 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2493 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2494 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2495 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2496 | return -EINVAL; |
| 2497 | } |
| 2498 | |
| 2499 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2500 | |
| 2501 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2502 | params.auth_type = nla_get_u32( |
| 2503 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2504 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2505 | return -EINVAL; |
| 2506 | } else |
| 2507 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2508 | |
| 2509 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2510 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2511 | if (err) |
| 2512 | return err; |
| 2513 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2514 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2515 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2516 | return -EOPNOTSUPP; |
| 2517 | params.inactivity_timeout = nla_get_u16( |
| 2518 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2519 | } |
| 2520 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2521 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 2522 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 2523 | |
| 2524 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 2525 | !nl80211_valid_channel_type(info, &channel_type)) |
| 2526 | return -EINVAL; |
| 2527 | |
| 2528 | params.channel = rdev_freq_to_chan(rdev, |
| 2529 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 2530 | channel_type); |
| 2531 | if (!params.channel) |
| 2532 | return -EINVAL; |
| 2533 | params.channel_type = channel_type; |
| 2534 | } else if (wdev->preset_chan) { |
| 2535 | params.channel = wdev->preset_chan; |
| 2536 | params.channel_type = wdev->preset_chantype; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2537 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2538 | return -EINVAL; |
| 2539 | |
| 2540 | if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel, |
| 2541 | params.channel_type)) |
| 2542 | return -EINVAL; |
| 2543 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 2544 | mutex_lock(&rdev->devlist_mtx); |
| 2545 | err = cfg80211_can_use_chan(rdev, wdev, params.channel, |
| 2546 | CHAN_MODE_SHARED); |
| 2547 | mutex_unlock(&rdev->devlist_mtx); |
| 2548 | |
| 2549 | if (err) |
| 2550 | return err; |
| 2551 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2552 | err = rdev->ops->start_ap(&rdev->wiphy, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2553 | if (!err) { |
| 2554 | wdev->preset_chan = params.channel; |
| 2555 | wdev->preset_chantype = params.channel_type; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2556 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | f4489eb | 2012-06-29 12:46:58 +0200 | [diff] [blame] | 2557 | wdev->channel = params.channel; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2558 | } |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2559 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2560 | } |
| 2561 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2562 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2563 | { |
| 2564 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2565 | struct net_device *dev = info->user_ptr[1]; |
| 2566 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2567 | struct cfg80211_beacon_data params; |
| 2568 | int err; |
| 2569 | |
| 2570 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2571 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2572 | return -EOPNOTSUPP; |
| 2573 | |
| 2574 | if (!rdev->ops->change_beacon) |
| 2575 | return -EOPNOTSUPP; |
| 2576 | |
| 2577 | if (!wdev->beacon_interval) |
| 2578 | return -EINVAL; |
| 2579 | |
| 2580 | err = nl80211_parse_beacon(info, ¶ms); |
| 2581 | if (err) |
| 2582 | return err; |
| 2583 | |
| 2584 | return rdev->ops->change_beacon(&rdev->wiphy, dev, ¶ms); |
| 2585 | } |
| 2586 | |
| 2587 | 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] | 2588 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2589 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2590 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2591 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 2592 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2593 | } |
| 2594 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2595 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2596 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2597 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2598 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2599 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2600 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2601 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2602 | }; |
| 2603 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2604 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2605 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2606 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2607 | { |
| 2608 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2609 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2610 | int flag; |
| 2611 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2612 | /* |
| 2613 | * Try parsing the new attribute first so userspace |
| 2614 | * can specify both for older kernels. |
| 2615 | */ |
| 2616 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2617 | if (nla) { |
| 2618 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2619 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2620 | sta_flags = nla_data(nla); |
| 2621 | params->sta_flags_mask = sta_flags->mask; |
| 2622 | params->sta_flags_set = sta_flags->set; |
| 2623 | if ((params->sta_flags_mask | |
| 2624 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2625 | return -EINVAL; |
| 2626 | return 0; |
| 2627 | } |
| 2628 | |
| 2629 | /* if present, parse the old attribute */ |
| 2630 | |
| 2631 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2632 | if (!nla) |
| 2633 | return 0; |
| 2634 | |
| 2635 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2636 | nla, sta_flags_policy)) |
| 2637 | return -EINVAL; |
| 2638 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2639 | /* |
| 2640 | * Only allow certain flags for interface types so that |
| 2641 | * other attributes are silently ignored. Remember that |
| 2642 | * this is backward compatibility code with old userspace |
| 2643 | * and shouldn't be hit in other cases anyway. |
| 2644 | */ |
| 2645 | switch (iftype) { |
| 2646 | case NL80211_IFTYPE_AP: |
| 2647 | case NL80211_IFTYPE_AP_VLAN: |
| 2648 | case NL80211_IFTYPE_P2P_GO: |
| 2649 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2650 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2651 | BIT(NL80211_STA_FLAG_WME) | |
| 2652 | BIT(NL80211_STA_FLAG_MFP); |
| 2653 | break; |
| 2654 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2655 | case NL80211_IFTYPE_STATION: |
| 2656 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2657 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2658 | break; |
| 2659 | case NL80211_IFTYPE_MESH_POINT: |
| 2660 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2661 | BIT(NL80211_STA_FLAG_MFP) | |
| 2662 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2663 | default: |
| 2664 | return -EINVAL; |
| 2665 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2666 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2667 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 2668 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2669 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2670 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2671 | /* no longer support new API additions in old API */ |
| 2672 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 2673 | return -EINVAL; |
| 2674 | } |
| 2675 | } |
| 2676 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2677 | return 0; |
| 2678 | } |
| 2679 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2680 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2681 | int attr) |
| 2682 | { |
| 2683 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2684 | u32 bitrate; |
| 2685 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2686 | |
| 2687 | rate = nla_nest_start(msg, attr); |
| 2688 | if (!rate) |
| 2689 | goto nla_put_failure; |
| 2690 | |
| 2691 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2692 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2693 | /* report 16-bit bitrate only if we can */ |
| 2694 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2695 | if ((bitrate > 0 && |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 2696 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) || |
| 2697 | (bitrate_compat > 0 && |
| 2698 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2699 | ((info->flags & RATE_INFO_FLAGS_MCS) && |
| 2700 | nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) || |
| 2701 | ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) && |
| 2702 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) || |
| 2703 | ((info->flags & RATE_INFO_FLAGS_SHORT_GI) && |
| 2704 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))) |
| 2705 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2706 | |
| 2707 | nla_nest_end(msg, rate); |
| 2708 | return true; |
| 2709 | |
| 2710 | nla_put_failure: |
| 2711 | return false; |
| 2712 | } |
| 2713 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2714 | 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] | 2715 | int flags, |
| 2716 | struct cfg80211_registered_device *rdev, |
| 2717 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2718 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2719 | { |
| 2720 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2721 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2722 | |
| 2723 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2724 | if (!hdr) |
| 2725 | return -1; |
| 2726 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2727 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2728 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 2729 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 2730 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2731 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2732 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2733 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2734 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2735 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 2736 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2737 | sinfo->connected_time)) |
| 2738 | goto nla_put_failure; |
| 2739 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 2740 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2741 | sinfo->inactive_time)) |
| 2742 | goto nla_put_failure; |
| 2743 | if ((sinfo->filled & STATION_INFO_RX_BYTES) && |
| 2744 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2745 | sinfo->rx_bytes)) |
| 2746 | goto nla_put_failure; |
| 2747 | if ((sinfo->filled & STATION_INFO_TX_BYTES) && |
| 2748 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2749 | sinfo->tx_bytes)) |
| 2750 | goto nla_put_failure; |
| 2751 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 2752 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 2753 | goto nla_put_failure; |
| 2754 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 2755 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 2756 | goto nla_put_failure; |
| 2757 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 2758 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2759 | sinfo->plink_state)) |
| 2760 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2761 | switch (rdev->wiphy.signal_type) { |
| 2762 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2763 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 2764 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 2765 | sinfo->signal)) |
| 2766 | goto nla_put_failure; |
| 2767 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 2768 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2769 | sinfo->signal_avg)) |
| 2770 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2771 | break; |
| 2772 | default: |
| 2773 | break; |
| 2774 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2775 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2776 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2777 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2778 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2779 | } |
| 2780 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2781 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2782 | NL80211_STA_INFO_RX_BITRATE)) |
| 2783 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2784 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2785 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 2786 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2787 | sinfo->rx_packets)) |
| 2788 | goto nla_put_failure; |
| 2789 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 2790 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2791 | sinfo->tx_packets)) |
| 2792 | goto nla_put_failure; |
| 2793 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 2794 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2795 | sinfo->tx_retries)) |
| 2796 | goto nla_put_failure; |
| 2797 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 2798 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2799 | sinfo->tx_failed)) |
| 2800 | goto nla_put_failure; |
| 2801 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 2802 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 2803 | sinfo->beacon_loss_count)) |
| 2804 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2805 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2806 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2807 | if (!bss_param) |
| 2808 | goto nla_put_failure; |
| 2809 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2810 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 2811 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 2812 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 2813 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 2814 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 2815 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 2816 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2817 | sinfo->bss_param.dtim_period) || |
| 2818 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2819 | sinfo->bss_param.beacon_interval)) |
| 2820 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2821 | |
| 2822 | nla_nest_end(msg, bss_param); |
| 2823 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2824 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 2825 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2826 | sizeof(struct nl80211_sta_flag_update), |
| 2827 | &sinfo->sta_flags)) |
| 2828 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 2829 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 2830 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 2831 | sinfo->t_offset)) |
| 2832 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2833 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2834 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2835 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 2836 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2837 | sinfo->assoc_req_ies)) |
| 2838 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2839 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2840 | return genlmsg_end(msg, hdr); |
| 2841 | |
| 2842 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2843 | genlmsg_cancel(msg, hdr); |
| 2844 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2845 | } |
| 2846 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2847 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2848 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2849 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2850 | struct station_info sinfo; |
| 2851 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2852 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2853 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2854 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2855 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2856 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2857 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2858 | if (err) |
| 2859 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2860 | |
| 2861 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2862 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2863 | goto out_err; |
| 2864 | } |
| 2865 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2866 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2867 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2868 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2869 | mac_addr, &sinfo); |
| 2870 | if (err == -ENOENT) |
| 2871 | break; |
| 2872 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2873 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2874 | |
| 2875 | if (nl80211_send_station(skb, |
| 2876 | NETLINK_CB(cb->skb).pid, |
| 2877 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2878 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2879 | &sinfo) < 0) |
| 2880 | goto out; |
| 2881 | |
| 2882 | sta_idx++; |
| 2883 | } |
| 2884 | |
| 2885 | |
| 2886 | out: |
| 2887 | cb->args[1] = sta_idx; |
| 2888 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2889 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2890 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2891 | |
| 2892 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2893 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2894 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2895 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2896 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2897 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2898 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2899 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2900 | struct sk_buff *msg; |
| 2901 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2902 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2903 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2904 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2905 | |
| 2906 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2907 | return -EINVAL; |
| 2908 | |
| 2909 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2910 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2911 | if (!rdev->ops->get_station) |
| 2912 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2913 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2914 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2915 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2916 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2917 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2918 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2919 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2920 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2921 | |
| 2922 | 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] | 2923 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2924 | nlmsg_free(msg); |
| 2925 | return -ENOBUFS; |
| 2926 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2927 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2928 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2932 | * 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] | 2933 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2934 | static struct net_device *get_vlan(struct genl_info *info, |
| 2935 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2936 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2937 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2938 | struct net_device *v; |
| 2939 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2940 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2941 | if (!vlanattr) |
| 2942 | return NULL; |
| 2943 | |
| 2944 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 2945 | if (!v) |
| 2946 | return ERR_PTR(-ENODEV); |
| 2947 | |
| 2948 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 2949 | ret = -EINVAL; |
| 2950 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2951 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2952 | |
| 2953 | if (!netif_running(v)) { |
| 2954 | ret = -ENETDOWN; |
| 2955 | goto error; |
| 2956 | } |
| 2957 | |
| 2958 | return v; |
| 2959 | error: |
| 2960 | dev_put(v); |
| 2961 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2965 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2966 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2967 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2968 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2969 | struct station_parameters params; |
| 2970 | u8 *mac_addr = NULL; |
| 2971 | |
| 2972 | memset(¶ms, 0, sizeof(params)); |
| 2973 | |
| 2974 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2975 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2976 | |
| 2977 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2978 | return -EINVAL; |
| 2979 | |
| 2980 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2981 | return -EINVAL; |
| 2982 | |
| 2983 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2984 | |
| 2985 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2986 | params.supported_rates = |
| 2987 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2988 | params.supported_rates_len = |
| 2989 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2990 | } |
| 2991 | |
| 2992 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2993 | params.listen_interval = |
| 2994 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2995 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2996 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2997 | params.ht_capa = |
| 2998 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2999 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3000 | if (!rdev->ops->change_station) |
| 3001 | return -EOPNOTSUPP; |
| 3002 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3003 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3004 | return -EINVAL; |
| 3005 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3006 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3007 | params.plink_action = |
| 3008 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3009 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3010 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 3011 | params.plink_state = |
| 3012 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3013 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3014 | switch (dev->ieee80211_ptr->iftype) { |
| 3015 | case NL80211_IFTYPE_AP: |
| 3016 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3017 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3018 | /* disallow mesh-specific things */ |
| 3019 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3020 | return -EINVAL; |
| 3021 | |
| 3022 | /* TDLS can't be set, ... */ |
| 3023 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3024 | return -EINVAL; |
| 3025 | /* |
| 3026 | * ... but don't bother the driver with it. This works around |
| 3027 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3028 | * TLDS_PEER flag in the mask even for AP mode. |
| 3029 | */ |
| 3030 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3031 | |
| 3032 | /* accept only the listed bits */ |
| 3033 | if (params.sta_flags_mask & |
| 3034 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3035 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3036 | BIT(NL80211_STA_FLAG_WME) | |
| 3037 | BIT(NL80211_STA_FLAG_MFP))) |
| 3038 | return -EINVAL; |
| 3039 | |
| 3040 | /* must be last in here for error handling */ |
| 3041 | params.vlan = get_vlan(info, rdev); |
| 3042 | if (IS_ERR(params.vlan)) |
| 3043 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3044 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3045 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3046 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3047 | /* |
| 3048 | * Don't allow userspace to change the TDLS_PEER flag, |
| 3049 | * but silently ignore attempts to change it since we |
| 3050 | * don't have state here to verify that it doesn't try |
| 3051 | * to change the flag. |
| 3052 | */ |
| 3053 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3054 | /* fall through */ |
| 3055 | case NL80211_IFTYPE_ADHOC: |
| 3056 | /* disallow things sta doesn't support */ |
| 3057 | if (params.plink_action) |
| 3058 | return -EINVAL; |
| 3059 | if (params.ht_capa) |
| 3060 | return -EINVAL; |
| 3061 | if (params.listen_interval >= 0) |
| 3062 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3063 | /* reject any changes other than AUTHORIZED */ |
| 3064 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3065 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3066 | break; |
| 3067 | case NL80211_IFTYPE_MESH_POINT: |
| 3068 | /* disallow things mesh doesn't support */ |
| 3069 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3070 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3071 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3072 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3073 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3074 | return -EINVAL; |
| 3075 | /* |
| 3076 | * No special handling for TDLS here -- the userspace |
| 3077 | * mesh code doesn't have this bug. |
| 3078 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3079 | if (params.sta_flags_mask & |
| 3080 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3081 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3082 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3083 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3084 | break; |
| 3085 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3086 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3087 | } |
| 3088 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3089 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3090 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3091 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3092 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3093 | if (params.vlan) |
| 3094 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3095 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3096 | return err; |
| 3097 | } |
| 3098 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3099 | static struct nla_policy |
| 3100 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3101 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3102 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3103 | }; |
| 3104 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3105 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3106 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3107 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3108 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3109 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3110 | struct station_parameters params; |
| 3111 | u8 *mac_addr = NULL; |
| 3112 | |
| 3113 | memset(¶ms, 0, sizeof(params)); |
| 3114 | |
| 3115 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3116 | return -EINVAL; |
| 3117 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3118 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3119 | return -EINVAL; |
| 3120 | |
| 3121 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3122 | return -EINVAL; |
| 3123 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3124 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3125 | return -EINVAL; |
| 3126 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3127 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3128 | params.supported_rates = |
| 3129 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3130 | params.supported_rates_len = |
| 3131 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3132 | params.listen_interval = |
| 3133 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3134 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3135 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3136 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3137 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3138 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3139 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3140 | params.ht_capa = |
| 3141 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3142 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3143 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3144 | params.plink_action = |
| 3145 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3146 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3147 | if (!rdev->ops->add_station) |
| 3148 | return -EOPNOTSUPP; |
| 3149 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3150 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3151 | return -EINVAL; |
| 3152 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3153 | switch (dev->ieee80211_ptr->iftype) { |
| 3154 | case NL80211_IFTYPE_AP: |
| 3155 | case NL80211_IFTYPE_AP_VLAN: |
| 3156 | case NL80211_IFTYPE_P2P_GO: |
| 3157 | /* parse WME attributes if sta is WME capable */ |
| 3158 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3159 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3160 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3161 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3162 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3163 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3164 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3165 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3166 | nl80211_sta_wme_policy); |
| 3167 | if (err) |
| 3168 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3169 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3170 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3171 | params.uapsd_queues = |
| 3172 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3173 | if (params.uapsd_queues & |
| 3174 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3175 | return -EINVAL; |
| 3176 | |
| 3177 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3178 | params.max_sp = |
| 3179 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3180 | |
| 3181 | if (params.max_sp & |
| 3182 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3183 | return -EINVAL; |
| 3184 | |
| 3185 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3186 | } |
| 3187 | /* TDLS peers cannot be added */ |
| 3188 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3189 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3190 | /* but don't bother the driver with it */ |
| 3191 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3192 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3193 | /* must be last in here for error handling */ |
| 3194 | params.vlan = get_vlan(info, rdev); |
| 3195 | if (IS_ERR(params.vlan)) |
| 3196 | return PTR_ERR(params.vlan); |
| 3197 | break; |
| 3198 | case NL80211_IFTYPE_MESH_POINT: |
| 3199 | /* TDLS peers cannot be added */ |
| 3200 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3201 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3202 | break; |
| 3203 | case NL80211_IFTYPE_STATION: |
| 3204 | /* Only TDLS peers can be added */ |
| 3205 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3206 | return -EINVAL; |
| 3207 | /* Can only add if TDLS ... */ |
| 3208 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3209 | return -EOPNOTSUPP; |
| 3210 | /* ... with external setup is supported */ |
| 3211 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3212 | return -EOPNOTSUPP; |
| 3213 | break; |
| 3214 | default: |
| 3215 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3216 | } |
| 3217 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3218 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3219 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3220 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3221 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3222 | if (params.vlan) |
| 3223 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3224 | return err; |
| 3225 | } |
| 3226 | |
| 3227 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3228 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3229 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3230 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3231 | u8 *mac_addr = NULL; |
| 3232 | |
| 3233 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3234 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3235 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3236 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3237 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3238 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3239 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3240 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3241 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3242 | if (!rdev->ops->del_station) |
| 3243 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3244 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3245 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3246 | } |
| 3247 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3248 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 3249 | int flags, struct net_device *dev, |
| 3250 | u8 *dst, u8 *next_hop, |
| 3251 | struct mpath_info *pinfo) |
| 3252 | { |
| 3253 | void *hdr; |
| 3254 | struct nlattr *pinfoattr; |
| 3255 | |
| 3256 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 3257 | if (!hdr) |
| 3258 | return -1; |
| 3259 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3260 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3261 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3262 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3263 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3264 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3265 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3266 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3267 | if (!pinfoattr) |
| 3268 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3269 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3270 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3271 | pinfo->frame_qlen)) |
| 3272 | goto nla_put_failure; |
| 3273 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3274 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3275 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3276 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3277 | pinfo->metric)) || |
| 3278 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3279 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3280 | pinfo->exptime)) || |
| 3281 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3282 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3283 | pinfo->flags)) || |
| 3284 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3285 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3286 | pinfo->discovery_timeout)) || |
| 3287 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3288 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3289 | pinfo->discovery_retries))) |
| 3290 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3291 | |
| 3292 | nla_nest_end(msg, pinfoattr); |
| 3293 | |
| 3294 | return genlmsg_end(msg, hdr); |
| 3295 | |
| 3296 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3297 | genlmsg_cancel(msg, hdr); |
| 3298 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3302 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3303 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3304 | struct mpath_info pinfo; |
| 3305 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3306 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3307 | u8 dst[ETH_ALEN]; |
| 3308 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3309 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3310 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3311 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3312 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3313 | if (err) |
| 3314 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3315 | |
| 3316 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3317 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3318 | goto out_err; |
| 3319 | } |
| 3320 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3321 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3322 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3323 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3324 | } |
| 3325 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3326 | while (1) { |
| 3327 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 3328 | dst, next_hop, &pinfo); |
| 3329 | if (err == -ENOENT) |
| 3330 | break; |
| 3331 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3332 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3333 | |
| 3334 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 3335 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3336 | netdev, dst, next_hop, |
| 3337 | &pinfo) < 0) |
| 3338 | goto out; |
| 3339 | |
| 3340 | path_idx++; |
| 3341 | } |
| 3342 | |
| 3343 | |
| 3344 | out: |
| 3345 | cb->args[1] = path_idx; |
| 3346 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3347 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3348 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3349 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3353 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3354 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3355 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3356 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3357 | struct mpath_info pinfo; |
| 3358 | struct sk_buff *msg; |
| 3359 | u8 *dst = NULL; |
| 3360 | u8 next_hop[ETH_ALEN]; |
| 3361 | |
| 3362 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3363 | |
| 3364 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3365 | return -EINVAL; |
| 3366 | |
| 3367 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3368 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3369 | if (!rdev->ops->get_mpath) |
| 3370 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3371 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3372 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3373 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3374 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3375 | 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] | 3376 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3377 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3378 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3379 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3380 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3381 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3382 | |
| 3383 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3384 | dev, dst, next_hop, &pinfo) < 0) { |
| 3385 | nlmsg_free(msg); |
| 3386 | return -ENOBUFS; |
| 3387 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3388 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3389 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3390 | } |
| 3391 | |
| 3392 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3393 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3394 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3395 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3396 | u8 *dst = NULL; |
| 3397 | u8 *next_hop = NULL; |
| 3398 | |
| 3399 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3400 | return -EINVAL; |
| 3401 | |
| 3402 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3403 | return -EINVAL; |
| 3404 | |
| 3405 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3406 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3407 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3408 | if (!rdev->ops->change_mpath) |
| 3409 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3410 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3411 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3412 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3413 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3414 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3415 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3416 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3417 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3418 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3419 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3420 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3421 | u8 *dst = NULL; |
| 3422 | u8 *next_hop = NULL; |
| 3423 | |
| 3424 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3425 | return -EINVAL; |
| 3426 | |
| 3427 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3428 | return -EINVAL; |
| 3429 | |
| 3430 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3431 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3432 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3433 | if (!rdev->ops->add_mpath) |
| 3434 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3435 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3436 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3437 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3438 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3439 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3443 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3444 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3445 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3446 | u8 *dst = NULL; |
| 3447 | |
| 3448 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3449 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3450 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3451 | if (!rdev->ops->del_mpath) |
| 3452 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3453 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3454 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3455 | } |
| 3456 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3457 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3458 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3459 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3460 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3461 | struct bss_parameters params; |
| 3462 | |
| 3463 | memset(¶ms, 0, sizeof(params)); |
| 3464 | /* default to not changing parameters */ |
| 3465 | params.use_cts_prot = -1; |
| 3466 | params.use_short_preamble = -1; |
| 3467 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3468 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3469 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3470 | |
| 3471 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3472 | params.use_cts_prot = |
| 3473 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3474 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3475 | params.use_short_preamble = |
| 3476 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3477 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3478 | params.use_short_slot_time = |
| 3479 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3480 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3481 | params.basic_rates = |
| 3482 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3483 | params.basic_rates_len = |
| 3484 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3485 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3486 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3487 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3488 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3489 | params.ht_opmode = |
| 3490 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3491 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3492 | if (!rdev->ops->change_bss) |
| 3493 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3494 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3495 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3496 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3497 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3498 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3499 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3500 | } |
| 3501 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3502 | 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] | 3503 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3504 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3505 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3506 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3507 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3508 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3509 | }; |
| 3510 | |
| 3511 | static int parse_reg_rule(struct nlattr *tb[], |
| 3512 | struct ieee80211_reg_rule *reg_rule) |
| 3513 | { |
| 3514 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3515 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3516 | |
| 3517 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3518 | return -EINVAL; |
| 3519 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3520 | return -EINVAL; |
| 3521 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3522 | return -EINVAL; |
| 3523 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3524 | return -EINVAL; |
| 3525 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3526 | return -EINVAL; |
| 3527 | |
| 3528 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3529 | |
| 3530 | freq_range->start_freq_khz = |
| 3531 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3532 | freq_range->end_freq_khz = |
| 3533 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3534 | freq_range->max_bandwidth_khz = |
| 3535 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3536 | |
| 3537 | power_rule->max_eirp = |
| 3538 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3539 | |
| 3540 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3541 | power_rule->max_antenna_gain = |
| 3542 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3543 | |
| 3544 | return 0; |
| 3545 | } |
| 3546 | |
| 3547 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3548 | { |
| 3549 | int r; |
| 3550 | char *data = NULL; |
| 3551 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3552 | /* |
| 3553 | * You should only get this when cfg80211 hasn't yet initialized |
| 3554 | * completely when built-in to the kernel right between the time |
| 3555 | * window between nl80211_init() and regulatory_init(), if that is |
| 3556 | * even possible. |
| 3557 | */ |
| 3558 | mutex_lock(&cfg80211_mutex); |
| 3559 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3560 | mutex_unlock(&cfg80211_mutex); |
| 3561 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3562 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3563 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3564 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3565 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3566 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3567 | |
| 3568 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3569 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3570 | r = regulatory_hint_user(data); |
| 3571 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3572 | return r; |
| 3573 | } |
| 3574 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3575 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3576 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3577 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3578 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3579 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3580 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3581 | struct mesh_config cur_params; |
| 3582 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3583 | void *hdr; |
| 3584 | struct nlattr *pinfoattr; |
| 3585 | struct sk_buff *msg; |
| 3586 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3587 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3588 | return -EOPNOTSUPP; |
| 3589 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3590 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3591 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3592 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3593 | wdev_lock(wdev); |
| 3594 | /* If not connected, get default parameters */ |
| 3595 | if (!wdev->mesh_id_len) |
| 3596 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3597 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3598 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3599 | &cur_params); |
| 3600 | wdev_unlock(wdev); |
| 3601 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3602 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3603 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3604 | |
| 3605 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3606 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3607 | if (!msg) |
| 3608 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3609 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3610 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3611 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3612 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3613 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3614 | if (!pinfoattr) |
| 3615 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3616 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3617 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3618 | cur_params.dot11MeshRetryTimeout) || |
| 3619 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3620 | cur_params.dot11MeshConfirmTimeout) || |
| 3621 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3622 | cur_params.dot11MeshHoldingTimeout) || |
| 3623 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3624 | cur_params.dot11MeshMaxPeerLinks) || |
| 3625 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3626 | cur_params.dot11MeshMaxRetries) || |
| 3627 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 3628 | cur_params.dot11MeshTTL) || |
| 3629 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3630 | cur_params.element_ttl) || |
| 3631 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3632 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3633 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3634 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3635 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3636 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 3637 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3638 | cur_params.path_refresh_time) || |
| 3639 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3640 | cur_params.min_discovery_timeout) || |
| 3641 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3642 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 3643 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3644 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 3645 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3646 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 3647 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3648 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 3649 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3650 | cur_params.dot11MeshHWMPRootMode) || |
| 3651 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3652 | cur_params.dot11MeshHWMPRannInterval) || |
| 3653 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3654 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 3655 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 3656 | cur_params.dot11MeshForwarding) || |
| 3657 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3658 | cur_params.rssi_threshold) || |
| 3659 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3660 | cur_params.ht_opmode) || |
| 3661 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3662 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 3663 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3664 | cur_params.dot11MeshHWMProotInterval) || |
| 3665 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3666 | cur_params.dot11MeshHWMPconfirmationInterval)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3667 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3668 | nla_nest_end(msg, pinfoattr); |
| 3669 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3670 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3671 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3672 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3673 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3674 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3675 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3676 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3677 | } |
| 3678 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3679 | 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] | 3680 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3681 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3682 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3683 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3684 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3685 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3686 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3687 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3688 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3689 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3690 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3691 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3692 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3693 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3694 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3695 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3696 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3697 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3698 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3699 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3700 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 3701 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3702 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 3703 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3704 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3705 | }; |
| 3706 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3707 | static const struct nla_policy |
| 3708 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3709 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3710 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3711 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3712 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3713 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3714 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3715 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3716 | }; |
| 3717 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3718 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3719 | struct mesh_config *cfg, |
| 3720 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3721 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3722 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3723 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3724 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3725 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3726 | do {\ |
| 3727 | if (table[attr_num]) {\ |
| 3728 | cfg->param = nla_fn(table[attr_num]); \ |
| 3729 | mask |= (1 << (attr_num - 1)); \ |
| 3730 | } \ |
| 3731 | } while (0);\ |
| 3732 | |
| 3733 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3734 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3735 | return -EINVAL; |
| 3736 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3737 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3738 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3739 | return -EINVAL; |
| 3740 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3741 | /* This makes sure that there aren't more than 32 mesh config |
| 3742 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3743 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3744 | |
| 3745 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3746 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3747 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3748 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3749 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3750 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3751 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3752 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3753 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3754 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3755 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3756 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3757 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3758 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3759 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 3760 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3761 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3762 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3763 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3764 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 3765 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3766 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3767 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3768 | nla_get_u8); |
| 3769 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask, |
| 3770 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3771 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3772 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3773 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3774 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3775 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3776 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3777 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3778 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3779 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3780 | nla_get_u16); |
| 3781 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask, |
| 3782 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3783 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3784 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3785 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3786 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3787 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3788 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3789 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3790 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3791 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
| 3792 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3793 | nla_get_u16); |
| 3794 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 3795 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 3796 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 3797 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3798 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3799 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3800 | dot11MeshGateAnnouncementProtocol, mask, |
| 3801 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3802 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3803 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3804 | mask, NL80211_MESHCONF_FORWARDING, |
| 3805 | nla_get_u8); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 3806 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3807 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 3808 | nla_get_u32); |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3809 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3810 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 3811 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3812 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
| 3813 | mask, |
| 3814 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3815 | nla_get_u32); |
| 3816 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, |
| 3817 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 3818 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3819 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3820 | dot11MeshHWMPconfirmationInterval, mask, |
| 3821 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3822 | nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3823 | if (mask_out) |
| 3824 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3825 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3826 | return 0; |
| 3827 | |
| 3828 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3829 | } |
| 3830 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3831 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3832 | struct mesh_setup *setup) |
| 3833 | { |
| 3834 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3835 | |
| 3836 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3837 | return -EINVAL; |
| 3838 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3839 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3840 | nl80211_mesh_setup_params_policy)) |
| 3841 | return -EINVAL; |
| 3842 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3843 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 3844 | setup->sync_method = |
| 3845 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 3846 | IEEE80211_SYNC_METHOD_VENDOR : |
| 3847 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 3848 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3849 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3850 | setup->path_sel_proto = |
| 3851 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3852 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3853 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3854 | |
| 3855 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3856 | setup->path_metric = |
| 3857 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3858 | IEEE80211_PATH_METRIC_VENDOR : |
| 3859 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3860 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3861 | |
| 3862 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3863 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3864 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3865 | if (!is_valid_ie_attr(ieattr)) |
| 3866 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3867 | setup->ie = nla_data(ieattr); |
| 3868 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3869 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3870 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3871 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3872 | |
| 3873 | return 0; |
| 3874 | } |
| 3875 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3876 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3877 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3878 | { |
| 3879 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3880 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3881 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3882 | struct mesh_config cfg; |
| 3883 | u32 mask; |
| 3884 | int err; |
| 3885 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3886 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3887 | return -EOPNOTSUPP; |
| 3888 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3889 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3890 | return -EOPNOTSUPP; |
| 3891 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3892 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3893 | if (err) |
| 3894 | return err; |
| 3895 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3896 | wdev_lock(wdev); |
| 3897 | if (!wdev->mesh_id_len) |
| 3898 | err = -ENOLINK; |
| 3899 | |
| 3900 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3901 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3902 | mask, &cfg); |
| 3903 | |
| 3904 | wdev_unlock(wdev); |
| 3905 | |
| 3906 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3909 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3910 | { |
| 3911 | struct sk_buff *msg; |
| 3912 | void *hdr = NULL; |
| 3913 | struct nlattr *nl_reg_rules; |
| 3914 | unsigned int i; |
| 3915 | int err = -EINVAL; |
| 3916 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3917 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3918 | |
| 3919 | if (!cfg80211_regdomain) |
| 3920 | goto out; |
| 3921 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3922 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3923 | if (!msg) { |
| 3924 | err = -ENOBUFS; |
| 3925 | goto out; |
| 3926 | } |
| 3927 | |
| 3928 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3929 | NL80211_CMD_GET_REG); |
| 3930 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3931 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3932 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3933 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 3934 | cfg80211_regdomain->alpha2) || |
| 3935 | (cfg80211_regdomain->dfs_region && |
| 3936 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, |
| 3937 | cfg80211_regdomain->dfs_region))) |
| 3938 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3939 | |
| 3940 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3941 | if (!nl_reg_rules) |
| 3942 | goto nla_put_failure; |
| 3943 | |
| 3944 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3945 | struct nlattr *nl_reg_rule; |
| 3946 | const struct ieee80211_reg_rule *reg_rule; |
| 3947 | const struct ieee80211_freq_range *freq_range; |
| 3948 | const struct ieee80211_power_rule *power_rule; |
| 3949 | |
| 3950 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3951 | freq_range = ®_rule->freq_range; |
| 3952 | power_rule = ®_rule->power_rule; |
| 3953 | |
| 3954 | nl_reg_rule = nla_nest_start(msg, i); |
| 3955 | if (!nl_reg_rule) |
| 3956 | goto nla_put_failure; |
| 3957 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3958 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3959 | reg_rule->flags) || |
| 3960 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3961 | freq_range->start_freq_khz) || |
| 3962 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3963 | freq_range->end_freq_khz) || |
| 3964 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3965 | freq_range->max_bandwidth_khz) || |
| 3966 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3967 | power_rule->max_antenna_gain) || |
| 3968 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3969 | power_rule->max_eirp)) |
| 3970 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3971 | |
| 3972 | nla_nest_end(msg, nl_reg_rule); |
| 3973 | } |
| 3974 | |
| 3975 | nla_nest_end(msg, nl_reg_rules); |
| 3976 | |
| 3977 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3978 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3979 | goto out; |
| 3980 | |
| 3981 | nla_put_failure: |
| 3982 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3983 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3984 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3985 | err = -EMSGSIZE; |
| 3986 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3987 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3988 | return err; |
| 3989 | } |
| 3990 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3991 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3992 | { |
| 3993 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3994 | struct nlattr *nl_reg_rule; |
| 3995 | char *alpha2 = NULL; |
| 3996 | int rem_reg_rules = 0, r = 0; |
| 3997 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3998 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3999 | struct ieee80211_regdomain *rd = NULL; |
| 4000 | |
| 4001 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4002 | return -EINVAL; |
| 4003 | |
| 4004 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4005 | return -EINVAL; |
| 4006 | |
| 4007 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4008 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4009 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4010 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4011 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4012 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 4013 | rem_reg_rules) { |
| 4014 | num_rules++; |
| 4015 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4016 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4017 | } |
| 4018 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4019 | mutex_lock(&cfg80211_mutex); |
| 4020 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4021 | if (!reg_is_valid_request(alpha2)) { |
| 4022 | r = -EINVAL; |
| 4023 | goto bad_reg; |
| 4024 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4025 | |
| 4026 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 4027 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 4028 | |
| 4029 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4030 | if (!rd) { |
| 4031 | r = -ENOMEM; |
| 4032 | goto bad_reg; |
| 4033 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4034 | |
| 4035 | rd->n_reg_rules = num_rules; |
| 4036 | rd->alpha2[0] = alpha2[0]; |
| 4037 | rd->alpha2[1] = alpha2[1]; |
| 4038 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4039 | /* |
| 4040 | * Disable DFS master mode if the DFS region was |
| 4041 | * not supported or known on this kernel. |
| 4042 | */ |
| 4043 | if (reg_supported_dfs_region(dfs_region)) |
| 4044 | rd->dfs_region = 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 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 4049 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4050 | reg_rule_policy); |
| 4051 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4052 | if (r) |
| 4053 | goto bad_reg; |
| 4054 | |
| 4055 | rule_idx++; |
| 4056 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4057 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4058 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4059 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4060 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4061 | } |
| 4062 | |
| 4063 | BUG_ON(rule_idx != num_rules); |
| 4064 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4065 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4066 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 4067 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4068 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4069 | return r; |
| 4070 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4071 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4072 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4073 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4074 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4075 | } |
| 4076 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4077 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4078 | { |
| 4079 | struct nlattr *attr1, *attr2; |
| 4080 | int n_channels = 0, tmp1, tmp2; |
| 4081 | |
| 4082 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4083 | n_channels++; |
| 4084 | /* |
| 4085 | * Some hardware has a limited channel list for |
| 4086 | * scanning, and it is pretty much nonsensical |
| 4087 | * to scan for a channel twice, so disallow that |
| 4088 | * and don't require drivers to check that the |
| 4089 | * channel list they get isn't longer than what |
| 4090 | * they can scan, as long as they can scan all |
| 4091 | * the channels they registered at once. |
| 4092 | */ |
| 4093 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4094 | if (attr1 != attr2 && |
| 4095 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4096 | return 0; |
| 4097 | } |
| 4098 | |
| 4099 | return n_channels; |
| 4100 | } |
| 4101 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4102 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4103 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4104 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4105 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4106 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4107 | struct nlattr *attr; |
| 4108 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4109 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4110 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4111 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4112 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4113 | return -EINVAL; |
| 4114 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4115 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4116 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4117 | if (!rdev->ops->scan) |
| 4118 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4119 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4120 | if (rdev->scan_req) |
| 4121 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4122 | |
| 4123 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4124 | n_channels = validate_scan_freqs( |
| 4125 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4126 | if (!n_channels) |
| 4127 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4128 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4129 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4130 | n_channels = 0; |
| 4131 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4132 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4133 | if (wiphy->bands[band]) |
| 4134 | n_channels += wiphy->bands[band]->n_channels; |
| 4135 | } |
| 4136 | |
| 4137 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4138 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4139 | n_ssids++; |
| 4140 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4141 | if (n_ssids > wiphy->max_scan_ssids) |
| 4142 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4143 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4144 | if (info->attrs[NL80211_ATTR_IE]) |
| 4145 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4146 | else |
| 4147 | ie_len = 0; |
| 4148 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4149 | if (ie_len > wiphy->max_scan_ie_len) |
| 4150 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4151 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4152 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4153 | + sizeof(*request->ssids) * n_ssids |
| 4154 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4155 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4156 | if (!request) |
| 4157 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4158 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4159 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4160 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4161 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4162 | if (ie_len) { |
| 4163 | if (request->ssids) |
| 4164 | request->ie = (void *)(request->ssids + n_ssids); |
| 4165 | else |
| 4166 | request->ie = (void *)(request->channels + n_channels); |
| 4167 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4168 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4169 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4170 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4171 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4172 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4173 | struct ieee80211_channel *chan; |
| 4174 | |
| 4175 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4176 | |
| 4177 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4178 | err = -EINVAL; |
| 4179 | goto out_free; |
| 4180 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4181 | |
| 4182 | /* ignore disabled channels */ |
| 4183 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4184 | continue; |
| 4185 | |
| 4186 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4187 | i++; |
| 4188 | } |
| 4189 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4190 | enum ieee80211_band band; |
| 4191 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4192 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4193 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4194 | int j; |
| 4195 | if (!wiphy->bands[band]) |
| 4196 | continue; |
| 4197 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4198 | struct ieee80211_channel *chan; |
| 4199 | |
| 4200 | chan = &wiphy->bands[band]->channels[j]; |
| 4201 | |
| 4202 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4203 | continue; |
| 4204 | |
| 4205 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4206 | i++; |
| 4207 | } |
| 4208 | } |
| 4209 | } |
| 4210 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4211 | if (!i) { |
| 4212 | err = -EINVAL; |
| 4213 | goto out_free; |
| 4214 | } |
| 4215 | |
| 4216 | request->n_channels = i; |
| 4217 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4218 | i = 0; |
| 4219 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4220 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4221 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4222 | err = -EINVAL; |
| 4223 | goto out_free; |
| 4224 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4225 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4226 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4227 | i++; |
| 4228 | } |
| 4229 | } |
| 4230 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4231 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4232 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4233 | memcpy((void *)request->ie, |
| 4234 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4235 | request->ie_len); |
| 4236 | } |
| 4237 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4238 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4239 | if (wiphy->bands[i]) |
| 4240 | request->rates[i] = |
| 4241 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4242 | |
| 4243 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4244 | nla_for_each_nested(attr, |
| 4245 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4246 | tmp) { |
| 4247 | enum ieee80211_band band = nla_type(attr); |
| 4248 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4249 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4250 | err = -EINVAL; |
| 4251 | goto out_free; |
| 4252 | } |
| 4253 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4254 | nla_data(attr), |
| 4255 | nla_len(attr), |
| 4256 | &request->rates[band]); |
| 4257 | if (err) |
| 4258 | goto out_free; |
| 4259 | } |
| 4260 | } |
| 4261 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4262 | request->no_cck = |
| 4263 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4264 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4265 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4266 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4267 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4268 | rdev->scan_req = request; |
| 4269 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4270 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4271 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4272 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4273 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4274 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4275 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4276 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4277 | kfree(request); |
| 4278 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4279 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4280 | return err; |
| 4281 | } |
| 4282 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4283 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4284 | struct genl_info *info) |
| 4285 | { |
| 4286 | struct cfg80211_sched_scan_request *request; |
| 4287 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4288 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4289 | struct nlattr *attr; |
| 4290 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4291 | 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] | 4292 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4293 | enum ieee80211_band band; |
| 4294 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4295 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4296 | |
| 4297 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4298 | !rdev->ops->sched_scan_start) |
| 4299 | return -EOPNOTSUPP; |
| 4300 | |
| 4301 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4302 | return -EINVAL; |
| 4303 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4304 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4305 | return -EINVAL; |
| 4306 | |
| 4307 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4308 | if (interval == 0) |
| 4309 | return -EINVAL; |
| 4310 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4311 | wiphy = &rdev->wiphy; |
| 4312 | |
| 4313 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4314 | n_channels = validate_scan_freqs( |
| 4315 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4316 | if (!n_channels) |
| 4317 | return -EINVAL; |
| 4318 | } else { |
| 4319 | n_channels = 0; |
| 4320 | |
| 4321 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4322 | if (wiphy->bands[band]) |
| 4323 | n_channels += wiphy->bands[band]->n_channels; |
| 4324 | } |
| 4325 | |
| 4326 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4327 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4328 | tmp) |
| 4329 | n_ssids++; |
| 4330 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4331 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4332 | return -EINVAL; |
| 4333 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4334 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4335 | nla_for_each_nested(attr, |
| 4336 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4337 | tmp) |
| 4338 | n_match_sets++; |
| 4339 | |
| 4340 | if (n_match_sets > wiphy->max_match_sets) |
| 4341 | return -EINVAL; |
| 4342 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4343 | if (info->attrs[NL80211_ATTR_IE]) |
| 4344 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4345 | else |
| 4346 | ie_len = 0; |
| 4347 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4348 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4349 | return -EINVAL; |
| 4350 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4351 | mutex_lock(&rdev->sched_scan_mtx); |
| 4352 | |
| 4353 | if (rdev->sched_scan_req) { |
| 4354 | err = -EINPROGRESS; |
| 4355 | goto out; |
| 4356 | } |
| 4357 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4358 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4359 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4360 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4361 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4362 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4363 | if (!request) { |
| 4364 | err = -ENOMEM; |
| 4365 | goto out; |
| 4366 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4367 | |
| 4368 | if (n_ssids) |
| 4369 | request->ssids = (void *)&request->channels[n_channels]; |
| 4370 | request->n_ssids = n_ssids; |
| 4371 | if (ie_len) { |
| 4372 | if (request->ssids) |
| 4373 | request->ie = (void *)(request->ssids + n_ssids); |
| 4374 | else |
| 4375 | request->ie = (void *)(request->channels + n_channels); |
| 4376 | } |
| 4377 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4378 | if (n_match_sets) { |
| 4379 | if (request->ie) |
| 4380 | request->match_sets = (void *)(request->ie + ie_len); |
| 4381 | else if (request->ssids) |
| 4382 | request->match_sets = |
| 4383 | (void *)(request->ssids + n_ssids); |
| 4384 | else |
| 4385 | request->match_sets = |
| 4386 | (void *)(request->channels + n_channels); |
| 4387 | } |
| 4388 | request->n_match_sets = n_match_sets; |
| 4389 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4390 | i = 0; |
| 4391 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4392 | /* user specified, bail out if channel not found */ |
| 4393 | nla_for_each_nested(attr, |
| 4394 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4395 | tmp) { |
| 4396 | struct ieee80211_channel *chan; |
| 4397 | |
| 4398 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4399 | |
| 4400 | if (!chan) { |
| 4401 | err = -EINVAL; |
| 4402 | goto out_free; |
| 4403 | } |
| 4404 | |
| 4405 | /* ignore disabled channels */ |
| 4406 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4407 | continue; |
| 4408 | |
| 4409 | request->channels[i] = chan; |
| 4410 | i++; |
| 4411 | } |
| 4412 | } else { |
| 4413 | /* all channels */ |
| 4414 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4415 | int j; |
| 4416 | if (!wiphy->bands[band]) |
| 4417 | continue; |
| 4418 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4419 | struct ieee80211_channel *chan; |
| 4420 | |
| 4421 | chan = &wiphy->bands[band]->channels[j]; |
| 4422 | |
| 4423 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4424 | continue; |
| 4425 | |
| 4426 | request->channels[i] = chan; |
| 4427 | i++; |
| 4428 | } |
| 4429 | } |
| 4430 | } |
| 4431 | |
| 4432 | if (!i) { |
| 4433 | err = -EINVAL; |
| 4434 | goto out_free; |
| 4435 | } |
| 4436 | |
| 4437 | request->n_channels = i; |
| 4438 | |
| 4439 | i = 0; |
| 4440 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4441 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4442 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4443 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4444 | err = -EINVAL; |
| 4445 | goto out_free; |
| 4446 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4447 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4448 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4449 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4450 | i++; |
| 4451 | } |
| 4452 | } |
| 4453 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4454 | i = 0; |
| 4455 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4456 | nla_for_each_nested(attr, |
| 4457 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4458 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4459 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4460 | |
| 4461 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4462 | nla_data(attr), nla_len(attr), |
| 4463 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 4464 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4465 | if (ssid) { |
| 4466 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4467 | err = -EINVAL; |
| 4468 | goto out_free; |
| 4469 | } |
| 4470 | memcpy(request->match_sets[i].ssid.ssid, |
| 4471 | nla_data(ssid), nla_len(ssid)); |
| 4472 | request->match_sets[i].ssid.ssid_len = |
| 4473 | nla_len(ssid); |
| 4474 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 4475 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 4476 | if (rssi) |
| 4477 | request->rssi_thold = nla_get_u32(rssi); |
| 4478 | else |
| 4479 | request->rssi_thold = |
| 4480 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4481 | i++; |
| 4482 | } |
| 4483 | } |
| 4484 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4485 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4486 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4487 | memcpy((void *)request->ie, |
| 4488 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4489 | request->ie_len); |
| 4490 | } |
| 4491 | |
| 4492 | request->dev = dev; |
| 4493 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4494 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4495 | |
| 4496 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 4497 | if (!err) { |
| 4498 | rdev->sched_scan_req = request; |
| 4499 | nl80211_send_sched_scan(rdev, dev, |
| 4500 | NL80211_CMD_START_SCHED_SCAN); |
| 4501 | goto out; |
| 4502 | } |
| 4503 | |
| 4504 | out_free: |
| 4505 | kfree(request); |
| 4506 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4507 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4508 | return err; |
| 4509 | } |
| 4510 | |
| 4511 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4512 | struct genl_info *info) |
| 4513 | { |
| 4514 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4515 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4516 | |
| 4517 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4518 | !rdev->ops->sched_scan_stop) |
| 4519 | return -EOPNOTSUPP; |
| 4520 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4521 | mutex_lock(&rdev->sched_scan_mtx); |
| 4522 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4523 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4524 | |
| 4525 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4526 | } |
| 4527 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4528 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4529 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4530 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4531 | struct wireless_dev *wdev, |
| 4532 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4533 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4534 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4535 | void *hdr; |
| 4536 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4537 | |
| 4538 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4539 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4540 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4541 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4542 | if (!hdr) |
| 4543 | return -1; |
| 4544 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4545 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4546 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4547 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 4548 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 4549 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4550 | |
| 4551 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4552 | if (!bss) |
| 4553 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4554 | if ((!is_zero_ether_addr(res->bssid) && |
| 4555 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) || |
| 4556 | (res->information_elements && res->len_information_elements && |
| 4557 | nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4558 | res->len_information_elements, |
| 4559 | res->information_elements)) || |
| 4560 | (res->beacon_ies && res->len_beacon_ies && |
| 4561 | res->beacon_ies != res->information_elements && |
| 4562 | nla_put(msg, NL80211_BSS_BEACON_IES, |
| 4563 | res->len_beacon_ies, res->beacon_ies))) |
| 4564 | goto nla_put_failure; |
| 4565 | if (res->tsf && |
| 4566 | nla_put_u64(msg, NL80211_BSS_TSF, res->tsf)) |
| 4567 | goto nla_put_failure; |
| 4568 | if (res->beacon_interval && |
| 4569 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 4570 | goto nla_put_failure; |
| 4571 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 4572 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 4573 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4574 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 4575 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4576 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4577 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4578 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4579 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 4580 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4581 | break; |
| 4582 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4583 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 4584 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4585 | break; |
| 4586 | default: |
| 4587 | break; |
| 4588 | } |
| 4589 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4590 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4591 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4592 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4593 | if (intbss == wdev->current_bss && |
| 4594 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4595 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 4596 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4597 | break; |
| 4598 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4599 | if (intbss == wdev->current_bss && |
| 4600 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4601 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 4602 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4603 | break; |
| 4604 | default: |
| 4605 | break; |
| 4606 | } |
| 4607 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4608 | nla_nest_end(msg, bss); |
| 4609 | |
| 4610 | return genlmsg_end(msg, hdr); |
| 4611 | |
| 4612 | nla_put_failure: |
| 4613 | genlmsg_cancel(msg, hdr); |
| 4614 | return -EMSGSIZE; |
| 4615 | } |
| 4616 | |
| 4617 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4618 | struct netlink_callback *cb) |
| 4619 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4620 | struct cfg80211_registered_device *rdev; |
| 4621 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4622 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4623 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4624 | int start = cb->args[1], idx = 0; |
| 4625 | int err; |
| 4626 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4627 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4628 | if (err) |
| 4629 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4630 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4631 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4632 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4633 | wdev_lock(wdev); |
| 4634 | spin_lock_bh(&rdev->bss_lock); |
| 4635 | cfg80211_bss_expire(rdev); |
| 4636 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4637 | cb->seq = rdev->bss_generation; |
| 4638 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4639 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4640 | if (++idx <= start) |
| 4641 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4642 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4643 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4644 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4645 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4646 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4647 | } |
| 4648 | } |
| 4649 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4650 | spin_unlock_bh(&rdev->bss_lock); |
| 4651 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4652 | |
| 4653 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4654 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4655 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4656 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4657 | } |
| 4658 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4659 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4660 | int flags, struct net_device *dev, |
| 4661 | struct survey_info *survey) |
| 4662 | { |
| 4663 | void *hdr; |
| 4664 | struct nlattr *infoattr; |
| 4665 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4666 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4667 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4668 | if (!hdr) |
| 4669 | return -ENOMEM; |
| 4670 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4671 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 4672 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4673 | |
| 4674 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4675 | if (!infoattr) |
| 4676 | goto nla_put_failure; |
| 4677 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4678 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4679 | survey->channel->center_freq)) |
| 4680 | goto nla_put_failure; |
| 4681 | |
| 4682 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 4683 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 4684 | goto nla_put_failure; |
| 4685 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 4686 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 4687 | goto nla_put_failure; |
| 4688 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 4689 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4690 | survey->channel_time)) |
| 4691 | goto nla_put_failure; |
| 4692 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 4693 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4694 | survey->channel_time_busy)) |
| 4695 | goto nla_put_failure; |
| 4696 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 4697 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4698 | survey->channel_time_ext_busy)) |
| 4699 | goto nla_put_failure; |
| 4700 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 4701 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4702 | survey->channel_time_rx)) |
| 4703 | goto nla_put_failure; |
| 4704 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 4705 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4706 | survey->channel_time_tx)) |
| 4707 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4708 | |
| 4709 | nla_nest_end(msg, infoattr); |
| 4710 | |
| 4711 | return genlmsg_end(msg, hdr); |
| 4712 | |
| 4713 | nla_put_failure: |
| 4714 | genlmsg_cancel(msg, hdr); |
| 4715 | return -EMSGSIZE; |
| 4716 | } |
| 4717 | |
| 4718 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4719 | struct netlink_callback *cb) |
| 4720 | { |
| 4721 | struct survey_info survey; |
| 4722 | struct cfg80211_registered_device *dev; |
| 4723 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4724 | int survey_idx = cb->args[1]; |
| 4725 | int res; |
| 4726 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4727 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4728 | if (res) |
| 4729 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4730 | |
| 4731 | if (!dev->ops->dump_survey) { |
| 4732 | res = -EOPNOTSUPP; |
| 4733 | goto out_err; |
| 4734 | } |
| 4735 | |
| 4736 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4737 | struct ieee80211_channel *chan; |
| 4738 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4739 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4740 | &survey); |
| 4741 | if (res == -ENOENT) |
| 4742 | break; |
| 4743 | if (res) |
| 4744 | goto out_err; |
| 4745 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4746 | /* Survey without a channel doesn't make sense */ |
| 4747 | if (!survey.channel) { |
| 4748 | res = -EINVAL; |
| 4749 | goto out; |
| 4750 | } |
| 4751 | |
| 4752 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4753 | survey.channel->center_freq); |
| 4754 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4755 | survey_idx++; |
| 4756 | continue; |
| 4757 | } |
| 4758 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4759 | if (nl80211_send_survey(skb, |
| 4760 | NETLINK_CB(cb->skb).pid, |
| 4761 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4762 | netdev, |
| 4763 | &survey) < 0) |
| 4764 | goto out; |
| 4765 | survey_idx++; |
| 4766 | } |
| 4767 | |
| 4768 | out: |
| 4769 | cb->args[1] = survey_idx; |
| 4770 | res = skb->len; |
| 4771 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4772 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4773 | return res; |
| 4774 | } |
| 4775 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4776 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4777 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4778 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4779 | } |
| 4780 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4781 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4782 | { |
| 4783 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4784 | NL80211_WPA_VERSION_2)); |
| 4785 | } |
| 4786 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4787 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4788 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4789 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4790 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4791 | struct ieee80211_channel *chan; |
| 4792 | const u8 *bssid, *ssid, *ie = NULL; |
| 4793 | int err, ssid_len, ie_len = 0; |
| 4794 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4795 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4796 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4797 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4798 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4799 | return -EINVAL; |
| 4800 | |
| 4801 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4802 | return -EINVAL; |
| 4803 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4804 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4805 | return -EINVAL; |
| 4806 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4807 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4808 | return -EINVAL; |
| 4809 | |
| 4810 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4811 | return -EINVAL; |
| 4812 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4813 | err = nl80211_parse_key(info, &key); |
| 4814 | if (err) |
| 4815 | return err; |
| 4816 | |
| 4817 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4818 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4819 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4820 | if (!key.p.key || !key.p.key_len) |
| 4821 | return -EINVAL; |
| 4822 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4823 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4824 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4825 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4826 | return -EINVAL; |
| 4827 | if (key.idx > 4) |
| 4828 | return -EINVAL; |
| 4829 | } else { |
| 4830 | key.p.key_len = 0; |
| 4831 | key.p.key = NULL; |
| 4832 | } |
| 4833 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4834 | if (key.idx >= 0) { |
| 4835 | int i; |
| 4836 | bool ok = false; |
| 4837 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4838 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4839 | ok = true; |
| 4840 | break; |
| 4841 | } |
| 4842 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4843 | if (!ok) |
| 4844 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4845 | } |
| 4846 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4847 | if (!rdev->ops->auth) |
| 4848 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4849 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4850 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4851 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4852 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4853 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4854 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4855 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4856 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4857 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4858 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4859 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4860 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4861 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4862 | |
| 4863 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4864 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4865 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4866 | } |
| 4867 | |
| 4868 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4869 | if (!nl80211_valid_auth_type(auth_type)) |
| 4870 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4871 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4872 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4873 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 4874 | /* |
| 4875 | * Since we no longer track auth state, ignore |
| 4876 | * requests to only change local state. |
| 4877 | */ |
| 4878 | if (local_state_change) |
| 4879 | return 0; |
| 4880 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4881 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4882 | ssid, ssid_len, ie, ie_len, |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 4883 | key.p.key, key.p.key_len, key.idx); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4884 | } |
| 4885 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4886 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4887 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4888 | struct cfg80211_crypto_settings *settings, |
| 4889 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4890 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4891 | memset(settings, 0, sizeof(*settings)); |
| 4892 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4893 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4894 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4895 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4896 | u16 proto; |
| 4897 | proto = nla_get_u16( |
| 4898 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4899 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4900 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4901 | proto != ETH_P_PAE) |
| 4902 | return -EINVAL; |
| 4903 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4904 | settings->control_port_no_encrypt = true; |
| 4905 | } else |
| 4906 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4907 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4908 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4909 | void *data; |
| 4910 | int len, i; |
| 4911 | |
| 4912 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4913 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4914 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4915 | |
| 4916 | if (len % sizeof(u32)) |
| 4917 | return -EINVAL; |
| 4918 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4919 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4920 | return -EINVAL; |
| 4921 | |
| 4922 | memcpy(settings->ciphers_pairwise, data, len); |
| 4923 | |
| 4924 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4925 | if (!cfg80211_supported_cipher_suite( |
| 4926 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4927 | settings->ciphers_pairwise[i])) |
| 4928 | return -EINVAL; |
| 4929 | } |
| 4930 | |
| 4931 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4932 | settings->cipher_group = |
| 4933 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4934 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 4935 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4936 | return -EINVAL; |
| 4937 | } |
| 4938 | |
| 4939 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4940 | settings->wpa_versions = |
| 4941 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4942 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4943 | return -EINVAL; |
| 4944 | } |
| 4945 | |
| 4946 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4947 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 4948 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4949 | |
| 4950 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4951 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4952 | settings->n_akm_suites = len / sizeof(u32); |
| 4953 | |
| 4954 | if (len % sizeof(u32)) |
| 4955 | return -EINVAL; |
| 4956 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 4957 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4958 | return -EINVAL; |
| 4959 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4960 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4961 | } |
| 4962 | |
| 4963 | return 0; |
| 4964 | } |
| 4965 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4966 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4967 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4968 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4969 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4970 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4971 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4972 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4973 | int err, ssid_len, ie_len = 0; |
| 4974 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4975 | u32 flags = 0; |
| 4976 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 4977 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4978 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4979 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4980 | return -EINVAL; |
| 4981 | |
| 4982 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4983 | !info->attrs[NL80211_ATTR_SSID] || |
| 4984 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4985 | return -EINVAL; |
| 4986 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4987 | if (!rdev->ops->assoc) |
| 4988 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4989 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4990 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4991 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4992 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4993 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4994 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4995 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4996 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4997 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4998 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4999 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5000 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5001 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5002 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5003 | |
| 5004 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5005 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5006 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5007 | } |
| 5008 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5009 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5010 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5011 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 5012 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5013 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5014 | else if (mfp != NL80211_MFP_NO) |
| 5015 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 5016 | } |
| 5017 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5018 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 5019 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 5020 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5021 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5022 | flags |= ASSOC_REQ_DISABLE_HT; |
| 5023 | |
| 5024 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5025 | ht_capa_mask = |
| 5026 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 5027 | |
| 5028 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5029 | if (!ht_capa_mask) |
| 5030 | return -EINVAL; |
| 5031 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5032 | } |
| 5033 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5034 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5035 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 5036 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 5037 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5038 | &crypto, flags, ht_capa, |
| 5039 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5040 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5041 | return err; |
| 5042 | } |
| 5043 | |
| 5044 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 5045 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5046 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5047 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5048 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5049 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5050 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5051 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5052 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5053 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5054 | return -EINVAL; |
| 5055 | |
| 5056 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5057 | return -EINVAL; |
| 5058 | |
| 5059 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5060 | return -EINVAL; |
| 5061 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5062 | if (!rdev->ops->deauth) |
| 5063 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5064 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5065 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5066 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5067 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5068 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5069 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5070 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5071 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5072 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5073 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5074 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5075 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5076 | |
| 5077 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5078 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5079 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5080 | } |
| 5081 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5082 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5083 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5084 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5085 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5086 | } |
| 5087 | |
| 5088 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5089 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5090 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5091 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5092 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5093 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5094 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5095 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5096 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5097 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5098 | return -EINVAL; |
| 5099 | |
| 5100 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5101 | return -EINVAL; |
| 5102 | |
| 5103 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5104 | return -EINVAL; |
| 5105 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5106 | if (!rdev->ops->disassoc) |
| 5107 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5108 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5109 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5110 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5111 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5112 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5113 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5114 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5115 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5116 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5117 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5118 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5119 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5120 | |
| 5121 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5122 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5123 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5124 | } |
| 5125 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5126 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5127 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5128 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5129 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5130 | } |
| 5131 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5132 | static bool |
| 5133 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5134 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5135 | int rateval) |
| 5136 | { |
| 5137 | struct wiphy *wiphy = &rdev->wiphy; |
| 5138 | bool found = false; |
| 5139 | int band, i; |
| 5140 | |
| 5141 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5142 | struct ieee80211_supported_band *sband; |
| 5143 | |
| 5144 | sband = wiphy->bands[band]; |
| 5145 | if (!sband) |
| 5146 | continue; |
| 5147 | |
| 5148 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5149 | if (sband->bitrates[i].bitrate == rateval) { |
| 5150 | mcast_rate[band] = i + 1; |
| 5151 | found = true; |
| 5152 | break; |
| 5153 | } |
| 5154 | } |
| 5155 | } |
| 5156 | |
| 5157 | return found; |
| 5158 | } |
| 5159 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5160 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5161 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5162 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5163 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5164 | struct cfg80211_ibss_params ibss; |
| 5165 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5166 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5167 | int err; |
| 5168 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5169 | memset(&ibss, 0, sizeof(ibss)); |
| 5170 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5171 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5172 | return -EINVAL; |
| 5173 | |
| 5174 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5175 | !info->attrs[NL80211_ATTR_SSID] || |
| 5176 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5177 | return -EINVAL; |
| 5178 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5179 | ibss.beacon_interval = 100; |
| 5180 | |
| 5181 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5182 | ibss.beacon_interval = |
| 5183 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5184 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5185 | return -EINVAL; |
| 5186 | } |
| 5187 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5188 | if (!rdev->ops->join_ibss) |
| 5189 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5190 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5191 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5192 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5193 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5194 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5195 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5196 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5197 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5198 | |
| 5199 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5200 | return -EINVAL; |
| 5201 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5202 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5203 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5204 | |
| 5205 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5206 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5207 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5208 | } |
| 5209 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5210 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5211 | enum nl80211_channel_type channel_type; |
| 5212 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5213 | if (!nl80211_valid_channel_type(info, &channel_type)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5214 | return -EINVAL; |
| 5215 | |
| 5216 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5217 | !(wiphy->features & NL80211_FEATURE_HT_IBSS)) |
| 5218 | return -EINVAL; |
| 5219 | |
| 5220 | ibss.channel_type = channel_type; |
| 5221 | } else { |
| 5222 | ibss.channel_type = NL80211_CHAN_NO_HT; |
| 5223 | } |
| 5224 | |
| 5225 | ibss.channel = rdev_freq_to_chan(rdev, |
| 5226 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 5227 | ibss.channel_type); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5228 | if (!ibss.channel || |
| 5229 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5230 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5231 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5232 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5233 | /* Both channels should be able to initiate communication */ |
| 5234 | if ((ibss.channel_type == NL80211_CHAN_HT40PLUS || |
| 5235 | ibss.channel_type == NL80211_CHAN_HT40MINUS) && |
| 5236 | !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel, |
| 5237 | ibss.channel_type)) |
| 5238 | return -EINVAL; |
| 5239 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5240 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5241 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5242 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5243 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5244 | u8 *rates = |
| 5245 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5246 | int n_rates = |
| 5247 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5248 | struct ieee80211_supported_band *sband = |
| 5249 | wiphy->bands[ibss.channel->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5250 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5251 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5252 | &ibss.basic_rates); |
| 5253 | if (err) |
| 5254 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5255 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5256 | |
| 5257 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5258 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5259 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5260 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5261 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5262 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5263 | connkeys = nl80211_parse_connkeys(rdev, |
| 5264 | info->attrs[NL80211_ATTR_KEYS]); |
| 5265 | if (IS_ERR(connkeys)) |
| 5266 | return PTR_ERR(connkeys); |
| 5267 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5268 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5269 | ibss.control_port = |
| 5270 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5271 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5272 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5273 | if (err) |
| 5274 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5275 | return err; |
| 5276 | } |
| 5277 | |
| 5278 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5279 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5280 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5281 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5282 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5283 | if (!rdev->ops->leave_ibss) |
| 5284 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5285 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5286 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5287 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5288 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5289 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5290 | } |
| 5291 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5292 | #ifdef CONFIG_NL80211_TESTMODE |
| 5293 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5294 | .name = "testmode", |
| 5295 | }; |
| 5296 | |
| 5297 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5298 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5300 | int err; |
| 5301 | |
| 5302 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5303 | return -EINVAL; |
| 5304 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5305 | err = -EOPNOTSUPP; |
| 5306 | if (rdev->ops->testmode_cmd) { |
| 5307 | rdev->testmode_info = info; |
| 5308 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 5309 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5310 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5311 | rdev->testmode_info = NULL; |
| 5312 | } |
| 5313 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5314 | return err; |
| 5315 | } |
| 5316 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5317 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5318 | struct netlink_callback *cb) |
| 5319 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5320 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5321 | int err; |
| 5322 | long phy_idx; |
| 5323 | void *data = NULL; |
| 5324 | int data_len = 0; |
| 5325 | |
| 5326 | if (cb->args[0]) { |
| 5327 | /* |
| 5328 | * 0 is a valid index, but not valid for args[0], |
| 5329 | * so we need to offset by 1. |
| 5330 | */ |
| 5331 | phy_idx = cb->args[0] - 1; |
| 5332 | } else { |
| 5333 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5334 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5335 | nl80211_policy); |
| 5336 | if (err) |
| 5337 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5338 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5339 | mutex_lock(&cfg80211_mutex); |
| 5340 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 5341 | nl80211_fam.attrbuf); |
| 5342 | if (IS_ERR(rdev)) { |
| 5343 | mutex_unlock(&cfg80211_mutex); |
| 5344 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5345 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5346 | phy_idx = rdev->wiphy_idx; |
| 5347 | rdev = NULL; |
| 5348 | mutex_unlock(&cfg80211_mutex); |
| 5349 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5350 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 5351 | cb->args[1] = |
| 5352 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 5353 | } |
| 5354 | |
| 5355 | if (cb->args[1]) { |
| 5356 | data = nla_data((void *)cb->args[1]); |
| 5357 | data_len = nla_len((void *)cb->args[1]); |
| 5358 | } |
| 5359 | |
| 5360 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5361 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 5362 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5363 | mutex_unlock(&cfg80211_mutex); |
| 5364 | return -ENOENT; |
| 5365 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5366 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5367 | mutex_unlock(&cfg80211_mutex); |
| 5368 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5369 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5370 | err = -EOPNOTSUPP; |
| 5371 | goto out_err; |
| 5372 | } |
| 5373 | |
| 5374 | while (1) { |
| 5375 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 5376 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5377 | NL80211_CMD_TESTMODE); |
| 5378 | struct nlattr *tmdata; |
| 5379 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5380 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5381 | genlmsg_cancel(skb, hdr); |
| 5382 | break; |
| 5383 | } |
| 5384 | |
| 5385 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5386 | if (!tmdata) { |
| 5387 | genlmsg_cancel(skb, hdr); |
| 5388 | break; |
| 5389 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5390 | err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb, |
| 5391 | data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5392 | nla_nest_end(skb, tmdata); |
| 5393 | |
| 5394 | if (err == -ENOBUFS || err == -ENOENT) { |
| 5395 | genlmsg_cancel(skb, hdr); |
| 5396 | break; |
| 5397 | } else if (err) { |
| 5398 | genlmsg_cancel(skb, hdr); |
| 5399 | goto out_err; |
| 5400 | } |
| 5401 | |
| 5402 | genlmsg_end(skb, hdr); |
| 5403 | } |
| 5404 | |
| 5405 | err = skb->len; |
| 5406 | /* see above */ |
| 5407 | cb->args[0] = phy_idx + 1; |
| 5408 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5409 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5410 | return err; |
| 5411 | } |
| 5412 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5413 | static struct sk_buff * |
| 5414 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 5415 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 5416 | { |
| 5417 | struct sk_buff *skb; |
| 5418 | void *hdr; |
| 5419 | struct nlattr *data; |
| 5420 | |
| 5421 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5422 | if (!skb) |
| 5423 | return NULL; |
| 5424 | |
| 5425 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 5426 | if (!hdr) { |
| 5427 | kfree_skb(skb); |
| 5428 | return NULL; |
| 5429 | } |
| 5430 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5431 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 5432 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5433 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5434 | |
| 5435 | ((void **)skb->cb)[0] = rdev; |
| 5436 | ((void **)skb->cb)[1] = hdr; |
| 5437 | ((void **)skb->cb)[2] = data; |
| 5438 | |
| 5439 | return skb; |
| 5440 | |
| 5441 | nla_put_failure: |
| 5442 | kfree_skb(skb); |
| 5443 | return NULL; |
| 5444 | } |
| 5445 | |
| 5446 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5447 | int approxlen) |
| 5448 | { |
| 5449 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5450 | |
| 5451 | if (WARN_ON(!rdev->testmode_info)) |
| 5452 | return NULL; |
| 5453 | |
| 5454 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 5455 | rdev->testmode_info->snd_pid, |
| 5456 | rdev->testmode_info->snd_seq, |
| 5457 | GFP_KERNEL); |
| 5458 | } |
| 5459 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5460 | |
| 5461 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5462 | { |
| 5463 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5464 | void *hdr = ((void **)skb->cb)[1]; |
| 5465 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5466 | |
| 5467 | if (WARN_ON(!rdev->testmode_info)) { |
| 5468 | kfree_skb(skb); |
| 5469 | return -EINVAL; |
| 5470 | } |
| 5471 | |
| 5472 | nla_nest_end(skb, data); |
| 5473 | genlmsg_end(skb, hdr); |
| 5474 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5475 | } |
| 5476 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5477 | |
| 5478 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5479 | int approxlen, gfp_t gfp) |
| 5480 | { |
| 5481 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5482 | |
| 5483 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5484 | } |
| 5485 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5486 | |
| 5487 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5488 | { |
| 5489 | void *hdr = ((void **)skb->cb)[1]; |
| 5490 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5491 | |
| 5492 | nla_nest_end(skb, data); |
| 5493 | genlmsg_end(skb, hdr); |
| 5494 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5495 | } |
| 5496 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5497 | #endif |
| 5498 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5499 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5500 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5501 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5502 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5503 | struct cfg80211_connect_params connect; |
| 5504 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5505 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5506 | int err; |
| 5507 | |
| 5508 | memset(&connect, 0, sizeof(connect)); |
| 5509 | |
| 5510 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5511 | return -EINVAL; |
| 5512 | |
| 5513 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5514 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5515 | return -EINVAL; |
| 5516 | |
| 5517 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5518 | connect.auth_type = |
| 5519 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 5520 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 5521 | return -EINVAL; |
| 5522 | } else |
| 5523 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5524 | |
| 5525 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5526 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5527 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5528 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5529 | if (err) |
| 5530 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5531 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5532 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5533 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5534 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5535 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5536 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5537 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 5538 | connect.bg_scan_period = -1; |
| 5539 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 5540 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 5541 | connect.bg_scan_period = |
| 5542 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 5543 | } |
| 5544 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5545 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5546 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5547 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5548 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5549 | |
| 5550 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5551 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5552 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5553 | } |
| 5554 | |
| 5555 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5556 | connect.channel = |
| 5557 | ieee80211_get_channel(wiphy, |
| 5558 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5559 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5560 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5561 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5562 | } |
| 5563 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5564 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5565 | connkeys = nl80211_parse_connkeys(rdev, |
| 5566 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5567 | if (IS_ERR(connkeys)) |
| 5568 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5569 | } |
| 5570 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5571 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5572 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5573 | |
| 5574 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5575 | memcpy(&connect.ht_capa_mask, |
| 5576 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5577 | sizeof(connect.ht_capa_mask)); |
| 5578 | |
| 5579 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5580 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5581 | return -EINVAL; |
| 5582 | memcpy(&connect.ht_capa, |
| 5583 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5584 | sizeof(connect.ht_capa)); |
| 5585 | } |
| 5586 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5587 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5588 | if (err) |
| 5589 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5590 | return err; |
| 5591 | } |
| 5592 | |
| 5593 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5594 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5595 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5596 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5597 | u16 reason; |
| 5598 | |
| 5599 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5600 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5601 | else |
| 5602 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5603 | |
| 5604 | if (reason == 0) |
| 5605 | return -EINVAL; |
| 5606 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5607 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5608 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5609 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5610 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5611 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5612 | } |
| 5613 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5614 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5615 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5617 | struct net *net; |
| 5618 | int err; |
| 5619 | u32 pid; |
| 5620 | |
| 5621 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5622 | return -EINVAL; |
| 5623 | |
| 5624 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5625 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5626 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5627 | if (IS_ERR(net)) |
| 5628 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5629 | |
| 5630 | err = 0; |
| 5631 | |
| 5632 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5633 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5634 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5635 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5636 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5637 | return err; |
| 5638 | } |
| 5639 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5640 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5641 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5642 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5643 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5644 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5645 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5646 | struct cfg80211_pmksa pmksa; |
| 5647 | |
| 5648 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5649 | |
| 5650 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5651 | return -EINVAL; |
| 5652 | |
| 5653 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5654 | return -EINVAL; |
| 5655 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5656 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5657 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5658 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5659 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5660 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5661 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5662 | |
| 5663 | switch (info->genlhdr->cmd) { |
| 5664 | case NL80211_CMD_SET_PMKSA: |
| 5665 | rdev_ops = rdev->ops->set_pmksa; |
| 5666 | break; |
| 5667 | case NL80211_CMD_DEL_PMKSA: |
| 5668 | rdev_ops = rdev->ops->del_pmksa; |
| 5669 | break; |
| 5670 | default: |
| 5671 | WARN_ON(1); |
| 5672 | break; |
| 5673 | } |
| 5674 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5675 | if (!rdev_ops) |
| 5676 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5677 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5678 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5679 | } |
| 5680 | |
| 5681 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5682 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5683 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5684 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5685 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5686 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5687 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5688 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5689 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5690 | if (!rdev->ops->flush_pmksa) |
| 5691 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5692 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5693 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5694 | } |
| 5695 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5696 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5697 | { |
| 5698 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5699 | struct net_device *dev = info->user_ptr[1]; |
| 5700 | u8 action_code, dialog_token; |
| 5701 | u16 status_code; |
| 5702 | u8 *peer; |
| 5703 | |
| 5704 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5705 | !rdev->ops->tdls_mgmt) |
| 5706 | return -EOPNOTSUPP; |
| 5707 | |
| 5708 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5709 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5710 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5711 | !info->attrs[NL80211_ATTR_IE] || |
| 5712 | !info->attrs[NL80211_ATTR_MAC]) |
| 5713 | return -EINVAL; |
| 5714 | |
| 5715 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5716 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5717 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5718 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5719 | |
| 5720 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, |
| 5721 | dialog_token, status_code, |
| 5722 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5723 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 5724 | } |
| 5725 | |
| 5726 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5727 | { |
| 5728 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5729 | struct net_device *dev = info->user_ptr[1]; |
| 5730 | enum nl80211_tdls_operation operation; |
| 5731 | u8 *peer; |
| 5732 | |
| 5733 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5734 | !rdev->ops->tdls_oper) |
| 5735 | return -EOPNOTSUPP; |
| 5736 | |
| 5737 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5738 | !info->attrs[NL80211_ATTR_MAC]) |
| 5739 | return -EINVAL; |
| 5740 | |
| 5741 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5742 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5743 | |
| 5744 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); |
| 5745 | } |
| 5746 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5747 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5748 | struct genl_info *info) |
| 5749 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5750 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5751 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5752 | struct ieee80211_channel *chan; |
| 5753 | struct sk_buff *msg; |
| 5754 | void *hdr; |
| 5755 | u64 cookie; |
| 5756 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 5757 | u32 freq, duration; |
| 5758 | int err; |
| 5759 | |
| 5760 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5761 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5762 | return -EINVAL; |
| 5763 | |
| 5764 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5765 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5766 | if (!rdev->ops->remain_on_channel || |
| 5767 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5768 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5769 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 5770 | /* |
| 5771 | * We should be on that channel for at least a minimum amount of |
| 5772 | * time (10ms) but no longer than the driver supports. |
| 5773 | */ |
| 5774 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 5775 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 5776 | return -EINVAL; |
| 5777 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5778 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 5779 | !nl80211_valid_channel_type(info, &channel_type)) |
| 5780 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5781 | |
| 5782 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5783 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5784 | if (chan == NULL) |
| 5785 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5786 | |
| 5787 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5788 | if (!msg) |
| 5789 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5790 | |
| 5791 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5792 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5793 | |
| 5794 | if (IS_ERR(hdr)) { |
| 5795 | err = PTR_ERR(hdr); |
| 5796 | goto free_msg; |
| 5797 | } |
| 5798 | |
| 5799 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 5800 | channel_type, duration, &cookie); |
| 5801 | |
| 5802 | if (err) |
| 5803 | goto free_msg; |
| 5804 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5805 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 5806 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5807 | |
| 5808 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5809 | |
| 5810 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5811 | |
| 5812 | nla_put_failure: |
| 5813 | err = -ENOBUFS; |
| 5814 | free_msg: |
| 5815 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5816 | return err; |
| 5817 | } |
| 5818 | |
| 5819 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5820 | struct genl_info *info) |
| 5821 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5823 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5824 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5825 | |
| 5826 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5827 | return -EINVAL; |
| 5828 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5829 | if (!rdev->ops->cancel_remain_on_channel) |
| 5830 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5831 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5832 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5833 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5834 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5835 | } |
| 5836 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5837 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5838 | u8 *rates, u8 rates_len) |
| 5839 | { |
| 5840 | u8 i; |
| 5841 | u32 mask = 0; |
| 5842 | |
| 5843 | for (i = 0; i < rates_len; i++) { |
| 5844 | int rate = (rates[i] & 0x7f) * 5; |
| 5845 | int ridx; |
| 5846 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5847 | struct ieee80211_rate *srate = |
| 5848 | &sband->bitrates[ridx]; |
| 5849 | if (rate == srate->bitrate) { |
| 5850 | mask |= 1 << ridx; |
| 5851 | break; |
| 5852 | } |
| 5853 | } |
| 5854 | if (ridx == sband->n_bitrates) |
| 5855 | return 0; /* rate not found */ |
| 5856 | } |
| 5857 | |
| 5858 | return mask; |
| 5859 | } |
| 5860 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5861 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5862 | u8 *rates, u8 rates_len, |
| 5863 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 5864 | { |
| 5865 | u8 i; |
| 5866 | |
| 5867 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 5868 | |
| 5869 | for (i = 0; i < rates_len; i++) { |
| 5870 | int ridx, rbit; |
| 5871 | |
| 5872 | ridx = rates[i] / 8; |
| 5873 | rbit = BIT(rates[i] % 8); |
| 5874 | |
| 5875 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 5876 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5877 | return false; |
| 5878 | |
| 5879 | /* check availability */ |
| 5880 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 5881 | mcs[ridx] |= rbit; |
| 5882 | else |
| 5883 | return false; |
| 5884 | } |
| 5885 | |
| 5886 | return true; |
| 5887 | } |
| 5888 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5889 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5890 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5891 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5892 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 5893 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5894 | }; |
| 5895 | |
| 5896 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5897 | struct genl_info *info) |
| 5898 | { |
| 5899 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5900 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5901 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5902 | int rem, i; |
| 5903 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5904 | struct nlattr *tx_rates; |
| 5905 | struct ieee80211_supported_band *sband; |
| 5906 | |
| 5907 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5908 | return -EINVAL; |
| 5909 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5910 | if (!rdev->ops->set_bitrate_mask) |
| 5911 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5912 | |
| 5913 | memset(&mask, 0, sizeof(mask)); |
| 5914 | /* Default to all rates enabled */ |
| 5915 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5916 | sband = rdev->wiphy.bands[i]; |
| 5917 | mask.control[i].legacy = |
| 5918 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5919 | if (sband) |
| 5920 | memcpy(mask.control[i].mcs, |
| 5921 | sband->ht_cap.mcs.rx_mask, |
| 5922 | sizeof(mask.control[i].mcs)); |
| 5923 | else |
| 5924 | memset(mask.control[i].mcs, 0, |
| 5925 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5926 | } |
| 5927 | |
| 5928 | /* |
| 5929 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5930 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5931 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5932 | 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] | 5933 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5934 | { |
| 5935 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5936 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5937 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5938 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5939 | if (sband == NULL) |
| 5940 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5941 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5942 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5943 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5944 | mask.control[band].legacy = rateset_to_mask( |
| 5945 | sband, |
| 5946 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5947 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 5948 | if ((mask.control[band].legacy == 0) && |
| 5949 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 5950 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5951 | } |
| 5952 | if (tb[NL80211_TXRATE_MCS]) { |
| 5953 | if (!ht_rateset_to_mask( |
| 5954 | sband, |
| 5955 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 5956 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 5957 | mask.control[band].mcs)) |
| 5958 | return -EINVAL; |
| 5959 | } |
| 5960 | |
| 5961 | if (mask.control[band].legacy == 0) { |
| 5962 | /* don't allow empty legacy rates if HT |
| 5963 | * is not even supported. */ |
| 5964 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 5965 | return -EINVAL; |
| 5966 | |
| 5967 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 5968 | if (mask.control[band].mcs[i]) |
| 5969 | break; |
| 5970 | |
| 5971 | /* legacy and mcs rates may not be both empty */ |
| 5972 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5973 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5974 | } |
| 5975 | } |
| 5976 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5977 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5978 | } |
| 5979 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5980 | 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] | 5981 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5982 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5983 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5984 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5985 | |
| 5986 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5987 | return -EINVAL; |
| 5988 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5989 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5990 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5991 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5992 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5993 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5994 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5995 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5996 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5997 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5998 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5999 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6000 | |
| 6001 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6002 | if (!rdev->ops->mgmt_tx) |
| 6003 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6004 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6005 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6006 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6007 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 6008 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6009 | } |
| 6010 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6011 | 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] | 6012 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6013 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6014 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6015 | struct ieee80211_channel *chan; |
| 6016 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 6017 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6018 | u32 freq; |
| 6019 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 6020 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6021 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6022 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6023 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6024 | bool offchan, no_cck, dont_wait_for_ack; |
| 6025 | |
| 6026 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6027 | |
| 6028 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 6029 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6030 | return -EINVAL; |
| 6031 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6032 | if (!rdev->ops->mgmt_tx) |
| 6033 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6034 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 6035 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6036 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 6037 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 6038 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 6039 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 6040 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6041 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6042 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6043 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6044 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6045 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6046 | return -EINVAL; |
| 6047 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6048 | |
| 6049 | /* |
| 6050 | * We should wait on the channel for at least a minimum amount |
| 6051 | * of time (10ms) but no longer than the driver supports. |
| 6052 | */ |
| 6053 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6054 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 6055 | return -EINVAL; |
| 6056 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6057 | } |
| 6058 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6059 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 6060 | if (!nl80211_valid_channel_type(info, &channel_type)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6061 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 6062 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6063 | } |
| 6064 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6065 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 6066 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6067 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 6068 | return -EINVAL; |
| 6069 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6070 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6071 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6072 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6073 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6074 | if (chan == NULL) |
| 6075 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6076 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6077 | if (!dont_wait_for_ack) { |
| 6078 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6079 | if (!msg) |
| 6080 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6081 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6082 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6083 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6084 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6085 | if (IS_ERR(hdr)) { |
| 6086 | err = PTR_ERR(hdr); |
| 6087 | goto free_msg; |
| 6088 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6089 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6090 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6091 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 6092 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6093 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6094 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6095 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6096 | if (err) |
| 6097 | goto free_msg; |
| 6098 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6099 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6100 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6101 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6102 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6103 | genlmsg_end(msg, hdr); |
| 6104 | return genlmsg_reply(msg, info); |
| 6105 | } |
| 6106 | |
| 6107 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6108 | |
| 6109 | nla_put_failure: |
| 6110 | err = -ENOBUFS; |
| 6111 | free_msg: |
| 6112 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6113 | return err; |
| 6114 | } |
| 6115 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6116 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6117 | { |
| 6118 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6119 | struct net_device *dev = info->user_ptr[1]; |
| 6120 | u64 cookie; |
| 6121 | |
| 6122 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6123 | return -EINVAL; |
| 6124 | |
| 6125 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6126 | return -EOPNOTSUPP; |
| 6127 | |
| 6128 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 6129 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6130 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 6131 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 6132 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 6133 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6134 | return -EOPNOTSUPP; |
| 6135 | |
| 6136 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6137 | |
| 6138 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 6139 | } |
| 6140 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6141 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6142 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6143 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6144 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6145 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6146 | u8 ps_state; |
| 6147 | bool state; |
| 6148 | int err; |
| 6149 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6150 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6151 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6152 | |
| 6153 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6154 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6155 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6156 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6157 | |
| 6158 | wdev = dev->ieee80211_ptr; |
| 6159 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6160 | if (!rdev->ops->set_power_mgmt) |
| 6161 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6162 | |
| 6163 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6164 | |
| 6165 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6166 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6167 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6168 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 6169 | wdev->ps_timeout); |
| 6170 | if (!err) |
| 6171 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6172 | return err; |
| 6173 | } |
| 6174 | |
| 6175 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6176 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6177 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6178 | enum nl80211_ps_state ps_state; |
| 6179 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6180 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6181 | struct sk_buff *msg; |
| 6182 | void *hdr; |
| 6183 | int err; |
| 6184 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6185 | wdev = dev->ieee80211_ptr; |
| 6186 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6187 | if (!rdev->ops->set_power_mgmt) |
| 6188 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6189 | |
| 6190 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6191 | if (!msg) |
| 6192 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6193 | |
| 6194 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6195 | NL80211_CMD_GET_POWER_SAVE); |
| 6196 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6197 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6198 | goto free_msg; |
| 6199 | } |
| 6200 | |
| 6201 | if (wdev->ps) |
| 6202 | ps_state = NL80211_PS_ENABLED; |
| 6203 | else |
| 6204 | ps_state = NL80211_PS_DISABLED; |
| 6205 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6206 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6207 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6208 | |
| 6209 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6210 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6211 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6212 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6213 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6214 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6215 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6216 | return err; |
| 6217 | } |
| 6218 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6219 | static struct nla_policy |
| 6220 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6221 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6222 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6223 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 6224 | }; |
| 6225 | |
| 6226 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6227 | s32 threshold, u32 hysteresis) |
| 6228 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6229 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6230 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6231 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6232 | |
| 6233 | if (threshold > 0) |
| 6234 | return -EINVAL; |
| 6235 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6236 | wdev = dev->ieee80211_ptr; |
| 6237 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6238 | if (!rdev->ops->set_cqm_rssi_config) |
| 6239 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6240 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6241 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6242 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6243 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6244 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6245 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 6246 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6247 | } |
| 6248 | |
| 6249 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6250 | { |
| 6251 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6252 | struct nlattr *cqm; |
| 6253 | int err; |
| 6254 | |
| 6255 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6256 | if (!cqm) { |
| 6257 | err = -EINVAL; |
| 6258 | goto out; |
| 6259 | } |
| 6260 | |
| 6261 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6262 | nl80211_attr_cqm_policy); |
| 6263 | if (err) |
| 6264 | goto out; |
| 6265 | |
| 6266 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6267 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6268 | s32 threshold; |
| 6269 | u32 hysteresis; |
| 6270 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6271 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6272 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 6273 | } else |
| 6274 | err = -EINVAL; |
| 6275 | |
| 6276 | out: |
| 6277 | return err; |
| 6278 | } |
| 6279 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6280 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6281 | { |
| 6282 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6283 | struct net_device *dev = info->user_ptr[1]; |
| 6284 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6285 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6286 | int err; |
| 6287 | |
| 6288 | /* start with default */ |
| 6289 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6290 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6291 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6292 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6293 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6294 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6295 | if (err) |
| 6296 | return err; |
| 6297 | } |
| 6298 | |
| 6299 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6300 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 6301 | return -EINVAL; |
| 6302 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6303 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6304 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6305 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 6306 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6307 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 6308 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6309 | return -EINVAL; |
| 6310 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6311 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 6312 | /* parse additional setup parameters if given */ |
| 6313 | err = nl80211_parse_mesh_setup(info, &setup); |
| 6314 | if (err) |
| 6315 | return err; |
| 6316 | } |
| 6317 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6318 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6319 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 6320 | |
| 6321 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 6322 | !nl80211_valid_channel_type(info, &channel_type)) |
| 6323 | return -EINVAL; |
| 6324 | |
| 6325 | setup.channel = rdev_freq_to_chan(rdev, |
| 6326 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 6327 | channel_type); |
| 6328 | if (!setup.channel) |
| 6329 | return -EINVAL; |
| 6330 | setup.channel_type = channel_type; |
| 6331 | } else { |
| 6332 | /* cfg80211_join_mesh() will sort it out */ |
| 6333 | setup.channel = NULL; |
| 6334 | } |
| 6335 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6336 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6337 | } |
| 6338 | |
| 6339 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6340 | { |
| 6341 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6342 | struct net_device *dev = info->user_ptr[1]; |
| 6343 | |
| 6344 | return cfg80211_leave_mesh(rdev, dev); |
| 6345 | } |
| 6346 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6347 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6348 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6349 | { |
| 6350 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6351 | struct sk_buff *msg; |
| 6352 | void *hdr; |
| 6353 | |
| 6354 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6355 | return -EOPNOTSUPP; |
| 6356 | |
| 6357 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6358 | if (!msg) |
| 6359 | return -ENOMEM; |
| 6360 | |
| 6361 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6362 | NL80211_CMD_GET_WOWLAN); |
| 6363 | if (!hdr) |
| 6364 | goto nla_put_failure; |
| 6365 | |
| 6366 | if (rdev->wowlan) { |
| 6367 | struct nlattr *nl_wowlan; |
| 6368 | |
| 6369 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 6370 | if (!nl_wowlan) |
| 6371 | goto nla_put_failure; |
| 6372 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6373 | if ((rdev->wowlan->any && |
| 6374 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 6375 | (rdev->wowlan->disconnect && |
| 6376 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 6377 | (rdev->wowlan->magic_pkt && |
| 6378 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 6379 | (rdev->wowlan->gtk_rekey_failure && |
| 6380 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 6381 | (rdev->wowlan->eap_identity_req && |
| 6382 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 6383 | (rdev->wowlan->four_way_handshake && |
| 6384 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 6385 | (rdev->wowlan->rfkill_release && |
| 6386 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 6387 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6388 | if (rdev->wowlan->n_patterns) { |
| 6389 | struct nlattr *nl_pats, *nl_pat; |
| 6390 | int i, pat_len; |
| 6391 | |
| 6392 | nl_pats = nla_nest_start(msg, |
| 6393 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 6394 | if (!nl_pats) |
| 6395 | goto nla_put_failure; |
| 6396 | |
| 6397 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 6398 | nl_pat = nla_nest_start(msg, i + 1); |
| 6399 | if (!nl_pat) |
| 6400 | goto nla_put_failure; |
| 6401 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6402 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 6403 | DIV_ROUND_UP(pat_len, 8), |
| 6404 | rdev->wowlan->patterns[i].mask) || |
| 6405 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 6406 | pat_len, |
| 6407 | rdev->wowlan->patterns[i].pattern)) |
| 6408 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6409 | nla_nest_end(msg, nl_pat); |
| 6410 | } |
| 6411 | nla_nest_end(msg, nl_pats); |
| 6412 | } |
| 6413 | |
| 6414 | nla_nest_end(msg, nl_wowlan); |
| 6415 | } |
| 6416 | |
| 6417 | genlmsg_end(msg, hdr); |
| 6418 | return genlmsg_reply(msg, info); |
| 6419 | |
| 6420 | nla_put_failure: |
| 6421 | nlmsg_free(msg); |
| 6422 | return -ENOBUFS; |
| 6423 | } |
| 6424 | |
| 6425 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6426 | { |
| 6427 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6428 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 6429 | struct cfg80211_wowlan no_triggers = {}; |
| 6430 | struct cfg80211_wowlan new_triggers = {}; |
| 6431 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 6432 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6433 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6434 | |
| 6435 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6436 | return -EOPNOTSUPP; |
| 6437 | |
| 6438 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 6439 | goto no_triggers; |
| 6440 | |
| 6441 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 6442 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6443 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6444 | nl80211_wowlan_policy); |
| 6445 | if (err) |
| 6446 | return err; |
| 6447 | |
| 6448 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 6449 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 6450 | return -EINVAL; |
| 6451 | new_triggers.any = true; |
| 6452 | } |
| 6453 | |
| 6454 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 6455 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 6456 | return -EINVAL; |
| 6457 | new_triggers.disconnect = true; |
| 6458 | } |
| 6459 | |
| 6460 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 6461 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 6462 | return -EINVAL; |
| 6463 | new_triggers.magic_pkt = true; |
| 6464 | } |
| 6465 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 6466 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 6467 | return -EINVAL; |
| 6468 | |
| 6469 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 6470 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 6471 | return -EINVAL; |
| 6472 | new_triggers.gtk_rekey_failure = true; |
| 6473 | } |
| 6474 | |
| 6475 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 6476 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 6477 | return -EINVAL; |
| 6478 | new_triggers.eap_identity_req = true; |
| 6479 | } |
| 6480 | |
| 6481 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 6482 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 6483 | return -EINVAL; |
| 6484 | new_triggers.four_way_handshake = true; |
| 6485 | } |
| 6486 | |
| 6487 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 6488 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 6489 | return -EINVAL; |
| 6490 | new_triggers.rfkill_release = true; |
| 6491 | } |
| 6492 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6493 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 6494 | struct nlattr *pat; |
| 6495 | int n_patterns = 0; |
| 6496 | int rem, pat_len, mask_len; |
| 6497 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6498 | |
| 6499 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6500 | rem) |
| 6501 | n_patterns++; |
| 6502 | if (n_patterns > wowlan->n_patterns) |
| 6503 | return -EINVAL; |
| 6504 | |
| 6505 | new_triggers.patterns = kcalloc(n_patterns, |
| 6506 | sizeof(new_triggers.patterns[0]), |
| 6507 | GFP_KERNEL); |
| 6508 | if (!new_triggers.patterns) |
| 6509 | return -ENOMEM; |
| 6510 | |
| 6511 | new_triggers.n_patterns = n_patterns; |
| 6512 | i = 0; |
| 6513 | |
| 6514 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6515 | rem) { |
| 6516 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6517 | nla_data(pat), nla_len(pat), NULL); |
| 6518 | err = -EINVAL; |
| 6519 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6520 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6521 | goto error; |
| 6522 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6523 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6524 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6525 | mask_len) |
| 6526 | goto error; |
| 6527 | if (pat_len > wowlan->pattern_max_len || |
| 6528 | pat_len < wowlan->pattern_min_len) |
| 6529 | goto error; |
| 6530 | |
| 6531 | new_triggers.patterns[i].mask = |
| 6532 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6533 | if (!new_triggers.patterns[i].mask) { |
| 6534 | err = -ENOMEM; |
| 6535 | goto error; |
| 6536 | } |
| 6537 | new_triggers.patterns[i].pattern = |
| 6538 | new_triggers.patterns[i].mask + mask_len; |
| 6539 | memcpy(new_triggers.patterns[i].mask, |
| 6540 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6541 | mask_len); |
| 6542 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6543 | memcpy(new_triggers.patterns[i].pattern, |
| 6544 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6545 | pat_len); |
| 6546 | i++; |
| 6547 | } |
| 6548 | } |
| 6549 | |
| 6550 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 6551 | struct cfg80211_wowlan *ntrig; |
| 6552 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 6553 | GFP_KERNEL); |
| 6554 | if (!ntrig) { |
| 6555 | err = -ENOMEM; |
| 6556 | goto error; |
| 6557 | } |
| 6558 | cfg80211_rdev_free_wowlan(rdev); |
| 6559 | rdev->wowlan = ntrig; |
| 6560 | } else { |
| 6561 | no_triggers: |
| 6562 | cfg80211_rdev_free_wowlan(rdev); |
| 6563 | rdev->wowlan = NULL; |
| 6564 | } |
| 6565 | |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6566 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
| 6567 | rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan); |
| 6568 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6569 | return 0; |
| 6570 | error: |
| 6571 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6572 | kfree(new_triggers.patterns[i].mask); |
| 6573 | kfree(new_triggers.patterns); |
| 6574 | return err; |
| 6575 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6576 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6577 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6578 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6579 | { |
| 6580 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6581 | struct net_device *dev = info->user_ptr[1]; |
| 6582 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6583 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6584 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6585 | int err; |
| 6586 | |
| 6587 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6588 | return -EINVAL; |
| 6589 | |
| 6590 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6591 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6592 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6593 | nl80211_rekey_policy); |
| 6594 | if (err) |
| 6595 | return err; |
| 6596 | |
| 6597 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6598 | return -ERANGE; |
| 6599 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6600 | return -ERANGE; |
| 6601 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6602 | return -ERANGE; |
| 6603 | |
| 6604 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6605 | NL80211_KEK_LEN); |
| 6606 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6607 | NL80211_KCK_LEN); |
| 6608 | memcpy(rekey_data.replay_ctr, |
| 6609 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6610 | NL80211_REPLAY_CTR_LEN); |
| 6611 | |
| 6612 | wdev_lock(wdev); |
| 6613 | if (!wdev->current_bss) { |
| 6614 | err = -ENOTCONN; |
| 6615 | goto out; |
| 6616 | } |
| 6617 | |
| 6618 | if (!rdev->ops->set_rekey_data) { |
| 6619 | err = -EOPNOTSUPP; |
| 6620 | goto out; |
| 6621 | } |
| 6622 | |
| 6623 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 6624 | out: |
| 6625 | wdev_unlock(wdev); |
| 6626 | return err; |
| 6627 | } |
| 6628 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6629 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6630 | struct genl_info *info) |
| 6631 | { |
| 6632 | struct net_device *dev = info->user_ptr[1]; |
| 6633 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6634 | |
| 6635 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6636 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6637 | return -EINVAL; |
| 6638 | |
| 6639 | if (wdev->ap_unexpected_nlpid) |
| 6640 | return -EBUSY; |
| 6641 | |
| 6642 | wdev->ap_unexpected_nlpid = info->snd_pid; |
| 6643 | return 0; |
| 6644 | } |
| 6645 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6646 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6647 | struct genl_info *info) |
| 6648 | { |
| 6649 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6650 | struct net_device *dev = info->user_ptr[1]; |
| 6651 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6652 | struct sk_buff *msg; |
| 6653 | void *hdr; |
| 6654 | const u8 *addr; |
| 6655 | u64 cookie; |
| 6656 | int err; |
| 6657 | |
| 6658 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6659 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6660 | return -EOPNOTSUPP; |
| 6661 | |
| 6662 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6663 | return -EINVAL; |
| 6664 | |
| 6665 | if (!rdev->ops->probe_client) |
| 6666 | return -EOPNOTSUPP; |
| 6667 | |
| 6668 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6669 | if (!msg) |
| 6670 | return -ENOMEM; |
| 6671 | |
| 6672 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6673 | NL80211_CMD_PROBE_CLIENT); |
| 6674 | |
| 6675 | if (IS_ERR(hdr)) { |
| 6676 | err = PTR_ERR(hdr); |
| 6677 | goto free_msg; |
| 6678 | } |
| 6679 | |
| 6680 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6681 | |
| 6682 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); |
| 6683 | if (err) |
| 6684 | goto free_msg; |
| 6685 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6686 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6687 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6688 | |
| 6689 | genlmsg_end(msg, hdr); |
| 6690 | |
| 6691 | return genlmsg_reply(msg, info); |
| 6692 | |
| 6693 | nla_put_failure: |
| 6694 | err = -ENOBUFS; |
| 6695 | free_msg: |
| 6696 | nlmsg_free(msg); |
| 6697 | return err; |
| 6698 | } |
| 6699 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6700 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 6701 | { |
| 6702 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6703 | |
| 6704 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 6705 | return -EOPNOTSUPP; |
| 6706 | |
| 6707 | if (rdev->ap_beacons_nlpid) |
| 6708 | return -EBUSY; |
| 6709 | |
| 6710 | rdev->ap_beacons_nlpid = info->snd_pid; |
| 6711 | |
| 6712 | return 0; |
| 6713 | } |
| 6714 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6715 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 6716 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 6717 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6718 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 6719 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 6720 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6721 | |
| 6722 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6723 | struct genl_info *info) |
| 6724 | { |
| 6725 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame^] | 6726 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6727 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6728 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 6729 | |
| 6730 | if (rtnl) |
| 6731 | rtnl_lock(); |
| 6732 | |
| 6733 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 6734 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6735 | if (IS_ERR(rdev)) { |
| 6736 | if (rtnl) |
| 6737 | rtnl_unlock(); |
| 6738 | return PTR_ERR(rdev); |
| 6739 | } |
| 6740 | info->user_ptr[0] = rdev; |
| 6741 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame^] | 6742 | mutex_lock(&cfg80211_mutex); |
| 6743 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 6744 | info->attrs); |
| 6745 | if (IS_ERR(wdev)) { |
| 6746 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6747 | if (rtnl) |
| 6748 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame^] | 6749 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6750 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame^] | 6751 | |
| 6752 | if (!wdev->netdev) { |
| 6753 | mutex_unlock(&cfg80211_mutex); |
| 6754 | if (rtnl) |
| 6755 | rtnl_unlock(); |
| 6756 | return -EINVAL; |
| 6757 | } |
| 6758 | |
| 6759 | dev = wdev->netdev; |
| 6760 | rdev = wiphy_to_dev(wdev->wiphy); |
| 6761 | |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6762 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 6763 | !netif_running(dev)) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame^] | 6764 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6765 | if (rtnl) |
| 6766 | rtnl_unlock(); |
| 6767 | return -ENETDOWN; |
| 6768 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame^] | 6769 | |
| 6770 | dev_hold(dev); |
| 6771 | cfg80211_lock_rdev(rdev); |
| 6772 | |
| 6773 | mutex_unlock(&cfg80211_mutex); |
| 6774 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6775 | info->user_ptr[0] = rdev; |
| 6776 | info->user_ptr[1] = dev; |
| 6777 | } |
| 6778 | |
| 6779 | return 0; |
| 6780 | } |
| 6781 | |
| 6782 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6783 | struct genl_info *info) |
| 6784 | { |
| 6785 | if (info->user_ptr[0]) |
| 6786 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 6787 | if (info->user_ptr[1]) |
| 6788 | dev_put(info->user_ptr[1]); |
| 6789 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 6790 | rtnl_unlock(); |
| 6791 | } |
| 6792 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6793 | static struct genl_ops nl80211_ops[] = { |
| 6794 | { |
| 6795 | .cmd = NL80211_CMD_GET_WIPHY, |
| 6796 | .doit = nl80211_get_wiphy, |
| 6797 | .dumpit = nl80211_dump_wiphy, |
| 6798 | .policy = nl80211_policy, |
| 6799 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6800 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6801 | }, |
| 6802 | { |
| 6803 | .cmd = NL80211_CMD_SET_WIPHY, |
| 6804 | .doit = nl80211_set_wiphy, |
| 6805 | .policy = nl80211_policy, |
| 6806 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6807 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6808 | }, |
| 6809 | { |
| 6810 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 6811 | .doit = nl80211_get_interface, |
| 6812 | .dumpit = nl80211_dump_interface, |
| 6813 | .policy = nl80211_policy, |
| 6814 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6815 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6816 | }, |
| 6817 | { |
| 6818 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 6819 | .doit = nl80211_set_interface, |
| 6820 | .policy = nl80211_policy, |
| 6821 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6822 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6823 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6824 | }, |
| 6825 | { |
| 6826 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 6827 | .doit = nl80211_new_interface, |
| 6828 | .policy = nl80211_policy, |
| 6829 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6830 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6831 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6832 | }, |
| 6833 | { |
| 6834 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 6835 | .doit = nl80211_del_interface, |
| 6836 | .policy = nl80211_policy, |
| 6837 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6838 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6839 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6840 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6841 | { |
| 6842 | .cmd = NL80211_CMD_GET_KEY, |
| 6843 | .doit = nl80211_get_key, |
| 6844 | .policy = nl80211_policy, |
| 6845 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6846 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6847 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6848 | }, |
| 6849 | { |
| 6850 | .cmd = NL80211_CMD_SET_KEY, |
| 6851 | .doit = nl80211_set_key, |
| 6852 | .policy = nl80211_policy, |
| 6853 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6854 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6855 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6856 | }, |
| 6857 | { |
| 6858 | .cmd = NL80211_CMD_NEW_KEY, |
| 6859 | .doit = nl80211_new_key, |
| 6860 | .policy = nl80211_policy, |
| 6861 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6862 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6863 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6864 | }, |
| 6865 | { |
| 6866 | .cmd = NL80211_CMD_DEL_KEY, |
| 6867 | .doit = nl80211_del_key, |
| 6868 | .policy = nl80211_policy, |
| 6869 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6870 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6871 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6872 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6873 | { |
| 6874 | .cmd = NL80211_CMD_SET_BEACON, |
| 6875 | .policy = nl80211_policy, |
| 6876 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6877 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6878 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6879 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6880 | }, |
| 6881 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6882 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6883 | .policy = nl80211_policy, |
| 6884 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6885 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6886 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6887 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6888 | }, |
| 6889 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6890 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6891 | .policy = nl80211_policy, |
| 6892 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6893 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6894 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6895 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6896 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6897 | { |
| 6898 | .cmd = NL80211_CMD_GET_STATION, |
| 6899 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6900 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6901 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6902 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6903 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6904 | }, |
| 6905 | { |
| 6906 | .cmd = NL80211_CMD_SET_STATION, |
| 6907 | .doit = nl80211_set_station, |
| 6908 | .policy = nl80211_policy, |
| 6909 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6910 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6911 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6912 | }, |
| 6913 | { |
| 6914 | .cmd = NL80211_CMD_NEW_STATION, |
| 6915 | .doit = nl80211_new_station, |
| 6916 | .policy = nl80211_policy, |
| 6917 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6918 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6919 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6920 | }, |
| 6921 | { |
| 6922 | .cmd = NL80211_CMD_DEL_STATION, |
| 6923 | .doit = nl80211_del_station, |
| 6924 | .policy = nl80211_policy, |
| 6925 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6926 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6927 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6928 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6929 | { |
| 6930 | .cmd = NL80211_CMD_GET_MPATH, |
| 6931 | .doit = nl80211_get_mpath, |
| 6932 | .dumpit = nl80211_dump_mpath, |
| 6933 | .policy = nl80211_policy, |
| 6934 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6935 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6936 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6937 | }, |
| 6938 | { |
| 6939 | .cmd = NL80211_CMD_SET_MPATH, |
| 6940 | .doit = nl80211_set_mpath, |
| 6941 | .policy = nl80211_policy, |
| 6942 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6943 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6944 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6945 | }, |
| 6946 | { |
| 6947 | .cmd = NL80211_CMD_NEW_MPATH, |
| 6948 | .doit = nl80211_new_mpath, |
| 6949 | .policy = nl80211_policy, |
| 6950 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6951 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6952 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6953 | }, |
| 6954 | { |
| 6955 | .cmd = NL80211_CMD_DEL_MPATH, |
| 6956 | .doit = nl80211_del_mpath, |
| 6957 | .policy = nl80211_policy, |
| 6958 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6959 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6960 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6961 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6962 | { |
| 6963 | .cmd = NL80211_CMD_SET_BSS, |
| 6964 | .doit = nl80211_set_bss, |
| 6965 | .policy = nl80211_policy, |
| 6966 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6967 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6968 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6969 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6970 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6971 | .cmd = NL80211_CMD_GET_REG, |
| 6972 | .doit = nl80211_get_reg, |
| 6973 | .policy = nl80211_policy, |
| 6974 | /* can be retrieved by unprivileged users */ |
| 6975 | }, |
| 6976 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6977 | .cmd = NL80211_CMD_SET_REG, |
| 6978 | .doit = nl80211_set_reg, |
| 6979 | .policy = nl80211_policy, |
| 6980 | .flags = GENL_ADMIN_PERM, |
| 6981 | }, |
| 6982 | { |
| 6983 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 6984 | .doit = nl80211_req_set_reg, |
| 6985 | .policy = nl80211_policy, |
| 6986 | .flags = GENL_ADMIN_PERM, |
| 6987 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6988 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6989 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 6990 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6991 | .policy = nl80211_policy, |
| 6992 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6993 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6994 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6995 | }, |
| 6996 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6997 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 6998 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6999 | .policy = nl80211_policy, |
| 7000 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7001 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7002 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7003 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 7004 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7005 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 7006 | .doit = nl80211_trigger_scan, |
| 7007 | .policy = nl80211_policy, |
| 7008 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7009 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7010 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7011 | }, |
| 7012 | { |
| 7013 | .cmd = NL80211_CMD_GET_SCAN, |
| 7014 | .policy = nl80211_policy, |
| 7015 | .dumpit = nl80211_dump_scan, |
| 7016 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7017 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7018 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 7019 | .doit = nl80211_start_sched_scan, |
| 7020 | .policy = nl80211_policy, |
| 7021 | .flags = GENL_ADMIN_PERM, |
| 7022 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7023 | NL80211_FLAG_NEED_RTNL, |
| 7024 | }, |
| 7025 | { |
| 7026 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 7027 | .doit = nl80211_stop_sched_scan, |
| 7028 | .policy = nl80211_policy, |
| 7029 | .flags = GENL_ADMIN_PERM, |
| 7030 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7031 | NL80211_FLAG_NEED_RTNL, |
| 7032 | }, |
| 7033 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7034 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 7035 | .doit = nl80211_authenticate, |
| 7036 | .policy = nl80211_policy, |
| 7037 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7038 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7039 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7040 | }, |
| 7041 | { |
| 7042 | .cmd = NL80211_CMD_ASSOCIATE, |
| 7043 | .doit = nl80211_associate, |
| 7044 | .policy = nl80211_policy, |
| 7045 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7046 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7047 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7048 | }, |
| 7049 | { |
| 7050 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 7051 | .doit = nl80211_deauthenticate, |
| 7052 | .policy = nl80211_policy, |
| 7053 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7054 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7055 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7056 | }, |
| 7057 | { |
| 7058 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 7059 | .doit = nl80211_disassociate, |
| 7060 | .policy = nl80211_policy, |
| 7061 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7062 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7063 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7064 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7065 | { |
| 7066 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 7067 | .doit = nl80211_join_ibss, |
| 7068 | .policy = nl80211_policy, |
| 7069 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7070 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7071 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7072 | }, |
| 7073 | { |
| 7074 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 7075 | .doit = nl80211_leave_ibss, |
| 7076 | .policy = nl80211_policy, |
| 7077 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7078 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7079 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7080 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7081 | #ifdef CONFIG_NL80211_TESTMODE |
| 7082 | { |
| 7083 | .cmd = NL80211_CMD_TESTMODE, |
| 7084 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7085 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7086 | .policy = nl80211_policy, |
| 7087 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7088 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7089 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7090 | }, |
| 7091 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7092 | { |
| 7093 | .cmd = NL80211_CMD_CONNECT, |
| 7094 | .doit = nl80211_connect, |
| 7095 | .policy = nl80211_policy, |
| 7096 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7097 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7098 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7099 | }, |
| 7100 | { |
| 7101 | .cmd = NL80211_CMD_DISCONNECT, |
| 7102 | .doit = nl80211_disconnect, |
| 7103 | .policy = nl80211_policy, |
| 7104 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7105 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7106 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7107 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7108 | { |
| 7109 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 7110 | .doit = nl80211_wiphy_netns, |
| 7111 | .policy = nl80211_policy, |
| 7112 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7113 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7114 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7115 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7116 | { |
| 7117 | .cmd = NL80211_CMD_GET_SURVEY, |
| 7118 | .policy = nl80211_policy, |
| 7119 | .dumpit = nl80211_dump_survey, |
| 7120 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7121 | { |
| 7122 | .cmd = NL80211_CMD_SET_PMKSA, |
| 7123 | .doit = nl80211_setdel_pmksa, |
| 7124 | .policy = nl80211_policy, |
| 7125 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7126 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7127 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7128 | }, |
| 7129 | { |
| 7130 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 7131 | .doit = nl80211_setdel_pmksa, |
| 7132 | .policy = nl80211_policy, |
| 7133 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7134 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7135 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7136 | }, |
| 7137 | { |
| 7138 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 7139 | .doit = nl80211_flush_pmksa, |
| 7140 | .policy = nl80211_policy, |
| 7141 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7142 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7143 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7144 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7145 | { |
| 7146 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7147 | .doit = nl80211_remain_on_channel, |
| 7148 | .policy = nl80211_policy, |
| 7149 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7150 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7151 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7152 | }, |
| 7153 | { |
| 7154 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7155 | .doit = nl80211_cancel_remain_on_channel, |
| 7156 | .policy = nl80211_policy, |
| 7157 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7158 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7159 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7160 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7161 | { |
| 7162 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 7163 | .doit = nl80211_set_tx_bitrate_mask, |
| 7164 | .policy = nl80211_policy, |
| 7165 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7166 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7167 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7168 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7169 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7170 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 7171 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7172 | .policy = nl80211_policy, |
| 7173 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7174 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7175 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7176 | }, |
| 7177 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7178 | .cmd = NL80211_CMD_FRAME, |
| 7179 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7180 | .policy = nl80211_policy, |
| 7181 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7182 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7183 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7184 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7185 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7186 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 7187 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 7188 | .policy = nl80211_policy, |
| 7189 | .flags = GENL_ADMIN_PERM, |
| 7190 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7191 | NL80211_FLAG_NEED_RTNL, |
| 7192 | }, |
| 7193 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7194 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 7195 | .doit = nl80211_set_power_save, |
| 7196 | .policy = nl80211_policy, |
| 7197 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7198 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7199 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7200 | }, |
| 7201 | { |
| 7202 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 7203 | .doit = nl80211_get_power_save, |
| 7204 | .policy = nl80211_policy, |
| 7205 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7206 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7207 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7208 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7209 | { |
| 7210 | .cmd = NL80211_CMD_SET_CQM, |
| 7211 | .doit = nl80211_set_cqm, |
| 7212 | .policy = nl80211_policy, |
| 7213 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7214 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7215 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7216 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7217 | { |
| 7218 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 7219 | .doit = nl80211_set_channel, |
| 7220 | .policy = nl80211_policy, |
| 7221 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7222 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7223 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7224 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7225 | { |
| 7226 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 7227 | .doit = nl80211_set_wds_peer, |
| 7228 | .policy = nl80211_policy, |
| 7229 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 7230 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7231 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7232 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7233 | { |
| 7234 | .cmd = NL80211_CMD_JOIN_MESH, |
| 7235 | .doit = nl80211_join_mesh, |
| 7236 | .policy = nl80211_policy, |
| 7237 | .flags = GENL_ADMIN_PERM, |
| 7238 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7239 | NL80211_FLAG_NEED_RTNL, |
| 7240 | }, |
| 7241 | { |
| 7242 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 7243 | .doit = nl80211_leave_mesh, |
| 7244 | .policy = nl80211_policy, |
| 7245 | .flags = GENL_ADMIN_PERM, |
| 7246 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7247 | NL80211_FLAG_NEED_RTNL, |
| 7248 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7249 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7250 | { |
| 7251 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 7252 | .doit = nl80211_get_wowlan, |
| 7253 | .policy = nl80211_policy, |
| 7254 | /* can be retrieved by unprivileged users */ |
| 7255 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7256 | NL80211_FLAG_NEED_RTNL, |
| 7257 | }, |
| 7258 | { |
| 7259 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 7260 | .doit = nl80211_set_wowlan, |
| 7261 | .policy = nl80211_policy, |
| 7262 | .flags = GENL_ADMIN_PERM, |
| 7263 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7264 | NL80211_FLAG_NEED_RTNL, |
| 7265 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7266 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7267 | { |
| 7268 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 7269 | .doit = nl80211_set_rekey_data, |
| 7270 | .policy = nl80211_policy, |
| 7271 | .flags = GENL_ADMIN_PERM, |
| 7272 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7273 | NL80211_FLAG_NEED_RTNL, |
| 7274 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7275 | { |
| 7276 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 7277 | .doit = nl80211_tdls_mgmt, |
| 7278 | .policy = nl80211_policy, |
| 7279 | .flags = GENL_ADMIN_PERM, |
| 7280 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7281 | NL80211_FLAG_NEED_RTNL, |
| 7282 | }, |
| 7283 | { |
| 7284 | .cmd = NL80211_CMD_TDLS_OPER, |
| 7285 | .doit = nl80211_tdls_oper, |
| 7286 | .policy = nl80211_policy, |
| 7287 | .flags = GENL_ADMIN_PERM, |
| 7288 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7289 | NL80211_FLAG_NEED_RTNL, |
| 7290 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7291 | { |
| 7292 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 7293 | .doit = nl80211_register_unexpected_frame, |
| 7294 | .policy = nl80211_policy, |
| 7295 | .flags = GENL_ADMIN_PERM, |
| 7296 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7297 | NL80211_FLAG_NEED_RTNL, |
| 7298 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7299 | { |
| 7300 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 7301 | .doit = nl80211_probe_client, |
| 7302 | .policy = nl80211_policy, |
| 7303 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7304 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7305 | NL80211_FLAG_NEED_RTNL, |
| 7306 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7307 | { |
| 7308 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 7309 | .doit = nl80211_register_beacons, |
| 7310 | .policy = nl80211_policy, |
| 7311 | .flags = GENL_ADMIN_PERM, |
| 7312 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7313 | NL80211_FLAG_NEED_RTNL, |
| 7314 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 7315 | { |
| 7316 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 7317 | .doit = nl80211_set_noack_map, |
| 7318 | .policy = nl80211_policy, |
| 7319 | .flags = GENL_ADMIN_PERM, |
| 7320 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7321 | NL80211_FLAG_NEED_RTNL, |
| 7322 | }, |
| 7323 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7324 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7325 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7326 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 7327 | .name = "mlme", |
| 7328 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7329 | |
| 7330 | /* multicast groups */ |
| 7331 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 7332 | .name = "config", |
| 7333 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7334 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 7335 | .name = "scan", |
| 7336 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7337 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 7338 | .name = "regulatory", |
| 7339 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7340 | |
| 7341 | /* notification functions */ |
| 7342 | |
| 7343 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 7344 | { |
| 7345 | struct sk_buff *msg; |
| 7346 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7347 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7348 | if (!msg) |
| 7349 | return; |
| 7350 | |
| 7351 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 7352 | nlmsg_free(msg); |
| 7353 | return; |
| 7354 | } |
| 7355 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7356 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7357 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7358 | } |
| 7359 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7360 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 7361 | struct cfg80211_registered_device *rdev) |
| 7362 | { |
| 7363 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 7364 | struct nlattr *nest; |
| 7365 | int i; |
| 7366 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7367 | ASSERT_RDEV_LOCK(rdev); |
| 7368 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7369 | if (WARN_ON(!req)) |
| 7370 | return 0; |
| 7371 | |
| 7372 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 7373 | if (!nest) |
| 7374 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7375 | for (i = 0; i < req->n_ssids; i++) { |
| 7376 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 7377 | goto nla_put_failure; |
| 7378 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7379 | nla_nest_end(msg, nest); |
| 7380 | |
| 7381 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 7382 | if (!nest) |
| 7383 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7384 | for (i = 0; i < req->n_channels; i++) { |
| 7385 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 7386 | goto nla_put_failure; |
| 7387 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7388 | nla_nest_end(msg, nest); |
| 7389 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7390 | if (req->ie && |
| 7391 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 7392 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7393 | |
| 7394 | return 0; |
| 7395 | nla_put_failure: |
| 7396 | return -ENOBUFS; |
| 7397 | } |
| 7398 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7399 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 7400 | struct cfg80211_registered_device *rdev, |
| 7401 | struct net_device *netdev, |
| 7402 | u32 pid, u32 seq, int flags, |
| 7403 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7404 | { |
| 7405 | void *hdr; |
| 7406 | |
| 7407 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 7408 | if (!hdr) |
| 7409 | return -1; |
| 7410 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7411 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7412 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7413 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7414 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7415 | /* ignore errors and send incomplete event anyway */ |
| 7416 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7417 | |
| 7418 | return genlmsg_end(msg, hdr); |
| 7419 | |
| 7420 | nla_put_failure: |
| 7421 | genlmsg_cancel(msg, hdr); |
| 7422 | return -EMSGSIZE; |
| 7423 | } |
| 7424 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7425 | static int |
| 7426 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 7427 | struct cfg80211_registered_device *rdev, |
| 7428 | struct net_device *netdev, |
| 7429 | u32 pid, u32 seq, int flags, u32 cmd) |
| 7430 | { |
| 7431 | void *hdr; |
| 7432 | |
| 7433 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 7434 | if (!hdr) |
| 7435 | return -1; |
| 7436 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7437 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7438 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7439 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7440 | |
| 7441 | return genlmsg_end(msg, hdr); |
| 7442 | |
| 7443 | nla_put_failure: |
| 7444 | genlmsg_cancel(msg, hdr); |
| 7445 | return -EMSGSIZE; |
| 7446 | } |
| 7447 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7448 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 7449 | struct net_device *netdev) |
| 7450 | { |
| 7451 | struct sk_buff *msg; |
| 7452 | |
| 7453 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 7454 | if (!msg) |
| 7455 | return; |
| 7456 | |
| 7457 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7458 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 7459 | nlmsg_free(msg); |
| 7460 | return; |
| 7461 | } |
| 7462 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7463 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7464 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7465 | } |
| 7466 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7467 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 7468 | struct net_device *netdev) |
| 7469 | { |
| 7470 | struct sk_buff *msg; |
| 7471 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7472 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7473 | if (!msg) |
| 7474 | return; |
| 7475 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7476 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7477 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7478 | nlmsg_free(msg); |
| 7479 | return; |
| 7480 | } |
| 7481 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7482 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7483 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7484 | } |
| 7485 | |
| 7486 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 7487 | struct net_device *netdev) |
| 7488 | { |
| 7489 | struct sk_buff *msg; |
| 7490 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7491 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7492 | if (!msg) |
| 7493 | return; |
| 7494 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7495 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7496 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7497 | nlmsg_free(msg); |
| 7498 | return; |
| 7499 | } |
| 7500 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7501 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7502 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7503 | } |
| 7504 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7505 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 7506 | struct net_device *netdev) |
| 7507 | { |
| 7508 | struct sk_buff *msg; |
| 7509 | |
| 7510 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7511 | if (!msg) |
| 7512 | return; |
| 7513 | |
| 7514 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7515 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 7516 | nlmsg_free(msg); |
| 7517 | return; |
| 7518 | } |
| 7519 | |
| 7520 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7521 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7522 | } |
| 7523 | |
| 7524 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 7525 | struct net_device *netdev, u32 cmd) |
| 7526 | { |
| 7527 | struct sk_buff *msg; |
| 7528 | |
| 7529 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 7530 | if (!msg) |
| 7531 | return; |
| 7532 | |
| 7533 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 7534 | nlmsg_free(msg); |
| 7535 | return; |
| 7536 | } |
| 7537 | |
| 7538 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7539 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7540 | } |
| 7541 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7542 | /* |
| 7543 | * This can happen on global regulatory changes or device specific settings |
| 7544 | * based on custom world regulatory domains. |
| 7545 | */ |
| 7546 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 7547 | { |
| 7548 | struct sk_buff *msg; |
| 7549 | void *hdr; |
| 7550 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7551 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7552 | if (!msg) |
| 7553 | return; |
| 7554 | |
| 7555 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 7556 | if (!hdr) { |
| 7557 | nlmsg_free(msg); |
| 7558 | return; |
| 7559 | } |
| 7560 | |
| 7561 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7562 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 7563 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7564 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7565 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 7566 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7567 | NL80211_REGDOM_TYPE_WORLD)) |
| 7568 | goto nla_put_failure; |
| 7569 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 7570 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7571 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 7572 | goto nla_put_failure; |
| 7573 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 7574 | request->intersect) { |
| 7575 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7576 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 7577 | goto nla_put_failure; |
| 7578 | } else { |
| 7579 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7580 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 7581 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 7582 | request->alpha2)) |
| 7583 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7584 | } |
| 7585 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7586 | if (wiphy_idx_valid(request->wiphy_idx) && |
| 7587 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 7588 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7589 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7590 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7591 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7592 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7593 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7594 | GFP_ATOMIC); |
| 7595 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7596 | |
| 7597 | return; |
| 7598 | |
| 7599 | nla_put_failure: |
| 7600 | genlmsg_cancel(msg, hdr); |
| 7601 | nlmsg_free(msg); |
| 7602 | } |
| 7603 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7604 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 7605 | struct net_device *netdev, |
| 7606 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7607 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7608 | { |
| 7609 | struct sk_buff *msg; |
| 7610 | void *hdr; |
| 7611 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7612 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7613 | if (!msg) |
| 7614 | return; |
| 7615 | |
| 7616 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7617 | if (!hdr) { |
| 7618 | nlmsg_free(msg); |
| 7619 | return; |
| 7620 | } |
| 7621 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7622 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7623 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7624 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 7625 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7626 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7627 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7628 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7629 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7630 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7631 | return; |
| 7632 | |
| 7633 | nla_put_failure: |
| 7634 | genlmsg_cancel(msg, hdr); |
| 7635 | nlmsg_free(msg); |
| 7636 | } |
| 7637 | |
| 7638 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7639 | struct net_device *netdev, const u8 *buf, |
| 7640 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7641 | { |
| 7642 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7643 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7644 | } |
| 7645 | |
| 7646 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 7647 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7648 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7649 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7650 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7651 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7652 | } |
| 7653 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7654 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7655 | struct net_device *netdev, const u8 *buf, |
| 7656 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7657 | { |
| 7658 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7659 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7660 | } |
| 7661 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7662 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 7663 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7664 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7665 | { |
| 7666 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7667 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7668 | } |
| 7669 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 7670 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 7671 | struct net_device *netdev, const u8 *buf, |
| 7672 | size_t len, gfp_t gfp) |
| 7673 | { |
| 7674 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7675 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 7676 | } |
| 7677 | |
| 7678 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 7679 | struct net_device *netdev, const u8 *buf, |
| 7680 | size_t len, gfp_t gfp) |
| 7681 | { |
| 7682 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7683 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 7684 | } |
| 7685 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 7686 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 7687 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7688 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7689 | { |
| 7690 | struct sk_buff *msg; |
| 7691 | void *hdr; |
| 7692 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7693 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7694 | if (!msg) |
| 7695 | return; |
| 7696 | |
| 7697 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7698 | if (!hdr) { |
| 7699 | nlmsg_free(msg); |
| 7700 | return; |
| 7701 | } |
| 7702 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7703 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7704 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7705 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 7706 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 7707 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7708 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7709 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7710 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7711 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7712 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7713 | return; |
| 7714 | |
| 7715 | nla_put_failure: |
| 7716 | genlmsg_cancel(msg, hdr); |
| 7717 | nlmsg_free(msg); |
| 7718 | } |
| 7719 | |
| 7720 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7721 | struct net_device *netdev, const u8 *addr, |
| 7722 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7723 | { |
| 7724 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7725 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7726 | } |
| 7727 | |
| 7728 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7729 | struct net_device *netdev, const u8 *addr, |
| 7730 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7731 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7732 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 7733 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7734 | } |
| 7735 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7736 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 7737 | struct net_device *netdev, const u8 *bssid, |
| 7738 | const u8 *req_ie, size_t req_ie_len, |
| 7739 | const u8 *resp_ie, size_t resp_ie_len, |
| 7740 | u16 status, gfp_t gfp) |
| 7741 | { |
| 7742 | struct sk_buff *msg; |
| 7743 | void *hdr; |
| 7744 | |
| 7745 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7746 | if (!msg) |
| 7747 | return; |
| 7748 | |
| 7749 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 7750 | if (!hdr) { |
| 7751 | nlmsg_free(msg); |
| 7752 | return; |
| 7753 | } |
| 7754 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7755 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7756 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7757 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 7758 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 7759 | (req_ie && |
| 7760 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 7761 | (resp_ie && |
| 7762 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 7763 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7764 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7765 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7766 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7767 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7768 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7769 | return; |
| 7770 | |
| 7771 | nla_put_failure: |
| 7772 | genlmsg_cancel(msg, hdr); |
| 7773 | nlmsg_free(msg); |
| 7774 | |
| 7775 | } |
| 7776 | |
| 7777 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 7778 | struct net_device *netdev, const u8 *bssid, |
| 7779 | const u8 *req_ie, size_t req_ie_len, |
| 7780 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 7781 | { |
| 7782 | struct sk_buff *msg; |
| 7783 | void *hdr; |
| 7784 | |
| 7785 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7786 | if (!msg) |
| 7787 | return; |
| 7788 | |
| 7789 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 7790 | if (!hdr) { |
| 7791 | nlmsg_free(msg); |
| 7792 | return; |
| 7793 | } |
| 7794 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7795 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7796 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7797 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 7798 | (req_ie && |
| 7799 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 7800 | (resp_ie && |
| 7801 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 7802 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7803 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7804 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7805 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7806 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7807 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7808 | return; |
| 7809 | |
| 7810 | nla_put_failure: |
| 7811 | genlmsg_cancel(msg, hdr); |
| 7812 | nlmsg_free(msg); |
| 7813 | |
| 7814 | } |
| 7815 | |
| 7816 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 7817 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7818 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7819 | { |
| 7820 | struct sk_buff *msg; |
| 7821 | void *hdr; |
| 7822 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7823 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7824 | if (!msg) |
| 7825 | return; |
| 7826 | |
| 7827 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 7828 | if (!hdr) { |
| 7829 | nlmsg_free(msg); |
| 7830 | return; |
| 7831 | } |
| 7832 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7833 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7834 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7835 | (from_ap && reason && |
| 7836 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 7837 | (from_ap && |
| 7838 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 7839 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 7840 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7841 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7842 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7843 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7844 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7845 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7846 | return; |
| 7847 | |
| 7848 | nla_put_failure: |
| 7849 | genlmsg_cancel(msg, hdr); |
| 7850 | nlmsg_free(msg); |
| 7851 | |
| 7852 | } |
| 7853 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7854 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 7855 | struct net_device *netdev, const u8 *bssid, |
| 7856 | gfp_t gfp) |
| 7857 | { |
| 7858 | struct sk_buff *msg; |
| 7859 | void *hdr; |
| 7860 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7861 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7862 | if (!msg) |
| 7863 | return; |
| 7864 | |
| 7865 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 7866 | if (!hdr) { |
| 7867 | nlmsg_free(msg); |
| 7868 | return; |
| 7869 | } |
| 7870 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7871 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7872 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7873 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 7874 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7875 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7876 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7877 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7878 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7879 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7880 | return; |
| 7881 | |
| 7882 | nla_put_failure: |
| 7883 | genlmsg_cancel(msg, hdr); |
| 7884 | nlmsg_free(msg); |
| 7885 | } |
| 7886 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7887 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 7888 | struct net_device *netdev, |
| 7889 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 7890 | gfp_t gfp) |
| 7891 | { |
| 7892 | struct sk_buff *msg; |
| 7893 | void *hdr; |
| 7894 | |
| 7895 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7896 | if (!msg) |
| 7897 | return; |
| 7898 | |
| 7899 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 7900 | if (!hdr) { |
| 7901 | nlmsg_free(msg); |
| 7902 | return; |
| 7903 | } |
| 7904 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7905 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7906 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7907 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 7908 | (ie_len && ie && |
| 7909 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 7910 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7911 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7912 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7913 | |
| 7914 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7915 | nl80211_mlme_mcgrp.id, gfp); |
| 7916 | return; |
| 7917 | |
| 7918 | nla_put_failure: |
| 7919 | genlmsg_cancel(msg, hdr); |
| 7920 | nlmsg_free(msg); |
| 7921 | } |
| 7922 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7923 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 7924 | struct net_device *netdev, const u8 *addr, |
| 7925 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7926 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7927 | { |
| 7928 | struct sk_buff *msg; |
| 7929 | void *hdr; |
| 7930 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7931 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7932 | if (!msg) |
| 7933 | return; |
| 7934 | |
| 7935 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 7936 | if (!hdr) { |
| 7937 | nlmsg_free(msg); |
| 7938 | return; |
| 7939 | } |
| 7940 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7941 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7942 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7943 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 7944 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 7945 | (key_id != -1 && |
| 7946 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 7947 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 7948 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7949 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7950 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7951 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7952 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7953 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7954 | return; |
| 7955 | |
| 7956 | nla_put_failure: |
| 7957 | genlmsg_cancel(msg, hdr); |
| 7958 | nlmsg_free(msg); |
| 7959 | } |
| 7960 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7961 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 7962 | struct ieee80211_channel *channel_before, |
| 7963 | struct ieee80211_channel *channel_after) |
| 7964 | { |
| 7965 | struct sk_buff *msg; |
| 7966 | void *hdr; |
| 7967 | struct nlattr *nl_freq; |
| 7968 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7969 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7970 | if (!msg) |
| 7971 | return; |
| 7972 | |
| 7973 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 7974 | if (!hdr) { |
| 7975 | nlmsg_free(msg); |
| 7976 | return; |
| 7977 | } |
| 7978 | |
| 7979 | /* |
| 7980 | * Since we are applying the beacon hint to a wiphy we know its |
| 7981 | * wiphy_idx is valid |
| 7982 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7983 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7984 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7985 | |
| 7986 | /* Before */ |
| 7987 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 7988 | if (!nl_freq) |
| 7989 | goto nla_put_failure; |
| 7990 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 7991 | goto nla_put_failure; |
| 7992 | nla_nest_end(msg, nl_freq); |
| 7993 | |
| 7994 | /* After */ |
| 7995 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 7996 | if (!nl_freq) |
| 7997 | goto nla_put_failure; |
| 7998 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 7999 | goto nla_put_failure; |
| 8000 | nla_nest_end(msg, nl_freq); |
| 8001 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8002 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8003 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8004 | rcu_read_lock(); |
| 8005 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 8006 | GFP_ATOMIC); |
| 8007 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 8008 | |
| 8009 | return; |
| 8010 | |
| 8011 | nla_put_failure: |
| 8012 | genlmsg_cancel(msg, hdr); |
| 8013 | nlmsg_free(msg); |
| 8014 | } |
| 8015 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8016 | static void nl80211_send_remain_on_chan_event( |
| 8017 | int cmd, struct cfg80211_registered_device *rdev, |
| 8018 | struct net_device *netdev, u64 cookie, |
| 8019 | struct ieee80211_channel *chan, |
| 8020 | enum nl80211_channel_type channel_type, |
| 8021 | unsigned int duration, gfp_t gfp) |
| 8022 | { |
| 8023 | struct sk_buff *msg; |
| 8024 | void *hdr; |
| 8025 | |
| 8026 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8027 | if (!msg) |
| 8028 | return; |
| 8029 | |
| 8030 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 8031 | if (!hdr) { |
| 8032 | nlmsg_free(msg); |
| 8033 | return; |
| 8034 | } |
| 8035 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8036 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8037 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8038 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
| 8039 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) || |
| 8040 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8041 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8042 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8043 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 8044 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 8045 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8046 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8047 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8048 | |
| 8049 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8050 | nl80211_mlme_mcgrp.id, gfp); |
| 8051 | return; |
| 8052 | |
| 8053 | nla_put_failure: |
| 8054 | genlmsg_cancel(msg, hdr); |
| 8055 | nlmsg_free(msg); |
| 8056 | } |
| 8057 | |
| 8058 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 8059 | struct net_device *netdev, u64 cookie, |
| 8060 | struct ieee80211_channel *chan, |
| 8061 | enum nl80211_channel_type channel_type, |
| 8062 | unsigned int duration, gfp_t gfp) |
| 8063 | { |
| 8064 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8065 | rdev, netdev, cookie, chan, |
| 8066 | channel_type, duration, gfp); |
| 8067 | } |
| 8068 | |
| 8069 | void nl80211_send_remain_on_channel_cancel( |
| 8070 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 8071 | u64 cookie, struct ieee80211_channel *chan, |
| 8072 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 8073 | { |
| 8074 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8075 | rdev, netdev, cookie, chan, |
| 8076 | channel_type, 0, gfp); |
| 8077 | } |
| 8078 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8079 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 8080 | struct net_device *dev, const u8 *mac_addr, |
| 8081 | struct station_info *sinfo, gfp_t gfp) |
| 8082 | { |
| 8083 | struct sk_buff *msg; |
| 8084 | |
| 8085 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8086 | if (!msg) |
| 8087 | return; |
| 8088 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 8089 | if (nl80211_send_station(msg, 0, 0, 0, |
| 8090 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 8091 | nlmsg_free(msg); |
| 8092 | return; |
| 8093 | } |
| 8094 | |
| 8095 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8096 | nl80211_mlme_mcgrp.id, gfp); |
| 8097 | } |
| 8098 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8099 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 8100 | struct net_device *dev, const u8 *mac_addr, |
| 8101 | gfp_t gfp) |
| 8102 | { |
| 8103 | struct sk_buff *msg; |
| 8104 | void *hdr; |
| 8105 | |
| 8106 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8107 | if (!msg) |
| 8108 | return; |
| 8109 | |
| 8110 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 8111 | if (!hdr) { |
| 8112 | nlmsg_free(msg); |
| 8113 | return; |
| 8114 | } |
| 8115 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8116 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8117 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 8118 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8119 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8120 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8121 | |
| 8122 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8123 | nl80211_mlme_mcgrp.id, gfp); |
| 8124 | return; |
| 8125 | |
| 8126 | nla_put_failure: |
| 8127 | genlmsg_cancel(msg, hdr); |
| 8128 | nlmsg_free(msg); |
| 8129 | } |
| 8130 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8131 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 8132 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8133 | { |
| 8134 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8135 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8136 | struct sk_buff *msg; |
| 8137 | void *hdr; |
| 8138 | int err; |
| 8139 | u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid); |
| 8140 | |
| 8141 | if (!nlpid) |
| 8142 | return false; |
| 8143 | |
| 8144 | msg = nlmsg_new(100, gfp); |
| 8145 | if (!msg) |
| 8146 | return true; |
| 8147 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8148 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8149 | if (!hdr) { |
| 8150 | nlmsg_free(msg); |
| 8151 | return true; |
| 8152 | } |
| 8153 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8154 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8155 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8156 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8157 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8158 | |
| 8159 | err = genlmsg_end(msg, hdr); |
| 8160 | if (err < 0) { |
| 8161 | nlmsg_free(msg); |
| 8162 | return true; |
| 8163 | } |
| 8164 | |
| 8165 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 8166 | return true; |
| 8167 | |
| 8168 | nla_put_failure: |
| 8169 | genlmsg_cancel(msg, hdr); |
| 8170 | nlmsg_free(msg); |
| 8171 | return true; |
| 8172 | } |
| 8173 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8174 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 8175 | { |
| 8176 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 8177 | addr, gfp); |
| 8178 | } |
| 8179 | |
| 8180 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 8181 | const u8 *addr, gfp_t gfp) |
| 8182 | { |
| 8183 | return __nl80211_unexpected_frame(dev, |
| 8184 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 8185 | addr, gfp); |
| 8186 | } |
| 8187 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8188 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 8189 | struct net_device *netdev, u32 nlpid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8190 | int freq, int sig_dbm, |
| 8191 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8192 | { |
| 8193 | struct sk_buff *msg; |
| 8194 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8195 | |
| 8196 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8197 | if (!msg) |
| 8198 | return -ENOMEM; |
| 8199 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8200 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8201 | if (!hdr) { |
| 8202 | nlmsg_free(msg); |
| 8203 | return -ENOMEM; |
| 8204 | } |
| 8205 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8206 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8207 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8208 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8209 | (sig_dbm && |
| 8210 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8211 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8212 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8213 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8214 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8215 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8216 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8217 | |
| 8218 | nla_put_failure: |
| 8219 | genlmsg_cancel(msg, hdr); |
| 8220 | nlmsg_free(msg); |
| 8221 | return -ENOBUFS; |
| 8222 | } |
| 8223 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8224 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 8225 | struct net_device *netdev, u64 cookie, |
| 8226 | const u8 *buf, size_t len, bool ack, |
| 8227 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8228 | { |
| 8229 | struct sk_buff *msg; |
| 8230 | void *hdr; |
| 8231 | |
| 8232 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8233 | if (!msg) |
| 8234 | return; |
| 8235 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8236 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8237 | if (!hdr) { |
| 8238 | nlmsg_free(msg); |
| 8239 | return; |
| 8240 | } |
| 8241 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8242 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8243 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8244 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 8245 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8246 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8247 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8248 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8249 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8250 | |
| 8251 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 8252 | return; |
| 8253 | |
| 8254 | nla_put_failure: |
| 8255 | genlmsg_cancel(msg, hdr); |
| 8256 | nlmsg_free(msg); |
| 8257 | } |
| 8258 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8259 | void |
| 8260 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 8261 | struct net_device *netdev, |
| 8262 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 8263 | gfp_t gfp) |
| 8264 | { |
| 8265 | struct sk_buff *msg; |
| 8266 | struct nlattr *pinfoattr; |
| 8267 | void *hdr; |
| 8268 | |
| 8269 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8270 | if (!msg) |
| 8271 | return; |
| 8272 | |
| 8273 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8274 | if (!hdr) { |
| 8275 | nlmsg_free(msg); |
| 8276 | return; |
| 8277 | } |
| 8278 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8279 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8280 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8281 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8282 | |
| 8283 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8284 | if (!pinfoattr) |
| 8285 | goto nla_put_failure; |
| 8286 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8287 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 8288 | rssi_event)) |
| 8289 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8290 | |
| 8291 | nla_nest_end(msg, pinfoattr); |
| 8292 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8293 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8294 | |
| 8295 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8296 | nl80211_mlme_mcgrp.id, gfp); |
| 8297 | return; |
| 8298 | |
| 8299 | nla_put_failure: |
| 8300 | genlmsg_cancel(msg, hdr); |
| 8301 | nlmsg_free(msg); |
| 8302 | } |
| 8303 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8304 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 8305 | struct net_device *netdev, const u8 *bssid, |
| 8306 | const u8 *replay_ctr, gfp_t gfp) |
| 8307 | { |
| 8308 | struct sk_buff *msg; |
| 8309 | struct nlattr *rekey_attr; |
| 8310 | void *hdr; |
| 8311 | |
| 8312 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8313 | if (!msg) |
| 8314 | return; |
| 8315 | |
| 8316 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 8317 | if (!hdr) { |
| 8318 | nlmsg_free(msg); |
| 8319 | return; |
| 8320 | } |
| 8321 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8322 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8323 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8324 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8325 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8326 | |
| 8327 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 8328 | if (!rekey_attr) |
| 8329 | goto nla_put_failure; |
| 8330 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8331 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 8332 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 8333 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8334 | |
| 8335 | nla_nest_end(msg, rekey_attr); |
| 8336 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8337 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8338 | |
| 8339 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8340 | nl80211_mlme_mcgrp.id, gfp); |
| 8341 | return; |
| 8342 | |
| 8343 | nla_put_failure: |
| 8344 | genlmsg_cancel(msg, hdr); |
| 8345 | nlmsg_free(msg); |
| 8346 | } |
| 8347 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8348 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 8349 | struct net_device *netdev, int index, |
| 8350 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 8351 | { |
| 8352 | struct sk_buff *msg; |
| 8353 | struct nlattr *attr; |
| 8354 | void *hdr; |
| 8355 | |
| 8356 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8357 | if (!msg) |
| 8358 | return; |
| 8359 | |
| 8360 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 8361 | if (!hdr) { |
| 8362 | nlmsg_free(msg); |
| 8363 | return; |
| 8364 | } |
| 8365 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8366 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8367 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8368 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8369 | |
| 8370 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 8371 | if (!attr) |
| 8372 | goto nla_put_failure; |
| 8373 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8374 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 8375 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 8376 | (preauth && |
| 8377 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 8378 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8379 | |
| 8380 | nla_nest_end(msg, attr); |
| 8381 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8382 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8383 | |
| 8384 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8385 | nl80211_mlme_mcgrp.id, gfp); |
| 8386 | return; |
| 8387 | |
| 8388 | nla_put_failure: |
| 8389 | genlmsg_cancel(msg, hdr); |
| 8390 | nlmsg_free(msg); |
| 8391 | } |
| 8392 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8393 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 8394 | struct net_device *netdev, int freq, |
| 8395 | enum nl80211_channel_type type, gfp_t gfp) |
| 8396 | { |
| 8397 | struct sk_buff *msg; |
| 8398 | void *hdr; |
| 8399 | |
| 8400 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8401 | if (!msg) |
| 8402 | return; |
| 8403 | |
| 8404 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 8405 | if (!hdr) { |
| 8406 | nlmsg_free(msg); |
| 8407 | return; |
| 8408 | } |
| 8409 | |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 8410 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8411 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8412 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type)) |
| 8413 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8414 | |
| 8415 | genlmsg_end(msg, hdr); |
| 8416 | |
| 8417 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8418 | nl80211_mlme_mcgrp.id, gfp); |
| 8419 | return; |
| 8420 | |
| 8421 | nla_put_failure: |
| 8422 | genlmsg_cancel(msg, hdr); |
| 8423 | nlmsg_free(msg); |
| 8424 | } |
| 8425 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8426 | void |
| 8427 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 8428 | struct net_device *netdev, const u8 *peer, |
| 8429 | u32 num_packets, gfp_t gfp) |
| 8430 | { |
| 8431 | struct sk_buff *msg; |
| 8432 | struct nlattr *pinfoattr; |
| 8433 | void *hdr; |
| 8434 | |
| 8435 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8436 | if (!msg) |
| 8437 | return; |
| 8438 | |
| 8439 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8440 | if (!hdr) { |
| 8441 | nlmsg_free(msg); |
| 8442 | return; |
| 8443 | } |
| 8444 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8445 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8446 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8447 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8448 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8449 | |
| 8450 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8451 | if (!pinfoattr) |
| 8452 | goto nla_put_failure; |
| 8453 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8454 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 8455 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8456 | |
| 8457 | nla_nest_end(msg, pinfoattr); |
| 8458 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8459 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8460 | |
| 8461 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8462 | nl80211_mlme_mcgrp.id, gfp); |
| 8463 | return; |
| 8464 | |
| 8465 | nla_put_failure: |
| 8466 | genlmsg_cancel(msg, hdr); |
| 8467 | nlmsg_free(msg); |
| 8468 | } |
| 8469 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8470 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 8471 | u64 cookie, bool acked, gfp_t gfp) |
| 8472 | { |
| 8473 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8474 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8475 | struct sk_buff *msg; |
| 8476 | void *hdr; |
| 8477 | int err; |
| 8478 | |
| 8479 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8480 | if (!msg) |
| 8481 | return; |
| 8482 | |
| 8483 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 8484 | if (!hdr) { |
| 8485 | nlmsg_free(msg); |
| 8486 | return; |
| 8487 | } |
| 8488 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8489 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8490 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8491 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8492 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8493 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8494 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8495 | |
| 8496 | err = genlmsg_end(msg, hdr); |
| 8497 | if (err < 0) { |
| 8498 | nlmsg_free(msg); |
| 8499 | return; |
| 8500 | } |
| 8501 | |
| 8502 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8503 | nl80211_mlme_mcgrp.id, gfp); |
| 8504 | return; |
| 8505 | |
| 8506 | nla_put_failure: |
| 8507 | genlmsg_cancel(msg, hdr); |
| 8508 | nlmsg_free(msg); |
| 8509 | } |
| 8510 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 8511 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8512 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 8513 | const u8 *frame, size_t len, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8514 | int freq, int sig_dbm, gfp_t gfp) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8515 | { |
| 8516 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 8517 | struct sk_buff *msg; |
| 8518 | void *hdr; |
| 8519 | u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid); |
| 8520 | |
| 8521 | if (!nlpid) |
| 8522 | return; |
| 8523 | |
| 8524 | msg = nlmsg_new(len + 100, gfp); |
| 8525 | if (!msg) |
| 8526 | return; |
| 8527 | |
| 8528 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 8529 | if (!hdr) { |
| 8530 | nlmsg_free(msg); |
| 8531 | return; |
| 8532 | } |
| 8533 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8534 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8535 | (freq && |
| 8536 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 8537 | (sig_dbm && |
| 8538 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8539 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 8540 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8541 | |
| 8542 | genlmsg_end(msg, hdr); |
| 8543 | |
| 8544 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 8545 | return; |
| 8546 | |
| 8547 | nla_put_failure: |
| 8548 | genlmsg_cancel(msg, hdr); |
| 8549 | nlmsg_free(msg); |
| 8550 | } |
| 8551 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 8552 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8553 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 8554 | unsigned long state, |
| 8555 | void *_notify) |
| 8556 | { |
| 8557 | struct netlink_notify *notify = _notify; |
| 8558 | struct cfg80211_registered_device *rdev; |
| 8559 | struct wireless_dev *wdev; |
| 8560 | |
| 8561 | if (state != NETLINK_URELEASE) |
| 8562 | return NOTIFY_DONE; |
| 8563 | |
| 8564 | rcu_read_lock(); |
| 8565 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8566 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame^] | 8567 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8568 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8569 | if (rdev->ap_beacons_nlpid == notify->pid) |
| 8570 | rdev->ap_beacons_nlpid = 0; |
| 8571 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8572 | |
| 8573 | rcu_read_unlock(); |
| 8574 | |
| 8575 | return NOTIFY_DONE; |
| 8576 | } |
| 8577 | |
| 8578 | static struct notifier_block nl80211_netlink_notifier = { |
| 8579 | .notifier_call = nl80211_netlink_notify, |
| 8580 | }; |
| 8581 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8582 | /* initialisation/exit functions */ |
| 8583 | |
| 8584 | int nl80211_init(void) |
| 8585 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8586 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8587 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8588 | err = genl_register_family_with_ops(&nl80211_fam, |
| 8589 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8590 | if (err) |
| 8591 | return err; |
| 8592 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8593 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 8594 | if (err) |
| 8595 | goto err_out; |
| 8596 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8597 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 8598 | if (err) |
| 8599 | goto err_out; |
| 8600 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8601 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 8602 | if (err) |
| 8603 | goto err_out; |
| 8604 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8605 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 8606 | if (err) |
| 8607 | goto err_out; |
| 8608 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8609 | #ifdef CONFIG_NL80211_TESTMODE |
| 8610 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 8611 | if (err) |
| 8612 | goto err_out; |
| 8613 | #endif |
| 8614 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8615 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 8616 | if (err) |
| 8617 | goto err_out; |
| 8618 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8619 | return 0; |
| 8620 | err_out: |
| 8621 | genl_unregister_family(&nl80211_fam); |
| 8622 | return err; |
| 8623 | } |
| 8624 | |
| 8625 | void nl80211_exit(void) |
| 8626 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8627 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8628 | genl_unregister_family(&nl80211_fam); |
| 8629 | } |