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 | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 50 | /* returns ERR_PTR values */ |
| 51 | static struct wireless_dev * |
| 52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 54 | struct cfg80211_registered_device *rdev; |
| 55 | struct wireless_dev *result = NULL; |
| 56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 58 | u64 wdev_id; |
| 59 | int wiphy_idx = -1; |
| 60 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 62 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | if (!have_ifidx && !have_wdev_id) |
| 65 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | if (have_ifidx) |
| 68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 69 | if (have_wdev_id) { |
| 70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 71 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 75 | struct wireless_dev *wdev; |
| 76 | |
| 77 | if (wiphy_net(&rdev->wiphy) != netns) |
| 78 | continue; |
| 79 | |
| 80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 81 | continue; |
| 82 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 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 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 94 | |
| 95 | if (result) |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | if (result) |
| 100 | return result; |
| 101 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 104 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 105 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 107 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 108 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 109 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 110 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 112 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 113 | !attrs[NL80211_ATTR_IFINDEX] && |
| 114 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 115 | return ERR_PTR(-EINVAL); |
| 116 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 117 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 118 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 120 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 121 | if (attrs[NL80211_ATTR_WDEV]) { |
| 122 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 123 | struct wireless_dev *wdev; |
| 124 | bool found = false; |
| 125 | |
| 126 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 127 | if (tmp) { |
| 128 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 129 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 130 | if (wdev->identifier != (u32)wdev_id) |
| 131 | continue; |
| 132 | found = true; |
| 133 | break; |
| 134 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 135 | |
| 136 | if (!found) |
| 137 | tmp = NULL; |
| 138 | |
| 139 | if (rdev && tmp != rdev) |
| 140 | return ERR_PTR(-EINVAL); |
| 141 | rdev = tmp; |
| 142 | } |
| 143 | } |
| 144 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 145 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 146 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 147 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 148 | if (netdev) { |
| 149 | if (netdev->ieee80211_ptr) |
| 150 | tmp = wiphy_to_dev( |
| 151 | netdev->ieee80211_ptr->wiphy); |
| 152 | else |
| 153 | tmp = NULL; |
| 154 | |
| 155 | dev_put(netdev); |
| 156 | |
| 157 | /* not wireless device -- return error */ |
| 158 | if (!tmp) |
| 159 | return ERR_PTR(-EINVAL); |
| 160 | |
| 161 | /* mismatch -- return error */ |
| 162 | if (rdev && tmp != rdev) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | |
| 165 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 166 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 169 | if (!rdev) |
| 170 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 171 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 172 | if (netns != wiphy_net(&rdev->wiphy)) |
| 173 | return ERR_PTR(-ENODEV); |
| 174 | |
| 175 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /* |
| 179 | * This function returns a pointer to the driver |
| 180 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 181 | * |
| 182 | * The result of this can be a PTR_ERR and hence must |
| 183 | * be checked with IS_ERR() for errors. |
| 184 | */ |
| 185 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 186 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 187 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 188 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 189 | } |
| 190 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 191 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 192 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 193 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 194 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 195 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 196 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 197 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 198 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 199 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 200 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 201 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 202 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 203 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 204 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 205 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 206 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 207 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 208 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 209 | |
| 210 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 211 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 212 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 213 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 214 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 215 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 216 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 217 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 218 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 219 | .len = WLAN_MAX_KEY_LEN }, |
| 220 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 221 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 222 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 223 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 224 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 225 | |
| 226 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 227 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 228 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 229 | .len = IEEE80211_MAX_DATA_LEN }, |
| 230 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 231 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 232 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 233 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 234 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 235 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 236 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 238 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 239 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 240 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 241 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 242 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 243 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 244 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 245 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 246 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 247 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 248 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 249 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 250 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 251 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 252 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 253 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 254 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 255 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 256 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 257 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 258 | |
| 259 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 260 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 263 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 264 | |
| 265 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 266 | .len = IEEE80211_MAX_SSID_LEN }, |
| 267 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 268 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 270 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 271 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 272 | [NL80211_ATTR_STA_FLAGS2] = { |
| 273 | .len = sizeof(struct nl80211_sta_flag_update), |
| 274 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 275 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 276 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 277 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 278 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 279 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 280 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 281 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 283 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 284 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 285 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 286 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 287 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 289 | .len = IEEE80211_MAX_DATA_LEN }, |
| 290 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 291 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 292 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 294 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 296 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 298 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 300 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 303 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 304 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 308 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 309 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 310 | .len = IEEE80211_MAX_DATA_LEN }, |
| 311 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 312 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 313 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 315 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 317 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 318 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 319 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 320 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 323 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 324 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 325 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 326 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 327 | .len = NL80211_HT_CAPABILITY_LEN |
| 328 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 329 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 330 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 331 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 333 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 335 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 336 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 337 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 339 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 340 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 342 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 343 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 347 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 348 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 349 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 350 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 351 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 352 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 353 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 354 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
| 355 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 }, |
| 356 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame^] | 357 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 358 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 359 | }; |
| 360 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 361 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 362 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 363 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 364 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 365 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 366 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 367 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 368 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 369 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 370 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 371 | }; |
| 372 | |
| 373 | /* policy for the key default flags */ |
| 374 | static const struct nla_policy |
| 375 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 376 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 377 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 378 | }; |
| 379 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 380 | /* policy for WoWLAN attributes */ |
| 381 | static const struct nla_policy |
| 382 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 383 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 384 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 385 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 386 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb13 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 387 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 388 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 389 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 390 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 391 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 392 | }; |
| 393 | |
| 394 | static const struct nla_policy |
| 395 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 396 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 397 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 398 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 399 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 400 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 401 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 402 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 403 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 404 | }, |
| 405 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 406 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 407 | }, |
| 408 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 409 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 410 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 411 | }; |
| 412 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 413 | /* policy for coalesce rule attributes */ |
| 414 | static const struct nla_policy |
| 415 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 416 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 417 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 418 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 419 | }; |
| 420 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 421 | /* policy for GTK rekey offload attributes */ |
| 422 | static const struct nla_policy |
| 423 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 424 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 425 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 426 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 427 | }; |
| 428 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 429 | static const struct nla_policy |
| 430 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 431 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 432 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 433 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 434 | }; |
| 435 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 436 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 437 | struct netlink_callback *cb, |
| 438 | struct cfg80211_registered_device **rdev, |
| 439 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 440 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 441 | int err; |
| 442 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 443 | rtnl_lock(); |
| 444 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 445 | if (!cb->args[0]) { |
| 446 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 447 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 448 | nl80211_policy); |
| 449 | if (err) |
| 450 | goto out_unlock; |
| 451 | |
| 452 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 453 | nl80211_fam.attrbuf); |
| 454 | if (IS_ERR(*wdev)) { |
| 455 | err = PTR_ERR(*wdev); |
| 456 | goto out_unlock; |
| 457 | } |
| 458 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 459 | /* 0 is the first index - add 1 to parse only once */ |
| 460 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 461 | cb->args[1] = (*wdev)->identifier; |
| 462 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 463 | /* subtract the 1 again here */ |
| 464 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 465 | struct wireless_dev *tmp; |
| 466 | |
| 467 | if (!wiphy) { |
| 468 | err = -ENODEV; |
| 469 | goto out_unlock; |
| 470 | } |
| 471 | *rdev = wiphy_to_dev(wiphy); |
| 472 | *wdev = NULL; |
| 473 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 474 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 475 | if (tmp->identifier == cb->args[1]) { |
| 476 | *wdev = tmp; |
| 477 | break; |
| 478 | } |
| 479 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 480 | |
| 481 | if (!*wdev) { |
| 482 | err = -ENODEV; |
| 483 | goto out_unlock; |
| 484 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 485 | } |
| 486 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 487 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 488 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 489 | rtnl_unlock(); |
| 490 | return err; |
| 491 | } |
| 492 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 493 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 494 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 495 | rtnl_unlock(); |
| 496 | } |
| 497 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 498 | /* IE validation */ |
| 499 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 500 | { |
| 501 | const u8 *pos; |
| 502 | int len; |
| 503 | |
| 504 | if (!attr) |
| 505 | return true; |
| 506 | |
| 507 | pos = nla_data(attr); |
| 508 | len = nla_len(attr); |
| 509 | |
| 510 | while (len) { |
| 511 | u8 elemlen; |
| 512 | |
| 513 | if (len < 2) |
| 514 | return false; |
| 515 | len -= 2; |
| 516 | |
| 517 | elemlen = pos[1]; |
| 518 | if (elemlen > len) |
| 519 | return false; |
| 520 | |
| 521 | len -= elemlen; |
| 522 | pos += 2 + elemlen; |
| 523 | } |
| 524 | |
| 525 | return true; |
| 526 | } |
| 527 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 528 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 529 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 530 | int flags, u8 cmd) |
| 531 | { |
| 532 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 533 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 534 | } |
| 535 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 536 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 537 | struct ieee80211_channel *chan, |
| 538 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 539 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 540 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 541 | chan->center_freq)) |
| 542 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 543 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 544 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 545 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 546 | goto nla_put_failure; |
| 547 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 548 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 549 | goto nla_put_failure; |
| 550 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 551 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 552 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 553 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 554 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 555 | goto nla_put_failure; |
| 556 | if (large) { |
| 557 | u32 time; |
| 558 | |
| 559 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 560 | |
| 561 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 562 | chan->dfs_state)) |
| 563 | goto nla_put_failure; |
| 564 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 565 | time)) |
| 566 | goto nla_put_failure; |
| 567 | } |
| 568 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 569 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 570 | if (large) { |
| 571 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 572 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 573 | goto nla_put_failure; |
| 574 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 575 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 576 | goto nla_put_failure; |
| 577 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 578 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 579 | goto nla_put_failure; |
| 580 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 581 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 582 | goto nla_put_failure; |
| 583 | } |
| 584 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 585 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 586 | DBM_TO_MBM(chan->max_power))) |
| 587 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 588 | |
| 589 | return 0; |
| 590 | |
| 591 | nla_put_failure: |
| 592 | return -ENOBUFS; |
| 593 | } |
| 594 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 595 | /* netlink command implementations */ |
| 596 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 597 | struct key_parse { |
| 598 | struct key_params p; |
| 599 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 600 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 601 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 602 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 603 | }; |
| 604 | |
| 605 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 606 | { |
| 607 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 608 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 609 | nl80211_key_policy); |
| 610 | if (err) |
| 611 | return err; |
| 612 | |
| 613 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 614 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 615 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 616 | if (k->def) { |
| 617 | k->def_uni = true; |
| 618 | k->def_multi = true; |
| 619 | } |
| 620 | if (k->defmgmt) |
| 621 | k->def_multi = true; |
| 622 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 623 | if (tb[NL80211_KEY_IDX]) |
| 624 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 625 | |
| 626 | if (tb[NL80211_KEY_DATA]) { |
| 627 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 628 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 629 | } |
| 630 | |
| 631 | if (tb[NL80211_KEY_SEQ]) { |
| 632 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 633 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 634 | } |
| 635 | |
| 636 | if (tb[NL80211_KEY_CIPHER]) |
| 637 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 638 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 639 | if (tb[NL80211_KEY_TYPE]) { |
| 640 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 641 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 642 | return -EINVAL; |
| 643 | } |
| 644 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 645 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 646 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 647 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 648 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 649 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 650 | if (err) |
| 651 | return err; |
| 652 | |
| 653 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 654 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 655 | } |
| 656 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 661 | { |
| 662 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 663 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 664 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 665 | } |
| 666 | |
| 667 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 668 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 669 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 670 | } |
| 671 | |
| 672 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 673 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 674 | |
| 675 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 676 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 677 | |
| 678 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 679 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 680 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 681 | if (k->def) { |
| 682 | k->def_uni = true; |
| 683 | k->def_multi = true; |
| 684 | } |
| 685 | if (k->defmgmt) |
| 686 | k->def_multi = true; |
| 687 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 688 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 689 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 690 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 691 | return -EINVAL; |
| 692 | } |
| 693 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 694 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 695 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 696 | int err = nla_parse_nested( |
| 697 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 698 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 699 | nl80211_key_default_policy); |
| 700 | if (err) |
| 701 | return err; |
| 702 | |
| 703 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 704 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 705 | } |
| 706 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 711 | { |
| 712 | int err; |
| 713 | |
| 714 | memset(k, 0, sizeof(*k)); |
| 715 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 716 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 717 | |
| 718 | if (info->attrs[NL80211_ATTR_KEY]) |
| 719 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 720 | else |
| 721 | err = nl80211_parse_key_old(info, k); |
| 722 | |
| 723 | if (err) |
| 724 | return err; |
| 725 | |
| 726 | if (k->def && k->defmgmt) |
| 727 | return -EINVAL; |
| 728 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 729 | if (k->defmgmt) { |
| 730 | if (k->def_uni || !k->def_multi) |
| 731 | return -EINVAL; |
| 732 | } |
| 733 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 734 | if (k->idx != -1) { |
| 735 | if (k->defmgmt) { |
| 736 | if (k->idx < 4 || k->idx > 5) |
| 737 | return -EINVAL; |
| 738 | } else if (k->def) { |
| 739 | if (k->idx < 0 || k->idx > 3) |
| 740 | return -EINVAL; |
| 741 | } else { |
| 742 | if (k->idx < 0 || k->idx > 5) |
| 743 | return -EINVAL; |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | return 0; |
| 748 | } |
| 749 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 750 | static struct cfg80211_cached_keys * |
| 751 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 752 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 753 | { |
| 754 | struct key_parse parse; |
| 755 | struct nlattr *key; |
| 756 | struct cfg80211_cached_keys *result; |
| 757 | int rem, err, def = 0; |
| 758 | |
| 759 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 760 | if (!result) |
| 761 | return ERR_PTR(-ENOMEM); |
| 762 | |
| 763 | result->def = -1; |
| 764 | result->defmgmt = -1; |
| 765 | |
| 766 | nla_for_each_nested(key, keys, rem) { |
| 767 | memset(&parse, 0, sizeof(parse)); |
| 768 | parse.idx = -1; |
| 769 | |
| 770 | err = nl80211_parse_key_new(key, &parse); |
| 771 | if (err) |
| 772 | goto error; |
| 773 | err = -EINVAL; |
| 774 | if (!parse.p.key) |
| 775 | goto error; |
| 776 | if (parse.idx < 0 || parse.idx > 4) |
| 777 | goto error; |
| 778 | if (parse.def) { |
| 779 | if (def) |
| 780 | goto error; |
| 781 | def = 1; |
| 782 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 783 | if (!parse.def_uni || !parse.def_multi) |
| 784 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 785 | } else if (parse.defmgmt) |
| 786 | goto error; |
| 787 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 788 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 789 | if (err) |
| 790 | goto error; |
| 791 | result->params[parse.idx].cipher = parse.p.cipher; |
| 792 | result->params[parse.idx].key_len = parse.p.key_len; |
| 793 | result->params[parse.idx].key = result->data[parse.idx]; |
| 794 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 795 | |
| 796 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 797 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 798 | if (no_ht) |
| 799 | *no_ht = true; |
| 800 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | return result; |
| 804 | error: |
| 805 | kfree(result); |
| 806 | return ERR_PTR(err); |
| 807 | } |
| 808 | |
| 809 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 810 | { |
| 811 | ASSERT_WDEV_LOCK(wdev); |
| 812 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 813 | switch (wdev->iftype) { |
| 814 | case NL80211_IFTYPE_AP: |
| 815 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 816 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 817 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 818 | break; |
| 819 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 820 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 821 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 822 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 823 | return -ENOLINK; |
| 824 | break; |
| 825 | default: |
| 826 | return -EINVAL; |
| 827 | } |
| 828 | |
| 829 | return 0; |
| 830 | } |
| 831 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 832 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 833 | { |
| 834 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 835 | int i; |
| 836 | |
| 837 | if (!nl_modes) |
| 838 | goto nla_put_failure; |
| 839 | |
| 840 | i = 0; |
| 841 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 842 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 843 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 844 | ifmodes >>= 1; |
| 845 | i++; |
| 846 | } |
| 847 | |
| 848 | nla_nest_end(msg, nl_modes); |
| 849 | return 0; |
| 850 | |
| 851 | nla_put_failure: |
| 852 | return -ENOBUFS; |
| 853 | } |
| 854 | |
| 855 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 856 | struct sk_buff *msg, |
| 857 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 858 | { |
| 859 | struct nlattr *nl_combis; |
| 860 | int i, j; |
| 861 | |
| 862 | nl_combis = nla_nest_start(msg, |
| 863 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 864 | if (!nl_combis) |
| 865 | goto nla_put_failure; |
| 866 | |
| 867 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 868 | const struct ieee80211_iface_combination *c; |
| 869 | struct nlattr *nl_combi, *nl_limits; |
| 870 | |
| 871 | c = &wiphy->iface_combinations[i]; |
| 872 | |
| 873 | nl_combi = nla_nest_start(msg, i + 1); |
| 874 | if (!nl_combi) |
| 875 | goto nla_put_failure; |
| 876 | |
| 877 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 878 | if (!nl_limits) |
| 879 | goto nla_put_failure; |
| 880 | |
| 881 | for (j = 0; j < c->n_limits; j++) { |
| 882 | struct nlattr *nl_limit; |
| 883 | |
| 884 | nl_limit = nla_nest_start(msg, j + 1); |
| 885 | if (!nl_limit) |
| 886 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 887 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 888 | c->limits[j].max)) |
| 889 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 890 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 891 | c->limits[j].types)) |
| 892 | goto nla_put_failure; |
| 893 | nla_nest_end(msg, nl_limit); |
| 894 | } |
| 895 | |
| 896 | nla_nest_end(msg, nl_limits); |
| 897 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 898 | if (c->beacon_int_infra_match && |
| 899 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 900 | goto nla_put_failure; |
| 901 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 902 | c->num_different_channels) || |
| 903 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 904 | c->max_interfaces)) |
| 905 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 906 | if (large && |
| 907 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 908 | c->radar_detect_widths)) |
| 909 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 910 | |
| 911 | nla_nest_end(msg, nl_combi); |
| 912 | } |
| 913 | |
| 914 | nla_nest_end(msg, nl_combis); |
| 915 | |
| 916 | return 0; |
| 917 | nla_put_failure: |
| 918 | return -ENOBUFS; |
| 919 | } |
| 920 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 921 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 922 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 923 | struct sk_buff *msg) |
| 924 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 925 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 926 | struct nlattr *nl_tcp; |
| 927 | |
| 928 | if (!tcp) |
| 929 | return 0; |
| 930 | |
| 931 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 932 | if (!nl_tcp) |
| 933 | return -ENOBUFS; |
| 934 | |
| 935 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 936 | tcp->data_payload_max)) |
| 937 | return -ENOBUFS; |
| 938 | |
| 939 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 940 | tcp->data_payload_max)) |
| 941 | return -ENOBUFS; |
| 942 | |
| 943 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 944 | return -ENOBUFS; |
| 945 | |
| 946 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 947 | sizeof(*tcp->tok), tcp->tok)) |
| 948 | return -ENOBUFS; |
| 949 | |
| 950 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 951 | tcp->data_interval_max)) |
| 952 | return -ENOBUFS; |
| 953 | |
| 954 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 955 | tcp->wake_payload_max)) |
| 956 | return -ENOBUFS; |
| 957 | |
| 958 | nla_nest_end(msg, nl_tcp); |
| 959 | return 0; |
| 960 | } |
| 961 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 962 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 963 | struct cfg80211_registered_device *dev, |
| 964 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 965 | { |
| 966 | struct nlattr *nl_wowlan; |
| 967 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 968 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 969 | return 0; |
| 970 | |
| 971 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 972 | if (!nl_wowlan) |
| 973 | return -ENOBUFS; |
| 974 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 975 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 976 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 977 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 978 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 979 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 980 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 981 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 982 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 983 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 984 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 985 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 986 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 987 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 988 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 989 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 990 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 991 | return -ENOBUFS; |
| 992 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 993 | if (dev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 994 | struct nl80211_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 995 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 996 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 997 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 998 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 999 | }; |
| 1000 | |
| 1001 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1002 | sizeof(pat), &pat)) |
| 1003 | return -ENOBUFS; |
| 1004 | } |
| 1005 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1006 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1007 | return -ENOBUFS; |
| 1008 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1009 | nla_nest_end(msg, nl_wowlan); |
| 1010 | |
| 1011 | return 0; |
| 1012 | } |
| 1013 | #endif |
| 1014 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1015 | static int nl80211_send_coalesce(struct sk_buff *msg, |
| 1016 | struct cfg80211_registered_device *dev) |
| 1017 | { |
| 1018 | struct nl80211_coalesce_rule_support rule; |
| 1019 | |
| 1020 | if (!dev->wiphy.coalesce) |
| 1021 | return 0; |
| 1022 | |
| 1023 | rule.max_rules = dev->wiphy.coalesce->n_rules; |
| 1024 | rule.max_delay = dev->wiphy.coalesce->max_delay; |
| 1025 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; |
| 1026 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; |
| 1027 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; |
| 1028 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; |
| 1029 | |
| 1030 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1031 | return -ENOBUFS; |
| 1032 | |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1036 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1037 | struct ieee80211_supported_band *sband) |
| 1038 | { |
| 1039 | struct nlattr *nl_rates, *nl_rate; |
| 1040 | struct ieee80211_rate *rate; |
| 1041 | int i; |
| 1042 | |
| 1043 | /* add HT info */ |
| 1044 | if (sband->ht_cap.ht_supported && |
| 1045 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1046 | sizeof(sband->ht_cap.mcs), |
| 1047 | &sband->ht_cap.mcs) || |
| 1048 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1049 | sband->ht_cap.cap) || |
| 1050 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1051 | sband->ht_cap.ampdu_factor) || |
| 1052 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1053 | sband->ht_cap.ampdu_density))) |
| 1054 | return -ENOBUFS; |
| 1055 | |
| 1056 | /* add VHT info */ |
| 1057 | if (sband->vht_cap.vht_supported && |
| 1058 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1059 | sizeof(sband->vht_cap.vht_mcs), |
| 1060 | &sband->vht_cap.vht_mcs) || |
| 1061 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1062 | sband->vht_cap.cap))) |
| 1063 | return -ENOBUFS; |
| 1064 | |
| 1065 | /* add bitrates */ |
| 1066 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1067 | if (!nl_rates) |
| 1068 | return -ENOBUFS; |
| 1069 | |
| 1070 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1071 | nl_rate = nla_nest_start(msg, i); |
| 1072 | if (!nl_rate) |
| 1073 | return -ENOBUFS; |
| 1074 | |
| 1075 | rate = &sband->bitrates[i]; |
| 1076 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1077 | rate->bitrate)) |
| 1078 | return -ENOBUFS; |
| 1079 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1080 | nla_put_flag(msg, |
| 1081 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1082 | return -ENOBUFS; |
| 1083 | |
| 1084 | nla_nest_end(msg, nl_rate); |
| 1085 | } |
| 1086 | |
| 1087 | nla_nest_end(msg, nl_rates); |
| 1088 | |
| 1089 | return 0; |
| 1090 | } |
| 1091 | |
| 1092 | static int |
| 1093 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1094 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1095 | { |
| 1096 | u16 stypes; |
| 1097 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1098 | enum nl80211_iftype ift; |
| 1099 | int i; |
| 1100 | |
| 1101 | if (!mgmt_stypes) |
| 1102 | return 0; |
| 1103 | |
| 1104 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1105 | if (!nl_ifs) |
| 1106 | return -ENOBUFS; |
| 1107 | |
| 1108 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1109 | nl_ftypes = nla_nest_start(msg, ift); |
| 1110 | if (!nl_ftypes) |
| 1111 | return -ENOBUFS; |
| 1112 | i = 0; |
| 1113 | stypes = mgmt_stypes[ift].tx; |
| 1114 | while (stypes) { |
| 1115 | if ((stypes & 1) && |
| 1116 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1117 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1118 | return -ENOBUFS; |
| 1119 | stypes >>= 1; |
| 1120 | i++; |
| 1121 | } |
| 1122 | nla_nest_end(msg, nl_ftypes); |
| 1123 | } |
| 1124 | |
| 1125 | nla_nest_end(msg, nl_ifs); |
| 1126 | |
| 1127 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1128 | if (!nl_ifs) |
| 1129 | return -ENOBUFS; |
| 1130 | |
| 1131 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1132 | nl_ftypes = nla_nest_start(msg, ift); |
| 1133 | if (!nl_ftypes) |
| 1134 | return -ENOBUFS; |
| 1135 | i = 0; |
| 1136 | stypes = mgmt_stypes[ift].rx; |
| 1137 | while (stypes) { |
| 1138 | if ((stypes & 1) && |
| 1139 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1140 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1141 | return -ENOBUFS; |
| 1142 | stypes >>= 1; |
| 1143 | i++; |
| 1144 | } |
| 1145 | nla_nest_end(msg, nl_ftypes); |
| 1146 | } |
| 1147 | nla_nest_end(msg, nl_ifs); |
| 1148 | |
| 1149 | return 0; |
| 1150 | } |
| 1151 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1152 | struct nl80211_dump_wiphy_state { |
| 1153 | s64 filter_wiphy; |
| 1154 | long start; |
| 1155 | long split_start, band_start, chan_start; |
| 1156 | bool split; |
| 1157 | }; |
| 1158 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1159 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1160 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1161 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1162 | { |
| 1163 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1164 | struct nlattr *nl_bands, *nl_band; |
| 1165 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1166 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1167 | enum ieee80211_band band; |
| 1168 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1169 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1170 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1171 | dev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1172 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1173 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1174 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1175 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1176 | return -ENOBUFS; |
| 1177 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1178 | if (WARN_ON(!state)) |
| 1179 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1180 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1181 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1182 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1183 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1184 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1185 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1186 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1187 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1188 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1189 | case 0: |
| 1190 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1191 | dev->wiphy.retry_short) || |
| 1192 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1193 | dev->wiphy.retry_long) || |
| 1194 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1195 | dev->wiphy.frag_threshold) || |
| 1196 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1197 | dev->wiphy.rts_threshold) || |
| 1198 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1199 | dev->wiphy.coverage_class) || |
| 1200 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1201 | dev->wiphy.max_scan_ssids) || |
| 1202 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1203 | dev->wiphy.max_sched_scan_ssids) || |
| 1204 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1205 | dev->wiphy.max_scan_ie_len) || |
| 1206 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1207 | dev->wiphy.max_sched_scan_ie_len) || |
| 1208 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1209 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1210 | goto nla_put_failure; |
| 1211 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1212 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1213 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1214 | goto nla_put_failure; |
| 1215 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1216 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1217 | goto nla_put_failure; |
| 1218 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1219 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1220 | goto nla_put_failure; |
| 1221 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1222 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1223 | goto nla_put_failure; |
| 1224 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1225 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1226 | goto nla_put_failure; |
| 1227 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1228 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1229 | goto nla_put_failure; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1230 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1231 | nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1232 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1233 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1234 | state->split_start++; |
| 1235 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1236 | break; |
| 1237 | case 1: |
| 1238 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1239 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1240 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1241 | goto nla_put_failure; |
| 1242 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1243 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1244 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1245 | goto nla_put_failure; |
| 1246 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1247 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1248 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1249 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1250 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1251 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1252 | dev->wiphy.available_antennas_tx) || |
| 1253 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1254 | dev->wiphy.available_antennas_rx)) |
| 1255 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1256 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1257 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1258 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1259 | dev->wiphy.probe_resp_offload)) |
| 1260 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1261 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1262 | if ((dev->wiphy.available_antennas_tx || |
| 1263 | dev->wiphy.available_antennas_rx) && |
| 1264 | dev->ops->get_antenna) { |
| 1265 | u32 tx_ant = 0, rx_ant = 0; |
| 1266 | int res; |
| 1267 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1268 | if (!res) { |
| 1269 | if (nla_put_u32(msg, |
| 1270 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1271 | tx_ant) || |
| 1272 | nla_put_u32(msg, |
| 1273 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1274 | rx_ant)) |
| 1275 | goto nla_put_failure; |
| 1276 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1277 | } |
| 1278 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1279 | state->split_start++; |
| 1280 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1281 | break; |
| 1282 | case 2: |
| 1283 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1284 | dev->wiphy.interface_modes)) |
| 1285 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1286 | state->split_start++; |
| 1287 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1288 | break; |
| 1289 | case 3: |
| 1290 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1291 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1292 | goto nla_put_failure; |
| 1293 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1294 | for (band = state->band_start; |
| 1295 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1296 | struct ieee80211_supported_band *sband; |
| 1297 | |
| 1298 | sband = dev->wiphy.bands[band]; |
| 1299 | |
| 1300 | if (!sband) |
| 1301 | continue; |
| 1302 | |
| 1303 | nl_band = nla_nest_start(msg, band); |
| 1304 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1305 | goto nla_put_failure; |
| 1306 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1307 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1308 | case 0: |
| 1309 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1310 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1311 | state->chan_start++; |
| 1312 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1313 | break; |
| 1314 | default: |
| 1315 | /* add frequencies */ |
| 1316 | nl_freqs = nla_nest_start( |
| 1317 | msg, NL80211_BAND_ATTR_FREQS); |
| 1318 | if (!nl_freqs) |
| 1319 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1320 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1321 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1322 | i < sband->n_channels; |
| 1323 | i++) { |
| 1324 | nl_freq = nla_nest_start(msg, i); |
| 1325 | if (!nl_freq) |
| 1326 | goto nla_put_failure; |
| 1327 | |
| 1328 | chan = &sband->channels[i]; |
| 1329 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1330 | if (nl80211_msg_put_channel( |
| 1331 | msg, chan, |
| 1332 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1333 | goto nla_put_failure; |
| 1334 | |
| 1335 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1336 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1337 | break; |
| 1338 | } |
| 1339 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1340 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1341 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1342 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1343 | nla_nest_end(msg, nl_freqs); |
| 1344 | } |
| 1345 | |
| 1346 | nla_nest_end(msg, nl_band); |
| 1347 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1348 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1349 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1350 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1351 | band--; |
| 1352 | break; |
| 1353 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1354 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1355 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1356 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1357 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1358 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1359 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1360 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1361 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1362 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1363 | if (state->band_start == 0 && state->chan_start == 0) |
| 1364 | state->split_start++; |
| 1365 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1366 | break; |
| 1367 | case 4: |
| 1368 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1369 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1370 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1371 | |
| 1372 | i = 0; |
| 1373 | #define CMD(op, n) \ |
| 1374 | do { \ |
| 1375 | if (dev->ops->op) { \ |
| 1376 | i++; \ |
| 1377 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1378 | goto nla_put_failure; \ |
| 1379 | } \ |
| 1380 | } while (0) |
| 1381 | |
| 1382 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1383 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1384 | CMD(add_key, NEW_KEY); |
| 1385 | CMD(start_ap, START_AP); |
| 1386 | CMD(add_station, NEW_STATION); |
| 1387 | CMD(add_mpath, NEW_MPATH); |
| 1388 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1389 | CMD(change_bss, SET_BSS); |
| 1390 | CMD(auth, AUTHENTICATE); |
| 1391 | CMD(assoc, ASSOCIATE); |
| 1392 | CMD(deauth, DEAUTHENTICATE); |
| 1393 | CMD(disassoc, DISASSOCIATE); |
| 1394 | CMD(join_ibss, JOIN_IBSS); |
| 1395 | CMD(join_mesh, JOIN_MESH); |
| 1396 | CMD(set_pmksa, SET_PMKSA); |
| 1397 | CMD(del_pmksa, DEL_PMKSA); |
| 1398 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1399 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1400 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1401 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1402 | CMD(mgmt_tx, FRAME); |
| 1403 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1404 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1405 | i++; |
| 1406 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1407 | goto nla_put_failure; |
| 1408 | } |
| 1409 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1410 | dev->ops->join_mesh) { |
| 1411 | i++; |
| 1412 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1413 | goto nla_put_failure; |
| 1414 | } |
| 1415 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1416 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1417 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1418 | CMD(tdls_oper, TDLS_OPER); |
| 1419 | } |
| 1420 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1421 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1422 | CMD(probe_client, PROBE_CLIENT); |
| 1423 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1424 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1425 | i++; |
| 1426 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1427 | goto nla_put_failure; |
| 1428 | } |
| 1429 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1430 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1431 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1432 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1433 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1434 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
| 1435 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1436 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1437 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1438 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1439 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1440 | #endif |
| 1441 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1442 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1443 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1444 | if (dev->ops->connect || dev->ops->auth) { |
| 1445 | i++; |
| 1446 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1447 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1448 | } |
| 1449 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1450 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1451 | i++; |
| 1452 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1453 | goto nla_put_failure; |
| 1454 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1455 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1456 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1457 | state->split_start++; |
| 1458 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1459 | break; |
| 1460 | case 5: |
| 1461 | if (dev->ops->remain_on_channel && |
| 1462 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1463 | nla_put_u32(msg, |
| 1464 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1465 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1466 | goto nla_put_failure; |
| 1467 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1468 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1469 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1470 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1471 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1472 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1473 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1474 | state->split_start++; |
| 1475 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1476 | break; |
| 1477 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1478 | #ifdef CONFIG_PM |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1479 | if (nl80211_send_wowlan(msg, dev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1480 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1481 | state->split_start++; |
| 1482 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1483 | break; |
| 1484 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1485 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1486 | #endif |
| 1487 | case 7: |
| 1488 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1489 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1490 | goto nla_put_failure; |
| 1491 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1492 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
| 1493 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1494 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1495 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1496 | state->split_start++; |
| 1497 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1498 | break; |
| 1499 | case 8: |
| 1500 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1501 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1502 | dev->wiphy.ap_sme_capa)) |
| 1503 | goto nla_put_failure; |
| 1504 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1505 | features = dev->wiphy.features; |
| 1506 | /* |
| 1507 | * We can only add the per-channel limit information if the |
| 1508 | * dump is split, otherwise it makes it too big. Therefore |
| 1509 | * only advertise it in that case. |
| 1510 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1511 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1512 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1513 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1514 | goto nla_put_failure; |
| 1515 | |
| 1516 | if (dev->wiphy.ht_capa_mod_mask && |
| 1517 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1518 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1519 | dev->wiphy.ht_capa_mod_mask)) |
| 1520 | goto nla_put_failure; |
| 1521 | |
| 1522 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1523 | dev->wiphy.max_acl_mac_addrs && |
| 1524 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1525 | dev->wiphy.max_acl_mac_addrs)) |
| 1526 | goto nla_put_failure; |
| 1527 | |
| 1528 | /* |
| 1529 | * Any information below this point is only available to |
| 1530 | * applications that can deal with it being split. This |
| 1531 | * helps ensure that newly added capabilities don't break |
| 1532 | * older tools by overrunning their buffers. |
| 1533 | * |
| 1534 | * We still increment split_start so that in the split |
| 1535 | * case we'll continue with more data in the next round, |
| 1536 | * but break unconditionally so unsplit data stops here. |
| 1537 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1538 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1539 | break; |
| 1540 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1541 | if (dev->wiphy.extended_capabilities && |
| 1542 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1543 | dev->wiphy.extended_capabilities_len, |
| 1544 | dev->wiphy.extended_capabilities) || |
| 1545 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1546 | dev->wiphy.extended_capabilities_len, |
| 1547 | dev->wiphy.extended_capabilities_mask))) |
| 1548 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1549 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1550 | if (dev->wiphy.vht_capa_mod_mask && |
| 1551 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1552 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1553 | dev->wiphy.vht_capa_mod_mask)) |
| 1554 | goto nla_put_failure; |
| 1555 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1556 | state->split_start++; |
| 1557 | break; |
| 1558 | case 10: |
| 1559 | if (nl80211_send_coalesce(msg, dev)) |
| 1560 | goto nla_put_failure; |
| 1561 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1562 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1563 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1564 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1565 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1566 | return genlmsg_end(msg, hdr); |
| 1567 | |
| 1568 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1569 | genlmsg_cancel(msg, hdr); |
| 1570 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1571 | } |
| 1572 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1573 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1574 | struct netlink_callback *cb, |
| 1575 | struct nl80211_dump_wiphy_state *state) |
| 1576 | { |
| 1577 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1578 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1579 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1580 | /* ignore parse errors for backward compatibility */ |
| 1581 | if (ret) |
| 1582 | return 0; |
| 1583 | |
| 1584 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1585 | if (tb[NL80211_ATTR_WIPHY]) |
| 1586 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1587 | if (tb[NL80211_ATTR_WDEV]) |
| 1588 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1589 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1590 | struct net_device *netdev; |
| 1591 | struct cfg80211_registered_device *rdev; |
| 1592 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1593 | |
| 1594 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1595 | if (!netdev) |
| 1596 | return -ENODEV; |
| 1597 | if (netdev->ieee80211_ptr) { |
| 1598 | rdev = wiphy_to_dev( |
| 1599 | netdev->ieee80211_ptr->wiphy); |
| 1600 | state->filter_wiphy = rdev->wiphy_idx; |
| 1601 | } |
| 1602 | dev_put(netdev); |
| 1603 | } |
| 1604 | |
| 1605 | return 0; |
| 1606 | } |
| 1607 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1608 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1609 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1610 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1611 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1612 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1613 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1614 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1615 | if (!state) { |
| 1616 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1617 | if (!state) { |
| 1618 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1619 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1620 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1621 | state->filter_wiphy = -1; |
| 1622 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1623 | if (ret) { |
| 1624 | kfree(state); |
| 1625 | rtnl_unlock(); |
| 1626 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1627 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1628 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1629 | } |
| 1630 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1631 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1632 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1633 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1634 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1635 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1636 | if (state->filter_wiphy != -1 && |
| 1637 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1638 | continue; |
| 1639 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1640 | do { |
| 1641 | ret = nl80211_send_wiphy(dev, skb, |
| 1642 | NETLINK_CB(cb->skb).portid, |
| 1643 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1644 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1645 | if (ret < 0) { |
| 1646 | /* |
| 1647 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1648 | * or EMSGSIZE returned), this SKB is still |
| 1649 | * empty (so it's not too big because another |
| 1650 | * wiphy dataset is already in the skb) and |
| 1651 | * we've not tried to adjust the dump allocation |
| 1652 | * yet ... then adjust the alloc size to be |
| 1653 | * bigger, and return 1 but with the empty skb. |
| 1654 | * This results in an empty message being RX'ed |
| 1655 | * in userspace, but that is ignored. |
| 1656 | * |
| 1657 | * We can then retry with the larger buffer. |
| 1658 | */ |
| 1659 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1660 | !skb->len && |
| 1661 | cb->min_dump_alloc < 4096) { |
| 1662 | cb->min_dump_alloc = 4096; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1663 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1664 | return 1; |
| 1665 | } |
| 1666 | idx--; |
| 1667 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1668 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1669 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1670 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1671 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1672 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1673 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1674 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1675 | |
| 1676 | return skb->len; |
| 1677 | } |
| 1678 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1679 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1680 | { |
| 1681 | kfree((void *)cb->args[0]); |
| 1682 | return 0; |
| 1683 | } |
| 1684 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1685 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1686 | { |
| 1687 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1688 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1689 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1690 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1691 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1692 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1693 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1694 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1695 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1696 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1697 | nlmsg_free(msg); |
| 1698 | return -ENOBUFS; |
| 1699 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1700 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1701 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1702 | } |
| 1703 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1704 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1705 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1706 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1707 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1708 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1709 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1710 | }; |
| 1711 | |
| 1712 | static int parse_txq_params(struct nlattr *tb[], |
| 1713 | struct ieee80211_txq_params *txq_params) |
| 1714 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1715 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1716 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1717 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1718 | return -EINVAL; |
| 1719 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1720 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1721 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1722 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1723 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1724 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1725 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1726 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1727 | return -EINVAL; |
| 1728 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1729 | return 0; |
| 1730 | } |
| 1731 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1732 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1733 | { |
| 1734 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1735 | * You can only set the channel explicitly for WDS interfaces, |
| 1736 | * all others have their channel managed via their respective |
| 1737 | * "establish a connection" command (connect, join, ...) |
| 1738 | * |
| 1739 | * For AP/GO and mesh mode, the channel can be set with the |
| 1740 | * channel userspace API, but is only stored and passed to the |
| 1741 | * low-level driver when the AP starts or the mesh is joined. |
| 1742 | * This is for backward compatibility, userspace can also give |
| 1743 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1744 | * |
| 1745 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1746 | * whatever else is going on, so they have their own special |
| 1747 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1748 | */ |
| 1749 | return !wdev || |
| 1750 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1751 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1752 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1753 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1754 | } |
| 1755 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1756 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1757 | struct genl_info *info, |
| 1758 | struct cfg80211_chan_def *chandef) |
| 1759 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1760 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1761 | |
| 1762 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1763 | return -EINVAL; |
| 1764 | |
| 1765 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1766 | |
| 1767 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1768 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1769 | chandef->center_freq1 = control_freq; |
| 1770 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1771 | |
| 1772 | /* Primary channel not allowed */ |
| 1773 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1774 | return -EINVAL; |
| 1775 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1776 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1777 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1778 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1779 | chantype = nla_get_u32( |
| 1780 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1781 | |
| 1782 | switch (chantype) { |
| 1783 | case NL80211_CHAN_NO_HT: |
| 1784 | case NL80211_CHAN_HT20: |
| 1785 | case NL80211_CHAN_HT40PLUS: |
| 1786 | case NL80211_CHAN_HT40MINUS: |
| 1787 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1788 | chantype); |
| 1789 | break; |
| 1790 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1791 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1792 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1793 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1794 | chandef->width = |
| 1795 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1796 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1797 | chandef->center_freq1 = |
| 1798 | nla_get_u32( |
| 1799 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1800 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1801 | chandef->center_freq2 = |
| 1802 | nla_get_u32( |
| 1803 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1804 | } |
| 1805 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1806 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1807 | return -EINVAL; |
| 1808 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1809 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1810 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1811 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1812 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1813 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1814 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1815 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1816 | return -EINVAL; |
| 1817 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1818 | return 0; |
| 1819 | } |
| 1820 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1821 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1822 | struct wireless_dev *wdev, |
| 1823 | struct genl_info *info) |
| 1824 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1825 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1826 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1827 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1828 | |
| 1829 | if (wdev) |
| 1830 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1831 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1832 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1833 | return -EOPNOTSUPP; |
| 1834 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1835 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1836 | if (result) |
| 1837 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1838 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1839 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1840 | case NL80211_IFTYPE_AP: |
| 1841 | case NL80211_IFTYPE_P2P_GO: |
| 1842 | if (wdev->beacon_interval) { |
| 1843 | result = -EBUSY; |
| 1844 | break; |
| 1845 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1846 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1847 | result = -EINVAL; |
| 1848 | break; |
| 1849 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1850 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1851 | result = 0; |
| 1852 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1853 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1854 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1855 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1856 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1857 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1858 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1859 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1860 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1861 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1862 | |
| 1863 | return result; |
| 1864 | } |
| 1865 | |
| 1866 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1867 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1868 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1869 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1870 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1871 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1872 | } |
| 1873 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1874 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1875 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1876 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1877 | struct net_device *dev = info->user_ptr[1]; |
| 1878 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1879 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1880 | |
| 1881 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1882 | return -EINVAL; |
| 1883 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1884 | if (netif_running(dev)) |
| 1885 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1886 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1887 | if (!rdev->ops->set_wds_peer) |
| 1888 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1889 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1890 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1891 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1892 | |
| 1893 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1894 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1898 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1899 | { |
| 1900 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1901 | struct net_device *netdev = NULL; |
| 1902 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1903 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1904 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1905 | u32 changed; |
| 1906 | u8 retry_short = 0, retry_long = 0; |
| 1907 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1908 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1909 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1910 | ASSERT_RTNL(); |
| 1911 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1912 | /* |
| 1913 | * Try to find the wiphy and netdev. Normally this |
| 1914 | * function shouldn't need the netdev, but this is |
| 1915 | * done for backward compatibility -- previously |
| 1916 | * setting the channel was done per wiphy, but now |
| 1917 | * it is per netdev. Previous userland like hostapd |
| 1918 | * also passed a netdev to set_wiphy, so that it is |
| 1919 | * possible to let that go to the right netdev! |
| 1920 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1921 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1922 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1923 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1924 | |
| 1925 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1926 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1927 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1928 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1929 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1930 | } |
| 1931 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1932 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1933 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1934 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1935 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1936 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1937 | wdev = NULL; |
| 1938 | netdev = NULL; |
| 1939 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1940 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1941 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1942 | |
| 1943 | /* |
| 1944 | * end workaround code, by now the rdev is available |
| 1945 | * and locked, and wdev may or may not be NULL. |
| 1946 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1947 | |
| 1948 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1949 | result = cfg80211_dev_rename( |
| 1950 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1951 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1952 | if (result) |
| 1953 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1954 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1955 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1956 | struct ieee80211_txq_params txq_params; |
| 1957 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1958 | |
| 1959 | if (!rdev->ops->set_txq_params) { |
| 1960 | result = -EOPNOTSUPP; |
| 1961 | goto bad_res; |
| 1962 | } |
| 1963 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1964 | if (!netdev) { |
| 1965 | result = -EINVAL; |
| 1966 | goto bad_res; |
| 1967 | } |
| 1968 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1969 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1970 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1971 | result = -EINVAL; |
| 1972 | goto bad_res; |
| 1973 | } |
| 1974 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1975 | if (!netif_running(netdev)) { |
| 1976 | result = -ENETDOWN; |
| 1977 | goto bad_res; |
| 1978 | } |
| 1979 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1980 | nla_for_each_nested(nl_txq_params, |
| 1981 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1982 | rem_txq_params) { |
| 1983 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1984 | nla_data(nl_txq_params), |
| 1985 | nla_len(nl_txq_params), |
| 1986 | txq_params_policy); |
| 1987 | result = parse_txq_params(tb, &txq_params); |
| 1988 | if (result) |
| 1989 | goto bad_res; |
| 1990 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1991 | result = rdev_set_txq_params(rdev, netdev, |
| 1992 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1993 | if (result) |
| 1994 | goto bad_res; |
| 1995 | } |
| 1996 | } |
| 1997 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1998 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1999 | result = __nl80211_set_channel(rdev, |
| 2000 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 2001 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2002 | if (result) |
| 2003 | goto bad_res; |
| 2004 | } |
| 2005 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2006 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2007 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2008 | enum nl80211_tx_power_setting type; |
| 2009 | int idx, mbm = 0; |
| 2010 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2011 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2012 | txp_wdev = NULL; |
| 2013 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2014 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 2015 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2016 | goto bad_res; |
| 2017 | } |
| 2018 | |
| 2019 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2020 | type = nla_get_u32(info->attrs[idx]); |
| 2021 | |
| 2022 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 2023 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 2024 | result = -EINVAL; |
| 2025 | goto bad_res; |
| 2026 | } |
| 2027 | |
| 2028 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2029 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2030 | mbm = nla_get_u32(info->attrs[idx]); |
| 2031 | } |
| 2032 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2033 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2034 | if (result) |
| 2035 | goto bad_res; |
| 2036 | } |
| 2037 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2038 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2039 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2040 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2041 | if ((!rdev->wiphy.available_antennas_tx && |
| 2042 | !rdev->wiphy.available_antennas_rx) || |
| 2043 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2044 | result = -EOPNOTSUPP; |
| 2045 | goto bad_res; |
| 2046 | } |
| 2047 | |
| 2048 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2049 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2050 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2051 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2052 | * available antenna masks, except for the "all" mask */ |
| 2053 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2054 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2055 | result = -EINVAL; |
| 2056 | goto bad_res; |
| 2057 | } |
| 2058 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2059 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2060 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2061 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2062 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2063 | if (result) |
| 2064 | goto bad_res; |
| 2065 | } |
| 2066 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2067 | changed = 0; |
| 2068 | |
| 2069 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2070 | retry_short = nla_get_u8( |
| 2071 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2072 | if (retry_short == 0) { |
| 2073 | result = -EINVAL; |
| 2074 | goto bad_res; |
| 2075 | } |
| 2076 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2077 | } |
| 2078 | |
| 2079 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2080 | retry_long = nla_get_u8( |
| 2081 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2082 | if (retry_long == 0) { |
| 2083 | result = -EINVAL; |
| 2084 | goto bad_res; |
| 2085 | } |
| 2086 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2087 | } |
| 2088 | |
| 2089 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2090 | frag_threshold = nla_get_u32( |
| 2091 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2092 | if (frag_threshold < 256) { |
| 2093 | result = -EINVAL; |
| 2094 | goto bad_res; |
| 2095 | } |
| 2096 | if (frag_threshold != (u32) -1) { |
| 2097 | /* |
| 2098 | * Fragments (apart from the last one) are required to |
| 2099 | * have even length. Make the fragmentation code |
| 2100 | * simpler by stripping LSB should someone try to use |
| 2101 | * odd threshold value. |
| 2102 | */ |
| 2103 | frag_threshold &= ~0x1; |
| 2104 | } |
| 2105 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2106 | } |
| 2107 | |
| 2108 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2109 | rts_threshold = nla_get_u32( |
| 2110 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2111 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2112 | } |
| 2113 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2114 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2115 | coverage_class = nla_get_u8( |
| 2116 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2117 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2118 | } |
| 2119 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2120 | if (changed) { |
| 2121 | u8 old_retry_short, old_retry_long; |
| 2122 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2123 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2124 | |
| 2125 | if (!rdev->ops->set_wiphy_params) { |
| 2126 | result = -EOPNOTSUPP; |
| 2127 | goto bad_res; |
| 2128 | } |
| 2129 | |
| 2130 | old_retry_short = rdev->wiphy.retry_short; |
| 2131 | old_retry_long = rdev->wiphy.retry_long; |
| 2132 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2133 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2134 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2135 | |
| 2136 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2137 | rdev->wiphy.retry_short = retry_short; |
| 2138 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2139 | rdev->wiphy.retry_long = retry_long; |
| 2140 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2141 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2142 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2143 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2144 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2145 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2146 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2147 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2148 | if (result) { |
| 2149 | rdev->wiphy.retry_short = old_retry_short; |
| 2150 | rdev->wiphy.retry_long = old_retry_long; |
| 2151 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2152 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2153 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2154 | } |
| 2155 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2156 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2157 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2158 | if (netdev) |
| 2159 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2160 | return result; |
| 2161 | } |
| 2162 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2163 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2164 | { |
| 2165 | return (u64)wdev->identifier | |
| 2166 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2167 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2168 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2169 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 2170 | struct cfg80211_chan_def *chandef) |
| 2171 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2172 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2173 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2174 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2175 | chandef->chan->center_freq)) |
| 2176 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2177 | switch (chandef->width) { |
| 2178 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2179 | case NL80211_CHAN_WIDTH_20: |
| 2180 | case NL80211_CHAN_WIDTH_40: |
| 2181 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2182 | cfg80211_get_chandef_type(chandef))) |
| 2183 | return -ENOBUFS; |
| 2184 | break; |
| 2185 | default: |
| 2186 | break; |
| 2187 | } |
| 2188 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2189 | return -ENOBUFS; |
| 2190 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2191 | return -ENOBUFS; |
| 2192 | if (chandef->center_freq2 && |
| 2193 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2194 | return -ENOBUFS; |
| 2195 | return 0; |
| 2196 | } |
| 2197 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2198 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 2199 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2200 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2201 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2202 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2203 | void *hdr; |
| 2204 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2205 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2206 | if (!hdr) |
| 2207 | return -1; |
| 2208 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2209 | if (dev && |
| 2210 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2211 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2212 | goto nla_put_failure; |
| 2213 | |
| 2214 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2215 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2216 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2217 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2218 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2219 | rdev->devlist_generation ^ |
| 2220 | (cfg80211_rdev_list_generation << 2))) |
| 2221 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2222 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2223 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2224 | int ret; |
| 2225 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2226 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2227 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2228 | if (ret == 0) { |
| 2229 | if (nl80211_send_chandef(msg, &chandef)) |
| 2230 | goto nla_put_failure; |
| 2231 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2232 | } |
| 2233 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2234 | if (wdev->ssid_len) { |
| 2235 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2236 | goto nla_put_failure; |
| 2237 | } |
| 2238 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2239 | return genlmsg_end(msg, hdr); |
| 2240 | |
| 2241 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2242 | genlmsg_cancel(msg, hdr); |
| 2243 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2247 | { |
| 2248 | int wp_idx = 0; |
| 2249 | int if_idx = 0; |
| 2250 | int wp_start = cb->args[0]; |
| 2251 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2252 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2253 | struct wireless_dev *wdev; |
| 2254 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2255 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2256 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2257 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2258 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2259 | if (wp_idx < wp_start) { |
| 2260 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2261 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2262 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2263 | if_idx = 0; |
| 2264 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2265 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2266 | if (if_idx < if_start) { |
| 2267 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2268 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2269 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2270 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2271 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2272 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2273 | goto out; |
| 2274 | } |
| 2275 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2276 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2277 | |
| 2278 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2279 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2280 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2281 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2282 | |
| 2283 | cb->args[0] = wp_idx; |
| 2284 | cb->args[1] = if_idx; |
| 2285 | |
| 2286 | return skb->len; |
| 2287 | } |
| 2288 | |
| 2289 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2290 | { |
| 2291 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2292 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2293 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2294 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2295 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2296 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2297 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2298 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2299 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2300 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2301 | nlmsg_free(msg); |
| 2302 | return -ENOBUFS; |
| 2303 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2304 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2305 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2306 | } |
| 2307 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2308 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2309 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2310 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2311 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2312 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2313 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2314 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2315 | }; |
| 2316 | |
| 2317 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2318 | { |
| 2319 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2320 | int flag; |
| 2321 | |
| 2322 | *mntrflags = 0; |
| 2323 | |
| 2324 | if (!nla) |
| 2325 | return -EINVAL; |
| 2326 | |
| 2327 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2328 | nla, mntr_flags_policy)) |
| 2329 | return -EINVAL; |
| 2330 | |
| 2331 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2332 | if (flags[flag]) |
| 2333 | *mntrflags |= (1<<flag); |
| 2334 | |
| 2335 | return 0; |
| 2336 | } |
| 2337 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2338 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2339 | struct net_device *netdev, u8 use_4addr, |
| 2340 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2341 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2342 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2343 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2344 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2345 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2346 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2347 | |
| 2348 | switch (iftype) { |
| 2349 | case NL80211_IFTYPE_AP_VLAN: |
| 2350 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2351 | return 0; |
| 2352 | break; |
| 2353 | case NL80211_IFTYPE_STATION: |
| 2354 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2355 | return 0; |
| 2356 | break; |
| 2357 | default: |
| 2358 | break; |
| 2359 | } |
| 2360 | |
| 2361 | return -EOPNOTSUPP; |
| 2362 | } |
| 2363 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2364 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2365 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2366 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2367 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2368 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2369 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2370 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2371 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2372 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2373 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2374 | memset(¶ms, 0, sizeof(params)); |
| 2375 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2376 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2377 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2378 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2379 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2380 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2381 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2382 | if (ntype > NL80211_IFTYPE_MAX) |
| 2383 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2384 | } |
| 2385 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2386 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2387 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2388 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2389 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2390 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2391 | if (netif_running(dev)) |
| 2392 | return -EBUSY; |
| 2393 | |
| 2394 | wdev_lock(wdev); |
| 2395 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2396 | IEEE80211_MAX_MESH_ID_LEN); |
| 2397 | wdev->mesh_id_up_len = |
| 2398 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2399 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2400 | wdev->mesh_id_up_len); |
| 2401 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2402 | } |
| 2403 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2404 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2405 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2406 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2407 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2408 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2409 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2410 | } else { |
| 2411 | params.use_4addr = -1; |
| 2412 | } |
| 2413 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2414 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2415 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2416 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2417 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2418 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2419 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2420 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2421 | |
| 2422 | flags = &_flags; |
| 2423 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2424 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2425 | |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2426 | if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) && |
| 2427 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2428 | return -EOPNOTSUPP; |
| 2429 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2430 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2431 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2432 | else |
| 2433 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2434 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2435 | if (!err && params.use_4addr != -1) |
| 2436 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2437 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2438 | return err; |
| 2439 | } |
| 2440 | |
| 2441 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2442 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2443 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2444 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2445 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2446 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2447 | int err; |
| 2448 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2449 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2450 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2451 | memset(¶ms, 0, sizeof(params)); |
| 2452 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2453 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2454 | return -EINVAL; |
| 2455 | |
| 2456 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2457 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2458 | if (type > NL80211_IFTYPE_MAX) |
| 2459 | return -EINVAL; |
| 2460 | } |
| 2461 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2462 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2463 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2464 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2465 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2466 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2467 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2468 | ETH_ALEN); |
| 2469 | if (!is_valid_ether_addr(params.macaddr)) |
| 2470 | return -EADDRNOTAVAIL; |
| 2471 | } |
| 2472 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2473 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2474 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2475 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2476 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2477 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2478 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2479 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2480 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2481 | if (!msg) |
| 2482 | return -ENOMEM; |
| 2483 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2484 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2485 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2486 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2487 | |
| 2488 | if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) && |
| 2489 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2490 | return -EOPNOTSUPP; |
| 2491 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2492 | wdev = rdev_add_virtual_intf(rdev, |
| 2493 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2494 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2495 | if (IS_ERR(wdev)) { |
| 2496 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2497 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2498 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2499 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2500 | switch (type) { |
| 2501 | case NL80211_IFTYPE_MESH_POINT: |
| 2502 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2503 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2504 | wdev_lock(wdev); |
| 2505 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2506 | IEEE80211_MAX_MESH_ID_LEN); |
| 2507 | wdev->mesh_id_up_len = |
| 2508 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2509 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2510 | wdev->mesh_id_up_len); |
| 2511 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2512 | break; |
| 2513 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2514 | /* |
| 2515 | * P2P Device doesn't have a netdev, so doesn't go |
| 2516 | * through the netdev notifier and must be added here |
| 2517 | */ |
| 2518 | mutex_init(&wdev->mtx); |
| 2519 | INIT_LIST_HEAD(&wdev->event_list); |
| 2520 | spin_lock_init(&wdev->event_lock); |
| 2521 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2522 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2523 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2524 | wdev->identifier = ++rdev->wdev_id; |
| 2525 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2526 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2527 | break; |
| 2528 | default: |
| 2529 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2530 | } |
| 2531 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2532 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2533 | rdev, wdev) < 0) { |
| 2534 | nlmsg_free(msg); |
| 2535 | return -ENOBUFS; |
| 2536 | } |
| 2537 | |
| 2538 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2542 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2543 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2544 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2545 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2546 | if (!rdev->ops->del_virtual_intf) |
| 2547 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2548 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2549 | /* |
| 2550 | * If we remove a wireless device without a netdev then clear |
| 2551 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2552 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2553 | * since the wdev has been freed, unlike with a netdev where |
| 2554 | * we need the dev_put() for the netdev to really be freed. |
| 2555 | */ |
| 2556 | if (!wdev->netdev) |
| 2557 | info->user_ptr[1] = NULL; |
| 2558 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2559 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2560 | } |
| 2561 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2562 | static int nl80211_set_noack_map(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 | u16 noack_map; |
| 2567 | |
| 2568 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2569 | return -EINVAL; |
| 2570 | |
| 2571 | if (!rdev->ops->set_noack_map) |
| 2572 | return -EOPNOTSUPP; |
| 2573 | |
| 2574 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2575 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2576 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2577 | } |
| 2578 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2579 | struct get_key_cookie { |
| 2580 | struct sk_buff *msg; |
| 2581 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2582 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2583 | }; |
| 2584 | |
| 2585 | static void get_key_callback(void *c, struct key_params *params) |
| 2586 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2587 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2588 | struct get_key_cookie *cookie = c; |
| 2589 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2590 | if ((params->key && |
| 2591 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2592 | params->key_len, params->key)) || |
| 2593 | (params->seq && |
| 2594 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2595 | params->seq_len, params->seq)) || |
| 2596 | (params->cipher && |
| 2597 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2598 | params->cipher))) |
| 2599 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2600 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2601 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2602 | if (!key) |
| 2603 | goto nla_put_failure; |
| 2604 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2605 | if ((params->key && |
| 2606 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2607 | params->key_len, params->key)) || |
| 2608 | (params->seq && |
| 2609 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2610 | params->seq_len, params->seq)) || |
| 2611 | (params->cipher && |
| 2612 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2613 | params->cipher))) |
| 2614 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2615 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2616 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2617 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2618 | |
| 2619 | nla_nest_end(cookie->msg, key); |
| 2620 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2621 | return; |
| 2622 | nla_put_failure: |
| 2623 | cookie->error = 1; |
| 2624 | } |
| 2625 | |
| 2626 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2627 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2628 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2629 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2630 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2631 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2632 | const u8 *mac_addr = NULL; |
| 2633 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2634 | struct get_key_cookie cookie = { |
| 2635 | .error = 0, |
| 2636 | }; |
| 2637 | void *hdr; |
| 2638 | struct sk_buff *msg; |
| 2639 | |
| 2640 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2641 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2642 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2643 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2644 | return -EINVAL; |
| 2645 | |
| 2646 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2647 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2648 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2649 | pairwise = !!mac_addr; |
| 2650 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2651 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2652 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2653 | return -EINVAL; |
| 2654 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2655 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2656 | return -EINVAL; |
| 2657 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2658 | } |
| 2659 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2660 | if (!rdev->ops->get_key) |
| 2661 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2662 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2663 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2664 | if (!msg) |
| 2665 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2666 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2667 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2668 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2669 | if (!hdr) |
| 2670 | return -ENOBUFS; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2671 | |
| 2672 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2673 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2674 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2675 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2676 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2677 | goto nla_put_failure; |
| 2678 | if (mac_addr && |
| 2679 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2680 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2681 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2682 | if (pairwise && mac_addr && |
| 2683 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2684 | return -ENOENT; |
| 2685 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2686 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2687 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2688 | |
| 2689 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2690 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2691 | |
| 2692 | if (cookie.error) |
| 2693 | goto nla_put_failure; |
| 2694 | |
| 2695 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2696 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2697 | |
| 2698 | nla_put_failure: |
| 2699 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2700 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2701 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2702 | return err; |
| 2703 | } |
| 2704 | |
| 2705 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2706 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2707 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2708 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2709 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2710 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2711 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2712 | err = nl80211_parse_key(info, &key); |
| 2713 | if (err) |
| 2714 | return err; |
| 2715 | |
| 2716 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2717 | return -EINVAL; |
| 2718 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2719 | /* only support setting default key */ |
| 2720 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2721 | return -EINVAL; |
| 2722 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2723 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2724 | |
| 2725 | if (key.def) { |
| 2726 | if (!rdev->ops->set_default_key) { |
| 2727 | err = -EOPNOTSUPP; |
| 2728 | goto out; |
| 2729 | } |
| 2730 | |
| 2731 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2732 | if (err) |
| 2733 | goto out; |
| 2734 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2735 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2736 | key.def_uni, key.def_multi); |
| 2737 | |
| 2738 | if (err) |
| 2739 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2740 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2741 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2742 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2743 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2744 | } else { |
| 2745 | if (key.def_uni || !key.def_multi) { |
| 2746 | err = -EINVAL; |
| 2747 | goto out; |
| 2748 | } |
| 2749 | |
| 2750 | if (!rdev->ops->set_default_mgmt_key) { |
| 2751 | err = -EOPNOTSUPP; |
| 2752 | goto out; |
| 2753 | } |
| 2754 | |
| 2755 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2756 | if (err) |
| 2757 | goto out; |
| 2758 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2759 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2760 | if (err) |
| 2761 | goto out; |
| 2762 | |
| 2763 | #ifdef CONFIG_CFG80211_WEXT |
| 2764 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2765 | #endif |
| 2766 | } |
| 2767 | |
| 2768 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2769 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2770 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2771 | return err; |
| 2772 | } |
| 2773 | |
| 2774 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2775 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2776 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2777 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2778 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2779 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2780 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2781 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2782 | err = nl80211_parse_key(info, &key); |
| 2783 | if (err) |
| 2784 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2785 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2786 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2787 | return -EINVAL; |
| 2788 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2789 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2790 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2791 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2792 | if (key.type == -1) { |
| 2793 | if (mac_addr) |
| 2794 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2795 | else |
| 2796 | key.type = NL80211_KEYTYPE_GROUP; |
| 2797 | } |
| 2798 | |
| 2799 | /* for now */ |
| 2800 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2801 | key.type != NL80211_KEYTYPE_GROUP) |
| 2802 | return -EINVAL; |
| 2803 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2804 | if (!rdev->ops->add_key) |
| 2805 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2806 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2807 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2808 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2809 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2810 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2811 | |
| 2812 | wdev_lock(dev->ieee80211_ptr); |
| 2813 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2814 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2815 | err = rdev_add_key(rdev, dev, key.idx, |
| 2816 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2817 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2818 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2819 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2820 | return err; |
| 2821 | } |
| 2822 | |
| 2823 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2824 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2825 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2826 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2827 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2828 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2829 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2830 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2831 | err = nl80211_parse_key(info, &key); |
| 2832 | if (err) |
| 2833 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2834 | |
| 2835 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2836 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2837 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2838 | if (key.type == -1) { |
| 2839 | if (mac_addr) |
| 2840 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2841 | else |
| 2842 | key.type = NL80211_KEYTYPE_GROUP; |
| 2843 | } |
| 2844 | |
| 2845 | /* for now */ |
| 2846 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2847 | key.type != NL80211_KEYTYPE_GROUP) |
| 2848 | return -EINVAL; |
| 2849 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2850 | if (!rdev->ops->del_key) |
| 2851 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2852 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2853 | wdev_lock(dev->ieee80211_ptr); |
| 2854 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2855 | |
| 2856 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2857 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2858 | err = -ENOENT; |
| 2859 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2860 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2861 | err = rdev_del_key(rdev, dev, key.idx, |
| 2862 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2863 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2864 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2865 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2866 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2867 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2868 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2869 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2870 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2871 | } |
| 2872 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2873 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2874 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2875 | return err; |
| 2876 | } |
| 2877 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2878 | /* This function returns an error or the number of nested attributes */ |
| 2879 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2880 | { |
| 2881 | struct nlattr *attr; |
| 2882 | int n_entries = 0, tmp; |
| 2883 | |
| 2884 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2885 | if (nla_len(attr) != ETH_ALEN) |
| 2886 | return -EINVAL; |
| 2887 | |
| 2888 | n_entries++; |
| 2889 | } |
| 2890 | |
| 2891 | return n_entries; |
| 2892 | } |
| 2893 | |
| 2894 | /* |
| 2895 | * This function parses ACL information and allocates memory for ACL data. |
| 2896 | * On successful return, the calling function is responsible to free the |
| 2897 | * ACL buffer returned by this function. |
| 2898 | */ |
| 2899 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2900 | struct genl_info *info) |
| 2901 | { |
| 2902 | enum nl80211_acl_policy acl_policy; |
| 2903 | struct nlattr *attr; |
| 2904 | struct cfg80211_acl_data *acl; |
| 2905 | int i = 0, n_entries, tmp; |
| 2906 | |
| 2907 | if (!wiphy->max_acl_mac_addrs) |
| 2908 | return ERR_PTR(-EOPNOTSUPP); |
| 2909 | |
| 2910 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2911 | return ERR_PTR(-EINVAL); |
| 2912 | |
| 2913 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2914 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2915 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2916 | return ERR_PTR(-EINVAL); |
| 2917 | |
| 2918 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2919 | return ERR_PTR(-EINVAL); |
| 2920 | |
| 2921 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2922 | if (n_entries < 0) |
| 2923 | return ERR_PTR(n_entries); |
| 2924 | |
| 2925 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2926 | return ERR_PTR(-ENOTSUPP); |
| 2927 | |
| 2928 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2929 | GFP_KERNEL); |
| 2930 | if (!acl) |
| 2931 | return ERR_PTR(-ENOMEM); |
| 2932 | |
| 2933 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2934 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2935 | i++; |
| 2936 | } |
| 2937 | |
| 2938 | acl->n_acl_entries = n_entries; |
| 2939 | acl->acl_policy = acl_policy; |
| 2940 | |
| 2941 | return acl; |
| 2942 | } |
| 2943 | |
| 2944 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2945 | { |
| 2946 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2947 | struct net_device *dev = info->user_ptr[1]; |
| 2948 | struct cfg80211_acl_data *acl; |
| 2949 | int err; |
| 2950 | |
| 2951 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2952 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2953 | return -EOPNOTSUPP; |
| 2954 | |
| 2955 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2956 | return -EINVAL; |
| 2957 | |
| 2958 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2959 | if (IS_ERR(acl)) |
| 2960 | return PTR_ERR(acl); |
| 2961 | |
| 2962 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2963 | |
| 2964 | kfree(acl); |
| 2965 | |
| 2966 | return err; |
| 2967 | } |
| 2968 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2969 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2970 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2971 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2972 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2973 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2974 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2975 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 2976 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2977 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2978 | return -EINVAL; |
| 2979 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2980 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2981 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2982 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2983 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2984 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2985 | if (!bcn->head_len) |
| 2986 | return -EINVAL; |
| 2987 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2988 | } |
| 2989 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2990 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2991 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2992 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2993 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2994 | } |
| 2995 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2996 | if (!haveinfo) |
| 2997 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2998 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2999 | if (attrs[NL80211_ATTR_IE]) { |
| 3000 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3001 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3002 | } |
| 3003 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3004 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3005 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3006 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3007 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3008 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3009 | } |
| 3010 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3011 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3012 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3013 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3014 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3015 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3016 | } |
| 3017 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3018 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3019 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3020 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3021 | } |
| 3022 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3023 | return 0; |
| 3024 | } |
| 3025 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3026 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3027 | struct cfg80211_ap_settings *params) |
| 3028 | { |
| 3029 | struct wireless_dev *wdev; |
| 3030 | bool ret = false; |
| 3031 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3032 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3033 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3034 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3035 | continue; |
| 3036 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3037 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3038 | continue; |
| 3039 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3040 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3041 | ret = true; |
| 3042 | break; |
| 3043 | } |
| 3044 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3045 | return ret; |
| 3046 | } |
| 3047 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3048 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3049 | enum nl80211_auth_type auth_type, |
| 3050 | enum nl80211_commands cmd) |
| 3051 | { |
| 3052 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3053 | return false; |
| 3054 | |
| 3055 | switch (cmd) { |
| 3056 | case NL80211_CMD_AUTHENTICATE: |
| 3057 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3058 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3059 | return false; |
| 3060 | return true; |
| 3061 | case NL80211_CMD_CONNECT: |
| 3062 | case NL80211_CMD_START_AP: |
| 3063 | /* SAE not supported yet */ |
| 3064 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3065 | return false; |
| 3066 | return true; |
| 3067 | default: |
| 3068 | return false; |
| 3069 | } |
| 3070 | } |
| 3071 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3072 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3073 | { |
| 3074 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3075 | struct net_device *dev = info->user_ptr[1]; |
| 3076 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3077 | struct cfg80211_ap_settings params; |
| 3078 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3079 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3080 | |
| 3081 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3082 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3083 | return -EOPNOTSUPP; |
| 3084 | |
| 3085 | if (!rdev->ops->start_ap) |
| 3086 | return -EOPNOTSUPP; |
| 3087 | |
| 3088 | if (wdev->beacon_interval) |
| 3089 | return -EALREADY; |
| 3090 | |
| 3091 | memset(¶ms, 0, sizeof(params)); |
| 3092 | |
| 3093 | /* these are required for START_AP */ |
| 3094 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3095 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3096 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3097 | return -EINVAL; |
| 3098 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3099 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3100 | if (err) |
| 3101 | return err; |
| 3102 | |
| 3103 | params.beacon_interval = |
| 3104 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3105 | params.dtim_period = |
| 3106 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3107 | |
| 3108 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3109 | if (err) |
| 3110 | return err; |
| 3111 | |
| 3112 | /* |
| 3113 | * In theory, some of these attributes should be required here |
| 3114 | * but since they were not used when the command was originally |
| 3115 | * added, keep them optional for old user space programs to let |
| 3116 | * them continue to work with drivers that do not need the |
| 3117 | * additional information -- drivers must check! |
| 3118 | */ |
| 3119 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3120 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3121 | params.ssid_len = |
| 3122 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3123 | if (params.ssid_len == 0 || |
| 3124 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3125 | return -EINVAL; |
| 3126 | } |
| 3127 | |
| 3128 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3129 | params.hidden_ssid = nla_get_u32( |
| 3130 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3131 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3132 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3133 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3134 | return -EINVAL; |
| 3135 | } |
| 3136 | |
| 3137 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3138 | |
| 3139 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3140 | params.auth_type = nla_get_u32( |
| 3141 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3142 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3143 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3144 | return -EINVAL; |
| 3145 | } else |
| 3146 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3147 | |
| 3148 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3149 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3150 | if (err) |
| 3151 | return err; |
| 3152 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3153 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3154 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3155 | return -EOPNOTSUPP; |
| 3156 | params.inactivity_timeout = nla_get_u16( |
| 3157 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3158 | } |
| 3159 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3160 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3161 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3162 | return -EINVAL; |
| 3163 | params.p2p_ctwindow = |
| 3164 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3165 | if (params.p2p_ctwindow > 127) |
| 3166 | return -EINVAL; |
| 3167 | if (params.p2p_ctwindow != 0 && |
| 3168 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3169 | return -EINVAL; |
| 3170 | } |
| 3171 | |
| 3172 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3173 | u8 tmp; |
| 3174 | |
| 3175 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3176 | return -EINVAL; |
| 3177 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3178 | if (tmp > 1) |
| 3179 | return -EINVAL; |
| 3180 | params.p2p_opp_ps = tmp; |
| 3181 | if (params.p2p_opp_ps != 0 && |
| 3182 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3183 | return -EINVAL; |
| 3184 | } |
| 3185 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3186 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3187 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3188 | if (err) |
| 3189 | return err; |
| 3190 | } else if (wdev->preset_chandef.chan) { |
| 3191 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3192 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3193 | return -EINVAL; |
| 3194 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3195 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3196 | return -EINVAL; |
| 3197 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3198 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3199 | if (err < 0) |
| 3200 | return err; |
| 3201 | if (err) { |
| 3202 | radar_detect_width = BIT(params.chandef.width); |
| 3203 | params.radar_required = true; |
| 3204 | } |
| 3205 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3206 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3207 | params.chandef.chan, |
| 3208 | CHAN_MODE_SHARED, |
| 3209 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3210 | if (err) |
| 3211 | return err; |
| 3212 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3213 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3214 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3215 | if (IS_ERR(params.acl)) |
| 3216 | return PTR_ERR(params.acl); |
| 3217 | } |
| 3218 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3219 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3220 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3221 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3222 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3223 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3224 | wdev->ssid_len = params.ssid_len; |
| 3225 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3226 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3227 | |
| 3228 | kfree(params.acl); |
| 3229 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3230 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3231 | } |
| 3232 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3233 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3234 | { |
| 3235 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3236 | struct net_device *dev = info->user_ptr[1]; |
| 3237 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3238 | struct cfg80211_beacon_data params; |
| 3239 | int err; |
| 3240 | |
| 3241 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3242 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3243 | return -EOPNOTSUPP; |
| 3244 | |
| 3245 | if (!rdev->ops->change_beacon) |
| 3246 | return -EOPNOTSUPP; |
| 3247 | |
| 3248 | if (!wdev->beacon_interval) |
| 3249 | return -EINVAL; |
| 3250 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3251 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3252 | if (err) |
| 3253 | return err; |
| 3254 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3255 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | 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] | 3259 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3260 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3261 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3262 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3263 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3264 | } |
| 3265 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3266 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3267 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3268 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3269 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3270 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3271 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3272 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3273 | }; |
| 3274 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3275 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3276 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3277 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3278 | { |
| 3279 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3280 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3281 | int flag; |
| 3282 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3283 | /* |
| 3284 | * Try parsing the new attribute first so userspace |
| 3285 | * can specify both for older kernels. |
| 3286 | */ |
| 3287 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3288 | if (nla) { |
| 3289 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3290 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3291 | sta_flags = nla_data(nla); |
| 3292 | params->sta_flags_mask = sta_flags->mask; |
| 3293 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3294 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3295 | if ((params->sta_flags_mask | |
| 3296 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3297 | return -EINVAL; |
| 3298 | return 0; |
| 3299 | } |
| 3300 | |
| 3301 | /* if present, parse the old attribute */ |
| 3302 | |
| 3303 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3304 | if (!nla) |
| 3305 | return 0; |
| 3306 | |
| 3307 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3308 | nla, sta_flags_policy)) |
| 3309 | return -EINVAL; |
| 3310 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3311 | /* |
| 3312 | * Only allow certain flags for interface types so that |
| 3313 | * other attributes are silently ignored. Remember that |
| 3314 | * this is backward compatibility code with old userspace |
| 3315 | * and shouldn't be hit in other cases anyway. |
| 3316 | */ |
| 3317 | switch (iftype) { |
| 3318 | case NL80211_IFTYPE_AP: |
| 3319 | case NL80211_IFTYPE_AP_VLAN: |
| 3320 | case NL80211_IFTYPE_P2P_GO: |
| 3321 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3322 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3323 | BIT(NL80211_STA_FLAG_WME) | |
| 3324 | BIT(NL80211_STA_FLAG_MFP); |
| 3325 | break; |
| 3326 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3327 | case NL80211_IFTYPE_STATION: |
| 3328 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3329 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3330 | break; |
| 3331 | case NL80211_IFTYPE_MESH_POINT: |
| 3332 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3333 | BIT(NL80211_STA_FLAG_MFP) | |
| 3334 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3335 | default: |
| 3336 | return -EINVAL; |
| 3337 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3338 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3339 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3340 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3341 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3342 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3343 | /* no longer support new API additions in old API */ |
| 3344 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3345 | return -EINVAL; |
| 3346 | } |
| 3347 | } |
| 3348 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3349 | return 0; |
| 3350 | } |
| 3351 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3352 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3353 | int attr) |
| 3354 | { |
| 3355 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3356 | u32 bitrate; |
| 3357 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3358 | |
| 3359 | rate = nla_nest_start(msg, attr); |
| 3360 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3361 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3362 | |
| 3363 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3364 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3365 | /* report 16-bit bitrate only if we can */ |
| 3366 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3367 | if (bitrate > 0 && |
| 3368 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3369 | return false; |
| 3370 | if (bitrate_compat > 0 && |
| 3371 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3372 | return false; |
| 3373 | |
| 3374 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3375 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3376 | return false; |
| 3377 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3378 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3379 | return false; |
| 3380 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3381 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3382 | return false; |
| 3383 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3384 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3385 | return false; |
| 3386 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3387 | return false; |
| 3388 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3389 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3390 | return false; |
| 3391 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3392 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3393 | return false; |
| 3394 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3395 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3396 | return false; |
| 3397 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3398 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3399 | return false; |
| 3400 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3401 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3402 | return false; |
| 3403 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3404 | |
| 3405 | nla_nest_end(msg, rate); |
| 3406 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3407 | } |
| 3408 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3409 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3410 | int id) |
| 3411 | { |
| 3412 | void *attr; |
| 3413 | int i = 0; |
| 3414 | |
| 3415 | if (!mask) |
| 3416 | return true; |
| 3417 | |
| 3418 | attr = nla_nest_start(msg, id); |
| 3419 | if (!attr) |
| 3420 | return false; |
| 3421 | |
| 3422 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3423 | if (!(mask & BIT(i))) |
| 3424 | continue; |
| 3425 | |
| 3426 | if (nla_put_u8(msg, i, signal[i])) |
| 3427 | return false; |
| 3428 | } |
| 3429 | |
| 3430 | nla_nest_end(msg, attr); |
| 3431 | |
| 3432 | return true; |
| 3433 | } |
| 3434 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3435 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3436 | int flags, |
| 3437 | struct cfg80211_registered_device *rdev, |
| 3438 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3439 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3440 | { |
| 3441 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3442 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3443 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3444 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3445 | if (!hdr) |
| 3446 | return -1; |
| 3447 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3448 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3449 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3450 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3451 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3452 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3453 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3454 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3455 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3456 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3457 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3458 | sinfo->connected_time)) |
| 3459 | goto nla_put_failure; |
| 3460 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3461 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3462 | sinfo->inactive_time)) |
| 3463 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3464 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3465 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3466 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3467 | (u32)sinfo->rx_bytes)) |
| 3468 | goto nla_put_failure; |
| 3469 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3470 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3471 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3472 | (u32)sinfo->tx_bytes)) |
| 3473 | goto nla_put_failure; |
| 3474 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3475 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3476 | sinfo->rx_bytes)) |
| 3477 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3478 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3479 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3480 | sinfo->tx_bytes)) |
| 3481 | goto nla_put_failure; |
| 3482 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3483 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3484 | goto nla_put_failure; |
| 3485 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3486 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3487 | goto nla_put_failure; |
| 3488 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3489 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3490 | sinfo->plink_state)) |
| 3491 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3492 | switch (rdev->wiphy.signal_type) { |
| 3493 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3494 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3495 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3496 | sinfo->signal)) |
| 3497 | goto nla_put_failure; |
| 3498 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3499 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3500 | sinfo->signal_avg)) |
| 3501 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3502 | break; |
| 3503 | default: |
| 3504 | break; |
| 3505 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3506 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3507 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3508 | sinfo->chain_signal, |
| 3509 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3510 | goto nla_put_failure; |
| 3511 | } |
| 3512 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3513 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3514 | sinfo->chain_signal_avg, |
| 3515 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3516 | goto nla_put_failure; |
| 3517 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3518 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3519 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3520 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3521 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3522 | } |
| 3523 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3524 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3525 | NL80211_STA_INFO_RX_BITRATE)) |
| 3526 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3527 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3528 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3529 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3530 | sinfo->rx_packets)) |
| 3531 | goto nla_put_failure; |
| 3532 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3533 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3534 | sinfo->tx_packets)) |
| 3535 | goto nla_put_failure; |
| 3536 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3537 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3538 | sinfo->tx_retries)) |
| 3539 | goto nla_put_failure; |
| 3540 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3541 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3542 | sinfo->tx_failed)) |
| 3543 | goto nla_put_failure; |
| 3544 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3545 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3546 | sinfo->beacon_loss_count)) |
| 3547 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3548 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3549 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3550 | sinfo->local_pm)) |
| 3551 | goto nla_put_failure; |
| 3552 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3553 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3554 | sinfo->peer_pm)) |
| 3555 | goto nla_put_failure; |
| 3556 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3557 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3558 | sinfo->nonpeer_pm)) |
| 3559 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3560 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3561 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3562 | if (!bss_param) |
| 3563 | goto nla_put_failure; |
| 3564 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3565 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3566 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3567 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3568 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3569 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3570 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3571 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3572 | sinfo->bss_param.dtim_period) || |
| 3573 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3574 | sinfo->bss_param.beacon_interval)) |
| 3575 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3576 | |
| 3577 | nla_nest_end(msg, bss_param); |
| 3578 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3579 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3580 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3581 | sizeof(struct nl80211_sta_flag_update), |
| 3582 | &sinfo->sta_flags)) |
| 3583 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3584 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3585 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3586 | sinfo->t_offset)) |
| 3587 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3588 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3589 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3590 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3591 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3592 | sinfo->assoc_req_ies)) |
| 3593 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3594 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3595 | return genlmsg_end(msg, hdr); |
| 3596 | |
| 3597 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3598 | genlmsg_cancel(msg, hdr); |
| 3599 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3600 | } |
| 3601 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3602 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3603 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3604 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3605 | struct station_info sinfo; |
| 3606 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3607 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3608 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3609 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3610 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3611 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3612 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3613 | if (err) |
| 3614 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3615 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3616 | if (!wdev->netdev) { |
| 3617 | err = -EINVAL; |
| 3618 | goto out_err; |
| 3619 | } |
| 3620 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3621 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3622 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3623 | goto out_err; |
| 3624 | } |
| 3625 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3626 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3627 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3628 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3629 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3630 | if (err == -ENOENT) |
| 3631 | break; |
| 3632 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3633 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3634 | |
| 3635 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3636 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3637 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3638 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3639 | &sinfo) < 0) |
| 3640 | goto out; |
| 3641 | |
| 3642 | sta_idx++; |
| 3643 | } |
| 3644 | |
| 3645 | |
| 3646 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3647 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3648 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3649 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3650 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3651 | |
| 3652 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3653 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3654 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3655 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3656 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3657 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3658 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3659 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3660 | struct sk_buff *msg; |
| 3661 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3662 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3663 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3664 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3665 | |
| 3666 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3667 | return -EINVAL; |
| 3668 | |
| 3669 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3670 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3671 | if (!rdev->ops->get_station) |
| 3672 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3673 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3674 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3675 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3676 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3677 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3678 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3679 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3680 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3681 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3682 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3683 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3684 | nlmsg_free(msg); |
| 3685 | return -ENOBUFS; |
| 3686 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3687 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3688 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3689 | } |
| 3690 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3691 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3692 | struct station_parameters *params, |
| 3693 | enum cfg80211_station_type statype) |
| 3694 | { |
| 3695 | if (params->listen_interval != -1) |
| 3696 | return -EINVAL; |
| 3697 | if (params->aid) |
| 3698 | return -EINVAL; |
| 3699 | |
| 3700 | /* When you run into this, adjust the code below for the new flag */ |
| 3701 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3702 | |
| 3703 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3704 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3705 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3706 | /* |
| 3707 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3708 | * code doesn't have the bug of including TDLS in the |
| 3709 | * mask everywhere. |
| 3710 | */ |
| 3711 | if (params->sta_flags_mask & |
| 3712 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3713 | BIT(NL80211_STA_FLAG_MFP) | |
| 3714 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3715 | return -EINVAL; |
| 3716 | break; |
| 3717 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3718 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3719 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3720 | return -EINVAL; |
| 3721 | /* ignore since it can't change */ |
| 3722 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3723 | break; |
| 3724 | default: |
| 3725 | /* disallow mesh-specific things */ |
| 3726 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3727 | return -EINVAL; |
| 3728 | if (params->local_pm) |
| 3729 | return -EINVAL; |
| 3730 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3731 | return -EINVAL; |
| 3732 | } |
| 3733 | |
| 3734 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3735 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3736 | /* TDLS can't be set, ... */ |
| 3737 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3738 | return -EINVAL; |
| 3739 | /* |
| 3740 | * ... but don't bother the driver with it. This works around |
| 3741 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3742 | * TLDS_PEER flag in the mask even for AP mode. |
| 3743 | */ |
| 3744 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3745 | } |
| 3746 | |
| 3747 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3748 | /* reject other things that can't change */ |
| 3749 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3750 | return -EINVAL; |
| 3751 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3752 | return -EINVAL; |
| 3753 | if (params->supported_rates) |
| 3754 | return -EINVAL; |
| 3755 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3756 | return -EINVAL; |
| 3757 | } |
| 3758 | |
| 3759 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3760 | if (params->vlan) |
| 3761 | return -EINVAL; |
| 3762 | } |
| 3763 | |
| 3764 | switch (statype) { |
| 3765 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3766 | /* Use this only for authorizing/unauthorizing a station */ |
| 3767 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3768 | return -EOPNOTSUPP; |
| 3769 | break; |
| 3770 | case CFG80211_STA_AP_CLIENT: |
| 3771 | /* accept only the listed bits */ |
| 3772 | if (params->sta_flags_mask & |
| 3773 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3774 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3775 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3776 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3777 | BIT(NL80211_STA_FLAG_WME) | |
| 3778 | BIT(NL80211_STA_FLAG_MFP))) |
| 3779 | return -EINVAL; |
| 3780 | |
| 3781 | /* but authenticated/associated only if driver handles it */ |
| 3782 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3783 | params->sta_flags_mask & |
| 3784 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3785 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3786 | return -EINVAL; |
| 3787 | break; |
| 3788 | case CFG80211_STA_IBSS: |
| 3789 | case CFG80211_STA_AP_STA: |
| 3790 | /* reject any changes other than AUTHORIZED */ |
| 3791 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3792 | return -EINVAL; |
| 3793 | break; |
| 3794 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3795 | /* reject any changes other than AUTHORIZED or WME */ |
| 3796 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3797 | BIT(NL80211_STA_FLAG_WME))) |
| 3798 | return -EINVAL; |
| 3799 | /* force (at least) rates when authorizing */ |
| 3800 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3801 | !params->supported_rates) |
| 3802 | return -EINVAL; |
| 3803 | break; |
| 3804 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3805 | /* reject any changes */ |
| 3806 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3807 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3808 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3809 | return -EINVAL; |
| 3810 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3811 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3812 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3813 | return -EINVAL; |
| 3814 | break; |
| 3815 | } |
| 3816 | |
| 3817 | return 0; |
| 3818 | } |
| 3819 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3820 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3821 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3822 | * 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] | 3823 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3824 | static struct net_device *get_vlan(struct genl_info *info, |
| 3825 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3826 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3827 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3828 | struct net_device *v; |
| 3829 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3830 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3831 | if (!vlanattr) |
| 3832 | return NULL; |
| 3833 | |
| 3834 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3835 | if (!v) |
| 3836 | return ERR_PTR(-ENODEV); |
| 3837 | |
| 3838 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3839 | ret = -EINVAL; |
| 3840 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3841 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3842 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3843 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3844 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3845 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3846 | ret = -EINVAL; |
| 3847 | goto error; |
| 3848 | } |
| 3849 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3850 | if (!netif_running(v)) { |
| 3851 | ret = -ENETDOWN; |
| 3852 | goto error; |
| 3853 | } |
| 3854 | |
| 3855 | return v; |
| 3856 | error: |
| 3857 | dev_put(v); |
| 3858 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3859 | } |
| 3860 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3861 | static struct nla_policy |
| 3862 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3863 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3864 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3865 | }; |
| 3866 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3867 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3868 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3869 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3870 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3871 | struct nlattr *nla; |
| 3872 | int err; |
| 3873 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3874 | /* parse WME attributes if present */ |
| 3875 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3876 | return 0; |
| 3877 | |
| 3878 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3879 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3880 | nl80211_sta_wme_policy); |
| 3881 | if (err) |
| 3882 | return err; |
| 3883 | |
| 3884 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3885 | params->uapsd_queues = nla_get_u8( |
| 3886 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3887 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3888 | return -EINVAL; |
| 3889 | |
| 3890 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3891 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3892 | |
| 3893 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3894 | return -EINVAL; |
| 3895 | |
| 3896 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3897 | |
| 3898 | return 0; |
| 3899 | } |
| 3900 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame^] | 3901 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 3902 | struct station_parameters *params) |
| 3903 | { |
| 3904 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 3905 | params->supported_channels = |
| 3906 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3907 | params->supported_channels_len = |
| 3908 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3909 | /* |
| 3910 | * Need to include at least one (first channel, number of |
| 3911 | * channels) tuple for each subband, and must have proper |
| 3912 | * tuples for the rest of the data as well. |
| 3913 | */ |
| 3914 | if (params->supported_channels_len < 2) |
| 3915 | return -EINVAL; |
| 3916 | if (params->supported_channels_len % 2) |
| 3917 | return -EINVAL; |
| 3918 | } |
| 3919 | |
| 3920 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 3921 | params->supported_oper_classes = |
| 3922 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3923 | params->supported_oper_classes_len = |
| 3924 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3925 | /* |
| 3926 | * The value of the Length field of the Supported Operating |
| 3927 | * Classes element is between 2 and 253. |
| 3928 | */ |
| 3929 | if (params->supported_oper_classes_len < 2 || |
| 3930 | params->supported_oper_classes_len > 253) |
| 3931 | return -EINVAL; |
| 3932 | } |
| 3933 | return 0; |
| 3934 | } |
| 3935 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3936 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3937 | struct station_parameters *params) |
| 3938 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame^] | 3939 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3940 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3941 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3942 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3943 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3944 | params->ht_capa = |
| 3945 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3946 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3947 | params->vht_capa = |
| 3948 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3949 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame^] | 3950 | err = nl80211_parse_sta_channel_info(info, params); |
| 3951 | if (err) |
| 3952 | return err; |
| 3953 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3954 | return nl80211_parse_sta_wme(info, params); |
| 3955 | } |
| 3956 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3957 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3958 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3959 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3960 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3961 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3962 | u8 *mac_addr; |
| 3963 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3964 | |
| 3965 | memset(¶ms, 0, sizeof(params)); |
| 3966 | |
| 3967 | params.listen_interval = -1; |
| 3968 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3969 | if (!rdev->ops->change_station) |
| 3970 | return -EOPNOTSUPP; |
| 3971 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3972 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3973 | return -EINVAL; |
| 3974 | |
| 3975 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3976 | return -EINVAL; |
| 3977 | |
| 3978 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3979 | |
| 3980 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3981 | params.supported_rates = |
| 3982 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3983 | params.supported_rates_len = |
| 3984 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3985 | } |
| 3986 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3987 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3988 | params.capability = |
| 3989 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3990 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3991 | } |
| 3992 | |
| 3993 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3994 | params.ext_capab = |
| 3995 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3996 | params.ext_capab_len = |
| 3997 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3998 | } |
| 3999 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4000 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4001 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4002 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4003 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4004 | return -EINVAL; |
| 4005 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4006 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4007 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4008 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4009 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4010 | return -EINVAL; |
| 4011 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4012 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4013 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4014 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4015 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4016 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4017 | return -EINVAL; |
| 4018 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4019 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4020 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4021 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4022 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4023 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4024 | |
| 4025 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4026 | pm > NL80211_MESH_POWER_MAX) |
| 4027 | return -EINVAL; |
| 4028 | |
| 4029 | params.local_pm = pm; |
| 4030 | } |
| 4031 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4032 | /* Include parameters for TDLS peer (will check later) */ |
| 4033 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4034 | if (err) |
| 4035 | return err; |
| 4036 | |
| 4037 | params.vlan = get_vlan(info, rdev); |
| 4038 | if (IS_ERR(params.vlan)) |
| 4039 | return PTR_ERR(params.vlan); |
| 4040 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4041 | switch (dev->ieee80211_ptr->iftype) { |
| 4042 | case NL80211_IFTYPE_AP: |
| 4043 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4044 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4045 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4046 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4047 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4048 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4049 | break; |
| 4050 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4051 | err = -EOPNOTSUPP; |
| 4052 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4053 | } |
| 4054 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4055 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4056 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4057 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4058 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4059 | if (params.vlan) |
| 4060 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4061 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4062 | return err; |
| 4063 | } |
| 4064 | |
| 4065 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4066 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4067 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4068 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4069 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4070 | struct station_parameters params; |
| 4071 | u8 *mac_addr = NULL; |
| 4072 | |
| 4073 | memset(¶ms, 0, sizeof(params)); |
| 4074 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4075 | if (!rdev->ops->add_station) |
| 4076 | return -EOPNOTSUPP; |
| 4077 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4078 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4079 | return -EINVAL; |
| 4080 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4081 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4082 | return -EINVAL; |
| 4083 | |
| 4084 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4085 | return -EINVAL; |
| 4086 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4087 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4088 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4089 | return -EINVAL; |
| 4090 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4091 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4092 | params.supported_rates = |
| 4093 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4094 | params.supported_rates_len = |
| 4095 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4096 | params.listen_interval = |
| 4097 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4098 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4099 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4100 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4101 | else |
| 4102 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4103 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4104 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4105 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4106 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4107 | params.capability = |
| 4108 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4109 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4110 | } |
| 4111 | |
| 4112 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4113 | params.ext_capab = |
| 4114 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4115 | params.ext_capab_len = |
| 4116 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4117 | } |
| 4118 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4119 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4120 | params.ht_capa = |
| 4121 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4122 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4123 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4124 | params.vht_capa = |
| 4125 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4126 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4127 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4128 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4129 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4130 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4131 | return -EINVAL; |
| 4132 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4133 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame^] | 4134 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4135 | if (err) |
| 4136 | return err; |
| 4137 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4138 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4139 | if (err) |
| 4140 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4141 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4142 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4143 | return -EINVAL; |
| 4144 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4145 | /* When you run into this, adjust the code below for the new flag */ |
| 4146 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4147 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4148 | switch (dev->ieee80211_ptr->iftype) { |
| 4149 | case NL80211_IFTYPE_AP: |
| 4150 | case NL80211_IFTYPE_AP_VLAN: |
| 4151 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4152 | /* ignore WME attributes if iface/sta is not capable */ |
| 4153 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4154 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4155 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4156 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4157 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4158 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4159 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4160 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4161 | /* but don't bother the driver with it */ |
| 4162 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4163 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4164 | /* allow authenticated/associated only if driver handles it */ |
| 4165 | if (!(rdev->wiphy.features & |
| 4166 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4167 | params.sta_flags_mask & |
| 4168 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4169 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4170 | return -EINVAL; |
| 4171 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4172 | /* must be last in here for error handling */ |
| 4173 | params.vlan = get_vlan(info, rdev); |
| 4174 | if (IS_ERR(params.vlan)) |
| 4175 | return PTR_ERR(params.vlan); |
| 4176 | break; |
| 4177 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4178 | /* ignore uAPSD data */ |
| 4179 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4180 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4181 | /* associated is disallowed */ |
| 4182 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4183 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4184 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4185 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4186 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4187 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4188 | break; |
| 4189 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4190 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4191 | /* ignore uAPSD data */ |
| 4192 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4193 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4194 | /* these are disallowed */ |
| 4195 | if (params.sta_flags_mask & |
| 4196 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4197 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4198 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4199 | /* Only TDLS peers can be added */ |
| 4200 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4201 | return -EINVAL; |
| 4202 | /* Can only add if TDLS ... */ |
| 4203 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4204 | return -EOPNOTSUPP; |
| 4205 | /* ... with external setup is supported */ |
| 4206 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4207 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4208 | /* |
| 4209 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4210 | * as authorized, but it shouldn't yet be. |
| 4211 | */ |
| 4212 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4213 | break; |
| 4214 | default: |
| 4215 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4216 | } |
| 4217 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4218 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4219 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4220 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4221 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4222 | if (params.vlan) |
| 4223 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4224 | return err; |
| 4225 | } |
| 4226 | |
| 4227 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4228 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4229 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4230 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4231 | u8 *mac_addr = NULL; |
| 4232 | |
| 4233 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4234 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4235 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4236 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4237 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4238 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4239 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4240 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4241 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4242 | if (!rdev->ops->del_station) |
| 4243 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4244 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4245 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4246 | } |
| 4247 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4248 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4249 | int flags, struct net_device *dev, |
| 4250 | u8 *dst, u8 *next_hop, |
| 4251 | struct mpath_info *pinfo) |
| 4252 | { |
| 4253 | void *hdr; |
| 4254 | struct nlattr *pinfoattr; |
| 4255 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4256 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4257 | if (!hdr) |
| 4258 | return -1; |
| 4259 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4260 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4261 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4262 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4263 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4264 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4265 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4266 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4267 | if (!pinfoattr) |
| 4268 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4269 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4270 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4271 | pinfo->frame_qlen)) |
| 4272 | goto nla_put_failure; |
| 4273 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4274 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4275 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4276 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4277 | pinfo->metric)) || |
| 4278 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4279 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4280 | pinfo->exptime)) || |
| 4281 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4282 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4283 | pinfo->flags)) || |
| 4284 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4285 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4286 | pinfo->discovery_timeout)) || |
| 4287 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4288 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4289 | pinfo->discovery_retries))) |
| 4290 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4291 | |
| 4292 | nla_nest_end(msg, pinfoattr); |
| 4293 | |
| 4294 | return genlmsg_end(msg, hdr); |
| 4295 | |
| 4296 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4297 | genlmsg_cancel(msg, hdr); |
| 4298 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4302 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4303 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4304 | struct mpath_info pinfo; |
| 4305 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4306 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4307 | u8 dst[ETH_ALEN]; |
| 4308 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4309 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4310 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4311 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4312 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4313 | if (err) |
| 4314 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4315 | |
| 4316 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4317 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4318 | goto out_err; |
| 4319 | } |
| 4320 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4321 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4322 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4323 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4324 | } |
| 4325 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4326 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4327 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4328 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4329 | if (err == -ENOENT) |
| 4330 | break; |
| 4331 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4332 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4333 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4334 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4335 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4336 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4337 | &pinfo) < 0) |
| 4338 | goto out; |
| 4339 | |
| 4340 | path_idx++; |
| 4341 | } |
| 4342 | |
| 4343 | |
| 4344 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4345 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4346 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4347 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4348 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4349 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4353 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4354 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4355 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4356 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4357 | struct mpath_info pinfo; |
| 4358 | struct sk_buff *msg; |
| 4359 | u8 *dst = NULL; |
| 4360 | u8 next_hop[ETH_ALEN]; |
| 4361 | |
| 4362 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4363 | |
| 4364 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4365 | return -EINVAL; |
| 4366 | |
| 4367 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4368 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4369 | if (!rdev->ops->get_mpath) |
| 4370 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4371 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4372 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4373 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4374 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4375 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4376 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4377 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4378 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4379 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4380 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4381 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4382 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4383 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4384 | dev, dst, next_hop, &pinfo) < 0) { |
| 4385 | nlmsg_free(msg); |
| 4386 | return -ENOBUFS; |
| 4387 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4388 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4389 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4390 | } |
| 4391 | |
| 4392 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4393 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4394 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4395 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4396 | u8 *dst = NULL; |
| 4397 | u8 *next_hop = NULL; |
| 4398 | |
| 4399 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4400 | return -EINVAL; |
| 4401 | |
| 4402 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4403 | return -EINVAL; |
| 4404 | |
| 4405 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4406 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4407 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4408 | if (!rdev->ops->change_mpath) |
| 4409 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4410 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4411 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4412 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4413 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4414 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4415 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4416 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4417 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4418 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4419 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4420 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4421 | u8 *dst = NULL; |
| 4422 | u8 *next_hop = NULL; |
| 4423 | |
| 4424 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4425 | return -EINVAL; |
| 4426 | |
| 4427 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4428 | return -EINVAL; |
| 4429 | |
| 4430 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4431 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4432 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4433 | if (!rdev->ops->add_mpath) |
| 4434 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4435 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4436 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4437 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4438 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4439 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4443 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4444 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4445 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4446 | u8 *dst = NULL; |
| 4447 | |
| 4448 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4449 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4450 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4451 | if (!rdev->ops->del_mpath) |
| 4452 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4453 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4454 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4455 | } |
| 4456 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4457 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4458 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4459 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4460 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4461 | struct bss_parameters params; |
| 4462 | |
| 4463 | memset(¶ms, 0, sizeof(params)); |
| 4464 | /* default to not changing parameters */ |
| 4465 | params.use_cts_prot = -1; |
| 4466 | params.use_short_preamble = -1; |
| 4467 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4468 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4469 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4470 | params.p2p_ctwindow = -1; |
| 4471 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4472 | |
| 4473 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4474 | params.use_cts_prot = |
| 4475 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4476 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4477 | params.use_short_preamble = |
| 4478 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4479 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4480 | params.use_short_slot_time = |
| 4481 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4482 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4483 | params.basic_rates = |
| 4484 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4485 | params.basic_rates_len = |
| 4486 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4487 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4488 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4489 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4490 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4491 | params.ht_opmode = |
| 4492 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4493 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4494 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4495 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4496 | return -EINVAL; |
| 4497 | params.p2p_ctwindow = |
| 4498 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4499 | if (params.p2p_ctwindow < 0) |
| 4500 | return -EINVAL; |
| 4501 | if (params.p2p_ctwindow != 0 && |
| 4502 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4503 | return -EINVAL; |
| 4504 | } |
| 4505 | |
| 4506 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4507 | u8 tmp; |
| 4508 | |
| 4509 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4510 | return -EINVAL; |
| 4511 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4512 | if (tmp > 1) |
| 4513 | return -EINVAL; |
| 4514 | params.p2p_opp_ps = tmp; |
| 4515 | if (params.p2p_opp_ps && |
| 4516 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4517 | return -EINVAL; |
| 4518 | } |
| 4519 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4520 | if (!rdev->ops->change_bss) |
| 4521 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4522 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4523 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4524 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4525 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4526 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4527 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4528 | } |
| 4529 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4530 | 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] | 4531 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4532 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4533 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4534 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4535 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4536 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4537 | }; |
| 4538 | |
| 4539 | static int parse_reg_rule(struct nlattr *tb[], |
| 4540 | struct ieee80211_reg_rule *reg_rule) |
| 4541 | { |
| 4542 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4543 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4544 | |
| 4545 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4546 | return -EINVAL; |
| 4547 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4548 | return -EINVAL; |
| 4549 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4550 | return -EINVAL; |
| 4551 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4552 | return -EINVAL; |
| 4553 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4554 | return -EINVAL; |
| 4555 | |
| 4556 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4557 | |
| 4558 | freq_range->start_freq_khz = |
| 4559 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4560 | freq_range->end_freq_khz = |
| 4561 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4562 | freq_range->max_bandwidth_khz = |
| 4563 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4564 | |
| 4565 | power_rule->max_eirp = |
| 4566 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4567 | |
| 4568 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4569 | power_rule->max_antenna_gain = |
| 4570 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4571 | |
| 4572 | return 0; |
| 4573 | } |
| 4574 | |
| 4575 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4576 | { |
| 4577 | int r; |
| 4578 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4579 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4580 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4581 | /* |
| 4582 | * You should only get this when cfg80211 hasn't yet initialized |
| 4583 | * completely when built-in to the kernel right between the time |
| 4584 | * window between nl80211_init() and regulatory_init(), if that is |
| 4585 | * even possible. |
| 4586 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4587 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4588 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4589 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4590 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4591 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4592 | |
| 4593 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4594 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4595 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4596 | user_reg_hint_type = |
| 4597 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4598 | else |
| 4599 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4600 | |
| 4601 | switch (user_reg_hint_type) { |
| 4602 | case NL80211_USER_REG_HINT_USER: |
| 4603 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4604 | break; |
| 4605 | default: |
| 4606 | return -EINVAL; |
| 4607 | } |
| 4608 | |
| 4609 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4610 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4611 | return r; |
| 4612 | } |
| 4613 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4614 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4615 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4616 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4617 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4618 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4619 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4620 | struct mesh_config cur_params; |
| 4621 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4622 | void *hdr; |
| 4623 | struct nlattr *pinfoattr; |
| 4624 | struct sk_buff *msg; |
| 4625 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4626 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4627 | return -EOPNOTSUPP; |
| 4628 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4629 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4630 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4631 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4632 | wdev_lock(wdev); |
| 4633 | /* If not connected, get default parameters */ |
| 4634 | if (!wdev->mesh_id_len) |
| 4635 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4636 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4637 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4638 | wdev_unlock(wdev); |
| 4639 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4640 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4641 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4642 | |
| 4643 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4644 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4645 | if (!msg) |
| 4646 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4647 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4648 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4649 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4650 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4651 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4652 | if (!pinfoattr) |
| 4653 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4654 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4655 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4656 | cur_params.dot11MeshRetryTimeout) || |
| 4657 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4658 | cur_params.dot11MeshConfirmTimeout) || |
| 4659 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4660 | cur_params.dot11MeshHoldingTimeout) || |
| 4661 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4662 | cur_params.dot11MeshMaxPeerLinks) || |
| 4663 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4664 | cur_params.dot11MeshMaxRetries) || |
| 4665 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4666 | cur_params.dot11MeshTTL) || |
| 4667 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4668 | cur_params.element_ttl) || |
| 4669 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4670 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4671 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4672 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4673 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4674 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4675 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4676 | cur_params.path_refresh_time) || |
| 4677 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4678 | cur_params.min_discovery_timeout) || |
| 4679 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4680 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4681 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4682 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4683 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4684 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4685 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4686 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4687 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4688 | cur_params.dot11MeshHWMPRootMode) || |
| 4689 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4690 | cur_params.dot11MeshHWMPRannInterval) || |
| 4691 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4692 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4693 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4694 | cur_params.dot11MeshForwarding) || |
| 4695 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4696 | cur_params.rssi_threshold) || |
| 4697 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4698 | cur_params.ht_opmode) || |
| 4699 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4700 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4701 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4702 | cur_params.dot11MeshHWMProotInterval) || |
| 4703 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4704 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4705 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4706 | cur_params.power_mode) || |
| 4707 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4708 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4709 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4710 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4711 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4712 | nla_nest_end(msg, pinfoattr); |
| 4713 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4714 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4715 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4716 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4717 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4718 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4719 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4720 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4721 | } |
| 4722 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4723 | 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] | 4724 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4725 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4726 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4727 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4728 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4729 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4730 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4731 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4732 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4733 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4734 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4735 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4736 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4737 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4738 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4739 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4740 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4741 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4742 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4743 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4744 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4745 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4746 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4747 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4748 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4749 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4750 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4751 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4752 | }; |
| 4753 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4754 | static const struct nla_policy |
| 4755 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4756 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4757 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4758 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4759 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4760 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4761 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4762 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4763 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4764 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4765 | }; |
| 4766 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4767 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4768 | struct mesh_config *cfg, |
| 4769 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4770 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4771 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4772 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4773 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4774 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4775 | do { \ |
| 4776 | if (tb[attr]) { \ |
| 4777 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4778 | return -EINVAL; \ |
| 4779 | cfg->param = fn(tb[attr]); \ |
| 4780 | mask |= (1 << (attr - 1)); \ |
| 4781 | } \ |
| 4782 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4783 | |
| 4784 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4785 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4786 | return -EINVAL; |
| 4787 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4788 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4789 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4790 | return -EINVAL; |
| 4791 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4792 | /* This makes sure that there aren't more than 32 mesh config |
| 4793 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4794 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4795 | |
| 4796 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4797 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4798 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4799 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4800 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4801 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4802 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4803 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4804 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4805 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4806 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4807 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4808 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4809 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4810 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4811 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4812 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4813 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4814 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4815 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4816 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4817 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4818 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4819 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4820 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4821 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4822 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4823 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4824 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4825 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4826 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4827 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4828 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4829 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4830 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4831 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4832 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4833 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4834 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4835 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4836 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4837 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4838 | 1, 65535, mask, |
| 4839 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4840 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4841 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4842 | 1, 65535, mask, |
| 4843 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4844 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4845 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4846 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4847 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4848 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4849 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4850 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4851 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4852 | nla_get_u8); |
| 4853 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4854 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4855 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4856 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4857 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4858 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4859 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4860 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4861 | mask, NL80211_MESHCONF_FORWARDING, |
| 4862 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4863 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4864 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4865 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4866 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4867 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4868 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4869 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4870 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4871 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4872 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4873 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4874 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4875 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4876 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4877 | dot11MeshHWMPconfirmationInterval, |
| 4878 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4879 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4880 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4881 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4882 | NL80211_MESH_POWER_ACTIVE, |
| 4883 | NL80211_MESH_POWER_MAX, |
| 4884 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4885 | nla_get_u32); |
| 4886 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4887 | 0, 65535, mask, |
| 4888 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4889 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4890 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4891 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4892 | if (mask_out) |
| 4893 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4894 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4895 | return 0; |
| 4896 | |
| 4897 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4898 | } |
| 4899 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4900 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4901 | struct mesh_setup *setup) |
| 4902 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4903 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4904 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4905 | |
| 4906 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4907 | return -EINVAL; |
| 4908 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4909 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4910 | nl80211_mesh_setup_params_policy)) |
| 4911 | return -EINVAL; |
| 4912 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4913 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4914 | setup->sync_method = |
| 4915 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4916 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4917 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4918 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4919 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4920 | setup->path_sel_proto = |
| 4921 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4922 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4923 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4924 | |
| 4925 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4926 | setup->path_metric = |
| 4927 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4928 | IEEE80211_PATH_METRIC_VENDOR : |
| 4929 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4930 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4931 | |
| 4932 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4933 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4934 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4935 | if (!is_valid_ie_attr(ieattr)) |
| 4936 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4937 | setup->ie = nla_data(ieattr); |
| 4938 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4939 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4940 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4941 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4942 | return -EINVAL; |
| 4943 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4944 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4945 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4946 | if (setup->is_secure) |
| 4947 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4948 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4949 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 4950 | if (!setup->user_mpm) |
| 4951 | return -EINVAL; |
| 4952 | setup->auth_id = |
| 4953 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 4954 | } |
| 4955 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4956 | return 0; |
| 4957 | } |
| 4958 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4959 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4960 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4961 | { |
| 4962 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4963 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4964 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4965 | struct mesh_config cfg; |
| 4966 | u32 mask; |
| 4967 | int err; |
| 4968 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4969 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4970 | return -EOPNOTSUPP; |
| 4971 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4972 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4973 | return -EOPNOTSUPP; |
| 4974 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4975 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4976 | if (err) |
| 4977 | return err; |
| 4978 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4979 | wdev_lock(wdev); |
| 4980 | if (!wdev->mesh_id_len) |
| 4981 | err = -ENOLINK; |
| 4982 | |
| 4983 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4984 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4985 | |
| 4986 | wdev_unlock(wdev); |
| 4987 | |
| 4988 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4989 | } |
| 4990 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4991 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4992 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4993 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4994 | struct sk_buff *msg; |
| 4995 | void *hdr = NULL; |
| 4996 | struct nlattr *nl_reg_rules; |
| 4997 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4998 | |
| 4999 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5000 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5001 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5002 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5003 | if (!msg) |
| 5004 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5005 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5006 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5007 | NL80211_CMD_GET_REG); |
| 5008 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5009 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5010 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5011 | if (reg_last_request_cell_base() && |
| 5012 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5013 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5014 | goto nla_put_failure; |
| 5015 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5016 | rcu_read_lock(); |
| 5017 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5018 | |
| 5019 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5020 | (regdom->dfs_region && |
| 5021 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5022 | goto nla_put_failure_rcu; |
| 5023 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5024 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5025 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5026 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5027 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5028 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5029 | struct nlattr *nl_reg_rule; |
| 5030 | const struct ieee80211_reg_rule *reg_rule; |
| 5031 | const struct ieee80211_freq_range *freq_range; |
| 5032 | const struct ieee80211_power_rule *power_rule; |
| 5033 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5034 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5035 | freq_range = ®_rule->freq_range; |
| 5036 | power_rule = ®_rule->power_rule; |
| 5037 | |
| 5038 | nl_reg_rule = nla_nest_start(msg, i); |
| 5039 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5040 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5041 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5042 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5043 | reg_rule->flags) || |
| 5044 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5045 | freq_range->start_freq_khz) || |
| 5046 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5047 | freq_range->end_freq_khz) || |
| 5048 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 5049 | freq_range->max_bandwidth_khz) || |
| 5050 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5051 | power_rule->max_antenna_gain) || |
| 5052 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 5053 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5054 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5055 | |
| 5056 | nla_nest_end(msg, nl_reg_rule); |
| 5057 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5058 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5059 | |
| 5060 | nla_nest_end(msg, nl_reg_rules); |
| 5061 | |
| 5062 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5063 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5064 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5065 | nla_put_failure_rcu: |
| 5066 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5067 | nla_put_failure: |
| 5068 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5069 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5070 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5071 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5072 | } |
| 5073 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5074 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5075 | { |
| 5076 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5077 | struct nlattr *nl_reg_rule; |
| 5078 | char *alpha2 = NULL; |
| 5079 | int rem_reg_rules = 0, r = 0; |
| 5080 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5081 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5082 | struct ieee80211_regdomain *rd = NULL; |
| 5083 | |
| 5084 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5085 | return -EINVAL; |
| 5086 | |
| 5087 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5088 | return -EINVAL; |
| 5089 | |
| 5090 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5091 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5092 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5093 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5094 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5095 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5096 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5097 | num_rules++; |
| 5098 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5099 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5100 | } |
| 5101 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5102 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5103 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5104 | |
| 5105 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5106 | if (!rd) |
| 5107 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5108 | |
| 5109 | rd->n_reg_rules = num_rules; |
| 5110 | rd->alpha2[0] = alpha2[0]; |
| 5111 | rd->alpha2[1] = alpha2[1]; |
| 5112 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5113 | /* |
| 5114 | * Disable DFS master mode if the DFS region was |
| 5115 | * not supported or known on this kernel. |
| 5116 | */ |
| 5117 | if (reg_supported_dfs_region(dfs_region)) |
| 5118 | rd->dfs_region = dfs_region; |
| 5119 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5120 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5121 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5122 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5123 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5124 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5125 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5126 | if (r) |
| 5127 | goto bad_reg; |
| 5128 | |
| 5129 | rule_idx++; |
| 5130 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5131 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5132 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5133 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5134 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5135 | } |
| 5136 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5137 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5138 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5139 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5140 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5141 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5142 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5143 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5144 | } |
| 5145 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5146 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5147 | { |
| 5148 | struct nlattr *attr1, *attr2; |
| 5149 | int n_channels = 0, tmp1, tmp2; |
| 5150 | |
| 5151 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5152 | n_channels++; |
| 5153 | /* |
| 5154 | * Some hardware has a limited channel list for |
| 5155 | * scanning, and it is pretty much nonsensical |
| 5156 | * to scan for a channel twice, so disallow that |
| 5157 | * and don't require drivers to check that the |
| 5158 | * channel list they get isn't longer than what |
| 5159 | * they can scan, as long as they can scan all |
| 5160 | * the channels they registered at once. |
| 5161 | */ |
| 5162 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5163 | if (attr1 != attr2 && |
| 5164 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5165 | return 0; |
| 5166 | } |
| 5167 | |
| 5168 | return n_channels; |
| 5169 | } |
| 5170 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5171 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5172 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5173 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5174 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5175 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5176 | struct nlattr *attr; |
| 5177 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5178 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5179 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5180 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5181 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5182 | return -EINVAL; |
| 5183 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5184 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5185 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5186 | if (!rdev->ops->scan) |
| 5187 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5188 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5189 | if (rdev->scan_req) { |
| 5190 | err = -EBUSY; |
| 5191 | goto unlock; |
| 5192 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5193 | |
| 5194 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5195 | n_channels = validate_scan_freqs( |
| 5196 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5197 | if (!n_channels) { |
| 5198 | err = -EINVAL; |
| 5199 | goto unlock; |
| 5200 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5201 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5202 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5203 | n_channels = 0; |
| 5204 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5205 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5206 | if (wiphy->bands[band]) |
| 5207 | n_channels += wiphy->bands[band]->n_channels; |
| 5208 | } |
| 5209 | |
| 5210 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5211 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5212 | n_ssids++; |
| 5213 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5214 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5215 | err = -EINVAL; |
| 5216 | goto unlock; |
| 5217 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5218 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5219 | if (info->attrs[NL80211_ATTR_IE]) |
| 5220 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5221 | else |
| 5222 | ie_len = 0; |
| 5223 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5224 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5225 | err = -EINVAL; |
| 5226 | goto unlock; |
| 5227 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5228 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5229 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5230 | + sizeof(*request->ssids) * n_ssids |
| 5231 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5232 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5233 | if (!request) { |
| 5234 | err = -ENOMEM; |
| 5235 | goto unlock; |
| 5236 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5237 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5238 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5239 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5240 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5241 | if (ie_len) { |
| 5242 | if (request->ssids) |
| 5243 | request->ie = (void *)(request->ssids + n_ssids); |
| 5244 | else |
| 5245 | request->ie = (void *)(request->channels + n_channels); |
| 5246 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5247 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5248 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5249 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5250 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5251 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5252 | struct ieee80211_channel *chan; |
| 5253 | |
| 5254 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5255 | |
| 5256 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5257 | err = -EINVAL; |
| 5258 | goto out_free; |
| 5259 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5260 | |
| 5261 | /* ignore disabled channels */ |
| 5262 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5263 | continue; |
| 5264 | |
| 5265 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5266 | i++; |
| 5267 | } |
| 5268 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5269 | enum ieee80211_band band; |
| 5270 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5271 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5272 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5273 | int j; |
| 5274 | if (!wiphy->bands[band]) |
| 5275 | continue; |
| 5276 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5277 | struct ieee80211_channel *chan; |
| 5278 | |
| 5279 | chan = &wiphy->bands[band]->channels[j]; |
| 5280 | |
| 5281 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5282 | continue; |
| 5283 | |
| 5284 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5285 | i++; |
| 5286 | } |
| 5287 | } |
| 5288 | } |
| 5289 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5290 | if (!i) { |
| 5291 | err = -EINVAL; |
| 5292 | goto out_free; |
| 5293 | } |
| 5294 | |
| 5295 | request->n_channels = i; |
| 5296 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5297 | i = 0; |
| 5298 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5299 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5300 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5301 | err = -EINVAL; |
| 5302 | goto out_free; |
| 5303 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5304 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5305 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5306 | i++; |
| 5307 | } |
| 5308 | } |
| 5309 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5310 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5311 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5312 | memcpy((void *)request->ie, |
| 5313 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5314 | request->ie_len); |
| 5315 | } |
| 5316 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5317 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5318 | if (wiphy->bands[i]) |
| 5319 | request->rates[i] = |
| 5320 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5321 | |
| 5322 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5323 | nla_for_each_nested(attr, |
| 5324 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5325 | tmp) { |
| 5326 | enum ieee80211_band band = nla_type(attr); |
| 5327 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5328 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5329 | err = -EINVAL; |
| 5330 | goto out_free; |
| 5331 | } |
| 5332 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5333 | nla_data(attr), |
| 5334 | nla_len(attr), |
| 5335 | &request->rates[band]); |
| 5336 | if (err) |
| 5337 | goto out_free; |
| 5338 | } |
| 5339 | } |
| 5340 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5341 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5342 | request->flags = nla_get_u32( |
| 5343 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5344 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5345 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5346 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5347 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5348 | err = -EOPNOTSUPP; |
| 5349 | goto out_free; |
| 5350 | } |
| 5351 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5352 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5353 | request->no_cck = |
| 5354 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5355 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5356 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5357 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5358 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5359 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5360 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5361 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5362 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5363 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5364 | nl80211_send_scan_start(rdev, wdev); |
| 5365 | if (wdev->netdev) |
| 5366 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5367 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5368 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5369 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5370 | kfree(request); |
| 5371 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5372 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5373 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5374 | return err; |
| 5375 | } |
| 5376 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5377 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5378 | struct genl_info *info) |
| 5379 | { |
| 5380 | struct cfg80211_sched_scan_request *request; |
| 5381 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5382 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5383 | struct nlattr *attr; |
| 5384 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5385 | 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] | 5386 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5387 | enum ieee80211_band band; |
| 5388 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5389 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5390 | |
| 5391 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5392 | !rdev->ops->sched_scan_start) |
| 5393 | return -EOPNOTSUPP; |
| 5394 | |
| 5395 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5396 | return -EINVAL; |
| 5397 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5398 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5399 | return -EINVAL; |
| 5400 | |
| 5401 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5402 | if (interval == 0) |
| 5403 | return -EINVAL; |
| 5404 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5405 | wiphy = &rdev->wiphy; |
| 5406 | |
| 5407 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5408 | n_channels = validate_scan_freqs( |
| 5409 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5410 | if (!n_channels) |
| 5411 | return -EINVAL; |
| 5412 | } else { |
| 5413 | n_channels = 0; |
| 5414 | |
| 5415 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5416 | if (wiphy->bands[band]) |
| 5417 | n_channels += wiphy->bands[band]->n_channels; |
| 5418 | } |
| 5419 | |
| 5420 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5421 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5422 | tmp) |
| 5423 | n_ssids++; |
| 5424 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5425 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5426 | return -EINVAL; |
| 5427 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5428 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5429 | nla_for_each_nested(attr, |
| 5430 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5431 | tmp) |
| 5432 | n_match_sets++; |
| 5433 | |
| 5434 | if (n_match_sets > wiphy->max_match_sets) |
| 5435 | return -EINVAL; |
| 5436 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5437 | if (info->attrs[NL80211_ATTR_IE]) |
| 5438 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5439 | else |
| 5440 | ie_len = 0; |
| 5441 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5442 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5443 | return -EINVAL; |
| 5444 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5445 | if (rdev->sched_scan_req) { |
| 5446 | err = -EINPROGRESS; |
| 5447 | goto out; |
| 5448 | } |
| 5449 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5450 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5451 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5452 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5453 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5454 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5455 | if (!request) { |
| 5456 | err = -ENOMEM; |
| 5457 | goto out; |
| 5458 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5459 | |
| 5460 | if (n_ssids) |
| 5461 | request->ssids = (void *)&request->channels[n_channels]; |
| 5462 | request->n_ssids = n_ssids; |
| 5463 | if (ie_len) { |
| 5464 | if (request->ssids) |
| 5465 | request->ie = (void *)(request->ssids + n_ssids); |
| 5466 | else |
| 5467 | request->ie = (void *)(request->channels + n_channels); |
| 5468 | } |
| 5469 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5470 | if (n_match_sets) { |
| 5471 | if (request->ie) |
| 5472 | request->match_sets = (void *)(request->ie + ie_len); |
| 5473 | else if (request->ssids) |
| 5474 | request->match_sets = |
| 5475 | (void *)(request->ssids + n_ssids); |
| 5476 | else |
| 5477 | request->match_sets = |
| 5478 | (void *)(request->channels + n_channels); |
| 5479 | } |
| 5480 | request->n_match_sets = n_match_sets; |
| 5481 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5482 | i = 0; |
| 5483 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5484 | /* user specified, bail out if channel not found */ |
| 5485 | nla_for_each_nested(attr, |
| 5486 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5487 | tmp) { |
| 5488 | struct ieee80211_channel *chan; |
| 5489 | |
| 5490 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5491 | |
| 5492 | if (!chan) { |
| 5493 | err = -EINVAL; |
| 5494 | goto out_free; |
| 5495 | } |
| 5496 | |
| 5497 | /* ignore disabled channels */ |
| 5498 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5499 | continue; |
| 5500 | |
| 5501 | request->channels[i] = chan; |
| 5502 | i++; |
| 5503 | } |
| 5504 | } else { |
| 5505 | /* all channels */ |
| 5506 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5507 | int j; |
| 5508 | if (!wiphy->bands[band]) |
| 5509 | continue; |
| 5510 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5511 | struct ieee80211_channel *chan; |
| 5512 | |
| 5513 | chan = &wiphy->bands[band]->channels[j]; |
| 5514 | |
| 5515 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5516 | continue; |
| 5517 | |
| 5518 | request->channels[i] = chan; |
| 5519 | i++; |
| 5520 | } |
| 5521 | } |
| 5522 | } |
| 5523 | |
| 5524 | if (!i) { |
| 5525 | err = -EINVAL; |
| 5526 | goto out_free; |
| 5527 | } |
| 5528 | |
| 5529 | request->n_channels = i; |
| 5530 | |
| 5531 | i = 0; |
| 5532 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5533 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5534 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5535 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5536 | err = -EINVAL; |
| 5537 | goto out_free; |
| 5538 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5539 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5540 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5541 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5542 | i++; |
| 5543 | } |
| 5544 | } |
| 5545 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5546 | i = 0; |
| 5547 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5548 | nla_for_each_nested(attr, |
| 5549 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5550 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5551 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5552 | |
| 5553 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5554 | nla_data(attr), nla_len(attr), |
| 5555 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5556 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5557 | if (ssid) { |
| 5558 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5559 | err = -EINVAL; |
| 5560 | goto out_free; |
| 5561 | } |
| 5562 | memcpy(request->match_sets[i].ssid.ssid, |
| 5563 | nla_data(ssid), nla_len(ssid)); |
| 5564 | request->match_sets[i].ssid.ssid_len = |
| 5565 | nla_len(ssid); |
| 5566 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5567 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5568 | if (rssi) |
| 5569 | request->rssi_thold = nla_get_u32(rssi); |
| 5570 | else |
| 5571 | request->rssi_thold = |
| 5572 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5573 | i++; |
| 5574 | } |
| 5575 | } |
| 5576 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5577 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5578 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5579 | memcpy((void *)request->ie, |
| 5580 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5581 | request->ie_len); |
| 5582 | } |
| 5583 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5584 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5585 | request->flags = nla_get_u32( |
| 5586 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5587 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5588 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5589 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5590 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5591 | err = -EOPNOTSUPP; |
| 5592 | goto out_free; |
| 5593 | } |
| 5594 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5595 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5596 | request->dev = dev; |
| 5597 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5598 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5599 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5600 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5601 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5602 | if (!err) { |
| 5603 | rdev->sched_scan_req = request; |
| 5604 | nl80211_send_sched_scan(rdev, dev, |
| 5605 | NL80211_CMD_START_SCHED_SCAN); |
| 5606 | goto out; |
| 5607 | } |
| 5608 | |
| 5609 | out_free: |
| 5610 | kfree(request); |
| 5611 | out: |
| 5612 | return err; |
| 5613 | } |
| 5614 | |
| 5615 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5616 | struct genl_info *info) |
| 5617 | { |
| 5618 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5619 | |
| 5620 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5621 | !rdev->ops->sched_scan_stop) |
| 5622 | return -EOPNOTSUPP; |
| 5623 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5624 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5625 | } |
| 5626 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5627 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5628 | struct genl_info *info) |
| 5629 | { |
| 5630 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5631 | struct net_device *dev = info->user_ptr[1]; |
| 5632 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5633 | struct cfg80211_chan_def chandef; |
| 5634 | int err; |
| 5635 | |
| 5636 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5637 | if (err) |
| 5638 | return err; |
| 5639 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5640 | if (netif_carrier_ok(dev)) |
| 5641 | return -EBUSY; |
| 5642 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5643 | if (wdev->cac_started) |
| 5644 | return -EBUSY; |
| 5645 | |
| 5646 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5647 | if (err < 0) |
| 5648 | return err; |
| 5649 | |
| 5650 | if (err == 0) |
| 5651 | return -EINVAL; |
| 5652 | |
| 5653 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5654 | return -EINVAL; |
| 5655 | |
| 5656 | if (!rdev->ops->start_radar_detection) |
| 5657 | return -EOPNOTSUPP; |
| 5658 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5659 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5660 | chandef.chan, CHAN_MODE_SHARED, |
| 5661 | BIT(chandef.width)); |
| 5662 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5663 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5664 | |
| 5665 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5666 | if (!err) { |
| 5667 | wdev->channel = chandef.chan; |
| 5668 | wdev->cac_started = true; |
| 5669 | wdev->cac_start_time = jiffies; |
| 5670 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5671 | return err; |
| 5672 | } |
| 5673 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5674 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5675 | { |
| 5676 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5677 | struct net_device *dev = info->user_ptr[1]; |
| 5678 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5679 | struct cfg80211_csa_settings params; |
| 5680 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5681 | * function is called under RTNL lock, so this should not be a problem. |
| 5682 | */ |
| 5683 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5684 | u8 radar_detect_width = 0; |
| 5685 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5686 | bool need_new_beacon = false; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5687 | |
| 5688 | if (!rdev->ops->channel_switch || |
| 5689 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5690 | return -EOPNOTSUPP; |
| 5691 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5692 | switch (dev->ieee80211_ptr->iftype) { |
| 5693 | case NL80211_IFTYPE_AP: |
| 5694 | case NL80211_IFTYPE_P2P_GO: |
| 5695 | need_new_beacon = true; |
| 5696 | |
| 5697 | /* useless if AP is not running */ |
| 5698 | if (!wdev->beacon_interval) |
| 5699 | return -EINVAL; |
| 5700 | break; |
| 5701 | case NL80211_IFTYPE_ADHOC: |
| 5702 | break; |
| 5703 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5704 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5705 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5706 | |
| 5707 | memset(¶ms, 0, sizeof(params)); |
| 5708 | |
| 5709 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5710 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5711 | return -EINVAL; |
| 5712 | |
| 5713 | /* only important for AP, IBSS and mesh create IEs internally */ |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5714 | if (need_new_beacon && |
| 5715 | (!info->attrs[NL80211_ATTR_CSA_IES] || |
| 5716 | !info->attrs[NL80211_ATTR_CSA_C_OFF_BEACON])) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5717 | return -EINVAL; |
| 5718 | |
| 5719 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5720 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5721 | if (!need_new_beacon) |
| 5722 | goto skip_beacons; |
| 5723 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5724 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5725 | if (err) |
| 5726 | return err; |
| 5727 | |
| 5728 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5729 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5730 | nl80211_policy); |
| 5731 | if (err) |
| 5732 | return err; |
| 5733 | |
| 5734 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5735 | if (err) |
| 5736 | return err; |
| 5737 | |
| 5738 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5739 | return -EINVAL; |
| 5740 | |
| 5741 | params.counter_offset_beacon = |
| 5742 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5743 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5744 | return -EINVAL; |
| 5745 | |
| 5746 | /* sanity check - counters should be the same */ |
| 5747 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5748 | params.count) |
| 5749 | return -EINVAL; |
| 5750 | |
| 5751 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5752 | params.counter_offset_presp = |
| 5753 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5754 | if (params.counter_offset_presp >= |
| 5755 | params.beacon_csa.probe_resp_len) |
| 5756 | return -EINVAL; |
| 5757 | |
| 5758 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5759 | params.count) |
| 5760 | return -EINVAL; |
| 5761 | } |
| 5762 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5763 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5764 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5765 | if (err) |
| 5766 | return err; |
| 5767 | |
| 5768 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5769 | return -EINVAL; |
| 5770 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5771 | /* DFS channels are only supported for AP/P2P GO ... for now. */ |
| 5772 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
| 5773 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO) { |
| 5774 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 5775 | ¶ms.chandef); |
| 5776 | if (err < 0) { |
| 5777 | return err; |
| 5778 | } else if (err) { |
| 5779 | radar_detect_width = BIT(params.chandef.width); |
| 5780 | params.radar_required = true; |
| 5781 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5785 | params.chandef.chan, |
| 5786 | CHAN_MODE_SHARED, |
| 5787 | radar_detect_width); |
| 5788 | if (err) |
| 5789 | return err; |
| 5790 | |
| 5791 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5792 | params.block_tx = true; |
| 5793 | |
| 5794 | return rdev_channel_switch(rdev, dev, ¶ms); |
| 5795 | } |
| 5796 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5797 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5798 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5799 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5800 | struct wireless_dev *wdev, |
| 5801 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5802 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5803 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5804 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5805 | void *hdr; |
| 5806 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5807 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5808 | |
| 5809 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5810 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5811 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5812 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5813 | if (!hdr) |
| 5814 | return -1; |
| 5815 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5816 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5817 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5818 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5819 | goto nla_put_failure; |
| 5820 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5821 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5822 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5823 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5824 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5825 | |
| 5826 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5827 | if (!bss) |
| 5828 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5829 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5830 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5831 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5832 | |
| 5833 | rcu_read_lock(); |
| 5834 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5835 | if (ies) { |
| 5836 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5837 | goto fail_unlock_rcu; |
| 5838 | tsf = true; |
| 5839 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5840 | ies->len, ies->data)) |
| 5841 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5842 | } |
| 5843 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5844 | if (ies) { |
| 5845 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5846 | goto fail_unlock_rcu; |
| 5847 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5848 | ies->len, ies->data)) |
| 5849 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5850 | } |
| 5851 | rcu_read_unlock(); |
| 5852 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5853 | if (res->beacon_interval && |
| 5854 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5855 | goto nla_put_failure; |
| 5856 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5857 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 5858 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5859 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5860 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5861 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5862 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5863 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5864 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5865 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5866 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5867 | break; |
| 5868 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5869 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5870 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5871 | break; |
| 5872 | default: |
| 5873 | break; |
| 5874 | } |
| 5875 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5876 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5877 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5878 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5879 | if (intbss == wdev->current_bss && |
| 5880 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5881 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5882 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5883 | break; |
| 5884 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5885 | if (intbss == wdev->current_bss && |
| 5886 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5887 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5888 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5889 | break; |
| 5890 | default: |
| 5891 | break; |
| 5892 | } |
| 5893 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5894 | nla_nest_end(msg, bss); |
| 5895 | |
| 5896 | return genlmsg_end(msg, hdr); |
| 5897 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5898 | fail_unlock_rcu: |
| 5899 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5900 | nla_put_failure: |
| 5901 | genlmsg_cancel(msg, hdr); |
| 5902 | return -EMSGSIZE; |
| 5903 | } |
| 5904 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5905 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5906 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5907 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5908 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5909 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5910 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5911 | int err; |
| 5912 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5913 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5914 | if (err) |
| 5915 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5916 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5917 | wdev_lock(wdev); |
| 5918 | spin_lock_bh(&rdev->bss_lock); |
| 5919 | cfg80211_bss_expire(rdev); |
| 5920 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5921 | cb->seq = rdev->bss_generation; |
| 5922 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5923 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5924 | if (++idx <= start) |
| 5925 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5926 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5927 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5928 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5929 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5930 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5931 | } |
| 5932 | } |
| 5933 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5934 | spin_unlock_bh(&rdev->bss_lock); |
| 5935 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5936 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5937 | cb->args[2] = idx; |
| 5938 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5939 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5940 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5941 | } |
| 5942 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5943 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5944 | int flags, struct net_device *dev, |
| 5945 | struct survey_info *survey) |
| 5946 | { |
| 5947 | void *hdr; |
| 5948 | struct nlattr *infoattr; |
| 5949 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5950 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5951 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5952 | if (!hdr) |
| 5953 | return -ENOMEM; |
| 5954 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5955 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5956 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5957 | |
| 5958 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5959 | if (!infoattr) |
| 5960 | goto nla_put_failure; |
| 5961 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5962 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5963 | survey->channel->center_freq)) |
| 5964 | goto nla_put_failure; |
| 5965 | |
| 5966 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5967 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5968 | goto nla_put_failure; |
| 5969 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5970 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5971 | goto nla_put_failure; |
| 5972 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5973 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5974 | survey->channel_time)) |
| 5975 | goto nla_put_failure; |
| 5976 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5977 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5978 | survey->channel_time_busy)) |
| 5979 | goto nla_put_failure; |
| 5980 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5981 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5982 | survey->channel_time_ext_busy)) |
| 5983 | goto nla_put_failure; |
| 5984 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5985 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5986 | survey->channel_time_rx)) |
| 5987 | goto nla_put_failure; |
| 5988 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5989 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5990 | survey->channel_time_tx)) |
| 5991 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5992 | |
| 5993 | nla_nest_end(msg, infoattr); |
| 5994 | |
| 5995 | return genlmsg_end(msg, hdr); |
| 5996 | |
| 5997 | nla_put_failure: |
| 5998 | genlmsg_cancel(msg, hdr); |
| 5999 | return -EMSGSIZE; |
| 6000 | } |
| 6001 | |
| 6002 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6003 | struct netlink_callback *cb) |
| 6004 | { |
| 6005 | struct survey_info survey; |
| 6006 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6007 | struct wireless_dev *wdev; |
| 6008 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6009 | int res; |
| 6010 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6011 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6012 | if (res) |
| 6013 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6014 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6015 | if (!wdev->netdev) { |
| 6016 | res = -EINVAL; |
| 6017 | goto out_err; |
| 6018 | } |
| 6019 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6020 | if (!dev->ops->dump_survey) { |
| 6021 | res = -EOPNOTSUPP; |
| 6022 | goto out_err; |
| 6023 | } |
| 6024 | |
| 6025 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6026 | struct ieee80211_channel *chan; |
| 6027 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6028 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6029 | if (res == -ENOENT) |
| 6030 | break; |
| 6031 | if (res) |
| 6032 | goto out_err; |
| 6033 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6034 | /* Survey without a channel doesn't make sense */ |
| 6035 | if (!survey.channel) { |
| 6036 | res = -EINVAL; |
| 6037 | goto out; |
| 6038 | } |
| 6039 | |
| 6040 | chan = ieee80211_get_channel(&dev->wiphy, |
| 6041 | survey.channel->center_freq); |
| 6042 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6043 | survey_idx++; |
| 6044 | continue; |
| 6045 | } |
| 6046 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6047 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6048 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6049 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6050 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6051 | goto out; |
| 6052 | survey_idx++; |
| 6053 | } |
| 6054 | |
| 6055 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6056 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6057 | res = skb->len; |
| 6058 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6059 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6060 | return res; |
| 6061 | } |
| 6062 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6063 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6064 | { |
| 6065 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6066 | NL80211_WPA_VERSION_2)); |
| 6067 | } |
| 6068 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6069 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6070 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6071 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6072 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6073 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6074 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6075 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6076 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6077 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6078 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6079 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6080 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6081 | return -EINVAL; |
| 6082 | |
| 6083 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6084 | return -EINVAL; |
| 6085 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6086 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6087 | return -EINVAL; |
| 6088 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6089 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6090 | return -EINVAL; |
| 6091 | |
| 6092 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6093 | return -EINVAL; |
| 6094 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6095 | err = nl80211_parse_key(info, &key); |
| 6096 | if (err) |
| 6097 | return err; |
| 6098 | |
| 6099 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6100 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6101 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6102 | if (!key.p.key || !key.p.key_len) |
| 6103 | return -EINVAL; |
| 6104 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6105 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6106 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6107 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6108 | return -EINVAL; |
| 6109 | if (key.idx > 4) |
| 6110 | return -EINVAL; |
| 6111 | } else { |
| 6112 | key.p.key_len = 0; |
| 6113 | key.p.key = NULL; |
| 6114 | } |
| 6115 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6116 | if (key.idx >= 0) { |
| 6117 | int i; |
| 6118 | bool ok = false; |
| 6119 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6120 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6121 | ok = true; |
| 6122 | break; |
| 6123 | } |
| 6124 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6125 | if (!ok) |
| 6126 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6127 | } |
| 6128 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6129 | if (!rdev->ops->auth) |
| 6130 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6131 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6132 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6133 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6134 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6135 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6136 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6137 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6138 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6139 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6140 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6141 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6142 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6143 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6144 | |
| 6145 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6146 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6147 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6148 | } |
| 6149 | |
| 6150 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6151 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6152 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6153 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6154 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6155 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6156 | return -EINVAL; |
| 6157 | |
| 6158 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6159 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6160 | return -EINVAL; |
| 6161 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6162 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6163 | /* need to include at least Auth Transaction and Status Code */ |
| 6164 | if (sae_data_len < 4) |
| 6165 | return -EINVAL; |
| 6166 | } |
| 6167 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6168 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6169 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6170 | /* |
| 6171 | * Since we no longer track auth state, ignore |
| 6172 | * requests to only change local state. |
| 6173 | */ |
| 6174 | if (local_state_change) |
| 6175 | return 0; |
| 6176 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6177 | wdev_lock(dev->ieee80211_ptr); |
| 6178 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6179 | ssid, ssid_len, ie, ie_len, |
| 6180 | key.p.key, key.p.key_len, key.idx, |
| 6181 | sae_data, sae_data_len); |
| 6182 | wdev_unlock(dev->ieee80211_ptr); |
| 6183 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6184 | } |
| 6185 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6186 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6187 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6188 | struct cfg80211_crypto_settings *settings, |
| 6189 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6190 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6191 | memset(settings, 0, sizeof(*settings)); |
| 6192 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6193 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6194 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6195 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6196 | u16 proto; |
| 6197 | proto = nla_get_u16( |
| 6198 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6199 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6200 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6201 | proto != ETH_P_PAE) |
| 6202 | return -EINVAL; |
| 6203 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6204 | settings->control_port_no_encrypt = true; |
| 6205 | } else |
| 6206 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6207 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6208 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6209 | void *data; |
| 6210 | int len, i; |
| 6211 | |
| 6212 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6213 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6214 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6215 | |
| 6216 | if (len % sizeof(u32)) |
| 6217 | return -EINVAL; |
| 6218 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6219 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6220 | return -EINVAL; |
| 6221 | |
| 6222 | memcpy(settings->ciphers_pairwise, data, len); |
| 6223 | |
| 6224 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6225 | if (!cfg80211_supported_cipher_suite( |
| 6226 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6227 | settings->ciphers_pairwise[i])) |
| 6228 | return -EINVAL; |
| 6229 | } |
| 6230 | |
| 6231 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6232 | settings->cipher_group = |
| 6233 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6234 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6235 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6236 | return -EINVAL; |
| 6237 | } |
| 6238 | |
| 6239 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6240 | settings->wpa_versions = |
| 6241 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6242 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6243 | return -EINVAL; |
| 6244 | } |
| 6245 | |
| 6246 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6247 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6248 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6249 | |
| 6250 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6251 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6252 | settings->n_akm_suites = len / sizeof(u32); |
| 6253 | |
| 6254 | if (len % sizeof(u32)) |
| 6255 | return -EINVAL; |
| 6256 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6257 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6258 | return -EINVAL; |
| 6259 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6260 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6261 | } |
| 6262 | |
| 6263 | return 0; |
| 6264 | } |
| 6265 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6266 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6267 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6268 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6269 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6270 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6271 | struct cfg80211_assoc_request req = {}; |
| 6272 | const u8 *bssid, *ssid; |
| 6273 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6274 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6275 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6276 | return -EINVAL; |
| 6277 | |
| 6278 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6279 | !info->attrs[NL80211_ATTR_SSID] || |
| 6280 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6281 | return -EINVAL; |
| 6282 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6283 | if (!rdev->ops->assoc) |
| 6284 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6285 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6286 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6287 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6288 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6289 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6290 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6291 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6292 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6293 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6294 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6295 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6296 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6297 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6298 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6299 | |
| 6300 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6301 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6302 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6303 | } |
| 6304 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6305 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6306 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6307 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6308 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6309 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6310 | else if (mfp != NL80211_MFP_NO) |
| 6311 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6312 | } |
| 6313 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6314 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6315 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6316 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6317 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6318 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6319 | |
| 6320 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6321 | memcpy(&req.ht_capa_mask, |
| 6322 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6323 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6324 | |
| 6325 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6326 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6327 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6328 | memcpy(&req.ht_capa, |
| 6329 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6330 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6331 | } |
| 6332 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6333 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6334 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6335 | |
| 6336 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6337 | memcpy(&req.vht_capa_mask, |
| 6338 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6339 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6340 | |
| 6341 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6342 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6343 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6344 | memcpy(&req.vht_capa, |
| 6345 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6346 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6347 | } |
| 6348 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6349 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6350 | if (!err) { |
| 6351 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6352 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6353 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6354 | wdev_unlock(dev->ieee80211_ptr); |
| 6355 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6356 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6357 | return err; |
| 6358 | } |
| 6359 | |
| 6360 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6361 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6363 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6364 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6365 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6366 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6367 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6368 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6369 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6370 | return -EINVAL; |
| 6371 | |
| 6372 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6373 | return -EINVAL; |
| 6374 | |
| 6375 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6376 | return -EINVAL; |
| 6377 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6378 | if (!rdev->ops->deauth) |
| 6379 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6380 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6381 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6382 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6383 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6384 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6385 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6386 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6387 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6388 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6389 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6390 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6391 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6392 | |
| 6393 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6394 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6395 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6396 | } |
| 6397 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6398 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6399 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6400 | wdev_lock(dev->ieee80211_ptr); |
| 6401 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6402 | local_state_change); |
| 6403 | wdev_unlock(dev->ieee80211_ptr); |
| 6404 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6405 | } |
| 6406 | |
| 6407 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6408 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6409 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6410 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6411 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6412 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6413 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6414 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6415 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6416 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6417 | return -EINVAL; |
| 6418 | |
| 6419 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6420 | return -EINVAL; |
| 6421 | |
| 6422 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6423 | return -EINVAL; |
| 6424 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6425 | if (!rdev->ops->disassoc) |
| 6426 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6427 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6428 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6429 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6430 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6431 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6432 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6433 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6434 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6435 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6436 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6437 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6438 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6439 | |
| 6440 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6441 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6442 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6443 | } |
| 6444 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6445 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6446 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6447 | wdev_lock(dev->ieee80211_ptr); |
| 6448 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6449 | local_state_change); |
| 6450 | wdev_unlock(dev->ieee80211_ptr); |
| 6451 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6452 | } |
| 6453 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6454 | static bool |
| 6455 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6456 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6457 | int rateval) |
| 6458 | { |
| 6459 | struct wiphy *wiphy = &rdev->wiphy; |
| 6460 | bool found = false; |
| 6461 | int band, i; |
| 6462 | |
| 6463 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6464 | struct ieee80211_supported_band *sband; |
| 6465 | |
| 6466 | sband = wiphy->bands[band]; |
| 6467 | if (!sband) |
| 6468 | continue; |
| 6469 | |
| 6470 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6471 | if (sband->bitrates[i].bitrate == rateval) { |
| 6472 | mcast_rate[band] = i + 1; |
| 6473 | found = true; |
| 6474 | break; |
| 6475 | } |
| 6476 | } |
| 6477 | } |
| 6478 | |
| 6479 | return found; |
| 6480 | } |
| 6481 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6482 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6483 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6484 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6485 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6486 | struct cfg80211_ibss_params ibss; |
| 6487 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6488 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6489 | int err; |
| 6490 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6491 | memset(&ibss, 0, sizeof(ibss)); |
| 6492 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6493 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6494 | return -EINVAL; |
| 6495 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6496 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6497 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6498 | return -EINVAL; |
| 6499 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6500 | ibss.beacon_interval = 100; |
| 6501 | |
| 6502 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6503 | ibss.beacon_interval = |
| 6504 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6505 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6506 | return -EINVAL; |
| 6507 | } |
| 6508 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6509 | if (!rdev->ops->join_ibss) |
| 6510 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6511 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6512 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6513 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6514 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6515 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6516 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6517 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6518 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6519 | |
| 6520 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6521 | return -EINVAL; |
| 6522 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6523 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6524 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6525 | |
| 6526 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6527 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6528 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6529 | } |
| 6530 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6531 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6532 | if (err) |
| 6533 | return err; |
Alexander Simon | 54858ee | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6534 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6535 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6536 | return -EINVAL; |
| 6537 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6538 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6539 | case NL80211_CHAN_WIDTH_5: |
| 6540 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6541 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6542 | break; |
| 6543 | case NL80211_CHAN_WIDTH_20: |
| 6544 | case NL80211_CHAN_WIDTH_40: |
| 6545 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6546 | break; |
| 6547 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6548 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6549 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6550 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6551 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6552 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6553 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6554 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6555 | u8 *rates = |
| 6556 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6557 | int n_rates = |
| 6558 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6559 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6560 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6561 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6562 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6563 | &ibss.basic_rates); |
| 6564 | if (err) |
| 6565 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6566 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6567 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6568 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6569 | memcpy(&ibss.ht_capa_mask, |
| 6570 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6571 | sizeof(ibss.ht_capa_mask)); |
| 6572 | |
| 6573 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6574 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6575 | return -EINVAL; |
| 6576 | memcpy(&ibss.ht_capa, |
| 6577 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6578 | sizeof(ibss.ht_capa)); |
| 6579 | } |
| 6580 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6581 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6582 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6583 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6584 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6585 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6586 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6587 | bool no_ht = false; |
| 6588 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6589 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6590 | info->attrs[NL80211_ATTR_KEYS], |
| 6591 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6592 | if (IS_ERR(connkeys)) |
| 6593 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6594 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6595 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6596 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6597 | kfree(connkeys); |
| 6598 | return -EINVAL; |
| 6599 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6600 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6601 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6602 | ibss.control_port = |
| 6603 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6604 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6605 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6606 | if (err) |
| 6607 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6608 | return err; |
| 6609 | } |
| 6610 | |
| 6611 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6612 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6613 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6614 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6615 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6616 | if (!rdev->ops->leave_ibss) |
| 6617 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6618 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6619 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6620 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6621 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6622 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6623 | } |
| 6624 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6625 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6626 | { |
| 6627 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6628 | struct net_device *dev = info->user_ptr[1]; |
| 6629 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6630 | u32 nla_rate; |
| 6631 | int err; |
| 6632 | |
| 6633 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6634 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6635 | return -EOPNOTSUPP; |
| 6636 | |
| 6637 | if (!rdev->ops->set_mcast_rate) |
| 6638 | return -EOPNOTSUPP; |
| 6639 | |
| 6640 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6641 | |
| 6642 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6643 | return -EINVAL; |
| 6644 | |
| 6645 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6646 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6647 | return -EINVAL; |
| 6648 | |
| 6649 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6650 | |
| 6651 | return err; |
| 6652 | } |
| 6653 | |
| 6654 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6655 | #ifdef CONFIG_NL80211_TESTMODE |
| 6656 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6657 | .name = "testmode", |
| 6658 | }; |
| 6659 | |
| 6660 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6661 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6662 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6663 | struct wireless_dev *wdev = |
| 6664 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6665 | int err; |
| 6666 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6667 | if (!rdev->ops->testmode_cmd) |
| 6668 | return -EOPNOTSUPP; |
| 6669 | |
| 6670 | if (IS_ERR(wdev)) { |
| 6671 | err = PTR_ERR(wdev); |
| 6672 | if (err != -EINVAL) |
| 6673 | return err; |
| 6674 | wdev = NULL; |
| 6675 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6676 | return -EINVAL; |
| 6677 | } |
| 6678 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6679 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6680 | return -EINVAL; |
| 6681 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6682 | rdev->testmode_info = info; |
| 6683 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6684 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6685 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6686 | rdev->testmode_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6687 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6688 | return err; |
| 6689 | } |
| 6690 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6691 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6692 | struct netlink_callback *cb) |
| 6693 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6694 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6695 | int err; |
| 6696 | long phy_idx; |
| 6697 | void *data = NULL; |
| 6698 | int data_len = 0; |
| 6699 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6700 | rtnl_lock(); |
| 6701 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6702 | if (cb->args[0]) { |
| 6703 | /* |
| 6704 | * 0 is a valid index, but not valid for args[0], |
| 6705 | * so we need to offset by 1. |
| 6706 | */ |
| 6707 | phy_idx = cb->args[0] - 1; |
| 6708 | } else { |
| 6709 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6710 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6711 | nl80211_policy); |
| 6712 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6713 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6714 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6715 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6716 | nl80211_fam.attrbuf); |
| 6717 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6718 | err = PTR_ERR(rdev); |
| 6719 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6720 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6721 | phy_idx = rdev->wiphy_idx; |
| 6722 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6723 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6724 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6725 | cb->args[1] = |
| 6726 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6727 | } |
| 6728 | |
| 6729 | if (cb->args[1]) { |
| 6730 | data = nla_data((void *)cb->args[1]); |
| 6731 | data_len = nla_len((void *)cb->args[1]); |
| 6732 | } |
| 6733 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6734 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6735 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6736 | err = -ENOENT; |
| 6737 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6738 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6739 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6740 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6741 | err = -EOPNOTSUPP; |
| 6742 | goto out_err; |
| 6743 | } |
| 6744 | |
| 6745 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6746 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6747 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6748 | NL80211_CMD_TESTMODE); |
| 6749 | struct nlattr *tmdata; |
| 6750 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 6751 | if (!hdr) |
| 6752 | break; |
| 6753 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6754 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6755 | genlmsg_cancel(skb, hdr); |
| 6756 | break; |
| 6757 | } |
| 6758 | |
| 6759 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6760 | if (!tmdata) { |
| 6761 | genlmsg_cancel(skb, hdr); |
| 6762 | break; |
| 6763 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6764 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6765 | nla_nest_end(skb, tmdata); |
| 6766 | |
| 6767 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6768 | genlmsg_cancel(skb, hdr); |
| 6769 | break; |
| 6770 | } else if (err) { |
| 6771 | genlmsg_cancel(skb, hdr); |
| 6772 | goto out_err; |
| 6773 | } |
| 6774 | |
| 6775 | genlmsg_end(skb, hdr); |
| 6776 | } |
| 6777 | |
| 6778 | err = skb->len; |
| 6779 | /* see above */ |
| 6780 | cb->args[0] = phy_idx + 1; |
| 6781 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6782 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6783 | return err; |
| 6784 | } |
| 6785 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6786 | static struct sk_buff * |
| 6787 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6788 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6789 | { |
| 6790 | struct sk_buff *skb; |
| 6791 | void *hdr; |
| 6792 | struct nlattr *data; |
| 6793 | |
| 6794 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6795 | if (!skb) |
| 6796 | return NULL; |
| 6797 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6798 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6799 | if (!hdr) { |
| 6800 | kfree_skb(skb); |
| 6801 | return NULL; |
| 6802 | } |
| 6803 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6804 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6805 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6806 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6807 | |
| 6808 | ((void **)skb->cb)[0] = rdev; |
| 6809 | ((void **)skb->cb)[1] = hdr; |
| 6810 | ((void **)skb->cb)[2] = data; |
| 6811 | |
| 6812 | return skb; |
| 6813 | |
| 6814 | nla_put_failure: |
| 6815 | kfree_skb(skb); |
| 6816 | return NULL; |
| 6817 | } |
| 6818 | |
| 6819 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6820 | int approxlen) |
| 6821 | { |
| 6822 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6823 | |
| 6824 | if (WARN_ON(!rdev->testmode_info)) |
| 6825 | return NULL; |
| 6826 | |
| 6827 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6828 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6829 | rdev->testmode_info->snd_seq, |
| 6830 | GFP_KERNEL); |
| 6831 | } |
| 6832 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6833 | |
| 6834 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6835 | { |
| 6836 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6837 | void *hdr = ((void **)skb->cb)[1]; |
| 6838 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6839 | |
| 6840 | if (WARN_ON(!rdev->testmode_info)) { |
| 6841 | kfree_skb(skb); |
| 6842 | return -EINVAL; |
| 6843 | } |
| 6844 | |
| 6845 | nla_nest_end(skb, data); |
| 6846 | genlmsg_end(skb, hdr); |
| 6847 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6848 | } |
| 6849 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6850 | |
| 6851 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6852 | int approxlen, gfp_t gfp) |
| 6853 | { |
| 6854 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6855 | |
| 6856 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6857 | } |
| 6858 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6859 | |
| 6860 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6861 | { |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6862 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6863 | void *hdr = ((void **)skb->cb)[1]; |
| 6864 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6865 | |
| 6866 | nla_nest_end(skb, data); |
| 6867 | genlmsg_end(skb, hdr); |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6868 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0, |
| 6869 | nl80211_testmode_mcgrp.id, gfp); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6870 | } |
| 6871 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6872 | #endif |
| 6873 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6874 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6875 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6876 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6877 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6878 | struct cfg80211_connect_params connect; |
| 6879 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6880 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6881 | int err; |
| 6882 | |
| 6883 | memset(&connect, 0, sizeof(connect)); |
| 6884 | |
| 6885 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6886 | return -EINVAL; |
| 6887 | |
| 6888 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6889 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6890 | return -EINVAL; |
| 6891 | |
| 6892 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6893 | connect.auth_type = |
| 6894 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6895 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6896 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6897 | return -EINVAL; |
| 6898 | } else |
| 6899 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6900 | |
| 6901 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6902 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6903 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6904 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6905 | if (err) |
| 6906 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6907 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6908 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6909 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6910 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6911 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6912 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6913 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6914 | connect.bg_scan_period = -1; |
| 6915 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6916 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6917 | connect.bg_scan_period = |
| 6918 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6919 | } |
| 6920 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6921 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6922 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6923 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6924 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6925 | |
| 6926 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6927 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6928 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6929 | } |
| 6930 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6931 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6932 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6933 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6934 | connect.mfp != NL80211_MFP_NO) |
| 6935 | return -EINVAL; |
| 6936 | } else { |
| 6937 | connect.mfp = NL80211_MFP_NO; |
| 6938 | } |
| 6939 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6940 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6941 | connect.channel = |
| 6942 | ieee80211_get_channel(wiphy, |
| 6943 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6944 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6945 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6946 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6947 | } |
| 6948 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6949 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6950 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6951 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6952 | if (IS_ERR(connkeys)) |
| 6953 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6954 | } |
| 6955 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6956 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6957 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6958 | |
| 6959 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6960 | memcpy(&connect.ht_capa_mask, |
| 6961 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6962 | sizeof(connect.ht_capa_mask)); |
| 6963 | |
| 6964 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6965 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6966 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6967 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6968 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6969 | memcpy(&connect.ht_capa, |
| 6970 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6971 | sizeof(connect.ht_capa)); |
| 6972 | } |
| 6973 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6974 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6975 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6976 | |
| 6977 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6978 | memcpy(&connect.vht_capa_mask, |
| 6979 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6980 | sizeof(connect.vht_capa_mask)); |
| 6981 | |
| 6982 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 6983 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 6984 | kfree(connkeys); |
| 6985 | return -EINVAL; |
| 6986 | } |
| 6987 | memcpy(&connect.vht_capa, |
| 6988 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6989 | sizeof(connect.vht_capa)); |
| 6990 | } |
| 6991 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6992 | wdev_lock(dev->ieee80211_ptr); |
| 6993 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 6994 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6995 | if (err) |
| 6996 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6997 | return err; |
| 6998 | } |
| 6999 | |
| 7000 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7001 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7003 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7004 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7005 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7006 | |
| 7007 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7008 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7009 | else |
| 7010 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7011 | |
| 7012 | if (reason == 0) |
| 7013 | return -EINVAL; |
| 7014 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7015 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7016 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7017 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7018 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7019 | wdev_lock(dev->ieee80211_ptr); |
| 7020 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7021 | wdev_unlock(dev->ieee80211_ptr); |
| 7022 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7023 | } |
| 7024 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7025 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7026 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7028 | struct net *net; |
| 7029 | int err; |
| 7030 | u32 pid; |
| 7031 | |
| 7032 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7033 | return -EINVAL; |
| 7034 | |
| 7035 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7036 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7037 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7038 | if (IS_ERR(net)) |
| 7039 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7040 | |
| 7041 | err = 0; |
| 7042 | |
| 7043 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7044 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7045 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7046 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7047 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7048 | return err; |
| 7049 | } |
| 7050 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7051 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7052 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7053 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7054 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7055 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7056 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7057 | struct cfg80211_pmksa pmksa; |
| 7058 | |
| 7059 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7060 | |
| 7061 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7062 | return -EINVAL; |
| 7063 | |
| 7064 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7065 | return -EINVAL; |
| 7066 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7067 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7068 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7069 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7070 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7071 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7072 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7073 | |
| 7074 | switch (info->genlhdr->cmd) { |
| 7075 | case NL80211_CMD_SET_PMKSA: |
| 7076 | rdev_ops = rdev->ops->set_pmksa; |
| 7077 | break; |
| 7078 | case NL80211_CMD_DEL_PMKSA: |
| 7079 | rdev_ops = rdev->ops->del_pmksa; |
| 7080 | break; |
| 7081 | default: |
| 7082 | WARN_ON(1); |
| 7083 | break; |
| 7084 | } |
| 7085 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7086 | if (!rdev_ops) |
| 7087 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7088 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7089 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7090 | } |
| 7091 | |
| 7092 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7093 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7094 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7095 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7096 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7097 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7098 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7099 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7100 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7101 | if (!rdev->ops->flush_pmksa) |
| 7102 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7103 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7104 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7105 | } |
| 7106 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7107 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7108 | { |
| 7109 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7110 | struct net_device *dev = info->user_ptr[1]; |
| 7111 | u8 action_code, dialog_token; |
| 7112 | u16 status_code; |
| 7113 | u8 *peer; |
| 7114 | |
| 7115 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7116 | !rdev->ops->tdls_mgmt) |
| 7117 | return -EOPNOTSUPP; |
| 7118 | |
| 7119 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7120 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7121 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7122 | !info->attrs[NL80211_ATTR_IE] || |
| 7123 | !info->attrs[NL80211_ATTR_MAC]) |
| 7124 | return -EINVAL; |
| 7125 | |
| 7126 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7127 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7128 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7129 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 7130 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7131 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 7132 | dialog_token, status_code, |
| 7133 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7134 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7135 | } |
| 7136 | |
| 7137 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7138 | { |
| 7139 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7140 | struct net_device *dev = info->user_ptr[1]; |
| 7141 | enum nl80211_tdls_operation operation; |
| 7142 | u8 *peer; |
| 7143 | |
| 7144 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7145 | !rdev->ops->tdls_oper) |
| 7146 | return -EOPNOTSUPP; |
| 7147 | |
| 7148 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7149 | !info->attrs[NL80211_ATTR_MAC]) |
| 7150 | return -EINVAL; |
| 7151 | |
| 7152 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7153 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7154 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7155 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7156 | } |
| 7157 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7158 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7159 | struct genl_info *info) |
| 7160 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7161 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7162 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7163 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7164 | struct sk_buff *msg; |
| 7165 | void *hdr; |
| 7166 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7167 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7168 | int err; |
| 7169 | |
| 7170 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7171 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7172 | return -EINVAL; |
| 7173 | |
| 7174 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7175 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7176 | if (!rdev->ops->remain_on_channel || |
| 7177 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7178 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7179 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7180 | /* |
| 7181 | * We should be on that channel for at least a minimum amount of |
| 7182 | * time (10ms) but no longer than the driver supports. |
| 7183 | */ |
| 7184 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7185 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7186 | return -EINVAL; |
| 7187 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7188 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7189 | if (err) |
| 7190 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7191 | |
| 7192 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7193 | if (!msg) |
| 7194 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7195 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7196 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7197 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7198 | if (!hdr) { |
| 7199 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7200 | goto free_msg; |
| 7201 | } |
| 7202 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7203 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7204 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7205 | |
| 7206 | if (err) |
| 7207 | goto free_msg; |
| 7208 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7209 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7210 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7211 | |
| 7212 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7213 | |
| 7214 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7215 | |
| 7216 | nla_put_failure: |
| 7217 | err = -ENOBUFS; |
| 7218 | free_msg: |
| 7219 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7220 | return err; |
| 7221 | } |
| 7222 | |
| 7223 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7224 | struct genl_info *info) |
| 7225 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7227 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7228 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7229 | |
| 7230 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7231 | return -EINVAL; |
| 7232 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7233 | if (!rdev->ops->cancel_remain_on_channel) |
| 7234 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7235 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7236 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7237 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7238 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7239 | } |
| 7240 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7241 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7242 | u8 *rates, u8 rates_len) |
| 7243 | { |
| 7244 | u8 i; |
| 7245 | u32 mask = 0; |
| 7246 | |
| 7247 | for (i = 0; i < rates_len; i++) { |
| 7248 | int rate = (rates[i] & 0x7f) * 5; |
| 7249 | int ridx; |
| 7250 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7251 | struct ieee80211_rate *srate = |
| 7252 | &sband->bitrates[ridx]; |
| 7253 | if (rate == srate->bitrate) { |
| 7254 | mask |= 1 << ridx; |
| 7255 | break; |
| 7256 | } |
| 7257 | } |
| 7258 | if (ridx == sband->n_bitrates) |
| 7259 | return 0; /* rate not found */ |
| 7260 | } |
| 7261 | |
| 7262 | return mask; |
| 7263 | } |
| 7264 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7265 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7266 | u8 *rates, u8 rates_len, |
| 7267 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7268 | { |
| 7269 | u8 i; |
| 7270 | |
| 7271 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7272 | |
| 7273 | for (i = 0; i < rates_len; i++) { |
| 7274 | int ridx, rbit; |
| 7275 | |
| 7276 | ridx = rates[i] / 8; |
| 7277 | rbit = BIT(rates[i] % 8); |
| 7278 | |
| 7279 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7280 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7281 | return false; |
| 7282 | |
| 7283 | /* check availability */ |
| 7284 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7285 | mcs[ridx] |= rbit; |
| 7286 | else |
| 7287 | return false; |
| 7288 | } |
| 7289 | |
| 7290 | return true; |
| 7291 | } |
| 7292 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7293 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7294 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7295 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7296 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 7297 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7298 | }; |
| 7299 | |
| 7300 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7301 | struct genl_info *info) |
| 7302 | { |
| 7303 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7304 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7305 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7306 | int rem, i; |
| 7307 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7308 | struct nlattr *tx_rates; |
| 7309 | struct ieee80211_supported_band *sband; |
| 7310 | |
| 7311 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7312 | return -EINVAL; |
| 7313 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7314 | if (!rdev->ops->set_bitrate_mask) |
| 7315 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7316 | |
| 7317 | memset(&mask, 0, sizeof(mask)); |
| 7318 | /* Default to all rates enabled */ |
| 7319 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7320 | sband = rdev->wiphy.bands[i]; |
| 7321 | mask.control[i].legacy = |
| 7322 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7323 | if (sband) |
| 7324 | memcpy(mask.control[i].mcs, |
| 7325 | sband->ht_cap.mcs.rx_mask, |
| 7326 | sizeof(mask.control[i].mcs)); |
| 7327 | else |
| 7328 | memset(mask.control[i].mcs, 0, |
| 7329 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7330 | } |
| 7331 | |
| 7332 | /* |
| 7333 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7334 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7335 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7336 | 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] | 7337 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7338 | { |
| 7339 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7340 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7341 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7342 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7343 | if (sband == NULL) |
| 7344 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7345 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7346 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7347 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7348 | mask.control[band].legacy = rateset_to_mask( |
| 7349 | sband, |
| 7350 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7351 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7352 | if ((mask.control[band].legacy == 0) && |
| 7353 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7354 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7355 | } |
| 7356 | if (tb[NL80211_TXRATE_MCS]) { |
| 7357 | if (!ht_rateset_to_mask( |
| 7358 | sband, |
| 7359 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7360 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7361 | mask.control[band].mcs)) |
| 7362 | return -EINVAL; |
| 7363 | } |
| 7364 | |
| 7365 | if (mask.control[band].legacy == 0) { |
| 7366 | /* don't allow empty legacy rates if HT |
| 7367 | * is not even supported. */ |
| 7368 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7369 | return -EINVAL; |
| 7370 | |
| 7371 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7372 | if (mask.control[band].mcs[i]) |
| 7373 | break; |
| 7374 | |
| 7375 | /* legacy and mcs rates may not be both empty */ |
| 7376 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7377 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7378 | } |
| 7379 | } |
| 7380 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7381 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7382 | } |
| 7383 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7384 | 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] | 7385 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7386 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7387 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7388 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7389 | |
| 7390 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7391 | return -EINVAL; |
| 7392 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7393 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7394 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7395 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7396 | switch (wdev->iftype) { |
| 7397 | case NL80211_IFTYPE_STATION: |
| 7398 | case NL80211_IFTYPE_ADHOC: |
| 7399 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7400 | case NL80211_IFTYPE_AP: |
| 7401 | case NL80211_IFTYPE_AP_VLAN: |
| 7402 | case NL80211_IFTYPE_MESH_POINT: |
| 7403 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7404 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7405 | break; |
| 7406 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7407 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7408 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7409 | |
| 7410 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7411 | if (!rdev->ops->mgmt_tx) |
| 7412 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7413 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7414 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7415 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7416 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7417 | } |
| 7418 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7419 | 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] | 7420 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7421 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7422 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7423 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7424 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7425 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7426 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7427 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7428 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7429 | bool offchan, no_cck, dont_wait_for_ack; |
| 7430 | |
| 7431 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7432 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7433 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7434 | return -EINVAL; |
| 7435 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7436 | if (!rdev->ops->mgmt_tx) |
| 7437 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7438 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7439 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7440 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7441 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7442 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7443 | case NL80211_IFTYPE_STATION: |
| 7444 | case NL80211_IFTYPE_ADHOC: |
| 7445 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7446 | case NL80211_IFTYPE_AP: |
| 7447 | case NL80211_IFTYPE_AP_VLAN: |
| 7448 | case NL80211_IFTYPE_MESH_POINT: |
| 7449 | case NL80211_IFTYPE_P2P_GO: |
| 7450 | break; |
| 7451 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7452 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7453 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7454 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7455 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7456 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7457 | return -EINVAL; |
| 7458 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7459 | |
| 7460 | /* |
| 7461 | * We should wait on the channel for at least a minimum amount |
| 7462 | * of time (10ms) but no longer than the driver supports. |
| 7463 | */ |
| 7464 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7465 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7466 | return -EINVAL; |
| 7467 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7468 | } |
| 7469 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7470 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7471 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7472 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7473 | return -EINVAL; |
| 7474 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7475 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7476 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7477 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7478 | * the driver. The latter will use the current one |
| 7479 | */ |
| 7480 | chandef.chan = NULL; |
| 7481 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7482 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7483 | if (err) |
| 7484 | return err; |
| 7485 | } |
| 7486 | |
| 7487 | if (!chandef.chan && offchan) |
| 7488 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7489 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7490 | if (!dont_wait_for_ack) { |
| 7491 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7492 | if (!msg) |
| 7493 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7494 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7495 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7496 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7497 | if (!hdr) { |
| 7498 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7499 | goto free_msg; |
| 7500 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7501 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7502 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7503 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7504 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7505 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7506 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7507 | if (err) |
| 7508 | goto free_msg; |
| 7509 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7510 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7511 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7512 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7513 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7514 | genlmsg_end(msg, hdr); |
| 7515 | return genlmsg_reply(msg, info); |
| 7516 | } |
| 7517 | |
| 7518 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7519 | |
| 7520 | nla_put_failure: |
| 7521 | err = -ENOBUFS; |
| 7522 | free_msg: |
| 7523 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7524 | return err; |
| 7525 | } |
| 7526 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7527 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7528 | { |
| 7529 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7530 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7531 | u64 cookie; |
| 7532 | |
| 7533 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7534 | return -EINVAL; |
| 7535 | |
| 7536 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7537 | return -EOPNOTSUPP; |
| 7538 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7539 | switch (wdev->iftype) { |
| 7540 | case NL80211_IFTYPE_STATION: |
| 7541 | case NL80211_IFTYPE_ADHOC: |
| 7542 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7543 | case NL80211_IFTYPE_AP: |
| 7544 | case NL80211_IFTYPE_AP_VLAN: |
| 7545 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7546 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7547 | break; |
| 7548 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7549 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7550 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7551 | |
| 7552 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7553 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7554 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7555 | } |
| 7556 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7557 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7558 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7559 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7560 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7561 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7562 | u8 ps_state; |
| 7563 | bool state; |
| 7564 | int err; |
| 7565 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7566 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7567 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7568 | |
| 7569 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7570 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7571 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7572 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7573 | |
| 7574 | wdev = dev->ieee80211_ptr; |
| 7575 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7576 | if (!rdev->ops->set_power_mgmt) |
| 7577 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7578 | |
| 7579 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7580 | |
| 7581 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7582 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7583 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7584 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7585 | if (!err) |
| 7586 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7587 | return err; |
| 7588 | } |
| 7589 | |
| 7590 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7591 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7592 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7593 | enum nl80211_ps_state ps_state; |
| 7594 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7595 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7596 | struct sk_buff *msg; |
| 7597 | void *hdr; |
| 7598 | int err; |
| 7599 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7600 | wdev = dev->ieee80211_ptr; |
| 7601 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7602 | if (!rdev->ops->set_power_mgmt) |
| 7603 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7604 | |
| 7605 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7606 | if (!msg) |
| 7607 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7608 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7609 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7610 | NL80211_CMD_GET_POWER_SAVE); |
| 7611 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7612 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7613 | goto free_msg; |
| 7614 | } |
| 7615 | |
| 7616 | if (wdev->ps) |
| 7617 | ps_state = NL80211_PS_ENABLED; |
| 7618 | else |
| 7619 | ps_state = NL80211_PS_DISABLED; |
| 7620 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7621 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7622 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7623 | |
| 7624 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7625 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7626 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7627 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7628 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7629 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7630 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7631 | return err; |
| 7632 | } |
| 7633 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7634 | static struct nla_policy |
| 7635 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7636 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7637 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7638 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7639 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7640 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7641 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7642 | }; |
| 7643 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7644 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7645 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7646 | { |
| 7647 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7648 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7649 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7650 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7651 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7652 | return -EINVAL; |
| 7653 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7654 | if (!rdev->ops->set_cqm_txe_config) |
| 7655 | return -EOPNOTSUPP; |
| 7656 | |
| 7657 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7658 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7659 | return -EOPNOTSUPP; |
| 7660 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7661 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7662 | } |
| 7663 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7664 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7665 | s32 threshold, u32 hysteresis) |
| 7666 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7667 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7668 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7669 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7670 | |
| 7671 | if (threshold > 0) |
| 7672 | return -EINVAL; |
| 7673 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7674 | /* disabling - hysteresis should also be zero then */ |
| 7675 | if (threshold == 0) |
| 7676 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7677 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7678 | if (!rdev->ops->set_cqm_rssi_config) |
| 7679 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7680 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7681 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7682 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7683 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7684 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7685 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7686 | } |
| 7687 | |
| 7688 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7689 | { |
| 7690 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7691 | struct nlattr *cqm; |
| 7692 | int err; |
| 7693 | |
| 7694 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7695 | if (!cqm) |
| 7696 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7697 | |
| 7698 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7699 | nl80211_attr_cqm_policy); |
| 7700 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7701 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7702 | |
| 7703 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7704 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7705 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7706 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7707 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7708 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7709 | } |
| 7710 | |
| 7711 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7712 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7713 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7714 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7715 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7716 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7717 | |
| 7718 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 7719 | } |
| 7720 | |
| 7721 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7722 | } |
| 7723 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7724 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7725 | { |
| 7726 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7727 | struct net_device *dev = info->user_ptr[1]; |
| 7728 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7729 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7730 | int err; |
| 7731 | |
| 7732 | /* start with default */ |
| 7733 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7734 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7735 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7736 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7737 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7738 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7739 | if (err) |
| 7740 | return err; |
| 7741 | } |
| 7742 | |
| 7743 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7744 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7745 | return -EINVAL; |
| 7746 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7747 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7748 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7749 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7750 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7751 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7752 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7753 | return -EINVAL; |
| 7754 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7755 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7756 | setup.beacon_interval = |
| 7757 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7758 | if (setup.beacon_interval < 10 || |
| 7759 | setup.beacon_interval > 10000) |
| 7760 | return -EINVAL; |
| 7761 | } |
| 7762 | |
| 7763 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7764 | setup.dtim_period = |
| 7765 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7766 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7767 | return -EINVAL; |
| 7768 | } |
| 7769 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7770 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7771 | /* parse additional setup parameters if given */ |
| 7772 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7773 | if (err) |
| 7774 | return err; |
| 7775 | } |
| 7776 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7777 | if (setup.user_mpm) |
| 7778 | cfg.auto_open_plinks = false; |
| 7779 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7780 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7781 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7782 | if (err) |
| 7783 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7784 | } else { |
| 7785 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7786 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7787 | } |
| 7788 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7789 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7790 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7791 | int n_rates = |
| 7792 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7793 | struct ieee80211_supported_band *sband; |
| 7794 | |
| 7795 | if (!setup.chandef.chan) |
| 7796 | return -EINVAL; |
| 7797 | |
| 7798 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7799 | |
| 7800 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7801 | &setup.basic_rates); |
| 7802 | if (err) |
| 7803 | return err; |
| 7804 | } |
| 7805 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7806 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7807 | } |
| 7808 | |
| 7809 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7810 | { |
| 7811 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7812 | struct net_device *dev = info->user_ptr[1]; |
| 7813 | |
| 7814 | return cfg80211_leave_mesh(rdev, dev); |
| 7815 | } |
| 7816 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7817 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7818 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7819 | struct cfg80211_registered_device *rdev) |
| 7820 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7821 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7822 | struct nlattr *nl_pats, *nl_pat; |
| 7823 | int i, pat_len; |
| 7824 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7825 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7826 | return 0; |
| 7827 | |
| 7828 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7829 | if (!nl_pats) |
| 7830 | return -ENOBUFS; |
| 7831 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7832 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7833 | nl_pat = nla_nest_start(msg, i + 1); |
| 7834 | if (!nl_pat) |
| 7835 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7836 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7837 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7838 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7839 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 7840 | wowlan->patterns[i].pattern) || |
| 7841 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7842 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7843 | return -ENOBUFS; |
| 7844 | nla_nest_end(msg, nl_pat); |
| 7845 | } |
| 7846 | nla_nest_end(msg, nl_pats); |
| 7847 | |
| 7848 | return 0; |
| 7849 | } |
| 7850 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7851 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7852 | struct cfg80211_wowlan_tcp *tcp) |
| 7853 | { |
| 7854 | struct nlattr *nl_tcp; |
| 7855 | |
| 7856 | if (!tcp) |
| 7857 | return 0; |
| 7858 | |
| 7859 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7860 | if (!nl_tcp) |
| 7861 | return -ENOBUFS; |
| 7862 | |
| 7863 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7864 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7865 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7866 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7867 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7868 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7869 | tcp->payload_len, tcp->payload) || |
| 7870 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7871 | tcp->data_interval) || |
| 7872 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7873 | tcp->wake_len, tcp->wake_data) || |
| 7874 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7875 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7876 | return -ENOBUFS; |
| 7877 | |
| 7878 | if (tcp->payload_seq.len && |
| 7879 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7880 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7881 | return -ENOBUFS; |
| 7882 | |
| 7883 | if (tcp->payload_tok.len && |
| 7884 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7885 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7886 | &tcp->payload_tok)) |
| 7887 | return -ENOBUFS; |
| 7888 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 7889 | nla_nest_end(msg, nl_tcp); |
| 7890 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7891 | return 0; |
| 7892 | } |
| 7893 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7894 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7895 | { |
| 7896 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7897 | struct sk_buff *msg; |
| 7898 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7899 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7900 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7901 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7902 | return -EOPNOTSUPP; |
| 7903 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7904 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7905 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7906 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 7907 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 7908 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 7909 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7910 | } |
| 7911 | |
| 7912 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7913 | if (!msg) |
| 7914 | return -ENOMEM; |
| 7915 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7916 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7917 | NL80211_CMD_GET_WOWLAN); |
| 7918 | if (!hdr) |
| 7919 | goto nla_put_failure; |
| 7920 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7921 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7922 | struct nlattr *nl_wowlan; |
| 7923 | |
| 7924 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7925 | if (!nl_wowlan) |
| 7926 | goto nla_put_failure; |
| 7927 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7928 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7929 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7930 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7931 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7932 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7933 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7934 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7935 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7936 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7937 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7938 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7939 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7940 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7941 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7942 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7943 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7944 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7945 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7946 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7947 | if (nl80211_send_wowlan_tcp(msg, |
| 7948 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7949 | goto nla_put_failure; |
| 7950 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7951 | nla_nest_end(msg, nl_wowlan); |
| 7952 | } |
| 7953 | |
| 7954 | genlmsg_end(msg, hdr); |
| 7955 | return genlmsg_reply(msg, info); |
| 7956 | |
| 7957 | nla_put_failure: |
| 7958 | nlmsg_free(msg); |
| 7959 | return -ENOBUFS; |
| 7960 | } |
| 7961 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7962 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7963 | struct nlattr *attr, |
| 7964 | struct cfg80211_wowlan *trig) |
| 7965 | { |
| 7966 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7967 | struct cfg80211_wowlan_tcp *cfg; |
| 7968 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7969 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7970 | u32 size; |
| 7971 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7972 | int err, port; |
| 7973 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7974 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7975 | return -EINVAL; |
| 7976 | |
| 7977 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7978 | nla_data(attr), nla_len(attr), |
| 7979 | nl80211_wowlan_tcp_policy); |
| 7980 | if (err) |
| 7981 | return err; |
| 7982 | |
| 7983 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7984 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7985 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7986 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7987 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7988 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7989 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7990 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7991 | return -EINVAL; |
| 7992 | |
| 7993 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7994 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7995 | return -EINVAL; |
| 7996 | |
| 7997 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7998 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 7999 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8000 | return -EINVAL; |
| 8001 | |
| 8002 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8003 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8004 | return -EINVAL; |
| 8005 | |
| 8006 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8007 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8008 | return -EINVAL; |
| 8009 | |
| 8010 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8011 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8012 | |
| 8013 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8014 | tokens_size = tokln - sizeof(*tok); |
| 8015 | |
| 8016 | if (!tok->len || tokens_size % tok->len) |
| 8017 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8018 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8019 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8020 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8021 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8022 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8023 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8024 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8025 | return -EINVAL; |
| 8026 | if (tok->offset + tok->len > data_size) |
| 8027 | return -EINVAL; |
| 8028 | } |
| 8029 | |
| 8030 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8031 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8032 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8033 | return -EINVAL; |
| 8034 | if (seq->len == 0 || seq->len > 4) |
| 8035 | return -EINVAL; |
| 8036 | if (seq->len + seq->offset > data_size) |
| 8037 | return -EINVAL; |
| 8038 | } |
| 8039 | |
| 8040 | size = sizeof(*cfg); |
| 8041 | size += data_size; |
| 8042 | size += wake_size + wake_mask_size; |
| 8043 | size += tokens_size; |
| 8044 | |
| 8045 | cfg = kzalloc(size, GFP_KERNEL); |
| 8046 | if (!cfg) |
| 8047 | return -ENOMEM; |
| 8048 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8049 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8050 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8051 | ETH_ALEN); |
| 8052 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8053 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8054 | else |
| 8055 | port = 0; |
| 8056 | #ifdef CONFIG_INET |
| 8057 | /* allocate a socket and port for it and use it */ |
| 8058 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8059 | IPPROTO_TCP, &cfg->sock, 1); |
| 8060 | if (err) { |
| 8061 | kfree(cfg); |
| 8062 | return err; |
| 8063 | } |
| 8064 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8065 | sock_release(cfg->sock); |
| 8066 | kfree(cfg); |
| 8067 | return -EADDRINUSE; |
| 8068 | } |
| 8069 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8070 | #else |
| 8071 | if (!port) { |
| 8072 | kfree(cfg); |
| 8073 | return -EINVAL; |
| 8074 | } |
| 8075 | cfg->src_port = port; |
| 8076 | #endif |
| 8077 | |
| 8078 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8079 | cfg->payload_len = data_size; |
| 8080 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8081 | memcpy((void *)cfg->payload, |
| 8082 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8083 | data_size); |
| 8084 | if (seq) |
| 8085 | cfg->payload_seq = *seq; |
| 8086 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8087 | cfg->wake_len = wake_size; |
| 8088 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8089 | memcpy((void *)cfg->wake_data, |
| 8090 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8091 | wake_size); |
| 8092 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8093 | data_size + wake_size; |
| 8094 | memcpy((void *)cfg->wake_mask, |
| 8095 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8096 | wake_mask_size); |
| 8097 | if (tok) { |
| 8098 | cfg->tokens_size = tokens_size; |
| 8099 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8100 | } |
| 8101 | |
| 8102 | trig->tcp = cfg; |
| 8103 | |
| 8104 | return 0; |
| 8105 | } |
| 8106 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8107 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8108 | { |
| 8109 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8110 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8111 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8112 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8113 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8114 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8115 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8116 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8117 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8118 | return -EOPNOTSUPP; |
| 8119 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8120 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8121 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8122 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8123 | goto set_wakeup; |
| 8124 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8125 | |
| 8126 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8127 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8128 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8129 | nl80211_wowlan_policy); |
| 8130 | if (err) |
| 8131 | return err; |
| 8132 | |
| 8133 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8134 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8135 | return -EINVAL; |
| 8136 | new_triggers.any = true; |
| 8137 | } |
| 8138 | |
| 8139 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8140 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8141 | return -EINVAL; |
| 8142 | new_triggers.disconnect = true; |
| 8143 | } |
| 8144 | |
| 8145 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8146 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8147 | return -EINVAL; |
| 8148 | new_triggers.magic_pkt = true; |
| 8149 | } |
| 8150 | |
Johannes Berg | 77dbbb13 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8151 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8152 | return -EINVAL; |
| 8153 | |
| 8154 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8155 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8156 | return -EINVAL; |
| 8157 | new_triggers.gtk_rekey_failure = true; |
| 8158 | } |
| 8159 | |
| 8160 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8161 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8162 | return -EINVAL; |
| 8163 | new_triggers.eap_identity_req = true; |
| 8164 | } |
| 8165 | |
| 8166 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8167 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8168 | return -EINVAL; |
| 8169 | new_triggers.four_way_handshake = true; |
| 8170 | } |
| 8171 | |
| 8172 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8173 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8174 | return -EINVAL; |
| 8175 | new_triggers.rfkill_release = true; |
| 8176 | } |
| 8177 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8178 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8179 | struct nlattr *pat; |
| 8180 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8181 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8182 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8183 | |
| 8184 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8185 | rem) |
| 8186 | n_patterns++; |
| 8187 | if (n_patterns > wowlan->n_patterns) |
| 8188 | return -EINVAL; |
| 8189 | |
| 8190 | new_triggers.patterns = kcalloc(n_patterns, |
| 8191 | sizeof(new_triggers.patterns[0]), |
| 8192 | GFP_KERNEL); |
| 8193 | if (!new_triggers.patterns) |
| 8194 | return -ENOMEM; |
| 8195 | |
| 8196 | new_triggers.n_patterns = n_patterns; |
| 8197 | i = 0; |
| 8198 | |
| 8199 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8200 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8201 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8202 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8203 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8204 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8205 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8206 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8207 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8208 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8209 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8210 | goto error; |
| 8211 | if (pat_len > wowlan->pattern_max_len || |
| 8212 | pat_len < wowlan->pattern_min_len) |
| 8213 | goto error; |
| 8214 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8215 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8216 | pkt_offset = 0; |
| 8217 | else |
| 8218 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8219 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8220 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8221 | goto error; |
| 8222 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8223 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8224 | new_triggers.patterns[i].mask = |
| 8225 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8226 | if (!new_triggers.patterns[i].mask) { |
| 8227 | err = -ENOMEM; |
| 8228 | goto error; |
| 8229 | } |
| 8230 | new_triggers.patterns[i].pattern = |
| 8231 | new_triggers.patterns[i].mask + mask_len; |
| 8232 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8233 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8234 | mask_len); |
| 8235 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8236 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8237 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8238 | pat_len); |
| 8239 | i++; |
| 8240 | } |
| 8241 | } |
| 8242 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8243 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8244 | err = nl80211_parse_wowlan_tcp( |
| 8245 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8246 | &new_triggers); |
| 8247 | if (err) |
| 8248 | goto error; |
| 8249 | } |
| 8250 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8251 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8252 | if (!ntrig) { |
| 8253 | err = -ENOMEM; |
| 8254 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8255 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8256 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8257 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8258 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8259 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8260 | if (rdev->ops->set_wakeup && |
| 8261 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8262 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8263 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8264 | return 0; |
| 8265 | error: |
| 8266 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8267 | kfree(new_triggers.patterns[i].mask); |
| 8268 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8269 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8270 | sock_release(new_triggers.tcp->sock); |
| 8271 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8272 | return err; |
| 8273 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8274 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8275 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8276 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8277 | struct cfg80211_registered_device *rdev) |
| 8278 | { |
| 8279 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8280 | int i, j, pat_len; |
| 8281 | struct cfg80211_coalesce_rules *rule; |
| 8282 | |
| 8283 | if (!rdev->coalesce->n_rules) |
| 8284 | return 0; |
| 8285 | |
| 8286 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8287 | if (!nl_rules) |
| 8288 | return -ENOBUFS; |
| 8289 | |
| 8290 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8291 | nl_rule = nla_nest_start(msg, i + 1); |
| 8292 | if (!nl_rule) |
| 8293 | return -ENOBUFS; |
| 8294 | |
| 8295 | rule = &rdev->coalesce->rules[i]; |
| 8296 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8297 | rule->delay)) |
| 8298 | return -ENOBUFS; |
| 8299 | |
| 8300 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8301 | rule->condition)) |
| 8302 | return -ENOBUFS; |
| 8303 | |
| 8304 | nl_pats = nla_nest_start(msg, |
| 8305 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8306 | if (!nl_pats) |
| 8307 | return -ENOBUFS; |
| 8308 | |
| 8309 | for (j = 0; j < rule->n_patterns; j++) { |
| 8310 | nl_pat = nla_nest_start(msg, j + 1); |
| 8311 | if (!nl_pat) |
| 8312 | return -ENOBUFS; |
| 8313 | pat_len = rule->patterns[j].pattern_len; |
| 8314 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8315 | DIV_ROUND_UP(pat_len, 8), |
| 8316 | rule->patterns[j].mask) || |
| 8317 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8318 | rule->patterns[j].pattern) || |
| 8319 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8320 | rule->patterns[j].pkt_offset)) |
| 8321 | return -ENOBUFS; |
| 8322 | nla_nest_end(msg, nl_pat); |
| 8323 | } |
| 8324 | nla_nest_end(msg, nl_pats); |
| 8325 | nla_nest_end(msg, nl_rule); |
| 8326 | } |
| 8327 | nla_nest_end(msg, nl_rules); |
| 8328 | |
| 8329 | return 0; |
| 8330 | } |
| 8331 | |
| 8332 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8333 | { |
| 8334 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8335 | struct sk_buff *msg; |
| 8336 | void *hdr; |
| 8337 | |
| 8338 | if (!rdev->wiphy.coalesce) |
| 8339 | return -EOPNOTSUPP; |
| 8340 | |
| 8341 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8342 | if (!msg) |
| 8343 | return -ENOMEM; |
| 8344 | |
| 8345 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8346 | NL80211_CMD_GET_COALESCE); |
| 8347 | if (!hdr) |
| 8348 | goto nla_put_failure; |
| 8349 | |
| 8350 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8351 | goto nla_put_failure; |
| 8352 | |
| 8353 | genlmsg_end(msg, hdr); |
| 8354 | return genlmsg_reply(msg, info); |
| 8355 | |
| 8356 | nla_put_failure: |
| 8357 | nlmsg_free(msg); |
| 8358 | return -ENOBUFS; |
| 8359 | } |
| 8360 | |
| 8361 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8362 | { |
| 8363 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8364 | int i, j; |
| 8365 | struct cfg80211_coalesce_rules *rule; |
| 8366 | |
| 8367 | if (!coalesce) |
| 8368 | return; |
| 8369 | |
| 8370 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8371 | rule = &coalesce->rules[i]; |
| 8372 | for (j = 0; j < rule->n_patterns; j++) |
| 8373 | kfree(rule->patterns[j].mask); |
| 8374 | kfree(rule->patterns); |
| 8375 | } |
| 8376 | kfree(coalesce->rules); |
| 8377 | kfree(coalesce); |
| 8378 | rdev->coalesce = NULL; |
| 8379 | } |
| 8380 | |
| 8381 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8382 | struct nlattr *rule, |
| 8383 | struct cfg80211_coalesce_rules *new_rule) |
| 8384 | { |
| 8385 | int err, i; |
| 8386 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8387 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8388 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8389 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8390 | |
| 8391 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8392 | nla_len(rule), nl80211_coalesce_policy); |
| 8393 | if (err) |
| 8394 | return err; |
| 8395 | |
| 8396 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8397 | new_rule->delay = |
| 8398 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8399 | if (new_rule->delay > coalesce->max_delay) |
| 8400 | return -EINVAL; |
| 8401 | |
| 8402 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8403 | new_rule->condition = |
| 8404 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8405 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8406 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8407 | return -EINVAL; |
| 8408 | |
| 8409 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8410 | return -EINVAL; |
| 8411 | |
| 8412 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8413 | rem) |
| 8414 | n_patterns++; |
| 8415 | if (n_patterns > coalesce->n_patterns) |
| 8416 | return -EINVAL; |
| 8417 | |
| 8418 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8419 | GFP_KERNEL); |
| 8420 | if (!new_rule->patterns) |
| 8421 | return -ENOMEM; |
| 8422 | |
| 8423 | new_rule->n_patterns = n_patterns; |
| 8424 | i = 0; |
| 8425 | |
| 8426 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8427 | rem) { |
| 8428 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8429 | nla_len(pat), NULL); |
| 8430 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8431 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8432 | return -EINVAL; |
| 8433 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8434 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8435 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8436 | return -EINVAL; |
| 8437 | if (pat_len > coalesce->pattern_max_len || |
| 8438 | pat_len < coalesce->pattern_min_len) |
| 8439 | return -EINVAL; |
| 8440 | |
| 8441 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8442 | pkt_offset = 0; |
| 8443 | else |
| 8444 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8445 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8446 | return -EINVAL; |
| 8447 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8448 | |
| 8449 | new_rule->patterns[i].mask = |
| 8450 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8451 | if (!new_rule->patterns[i].mask) |
| 8452 | return -ENOMEM; |
| 8453 | new_rule->patterns[i].pattern = |
| 8454 | new_rule->patterns[i].mask + mask_len; |
| 8455 | memcpy(new_rule->patterns[i].mask, |
| 8456 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8457 | new_rule->patterns[i].pattern_len = pat_len; |
| 8458 | memcpy(new_rule->patterns[i].pattern, |
| 8459 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8460 | i++; |
| 8461 | } |
| 8462 | |
| 8463 | return 0; |
| 8464 | } |
| 8465 | |
| 8466 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8467 | { |
| 8468 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8469 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8470 | struct cfg80211_coalesce new_coalesce = {}; |
| 8471 | struct cfg80211_coalesce *n_coalesce; |
| 8472 | int err, rem_rule, n_rules = 0, i, j; |
| 8473 | struct nlattr *rule; |
| 8474 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8475 | |
| 8476 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8477 | return -EOPNOTSUPP; |
| 8478 | |
| 8479 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8480 | cfg80211_rdev_free_coalesce(rdev); |
| 8481 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8482 | return 0; |
| 8483 | } |
| 8484 | |
| 8485 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8486 | rem_rule) |
| 8487 | n_rules++; |
| 8488 | if (n_rules > coalesce->n_rules) |
| 8489 | return -EINVAL; |
| 8490 | |
| 8491 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8492 | GFP_KERNEL); |
| 8493 | if (!new_coalesce.rules) |
| 8494 | return -ENOMEM; |
| 8495 | |
| 8496 | new_coalesce.n_rules = n_rules; |
| 8497 | i = 0; |
| 8498 | |
| 8499 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8500 | rem_rule) { |
| 8501 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8502 | &new_coalesce.rules[i]); |
| 8503 | if (err) |
| 8504 | goto error; |
| 8505 | |
| 8506 | i++; |
| 8507 | } |
| 8508 | |
| 8509 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8510 | if (err) |
| 8511 | goto error; |
| 8512 | |
| 8513 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8514 | if (!n_coalesce) { |
| 8515 | err = -ENOMEM; |
| 8516 | goto error; |
| 8517 | } |
| 8518 | cfg80211_rdev_free_coalesce(rdev); |
| 8519 | rdev->coalesce = n_coalesce; |
| 8520 | |
| 8521 | return 0; |
| 8522 | error: |
| 8523 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8524 | tmp_rule = &new_coalesce.rules[i]; |
| 8525 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8526 | kfree(tmp_rule->patterns[j].mask); |
| 8527 | kfree(tmp_rule->patterns); |
| 8528 | } |
| 8529 | kfree(new_coalesce.rules); |
| 8530 | |
| 8531 | return err; |
| 8532 | } |
| 8533 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8534 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8535 | { |
| 8536 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8537 | struct net_device *dev = info->user_ptr[1]; |
| 8538 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8539 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8540 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8541 | int err; |
| 8542 | |
| 8543 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8544 | return -EINVAL; |
| 8545 | |
| 8546 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8547 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8548 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8549 | nl80211_rekey_policy); |
| 8550 | if (err) |
| 8551 | return err; |
| 8552 | |
| 8553 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8554 | return -ERANGE; |
| 8555 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8556 | return -ERANGE; |
| 8557 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8558 | return -ERANGE; |
| 8559 | |
| 8560 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8561 | NL80211_KEK_LEN); |
| 8562 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8563 | NL80211_KCK_LEN); |
| 8564 | memcpy(rekey_data.replay_ctr, |
| 8565 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8566 | NL80211_REPLAY_CTR_LEN); |
| 8567 | |
| 8568 | wdev_lock(wdev); |
| 8569 | if (!wdev->current_bss) { |
| 8570 | err = -ENOTCONN; |
| 8571 | goto out; |
| 8572 | } |
| 8573 | |
| 8574 | if (!rdev->ops->set_rekey_data) { |
| 8575 | err = -EOPNOTSUPP; |
| 8576 | goto out; |
| 8577 | } |
| 8578 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8579 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8580 | out: |
| 8581 | wdev_unlock(wdev); |
| 8582 | return err; |
| 8583 | } |
| 8584 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8585 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8586 | struct genl_info *info) |
| 8587 | { |
| 8588 | struct net_device *dev = info->user_ptr[1]; |
| 8589 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8590 | |
| 8591 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8592 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8593 | return -EINVAL; |
| 8594 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8595 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8596 | return -EBUSY; |
| 8597 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8598 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8599 | return 0; |
| 8600 | } |
| 8601 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8602 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8603 | struct genl_info *info) |
| 8604 | { |
| 8605 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8606 | struct net_device *dev = info->user_ptr[1]; |
| 8607 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8608 | struct sk_buff *msg; |
| 8609 | void *hdr; |
| 8610 | const u8 *addr; |
| 8611 | u64 cookie; |
| 8612 | int err; |
| 8613 | |
| 8614 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8615 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8616 | return -EOPNOTSUPP; |
| 8617 | |
| 8618 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8619 | return -EINVAL; |
| 8620 | |
| 8621 | if (!rdev->ops->probe_client) |
| 8622 | return -EOPNOTSUPP; |
| 8623 | |
| 8624 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8625 | if (!msg) |
| 8626 | return -ENOMEM; |
| 8627 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8628 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8629 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8630 | if (!hdr) { |
| 8631 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8632 | goto free_msg; |
| 8633 | } |
| 8634 | |
| 8635 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8636 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8637 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8638 | if (err) |
| 8639 | goto free_msg; |
| 8640 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8641 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8642 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8643 | |
| 8644 | genlmsg_end(msg, hdr); |
| 8645 | |
| 8646 | return genlmsg_reply(msg, info); |
| 8647 | |
| 8648 | nla_put_failure: |
| 8649 | err = -ENOBUFS; |
| 8650 | free_msg: |
| 8651 | nlmsg_free(msg); |
| 8652 | return err; |
| 8653 | } |
| 8654 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8655 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8656 | { |
| 8657 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8658 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8659 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8660 | |
| 8661 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8662 | return -EOPNOTSUPP; |
| 8663 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8664 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8665 | if (!nreg) |
| 8666 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8667 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8668 | /* First, check if already registered. */ |
| 8669 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8670 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8671 | if (reg->nlportid == info->snd_portid) { |
| 8672 | rv = -EALREADY; |
| 8673 | goto out_err; |
| 8674 | } |
| 8675 | } |
| 8676 | /* Add it to the list */ |
| 8677 | nreg->nlportid = info->snd_portid; |
| 8678 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8679 | |
| 8680 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8681 | |
| 8682 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8683 | out_err: |
| 8684 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8685 | kfree(nreg); |
| 8686 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8687 | } |
| 8688 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8689 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8690 | { |
| 8691 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8692 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8693 | int err; |
| 8694 | |
| 8695 | if (!rdev->ops->start_p2p_device) |
| 8696 | return -EOPNOTSUPP; |
| 8697 | |
| 8698 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8699 | return -EOPNOTSUPP; |
| 8700 | |
| 8701 | if (wdev->p2p_started) |
| 8702 | return 0; |
| 8703 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8704 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8705 | if (err) |
| 8706 | return err; |
| 8707 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8708 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8709 | if (err) |
| 8710 | return err; |
| 8711 | |
| 8712 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8713 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8714 | |
| 8715 | return 0; |
| 8716 | } |
| 8717 | |
| 8718 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8719 | { |
| 8720 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8721 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8722 | |
| 8723 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8724 | return -EOPNOTSUPP; |
| 8725 | |
| 8726 | if (!rdev->ops->stop_p2p_device) |
| 8727 | return -EOPNOTSUPP; |
| 8728 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8729 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8730 | |
| 8731 | return 0; |
| 8732 | } |
| 8733 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8734 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8735 | struct genl_info *info) |
| 8736 | { |
| 8737 | void *hdr; |
| 8738 | struct sk_buff *msg; |
| 8739 | |
| 8740 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8741 | if (!msg) |
| 8742 | return -ENOMEM; |
| 8743 | |
| 8744 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8745 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8746 | if (!hdr) |
| 8747 | goto nla_put_failure; |
| 8748 | |
| 8749 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8750 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8751 | goto nla_put_failure; |
| 8752 | |
| 8753 | genlmsg_end(msg, hdr); |
| 8754 | return genlmsg_reply(msg, info); |
| 8755 | |
| 8756 | nla_put_failure: |
| 8757 | kfree_skb(msg); |
| 8758 | return -ENOBUFS; |
| 8759 | } |
| 8760 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8761 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8762 | { |
| 8763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8764 | struct cfg80211_update_ft_ies_params ft_params; |
| 8765 | struct net_device *dev = info->user_ptr[1]; |
| 8766 | |
| 8767 | if (!rdev->ops->update_ft_ies) |
| 8768 | return -EOPNOTSUPP; |
| 8769 | |
| 8770 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8771 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8772 | return -EINVAL; |
| 8773 | |
| 8774 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8775 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8776 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8777 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8778 | |
| 8779 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8780 | } |
| 8781 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8782 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8783 | struct genl_info *info) |
| 8784 | { |
| 8785 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8786 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8787 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8788 | u16 duration; |
| 8789 | int ret; |
| 8790 | |
| 8791 | if (!rdev->ops->crit_proto_start) |
| 8792 | return -EOPNOTSUPP; |
| 8793 | |
| 8794 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8795 | return -EINVAL; |
| 8796 | |
| 8797 | if (rdev->crit_proto_nlportid) |
| 8798 | return -EBUSY; |
| 8799 | |
| 8800 | /* determine protocol if provided */ |
| 8801 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8802 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8803 | |
| 8804 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8805 | return -EINVAL; |
| 8806 | |
| 8807 | /* timeout must be provided */ |
| 8808 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8809 | return -EINVAL; |
| 8810 | |
| 8811 | duration = |
| 8812 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8813 | |
| 8814 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8815 | return -ERANGE; |
| 8816 | |
| 8817 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8818 | if (!ret) |
| 8819 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8820 | |
| 8821 | return ret; |
| 8822 | } |
| 8823 | |
| 8824 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8825 | struct genl_info *info) |
| 8826 | { |
| 8827 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8828 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8829 | |
| 8830 | if (!rdev->ops->crit_proto_stop) |
| 8831 | return -EOPNOTSUPP; |
| 8832 | |
| 8833 | if (rdev->crit_proto_nlportid) { |
| 8834 | rdev->crit_proto_nlportid = 0; |
| 8835 | rdev_crit_proto_stop(rdev, wdev); |
| 8836 | } |
| 8837 | return 0; |
| 8838 | } |
| 8839 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8840 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8841 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8842 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8843 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8844 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8845 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8846 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8847 | /* If a netdev is associated, it must be UP, P2P must be started */ |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8848 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8849 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8850 | |
| 8851 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8852 | struct genl_info *info) |
| 8853 | { |
| 8854 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8855 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8856 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8857 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8858 | |
| 8859 | if (rtnl) |
| 8860 | rtnl_lock(); |
| 8861 | |
| 8862 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8863 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8864 | if (IS_ERR(rdev)) { |
| 8865 | if (rtnl) |
| 8866 | rtnl_unlock(); |
| 8867 | return PTR_ERR(rdev); |
| 8868 | } |
| 8869 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8870 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8871 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8872 | ASSERT_RTNL(); |
| 8873 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8874 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8875 | info->attrs); |
| 8876 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8877 | if (rtnl) |
| 8878 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8879 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8880 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8881 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8882 | dev = wdev->netdev; |
| 8883 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8884 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8885 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8886 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8887 | if (rtnl) |
| 8888 | rtnl_unlock(); |
| 8889 | return -EINVAL; |
| 8890 | } |
| 8891 | |
| 8892 | info->user_ptr[1] = dev; |
| 8893 | } else { |
| 8894 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8895 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8896 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8897 | if (dev) { |
| 8898 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8899 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8900 | if (rtnl) |
| 8901 | rtnl_unlock(); |
| 8902 | return -ENETDOWN; |
| 8903 | } |
| 8904 | |
| 8905 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8906 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8907 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8908 | if (rtnl) |
| 8909 | rtnl_unlock(); |
| 8910 | return -ENETDOWN; |
| 8911 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8912 | } |
| 8913 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8914 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8915 | } |
| 8916 | |
| 8917 | return 0; |
| 8918 | } |
| 8919 | |
| 8920 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8921 | struct genl_info *info) |
| 8922 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8923 | if (info->user_ptr[1]) { |
| 8924 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8925 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8926 | |
| 8927 | if (wdev->netdev) |
| 8928 | dev_put(wdev->netdev); |
| 8929 | } else { |
| 8930 | dev_put(info->user_ptr[1]); |
| 8931 | } |
| 8932 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8933 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8934 | rtnl_unlock(); |
| 8935 | } |
| 8936 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8937 | static struct genl_ops nl80211_ops[] = { |
| 8938 | { |
| 8939 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8940 | .doit = nl80211_get_wiphy, |
| 8941 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 8942 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8943 | .policy = nl80211_policy, |
| 8944 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8945 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8946 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8947 | }, |
| 8948 | { |
| 8949 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8950 | .doit = nl80211_set_wiphy, |
| 8951 | .policy = nl80211_policy, |
| 8952 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8953 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8954 | }, |
| 8955 | { |
| 8956 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8957 | .doit = nl80211_get_interface, |
| 8958 | .dumpit = nl80211_dump_interface, |
| 8959 | .policy = nl80211_policy, |
| 8960 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8961 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8962 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8963 | }, |
| 8964 | { |
| 8965 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8966 | .doit = nl80211_set_interface, |
| 8967 | .policy = nl80211_policy, |
| 8968 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8969 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8970 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8971 | }, |
| 8972 | { |
| 8973 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8974 | .doit = nl80211_new_interface, |
| 8975 | .policy = nl80211_policy, |
| 8976 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8977 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8978 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8979 | }, |
| 8980 | { |
| 8981 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 8982 | .doit = nl80211_del_interface, |
| 8983 | .policy = nl80211_policy, |
| 8984 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 8985 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8986 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8987 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8988 | { |
| 8989 | .cmd = NL80211_CMD_GET_KEY, |
| 8990 | .doit = nl80211_get_key, |
| 8991 | .policy = nl80211_policy, |
| 8992 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8993 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8994 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8995 | }, |
| 8996 | { |
| 8997 | .cmd = NL80211_CMD_SET_KEY, |
| 8998 | .doit = nl80211_set_key, |
| 8999 | .policy = nl80211_policy, |
| 9000 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9001 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9002 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9003 | }, |
| 9004 | { |
| 9005 | .cmd = NL80211_CMD_NEW_KEY, |
| 9006 | .doit = nl80211_new_key, |
| 9007 | .policy = nl80211_policy, |
| 9008 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9009 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9010 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9011 | }, |
| 9012 | { |
| 9013 | .cmd = NL80211_CMD_DEL_KEY, |
| 9014 | .doit = nl80211_del_key, |
| 9015 | .policy = nl80211_policy, |
| 9016 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9017 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9018 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9019 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9020 | { |
| 9021 | .cmd = NL80211_CMD_SET_BEACON, |
| 9022 | .policy = nl80211_policy, |
| 9023 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9024 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9025 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9026 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9027 | }, |
| 9028 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9029 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9030 | .policy = nl80211_policy, |
| 9031 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9032 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9033 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9034 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9035 | }, |
| 9036 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9037 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9038 | .policy = nl80211_policy, |
| 9039 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9040 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9041 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9042 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9043 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9044 | { |
| 9045 | .cmd = NL80211_CMD_GET_STATION, |
| 9046 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9047 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9048 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9049 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9050 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9051 | }, |
| 9052 | { |
| 9053 | .cmd = NL80211_CMD_SET_STATION, |
| 9054 | .doit = nl80211_set_station, |
| 9055 | .policy = nl80211_policy, |
| 9056 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9057 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9058 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9059 | }, |
| 9060 | { |
| 9061 | .cmd = NL80211_CMD_NEW_STATION, |
| 9062 | .doit = nl80211_new_station, |
| 9063 | .policy = nl80211_policy, |
| 9064 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9065 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9066 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9067 | }, |
| 9068 | { |
| 9069 | .cmd = NL80211_CMD_DEL_STATION, |
| 9070 | .doit = nl80211_del_station, |
| 9071 | .policy = nl80211_policy, |
| 9072 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9073 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9074 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9075 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9076 | { |
| 9077 | .cmd = NL80211_CMD_GET_MPATH, |
| 9078 | .doit = nl80211_get_mpath, |
| 9079 | .dumpit = nl80211_dump_mpath, |
| 9080 | .policy = nl80211_policy, |
| 9081 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9082 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9083 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9084 | }, |
| 9085 | { |
| 9086 | .cmd = NL80211_CMD_SET_MPATH, |
| 9087 | .doit = nl80211_set_mpath, |
| 9088 | .policy = nl80211_policy, |
| 9089 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9090 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9091 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9092 | }, |
| 9093 | { |
| 9094 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9095 | .doit = nl80211_new_mpath, |
| 9096 | .policy = nl80211_policy, |
| 9097 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9098 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9099 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9100 | }, |
| 9101 | { |
| 9102 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9103 | .doit = nl80211_del_mpath, |
| 9104 | .policy = nl80211_policy, |
| 9105 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9106 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9107 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9108 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9109 | { |
| 9110 | .cmd = NL80211_CMD_SET_BSS, |
| 9111 | .doit = nl80211_set_bss, |
| 9112 | .policy = nl80211_policy, |
| 9113 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9114 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9115 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9116 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9117 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9118 | .cmd = NL80211_CMD_GET_REG, |
| 9119 | .doit = nl80211_get_reg, |
| 9120 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9121 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9122 | /* can be retrieved by unprivileged users */ |
| 9123 | }, |
| 9124 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9125 | .cmd = NL80211_CMD_SET_REG, |
| 9126 | .doit = nl80211_set_reg, |
| 9127 | .policy = nl80211_policy, |
| 9128 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9129 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9130 | }, |
| 9131 | { |
| 9132 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9133 | .doit = nl80211_req_set_reg, |
| 9134 | .policy = nl80211_policy, |
| 9135 | .flags = GENL_ADMIN_PERM, |
| 9136 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9137 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9138 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9139 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9140 | .policy = nl80211_policy, |
| 9141 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9142 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9143 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9144 | }, |
| 9145 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9146 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9147 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9148 | .policy = nl80211_policy, |
| 9149 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9150 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9151 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9152 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9153 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9154 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9155 | .doit = nl80211_trigger_scan, |
| 9156 | .policy = nl80211_policy, |
| 9157 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9158 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9159 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9160 | }, |
| 9161 | { |
| 9162 | .cmd = NL80211_CMD_GET_SCAN, |
| 9163 | .policy = nl80211_policy, |
| 9164 | .dumpit = nl80211_dump_scan, |
| 9165 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9166 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9167 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9168 | .doit = nl80211_start_sched_scan, |
| 9169 | .policy = nl80211_policy, |
| 9170 | .flags = GENL_ADMIN_PERM, |
| 9171 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9172 | NL80211_FLAG_NEED_RTNL, |
| 9173 | }, |
| 9174 | { |
| 9175 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9176 | .doit = nl80211_stop_sched_scan, |
| 9177 | .policy = nl80211_policy, |
| 9178 | .flags = GENL_ADMIN_PERM, |
| 9179 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9180 | NL80211_FLAG_NEED_RTNL, |
| 9181 | }, |
| 9182 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9183 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9184 | .doit = nl80211_authenticate, |
| 9185 | .policy = nl80211_policy, |
| 9186 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9187 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9188 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9189 | }, |
| 9190 | { |
| 9191 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9192 | .doit = nl80211_associate, |
| 9193 | .policy = nl80211_policy, |
| 9194 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9195 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9196 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9197 | }, |
| 9198 | { |
| 9199 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9200 | .doit = nl80211_deauthenticate, |
| 9201 | .policy = nl80211_policy, |
| 9202 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9203 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9204 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9205 | }, |
| 9206 | { |
| 9207 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9208 | .doit = nl80211_disassociate, |
| 9209 | .policy = nl80211_policy, |
| 9210 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9211 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9212 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9213 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9214 | { |
| 9215 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9216 | .doit = nl80211_join_ibss, |
| 9217 | .policy = nl80211_policy, |
| 9218 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9219 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9220 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9221 | }, |
| 9222 | { |
| 9223 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9224 | .doit = nl80211_leave_ibss, |
| 9225 | .policy = nl80211_policy, |
| 9226 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9227 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9228 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9229 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9230 | #ifdef CONFIG_NL80211_TESTMODE |
| 9231 | { |
| 9232 | .cmd = NL80211_CMD_TESTMODE, |
| 9233 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9234 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9235 | .policy = nl80211_policy, |
| 9236 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9237 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9238 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9239 | }, |
| 9240 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9241 | { |
| 9242 | .cmd = NL80211_CMD_CONNECT, |
| 9243 | .doit = nl80211_connect, |
| 9244 | .policy = nl80211_policy, |
| 9245 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9246 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9247 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9248 | }, |
| 9249 | { |
| 9250 | .cmd = NL80211_CMD_DISCONNECT, |
| 9251 | .doit = nl80211_disconnect, |
| 9252 | .policy = nl80211_policy, |
| 9253 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9254 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9255 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9256 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9257 | { |
| 9258 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9259 | .doit = nl80211_wiphy_netns, |
| 9260 | .policy = nl80211_policy, |
| 9261 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9262 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9263 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9264 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9265 | { |
| 9266 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9267 | .policy = nl80211_policy, |
| 9268 | .dumpit = nl80211_dump_survey, |
| 9269 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9270 | { |
| 9271 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9272 | .doit = nl80211_setdel_pmksa, |
| 9273 | .policy = nl80211_policy, |
| 9274 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9275 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9276 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9277 | }, |
| 9278 | { |
| 9279 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9280 | .doit = nl80211_setdel_pmksa, |
| 9281 | .policy = nl80211_policy, |
| 9282 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9283 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9284 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9285 | }, |
| 9286 | { |
| 9287 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9288 | .doit = nl80211_flush_pmksa, |
| 9289 | .policy = nl80211_policy, |
| 9290 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9291 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9292 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9293 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9294 | { |
| 9295 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9296 | .doit = nl80211_remain_on_channel, |
| 9297 | .policy = nl80211_policy, |
| 9298 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9299 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9300 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9301 | }, |
| 9302 | { |
| 9303 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9304 | .doit = nl80211_cancel_remain_on_channel, |
| 9305 | .policy = nl80211_policy, |
| 9306 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9307 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9308 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9309 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9310 | { |
| 9311 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9312 | .doit = nl80211_set_tx_bitrate_mask, |
| 9313 | .policy = nl80211_policy, |
| 9314 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9315 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9316 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9317 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9318 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9319 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9320 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9321 | .policy = nl80211_policy, |
| 9322 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9323 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9324 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9325 | }, |
| 9326 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9327 | .cmd = NL80211_CMD_FRAME, |
| 9328 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9329 | .policy = nl80211_policy, |
| 9330 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9331 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9332 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9333 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9334 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9335 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9336 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9337 | .policy = nl80211_policy, |
| 9338 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9339 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9340 | NL80211_FLAG_NEED_RTNL, |
| 9341 | }, |
| 9342 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9343 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9344 | .doit = nl80211_set_power_save, |
| 9345 | .policy = nl80211_policy, |
| 9346 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9347 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9348 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9349 | }, |
| 9350 | { |
| 9351 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9352 | .doit = nl80211_get_power_save, |
| 9353 | .policy = nl80211_policy, |
| 9354 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9355 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9356 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9357 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9358 | { |
| 9359 | .cmd = NL80211_CMD_SET_CQM, |
| 9360 | .doit = nl80211_set_cqm, |
| 9361 | .policy = nl80211_policy, |
| 9362 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9363 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9364 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9365 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9366 | { |
| 9367 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9368 | .doit = nl80211_set_channel, |
| 9369 | .policy = nl80211_policy, |
| 9370 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9371 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9372 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9373 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9374 | { |
| 9375 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9376 | .doit = nl80211_set_wds_peer, |
| 9377 | .policy = nl80211_policy, |
| 9378 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9379 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9380 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9381 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9382 | { |
| 9383 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9384 | .doit = nl80211_join_mesh, |
| 9385 | .policy = nl80211_policy, |
| 9386 | .flags = GENL_ADMIN_PERM, |
| 9387 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9388 | NL80211_FLAG_NEED_RTNL, |
| 9389 | }, |
| 9390 | { |
| 9391 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9392 | .doit = nl80211_leave_mesh, |
| 9393 | .policy = nl80211_policy, |
| 9394 | .flags = GENL_ADMIN_PERM, |
| 9395 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9396 | NL80211_FLAG_NEED_RTNL, |
| 9397 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9398 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9399 | { |
| 9400 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9401 | .doit = nl80211_get_wowlan, |
| 9402 | .policy = nl80211_policy, |
| 9403 | /* can be retrieved by unprivileged users */ |
| 9404 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9405 | NL80211_FLAG_NEED_RTNL, |
| 9406 | }, |
| 9407 | { |
| 9408 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9409 | .doit = nl80211_set_wowlan, |
| 9410 | .policy = nl80211_policy, |
| 9411 | .flags = GENL_ADMIN_PERM, |
| 9412 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9413 | NL80211_FLAG_NEED_RTNL, |
| 9414 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9415 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9416 | { |
| 9417 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9418 | .doit = nl80211_set_rekey_data, |
| 9419 | .policy = nl80211_policy, |
| 9420 | .flags = GENL_ADMIN_PERM, |
| 9421 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9422 | NL80211_FLAG_NEED_RTNL, |
| 9423 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9424 | { |
| 9425 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9426 | .doit = nl80211_tdls_mgmt, |
| 9427 | .policy = nl80211_policy, |
| 9428 | .flags = GENL_ADMIN_PERM, |
| 9429 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9430 | NL80211_FLAG_NEED_RTNL, |
| 9431 | }, |
| 9432 | { |
| 9433 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9434 | .doit = nl80211_tdls_oper, |
| 9435 | .policy = nl80211_policy, |
| 9436 | .flags = GENL_ADMIN_PERM, |
| 9437 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9438 | NL80211_FLAG_NEED_RTNL, |
| 9439 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9440 | { |
| 9441 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9442 | .doit = nl80211_register_unexpected_frame, |
| 9443 | .policy = nl80211_policy, |
| 9444 | .flags = GENL_ADMIN_PERM, |
| 9445 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9446 | NL80211_FLAG_NEED_RTNL, |
| 9447 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9448 | { |
| 9449 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9450 | .doit = nl80211_probe_client, |
| 9451 | .policy = nl80211_policy, |
| 9452 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9453 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9454 | NL80211_FLAG_NEED_RTNL, |
| 9455 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9456 | { |
| 9457 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9458 | .doit = nl80211_register_beacons, |
| 9459 | .policy = nl80211_policy, |
| 9460 | .flags = GENL_ADMIN_PERM, |
| 9461 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9462 | NL80211_FLAG_NEED_RTNL, |
| 9463 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9464 | { |
| 9465 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9466 | .doit = nl80211_set_noack_map, |
| 9467 | .policy = nl80211_policy, |
| 9468 | .flags = GENL_ADMIN_PERM, |
| 9469 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9470 | NL80211_FLAG_NEED_RTNL, |
| 9471 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9472 | { |
| 9473 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9474 | .doit = nl80211_start_p2p_device, |
| 9475 | .policy = nl80211_policy, |
| 9476 | .flags = GENL_ADMIN_PERM, |
| 9477 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9478 | NL80211_FLAG_NEED_RTNL, |
| 9479 | }, |
| 9480 | { |
| 9481 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9482 | .doit = nl80211_stop_p2p_device, |
| 9483 | .policy = nl80211_policy, |
| 9484 | .flags = GENL_ADMIN_PERM, |
| 9485 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9486 | NL80211_FLAG_NEED_RTNL, |
| 9487 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9488 | { |
| 9489 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9490 | .doit = nl80211_set_mcast_rate, |
| 9491 | .policy = nl80211_policy, |
| 9492 | .flags = GENL_ADMIN_PERM, |
| 9493 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9494 | NL80211_FLAG_NEED_RTNL, |
| 9495 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9496 | { |
| 9497 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9498 | .doit = nl80211_set_mac_acl, |
| 9499 | .policy = nl80211_policy, |
| 9500 | .flags = GENL_ADMIN_PERM, |
| 9501 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9502 | NL80211_FLAG_NEED_RTNL, |
| 9503 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9504 | { |
| 9505 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9506 | .doit = nl80211_start_radar_detection, |
| 9507 | .policy = nl80211_policy, |
| 9508 | .flags = GENL_ADMIN_PERM, |
| 9509 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9510 | NL80211_FLAG_NEED_RTNL, |
| 9511 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9512 | { |
| 9513 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9514 | .doit = nl80211_get_protocol_features, |
| 9515 | .policy = nl80211_policy, |
| 9516 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9517 | { |
| 9518 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9519 | .doit = nl80211_update_ft_ies, |
| 9520 | .policy = nl80211_policy, |
| 9521 | .flags = GENL_ADMIN_PERM, |
| 9522 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9523 | NL80211_FLAG_NEED_RTNL, |
| 9524 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9525 | { |
| 9526 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9527 | .doit = nl80211_crit_protocol_start, |
| 9528 | .policy = nl80211_policy, |
| 9529 | .flags = GENL_ADMIN_PERM, |
| 9530 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9531 | NL80211_FLAG_NEED_RTNL, |
| 9532 | }, |
| 9533 | { |
| 9534 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9535 | .doit = nl80211_crit_protocol_stop, |
| 9536 | .policy = nl80211_policy, |
| 9537 | .flags = GENL_ADMIN_PERM, |
| 9538 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9539 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9540 | }, |
| 9541 | { |
| 9542 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9543 | .doit = nl80211_get_coalesce, |
| 9544 | .policy = nl80211_policy, |
| 9545 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9546 | NL80211_FLAG_NEED_RTNL, |
| 9547 | }, |
| 9548 | { |
| 9549 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9550 | .doit = nl80211_set_coalesce, |
| 9551 | .policy = nl80211_policy, |
| 9552 | .flags = GENL_ADMIN_PERM, |
| 9553 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9554 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9555 | }, |
| 9556 | { |
| 9557 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9558 | .doit = nl80211_channel_switch, |
| 9559 | .policy = nl80211_policy, |
| 9560 | .flags = GENL_ADMIN_PERM, |
| 9561 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9562 | NL80211_FLAG_NEED_RTNL, |
| 9563 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9564 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9565 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9566 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 9567 | .name = "mlme", |
| 9568 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9569 | |
| 9570 | /* multicast groups */ |
| 9571 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 9572 | .name = "config", |
| 9573 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9574 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 9575 | .name = "scan", |
| 9576 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9577 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 9578 | .name = "regulatory", |
| 9579 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9580 | |
| 9581 | /* notification functions */ |
| 9582 | |
| 9583 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9584 | { |
| 9585 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9586 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9587 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9588 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9589 | if (!msg) |
| 9590 | return; |
| 9591 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9592 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9593 | nlmsg_free(msg); |
| 9594 | return; |
| 9595 | } |
| 9596 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9597 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9598 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9599 | } |
| 9600 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9601 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9602 | struct cfg80211_registered_device *rdev) |
| 9603 | { |
| 9604 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9605 | struct nlattr *nest; |
| 9606 | int i; |
| 9607 | |
| 9608 | if (WARN_ON(!req)) |
| 9609 | return 0; |
| 9610 | |
| 9611 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9612 | if (!nest) |
| 9613 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9614 | for (i = 0; i < req->n_ssids; i++) { |
| 9615 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9616 | goto nla_put_failure; |
| 9617 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9618 | nla_nest_end(msg, nest); |
| 9619 | |
| 9620 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9621 | if (!nest) |
| 9622 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9623 | for (i = 0; i < req->n_channels; i++) { |
| 9624 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9625 | goto nla_put_failure; |
| 9626 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9627 | nla_nest_end(msg, nest); |
| 9628 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9629 | if (req->ie && |
| 9630 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9631 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9632 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9633 | if (req->flags) |
| 9634 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 9635 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9636 | return 0; |
| 9637 | nla_put_failure: |
| 9638 | return -ENOBUFS; |
| 9639 | } |
| 9640 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9641 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9642 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9643 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9644 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9645 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9646 | { |
| 9647 | void *hdr; |
| 9648 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9649 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9650 | if (!hdr) |
| 9651 | return -1; |
| 9652 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9653 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9654 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9655 | wdev->netdev->ifindex)) || |
| 9656 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9657 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9658 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9659 | /* ignore errors and send incomplete event anyway */ |
| 9660 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9661 | |
| 9662 | return genlmsg_end(msg, hdr); |
| 9663 | |
| 9664 | nla_put_failure: |
| 9665 | genlmsg_cancel(msg, hdr); |
| 9666 | return -EMSGSIZE; |
| 9667 | } |
| 9668 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9669 | static int |
| 9670 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9671 | struct cfg80211_registered_device *rdev, |
| 9672 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9673 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9674 | { |
| 9675 | void *hdr; |
| 9676 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9677 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9678 | if (!hdr) |
| 9679 | return -1; |
| 9680 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9681 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9682 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9683 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9684 | |
| 9685 | return genlmsg_end(msg, hdr); |
| 9686 | |
| 9687 | nla_put_failure: |
| 9688 | genlmsg_cancel(msg, hdr); |
| 9689 | return -EMSGSIZE; |
| 9690 | } |
| 9691 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9692 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9693 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9694 | { |
| 9695 | struct sk_buff *msg; |
| 9696 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9697 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9698 | if (!msg) |
| 9699 | return; |
| 9700 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9701 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9702 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9703 | nlmsg_free(msg); |
| 9704 | return; |
| 9705 | } |
| 9706 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9707 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9708 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9709 | } |
| 9710 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9711 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9712 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9713 | { |
| 9714 | struct sk_buff *msg; |
| 9715 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9716 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9717 | if (!msg) |
| 9718 | return; |
| 9719 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9720 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9721 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9722 | nlmsg_free(msg); |
| 9723 | return; |
| 9724 | } |
| 9725 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9726 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9727 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9728 | } |
| 9729 | |
| 9730 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9731 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9732 | { |
| 9733 | struct sk_buff *msg; |
| 9734 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9735 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9736 | if (!msg) |
| 9737 | return; |
| 9738 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9739 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9740 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9741 | nlmsg_free(msg); |
| 9742 | return; |
| 9743 | } |
| 9744 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9745 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9746 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9747 | } |
| 9748 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9749 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9750 | struct net_device *netdev) |
| 9751 | { |
| 9752 | struct sk_buff *msg; |
| 9753 | |
| 9754 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9755 | if (!msg) |
| 9756 | return; |
| 9757 | |
| 9758 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9759 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9760 | nlmsg_free(msg); |
| 9761 | return; |
| 9762 | } |
| 9763 | |
| 9764 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9765 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9766 | } |
| 9767 | |
| 9768 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9769 | struct net_device *netdev, u32 cmd) |
| 9770 | { |
| 9771 | struct sk_buff *msg; |
| 9772 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9773 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9774 | if (!msg) |
| 9775 | return; |
| 9776 | |
| 9777 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9778 | nlmsg_free(msg); |
| 9779 | return; |
| 9780 | } |
| 9781 | |
| 9782 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9783 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9784 | } |
| 9785 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9786 | /* |
| 9787 | * This can happen on global regulatory changes or device specific settings |
| 9788 | * based on custom world regulatory domains. |
| 9789 | */ |
| 9790 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9791 | { |
| 9792 | struct sk_buff *msg; |
| 9793 | void *hdr; |
| 9794 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9795 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9796 | if (!msg) |
| 9797 | return; |
| 9798 | |
| 9799 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9800 | if (!hdr) { |
| 9801 | nlmsg_free(msg); |
| 9802 | return; |
| 9803 | } |
| 9804 | |
| 9805 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9806 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9807 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9808 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9809 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9810 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9811 | NL80211_REGDOM_TYPE_WORLD)) |
| 9812 | goto nla_put_failure; |
| 9813 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9814 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9815 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9816 | goto nla_put_failure; |
| 9817 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9818 | request->intersect) { |
| 9819 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9820 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9821 | goto nla_put_failure; |
| 9822 | } else { |
| 9823 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9824 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9825 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9826 | request->alpha2)) |
| 9827 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9828 | } |
| 9829 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9830 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9831 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9832 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9833 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9834 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9835 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9836 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9837 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9838 | GFP_ATOMIC); |
| 9839 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9840 | |
| 9841 | return; |
| 9842 | |
| 9843 | nla_put_failure: |
| 9844 | genlmsg_cancel(msg, hdr); |
| 9845 | nlmsg_free(msg); |
| 9846 | } |
| 9847 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9848 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9849 | struct net_device *netdev, |
| 9850 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9851 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9852 | { |
| 9853 | struct sk_buff *msg; |
| 9854 | void *hdr; |
| 9855 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9856 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9857 | if (!msg) |
| 9858 | return; |
| 9859 | |
| 9860 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9861 | if (!hdr) { |
| 9862 | nlmsg_free(msg); |
| 9863 | return; |
| 9864 | } |
| 9865 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9866 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9867 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9868 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9869 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9870 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9871 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9872 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9873 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9874 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9875 | return; |
| 9876 | |
| 9877 | nla_put_failure: |
| 9878 | genlmsg_cancel(msg, hdr); |
| 9879 | nlmsg_free(msg); |
| 9880 | } |
| 9881 | |
| 9882 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9883 | struct net_device *netdev, const u8 *buf, |
| 9884 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9885 | { |
| 9886 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9887 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9888 | } |
| 9889 | |
| 9890 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9891 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9892 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9893 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9894 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9895 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9896 | } |
| 9897 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9898 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9899 | struct net_device *netdev, const u8 *buf, |
| 9900 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9901 | { |
| 9902 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9903 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9904 | } |
| 9905 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9906 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9907 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9908 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9909 | { |
| 9910 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9911 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9912 | } |
| 9913 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9914 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 9915 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9916 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9917 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9918 | struct wiphy *wiphy = wdev->wiphy; |
| 9919 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9920 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 9921 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9922 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9923 | if (WARN_ON(len < 2)) |
| 9924 | return; |
| 9925 | |
| 9926 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 9927 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 9928 | else |
| 9929 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 9930 | |
| 9931 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 9932 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9933 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9934 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9935 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9936 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9937 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9938 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9939 | { |
| 9940 | struct sk_buff *msg; |
| 9941 | void *hdr; |
| 9942 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9943 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9944 | if (!msg) |
| 9945 | return; |
| 9946 | |
| 9947 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9948 | if (!hdr) { |
| 9949 | nlmsg_free(msg); |
| 9950 | return; |
| 9951 | } |
| 9952 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9953 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9954 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9955 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9956 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9957 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9958 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9959 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9960 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9961 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9962 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9963 | return; |
| 9964 | |
| 9965 | nla_put_failure: |
| 9966 | genlmsg_cancel(msg, hdr); |
| 9967 | nlmsg_free(msg); |
| 9968 | } |
| 9969 | |
| 9970 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9971 | struct net_device *netdev, const u8 *addr, |
| 9972 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9973 | { |
| 9974 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9975 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9976 | } |
| 9977 | |
| 9978 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9979 | struct net_device *netdev, const u8 *addr, |
| 9980 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9981 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9982 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9983 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9984 | } |
| 9985 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9986 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9987 | struct net_device *netdev, const u8 *bssid, |
| 9988 | const u8 *req_ie, size_t req_ie_len, |
| 9989 | const u8 *resp_ie, size_t resp_ie_len, |
| 9990 | u16 status, gfp_t gfp) |
| 9991 | { |
| 9992 | struct sk_buff *msg; |
| 9993 | void *hdr; |
| 9994 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9995 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9996 | if (!msg) |
| 9997 | return; |
| 9998 | |
| 9999 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10000 | if (!hdr) { |
| 10001 | nlmsg_free(msg); |
| 10002 | return; |
| 10003 | } |
| 10004 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10005 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10006 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10007 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10008 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10009 | (req_ie && |
| 10010 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10011 | (resp_ie && |
| 10012 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10013 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10014 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10015 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10016 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10017 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10018 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10019 | return; |
| 10020 | |
| 10021 | nla_put_failure: |
| 10022 | genlmsg_cancel(msg, hdr); |
| 10023 | nlmsg_free(msg); |
| 10024 | |
| 10025 | } |
| 10026 | |
| 10027 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10028 | struct net_device *netdev, const u8 *bssid, |
| 10029 | const u8 *req_ie, size_t req_ie_len, |
| 10030 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10031 | { |
| 10032 | struct sk_buff *msg; |
| 10033 | void *hdr; |
| 10034 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10035 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10036 | if (!msg) |
| 10037 | return; |
| 10038 | |
| 10039 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10040 | if (!hdr) { |
| 10041 | nlmsg_free(msg); |
| 10042 | return; |
| 10043 | } |
| 10044 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10045 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10046 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10047 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10048 | (req_ie && |
| 10049 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10050 | (resp_ie && |
| 10051 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10052 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10053 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10054 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10055 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10056 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10057 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10058 | return; |
| 10059 | |
| 10060 | nla_put_failure: |
| 10061 | genlmsg_cancel(msg, hdr); |
| 10062 | nlmsg_free(msg); |
| 10063 | |
| 10064 | } |
| 10065 | |
| 10066 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10067 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10068 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10069 | { |
| 10070 | struct sk_buff *msg; |
| 10071 | void *hdr; |
| 10072 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10073 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10074 | if (!msg) |
| 10075 | return; |
| 10076 | |
| 10077 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10078 | if (!hdr) { |
| 10079 | nlmsg_free(msg); |
| 10080 | return; |
| 10081 | } |
| 10082 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10083 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10084 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10085 | (from_ap && reason && |
| 10086 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10087 | (from_ap && |
| 10088 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10089 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10090 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10091 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10092 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10093 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10094 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10095 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10096 | return; |
| 10097 | |
| 10098 | nla_put_failure: |
| 10099 | genlmsg_cancel(msg, hdr); |
| 10100 | nlmsg_free(msg); |
| 10101 | |
| 10102 | } |
| 10103 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10104 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10105 | struct net_device *netdev, const u8 *bssid, |
| 10106 | gfp_t gfp) |
| 10107 | { |
| 10108 | struct sk_buff *msg; |
| 10109 | void *hdr; |
| 10110 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10111 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10112 | if (!msg) |
| 10113 | return; |
| 10114 | |
| 10115 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10116 | if (!hdr) { |
| 10117 | nlmsg_free(msg); |
| 10118 | return; |
| 10119 | } |
| 10120 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10121 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10122 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10123 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10124 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10125 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10126 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10127 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10128 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10129 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10130 | return; |
| 10131 | |
| 10132 | nla_put_failure: |
| 10133 | genlmsg_cancel(msg, hdr); |
| 10134 | nlmsg_free(msg); |
| 10135 | } |
| 10136 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10137 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10138 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10139 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10140 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10141 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10142 | struct sk_buff *msg; |
| 10143 | void *hdr; |
| 10144 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10145 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10146 | return; |
| 10147 | |
| 10148 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10149 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10150 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10151 | if (!msg) |
| 10152 | return; |
| 10153 | |
| 10154 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10155 | if (!hdr) { |
| 10156 | nlmsg_free(msg); |
| 10157 | return; |
| 10158 | } |
| 10159 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10160 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10161 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10162 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10163 | (ie_len && ie && |
| 10164 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10165 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10166 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10167 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10168 | |
| 10169 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10170 | nl80211_mlme_mcgrp.id, gfp); |
| 10171 | return; |
| 10172 | |
| 10173 | nla_put_failure: |
| 10174 | genlmsg_cancel(msg, hdr); |
| 10175 | nlmsg_free(msg); |
| 10176 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10177 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10178 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10179 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10180 | struct net_device *netdev, const u8 *addr, |
| 10181 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10182 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10183 | { |
| 10184 | struct sk_buff *msg; |
| 10185 | void *hdr; |
| 10186 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10187 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10188 | if (!msg) |
| 10189 | return; |
| 10190 | |
| 10191 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10192 | if (!hdr) { |
| 10193 | nlmsg_free(msg); |
| 10194 | return; |
| 10195 | } |
| 10196 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10197 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10198 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10199 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10200 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10201 | (key_id != -1 && |
| 10202 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10203 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10204 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10205 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10206 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10207 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10208 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10209 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10210 | return; |
| 10211 | |
| 10212 | nla_put_failure: |
| 10213 | genlmsg_cancel(msg, hdr); |
| 10214 | nlmsg_free(msg); |
| 10215 | } |
| 10216 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10217 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10218 | struct ieee80211_channel *channel_before, |
| 10219 | struct ieee80211_channel *channel_after) |
| 10220 | { |
| 10221 | struct sk_buff *msg; |
| 10222 | void *hdr; |
| 10223 | struct nlattr *nl_freq; |
| 10224 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10225 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10226 | if (!msg) |
| 10227 | return; |
| 10228 | |
| 10229 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10230 | if (!hdr) { |
| 10231 | nlmsg_free(msg); |
| 10232 | return; |
| 10233 | } |
| 10234 | |
| 10235 | /* |
| 10236 | * Since we are applying the beacon hint to a wiphy we know its |
| 10237 | * wiphy_idx is valid |
| 10238 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10239 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10240 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10241 | |
| 10242 | /* Before */ |
| 10243 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10244 | if (!nl_freq) |
| 10245 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10246 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10247 | goto nla_put_failure; |
| 10248 | nla_nest_end(msg, nl_freq); |
| 10249 | |
| 10250 | /* After */ |
| 10251 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10252 | if (!nl_freq) |
| 10253 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10254 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10255 | goto nla_put_failure; |
| 10256 | nla_nest_end(msg, nl_freq); |
| 10257 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10258 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10259 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10260 | rcu_read_lock(); |
| 10261 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 10262 | GFP_ATOMIC); |
| 10263 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10264 | |
| 10265 | return; |
| 10266 | |
| 10267 | nla_put_failure: |
| 10268 | genlmsg_cancel(msg, hdr); |
| 10269 | nlmsg_free(msg); |
| 10270 | } |
| 10271 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10272 | static void nl80211_send_remain_on_chan_event( |
| 10273 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10274 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10275 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10276 | unsigned int duration, gfp_t gfp) |
| 10277 | { |
| 10278 | struct sk_buff *msg; |
| 10279 | void *hdr; |
| 10280 | |
| 10281 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10282 | if (!msg) |
| 10283 | return; |
| 10284 | |
| 10285 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10286 | if (!hdr) { |
| 10287 | nlmsg_free(msg); |
| 10288 | return; |
| 10289 | } |
| 10290 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10291 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10292 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10293 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10294 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10295 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10296 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10297 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10298 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10299 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10300 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10301 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10302 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10303 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10304 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10305 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10306 | |
| 10307 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10308 | nl80211_mlme_mcgrp.id, gfp); |
| 10309 | return; |
| 10310 | |
| 10311 | nla_put_failure: |
| 10312 | genlmsg_cancel(msg, hdr); |
| 10313 | nlmsg_free(msg); |
| 10314 | } |
| 10315 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10316 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10317 | struct ieee80211_channel *chan, |
| 10318 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10319 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10320 | struct wiphy *wiphy = wdev->wiphy; |
| 10321 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10322 | |
| 10323 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10324 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10325 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10326 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10327 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10328 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10329 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10330 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10331 | struct ieee80211_channel *chan, |
| 10332 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10333 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10334 | struct wiphy *wiphy = wdev->wiphy; |
| 10335 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10336 | |
| 10337 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10338 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10339 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10340 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10341 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10342 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10343 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10344 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10345 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10346 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10347 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10348 | struct sk_buff *msg; |
| 10349 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10350 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10351 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10352 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10353 | if (!msg) |
| 10354 | return; |
| 10355 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10356 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10357 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10358 | nlmsg_free(msg); |
| 10359 | return; |
| 10360 | } |
| 10361 | |
| 10362 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10363 | nl80211_mlme_mcgrp.id, gfp); |
| 10364 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10365 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10366 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10367 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10368 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10369 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10370 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10371 | struct sk_buff *msg; |
| 10372 | void *hdr; |
| 10373 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10374 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10375 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10376 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10377 | if (!msg) |
| 10378 | return; |
| 10379 | |
| 10380 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10381 | if (!hdr) { |
| 10382 | nlmsg_free(msg); |
| 10383 | return; |
| 10384 | } |
| 10385 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10386 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10387 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10388 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10389 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10390 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10391 | |
| 10392 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10393 | nl80211_mlme_mcgrp.id, gfp); |
| 10394 | return; |
| 10395 | |
| 10396 | nla_put_failure: |
| 10397 | genlmsg_cancel(msg, hdr); |
| 10398 | nlmsg_free(msg); |
| 10399 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10400 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10401 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10402 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10403 | enum nl80211_connect_failed_reason reason, |
| 10404 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10405 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10406 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10407 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10408 | struct sk_buff *msg; |
| 10409 | void *hdr; |
| 10410 | |
| 10411 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10412 | if (!msg) |
| 10413 | return; |
| 10414 | |
| 10415 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10416 | if (!hdr) { |
| 10417 | nlmsg_free(msg); |
| 10418 | return; |
| 10419 | } |
| 10420 | |
| 10421 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10422 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10423 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10424 | goto nla_put_failure; |
| 10425 | |
| 10426 | genlmsg_end(msg, hdr); |
| 10427 | |
| 10428 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10429 | nl80211_mlme_mcgrp.id, gfp); |
| 10430 | return; |
| 10431 | |
| 10432 | nla_put_failure: |
| 10433 | genlmsg_cancel(msg, hdr); |
| 10434 | nlmsg_free(msg); |
| 10435 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10436 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10437 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10438 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10439 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10440 | { |
| 10441 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10442 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10443 | struct sk_buff *msg; |
| 10444 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10445 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10446 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10447 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10448 | return false; |
| 10449 | |
| 10450 | msg = nlmsg_new(100, gfp); |
| 10451 | if (!msg) |
| 10452 | return true; |
| 10453 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10454 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10455 | if (!hdr) { |
| 10456 | nlmsg_free(msg); |
| 10457 | return true; |
| 10458 | } |
| 10459 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10460 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10461 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10462 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10463 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10464 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10465 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10466 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10467 | return true; |
| 10468 | |
| 10469 | nla_put_failure: |
| 10470 | genlmsg_cancel(msg, hdr); |
| 10471 | nlmsg_free(msg); |
| 10472 | return true; |
| 10473 | } |
| 10474 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10475 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10476 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10477 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10478 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10479 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10480 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10481 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10482 | |
| 10483 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10484 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10485 | trace_cfg80211_return_bool(false); |
| 10486 | return false; |
| 10487 | } |
| 10488 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10489 | addr, gfp); |
| 10490 | trace_cfg80211_return_bool(ret); |
| 10491 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10492 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10493 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10494 | |
| 10495 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10496 | const u8 *addr, gfp_t gfp) |
| 10497 | { |
| 10498 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10499 | bool ret; |
| 10500 | |
| 10501 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10502 | |
| 10503 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10504 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10505 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10506 | trace_cfg80211_return_bool(false); |
| 10507 | return false; |
| 10508 | } |
| 10509 | ret = __nl80211_unexpected_frame(dev, |
| 10510 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10511 | addr, gfp); |
| 10512 | trace_cfg80211_return_bool(ret); |
| 10513 | return ret; |
| 10514 | } |
| 10515 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10516 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10517 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10518 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10519 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10520 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10521 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10522 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10523 | struct sk_buff *msg; |
| 10524 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10525 | |
| 10526 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10527 | if (!msg) |
| 10528 | return -ENOMEM; |
| 10529 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10530 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10531 | if (!hdr) { |
| 10532 | nlmsg_free(msg); |
| 10533 | return -ENOMEM; |
| 10534 | } |
| 10535 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10536 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10537 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10538 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10539 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10540 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10541 | (sig_dbm && |
| 10542 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10543 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10544 | (flags && |
| 10545 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10546 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10547 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10548 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10549 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10550 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10551 | |
| 10552 | nla_put_failure: |
| 10553 | genlmsg_cancel(msg, hdr); |
| 10554 | nlmsg_free(msg); |
| 10555 | return -ENOBUFS; |
| 10556 | } |
| 10557 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10558 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10559 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10560 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10561 | struct wiphy *wiphy = wdev->wiphy; |
| 10562 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10563 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10564 | struct sk_buff *msg; |
| 10565 | void *hdr; |
| 10566 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10567 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10568 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10569 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10570 | if (!msg) |
| 10571 | return; |
| 10572 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10573 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10574 | if (!hdr) { |
| 10575 | nlmsg_free(msg); |
| 10576 | return; |
| 10577 | } |
| 10578 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10579 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10580 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10581 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10582 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10583 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10584 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10585 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10586 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10587 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10588 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10589 | |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 10590 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10591 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10592 | return; |
| 10593 | |
| 10594 | nla_put_failure: |
| 10595 | genlmsg_cancel(msg, hdr); |
| 10596 | nlmsg_free(msg); |
| 10597 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10598 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10599 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10600 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10601 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10602 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10603 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10604 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10605 | struct wiphy *wiphy = wdev->wiphy; |
| 10606 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10607 | struct sk_buff *msg; |
| 10608 | struct nlattr *pinfoattr; |
| 10609 | void *hdr; |
| 10610 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10611 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10612 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10613 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10614 | if (!msg) |
| 10615 | return; |
| 10616 | |
| 10617 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10618 | if (!hdr) { |
| 10619 | nlmsg_free(msg); |
| 10620 | return; |
| 10621 | } |
| 10622 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10623 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10624 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10625 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10626 | |
| 10627 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10628 | if (!pinfoattr) |
| 10629 | goto nla_put_failure; |
| 10630 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10631 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10632 | rssi_event)) |
| 10633 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10634 | |
| 10635 | nla_nest_end(msg, pinfoattr); |
| 10636 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10637 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10638 | |
| 10639 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10640 | nl80211_mlme_mcgrp.id, gfp); |
| 10641 | return; |
| 10642 | |
| 10643 | nla_put_failure: |
| 10644 | genlmsg_cancel(msg, hdr); |
| 10645 | nlmsg_free(msg); |
| 10646 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10647 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10648 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10649 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10650 | struct net_device *netdev, const u8 *bssid, |
| 10651 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10652 | { |
| 10653 | struct sk_buff *msg; |
| 10654 | struct nlattr *rekey_attr; |
| 10655 | void *hdr; |
| 10656 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10657 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10658 | if (!msg) |
| 10659 | return; |
| 10660 | |
| 10661 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10662 | if (!hdr) { |
| 10663 | nlmsg_free(msg); |
| 10664 | return; |
| 10665 | } |
| 10666 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10667 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10668 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10669 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10670 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10671 | |
| 10672 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10673 | if (!rekey_attr) |
| 10674 | goto nla_put_failure; |
| 10675 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10676 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10677 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10678 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10679 | |
| 10680 | nla_nest_end(msg, rekey_attr); |
| 10681 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10682 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10683 | |
| 10684 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10685 | nl80211_mlme_mcgrp.id, gfp); |
| 10686 | return; |
| 10687 | |
| 10688 | nla_put_failure: |
| 10689 | genlmsg_cancel(msg, hdr); |
| 10690 | nlmsg_free(msg); |
| 10691 | } |
| 10692 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10693 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10694 | const u8 *replay_ctr, gfp_t gfp) |
| 10695 | { |
| 10696 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10697 | struct wiphy *wiphy = wdev->wiphy; |
| 10698 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10699 | |
| 10700 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10701 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10702 | } |
| 10703 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10704 | |
| 10705 | static void |
| 10706 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10707 | struct net_device *netdev, int index, |
| 10708 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10709 | { |
| 10710 | struct sk_buff *msg; |
| 10711 | struct nlattr *attr; |
| 10712 | void *hdr; |
| 10713 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10714 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10715 | if (!msg) |
| 10716 | return; |
| 10717 | |
| 10718 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10719 | if (!hdr) { |
| 10720 | nlmsg_free(msg); |
| 10721 | return; |
| 10722 | } |
| 10723 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10724 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10725 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10726 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10727 | |
| 10728 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10729 | if (!attr) |
| 10730 | goto nla_put_failure; |
| 10731 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10732 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10733 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10734 | (preauth && |
| 10735 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10736 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10737 | |
| 10738 | nla_nest_end(msg, attr); |
| 10739 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10740 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10741 | |
| 10742 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10743 | nl80211_mlme_mcgrp.id, gfp); |
| 10744 | return; |
| 10745 | |
| 10746 | nla_put_failure: |
| 10747 | genlmsg_cancel(msg, hdr); |
| 10748 | nlmsg_free(msg); |
| 10749 | } |
| 10750 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10751 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10752 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10753 | { |
| 10754 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10755 | struct wiphy *wiphy = wdev->wiphy; |
| 10756 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10757 | |
| 10758 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10759 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10760 | } |
| 10761 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10762 | |
| 10763 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10764 | struct net_device *netdev, |
| 10765 | struct cfg80211_chan_def *chandef, |
| 10766 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10767 | { |
| 10768 | struct sk_buff *msg; |
| 10769 | void *hdr; |
| 10770 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10771 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10772 | if (!msg) |
| 10773 | return; |
| 10774 | |
| 10775 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10776 | if (!hdr) { |
| 10777 | nlmsg_free(msg); |
| 10778 | return; |
| 10779 | } |
| 10780 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10781 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10782 | goto nla_put_failure; |
| 10783 | |
| 10784 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10785 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10786 | |
| 10787 | genlmsg_end(msg, hdr); |
| 10788 | |
| 10789 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10790 | nl80211_mlme_mcgrp.id, gfp); |
| 10791 | return; |
| 10792 | |
| 10793 | nla_put_failure: |
| 10794 | genlmsg_cancel(msg, hdr); |
| 10795 | nlmsg_free(msg); |
| 10796 | } |
| 10797 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10798 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10799 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10800 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10801 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10802 | struct wiphy *wiphy = wdev->wiphy; |
| 10803 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10804 | |
| 10805 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10806 | |
| 10807 | wdev_lock(wdev); |
| 10808 | |
| 10809 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 10810 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10811 | wdev->iftype != NL80211_IFTYPE_ADHOC)) |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10812 | goto out; |
| 10813 | |
| 10814 | wdev->channel = chandef->chan; |
| 10815 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10816 | out: |
| 10817 | wdev_unlock(wdev); |
| 10818 | return; |
| 10819 | } |
| 10820 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10821 | |
| 10822 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10823 | const u8 *peer, u32 num_packets, |
| 10824 | u32 rate, u32 intvl, gfp_t gfp) |
| 10825 | { |
| 10826 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10827 | struct wiphy *wiphy = wdev->wiphy; |
| 10828 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10829 | struct sk_buff *msg; |
| 10830 | struct nlattr *pinfoattr; |
| 10831 | void *hdr; |
| 10832 | |
| 10833 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10834 | if (!msg) |
| 10835 | return; |
| 10836 | |
| 10837 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10838 | if (!hdr) { |
| 10839 | nlmsg_free(msg); |
| 10840 | return; |
| 10841 | } |
| 10842 | |
| 10843 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10844 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10845 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10846 | goto nla_put_failure; |
| 10847 | |
| 10848 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10849 | if (!pinfoattr) |
| 10850 | goto nla_put_failure; |
| 10851 | |
| 10852 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10853 | goto nla_put_failure; |
| 10854 | |
| 10855 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10856 | goto nla_put_failure; |
| 10857 | |
| 10858 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10859 | goto nla_put_failure; |
| 10860 | |
| 10861 | nla_nest_end(msg, pinfoattr); |
| 10862 | |
| 10863 | genlmsg_end(msg, hdr); |
| 10864 | |
| 10865 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10866 | nl80211_mlme_mcgrp.id, gfp); |
| 10867 | return; |
| 10868 | |
| 10869 | nla_put_failure: |
| 10870 | genlmsg_cancel(msg, hdr); |
| 10871 | nlmsg_free(msg); |
| 10872 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10873 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10874 | |
| 10875 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10876 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 10877 | struct cfg80211_chan_def *chandef, |
| 10878 | enum nl80211_radar_event event, |
| 10879 | struct net_device *netdev, gfp_t gfp) |
| 10880 | { |
| 10881 | struct sk_buff *msg; |
| 10882 | void *hdr; |
| 10883 | |
| 10884 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10885 | if (!msg) |
| 10886 | return; |
| 10887 | |
| 10888 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10889 | if (!hdr) { |
| 10890 | nlmsg_free(msg); |
| 10891 | return; |
| 10892 | } |
| 10893 | |
| 10894 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10895 | goto nla_put_failure; |
| 10896 | |
| 10897 | /* NOP and radar events don't need a netdev parameter */ |
| 10898 | if (netdev) { |
| 10899 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10900 | |
| 10901 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10902 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10903 | goto nla_put_failure; |
| 10904 | } |
| 10905 | |
| 10906 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10907 | goto nla_put_failure; |
| 10908 | |
| 10909 | if (nl80211_send_chandef(msg, chandef)) |
| 10910 | goto nla_put_failure; |
| 10911 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10912 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10913 | |
| 10914 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10915 | nl80211_mlme_mcgrp.id, gfp); |
| 10916 | return; |
| 10917 | |
| 10918 | nla_put_failure: |
| 10919 | genlmsg_cancel(msg, hdr); |
| 10920 | nlmsg_free(msg); |
| 10921 | } |
| 10922 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10923 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10924 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10925 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10926 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10927 | struct wiphy *wiphy = wdev->wiphy; |
| 10928 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10929 | struct sk_buff *msg; |
| 10930 | struct nlattr *pinfoattr; |
| 10931 | void *hdr; |
| 10932 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10933 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10934 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10935 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10936 | if (!msg) |
| 10937 | return; |
| 10938 | |
| 10939 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10940 | if (!hdr) { |
| 10941 | nlmsg_free(msg); |
| 10942 | return; |
| 10943 | } |
| 10944 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10945 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10946 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10947 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10948 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10949 | |
| 10950 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10951 | if (!pinfoattr) |
| 10952 | goto nla_put_failure; |
| 10953 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10954 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10955 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10956 | |
| 10957 | nla_nest_end(msg, pinfoattr); |
| 10958 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10959 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10960 | |
| 10961 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10962 | nl80211_mlme_mcgrp.id, gfp); |
| 10963 | return; |
| 10964 | |
| 10965 | nla_put_failure: |
| 10966 | genlmsg_cancel(msg, hdr); |
| 10967 | nlmsg_free(msg); |
| 10968 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10969 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10970 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10971 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10972 | u64 cookie, bool acked, gfp_t gfp) |
| 10973 | { |
| 10974 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10975 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10976 | struct sk_buff *msg; |
| 10977 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10978 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10979 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10980 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10981 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10982 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10983 | if (!msg) |
| 10984 | return; |
| 10985 | |
| 10986 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10987 | if (!hdr) { |
| 10988 | nlmsg_free(msg); |
| 10989 | return; |
| 10990 | } |
| 10991 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10992 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10993 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10994 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10995 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10996 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10997 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10998 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10999 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11000 | |
| 11001 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11002 | nl80211_mlme_mcgrp.id, gfp); |
| 11003 | return; |
| 11004 | |
| 11005 | nla_put_failure: |
| 11006 | genlmsg_cancel(msg, hdr); |
| 11007 | nlmsg_free(msg); |
| 11008 | } |
| 11009 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11010 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11011 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11012 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11013 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11014 | { |
| 11015 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11016 | struct sk_buff *msg; |
| 11017 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11018 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11019 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11020 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11021 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11022 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11023 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11024 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11025 | if (!msg) { |
| 11026 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11027 | return; |
| 11028 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11029 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11030 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11031 | if (!hdr) |
| 11032 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11033 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11034 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11035 | (freq && |
| 11036 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11037 | (sig_dbm && |
| 11038 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11039 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11040 | goto nla_put_failure; |
| 11041 | |
| 11042 | genlmsg_end(msg, hdr); |
| 11043 | |
| 11044 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11045 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11046 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11047 | return; |
| 11048 | |
| 11049 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11050 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11051 | if (hdr) |
| 11052 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11053 | nlmsg_free(msg); |
| 11054 | } |
| 11055 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11056 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11057 | #ifdef CONFIG_PM |
| 11058 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11059 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11060 | gfp_t gfp) |
| 11061 | { |
| 11062 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11063 | struct sk_buff *msg; |
| 11064 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11065 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11066 | |
| 11067 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11068 | |
| 11069 | if (wakeup) |
| 11070 | size += wakeup->packet_present_len; |
| 11071 | |
| 11072 | msg = nlmsg_new(size, gfp); |
| 11073 | if (!msg) |
| 11074 | return; |
| 11075 | |
| 11076 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11077 | if (!hdr) |
| 11078 | goto free_msg; |
| 11079 | |
| 11080 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11081 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11082 | goto free_msg; |
| 11083 | |
| 11084 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11085 | wdev->netdev->ifindex)) |
| 11086 | goto free_msg; |
| 11087 | |
| 11088 | if (wakeup) { |
| 11089 | struct nlattr *reasons; |
| 11090 | |
| 11091 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 11092 | |
| 11093 | if (wakeup->disconnect && |
| 11094 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11095 | goto free_msg; |
| 11096 | if (wakeup->magic_pkt && |
| 11097 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11098 | goto free_msg; |
| 11099 | if (wakeup->gtk_rekey_failure && |
| 11100 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11101 | goto free_msg; |
| 11102 | if (wakeup->eap_identity_req && |
| 11103 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11104 | goto free_msg; |
| 11105 | if (wakeup->four_way_handshake && |
| 11106 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11107 | goto free_msg; |
| 11108 | if (wakeup->rfkill_release && |
| 11109 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11110 | goto free_msg; |
| 11111 | |
| 11112 | if (wakeup->pattern_idx >= 0 && |
| 11113 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11114 | wakeup->pattern_idx)) |
| 11115 | goto free_msg; |
| 11116 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11117 | if (wakeup->tcp_match) |
| 11118 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 11119 | |
| 11120 | if (wakeup->tcp_connlost) |
| 11121 | nla_put_flag(msg, |
| 11122 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 11123 | |
| 11124 | if (wakeup->tcp_nomoretokens) |
| 11125 | nla_put_flag(msg, |
| 11126 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 11127 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11128 | if (wakeup->packet) { |
| 11129 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11130 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11131 | |
| 11132 | if (!wakeup->packet_80211) { |
| 11133 | pkt_attr = |
| 11134 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11135 | len_attr = |
| 11136 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11137 | } |
| 11138 | |
| 11139 | if (wakeup->packet_len && |
| 11140 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11141 | goto free_msg; |
| 11142 | |
| 11143 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11144 | wakeup->packet)) |
| 11145 | goto free_msg; |
| 11146 | } |
| 11147 | |
| 11148 | nla_nest_end(msg, reasons); |
| 11149 | } |
| 11150 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11151 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11152 | |
| 11153 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11154 | nl80211_mlme_mcgrp.id, gfp); |
| 11155 | return; |
| 11156 | |
| 11157 | free_msg: |
| 11158 | nlmsg_free(msg); |
| 11159 | } |
| 11160 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11161 | #endif |
| 11162 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11163 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11164 | enum nl80211_tdls_operation oper, |
| 11165 | u16 reason_code, gfp_t gfp) |
| 11166 | { |
| 11167 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11168 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11169 | struct sk_buff *msg; |
| 11170 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11171 | |
| 11172 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11173 | reason_code); |
| 11174 | |
| 11175 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11176 | if (!msg) |
| 11177 | return; |
| 11178 | |
| 11179 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11180 | if (!hdr) { |
| 11181 | nlmsg_free(msg); |
| 11182 | return; |
| 11183 | } |
| 11184 | |
| 11185 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11186 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11187 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11188 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11189 | (reason_code > 0 && |
| 11190 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11191 | goto nla_put_failure; |
| 11192 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11193 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11194 | |
| 11195 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11196 | nl80211_mlme_mcgrp.id, gfp); |
| 11197 | return; |
| 11198 | |
| 11199 | nla_put_failure: |
| 11200 | genlmsg_cancel(msg, hdr); |
| 11201 | nlmsg_free(msg); |
| 11202 | } |
| 11203 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11204 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11205 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11206 | unsigned long state, |
| 11207 | void *_notify) |
| 11208 | { |
| 11209 | struct netlink_notify *notify = _notify; |
| 11210 | struct cfg80211_registered_device *rdev; |
| 11211 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11212 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11213 | |
| 11214 | if (state != NETLINK_URELEASE) |
| 11215 | return NOTIFY_DONE; |
| 11216 | |
| 11217 | rcu_read_lock(); |
| 11218 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11219 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11220 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11221 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11222 | |
| 11223 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11224 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11225 | list) { |
| 11226 | if (reg->nlportid == notify->portid) { |
| 11227 | list_del(®->list); |
| 11228 | kfree(reg); |
| 11229 | break; |
| 11230 | } |
| 11231 | } |
| 11232 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11233 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11234 | |
| 11235 | rcu_read_unlock(); |
| 11236 | |
| 11237 | return NOTIFY_DONE; |
| 11238 | } |
| 11239 | |
| 11240 | static struct notifier_block nl80211_netlink_notifier = { |
| 11241 | .notifier_call = nl80211_netlink_notify, |
| 11242 | }; |
| 11243 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11244 | void cfg80211_ft_event(struct net_device *netdev, |
| 11245 | struct cfg80211_ft_event_params *ft_event) |
| 11246 | { |
| 11247 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11248 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11249 | struct sk_buff *msg; |
| 11250 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11251 | |
| 11252 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11253 | |
| 11254 | if (!ft_event->target_ap) |
| 11255 | return; |
| 11256 | |
| 11257 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11258 | if (!msg) |
| 11259 | return; |
| 11260 | |
| 11261 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 11262 | if (!hdr) { |
| 11263 | nlmsg_free(msg); |
| 11264 | return; |
| 11265 | } |
| 11266 | |
| 11267 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 11268 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 11269 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 11270 | if (ft_event->ies) |
| 11271 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 11272 | if (ft_event->ric_ies) |
| 11273 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11274 | ft_event->ric_ies); |
| 11275 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11276 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11277 | |
| 11278 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11279 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 11280 | } |
| 11281 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11282 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11283 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11284 | { |
| 11285 | struct cfg80211_registered_device *rdev; |
| 11286 | struct sk_buff *msg; |
| 11287 | void *hdr; |
| 11288 | u32 nlportid; |
| 11289 | |
| 11290 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11291 | if (!rdev->crit_proto_nlportid) |
| 11292 | return; |
| 11293 | |
| 11294 | nlportid = rdev->crit_proto_nlportid; |
| 11295 | rdev->crit_proto_nlportid = 0; |
| 11296 | |
| 11297 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11298 | if (!msg) |
| 11299 | return; |
| 11300 | |
| 11301 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11302 | if (!hdr) |
| 11303 | goto nla_put_failure; |
| 11304 | |
| 11305 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11306 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11307 | goto nla_put_failure; |
| 11308 | |
| 11309 | genlmsg_end(msg, hdr); |
| 11310 | |
| 11311 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11312 | return; |
| 11313 | |
| 11314 | nla_put_failure: |
| 11315 | if (hdr) |
| 11316 | genlmsg_cancel(msg, hdr); |
| 11317 | nlmsg_free(msg); |
| 11318 | |
| 11319 | } |
| 11320 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11321 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11322 | /* initialisation/exit functions */ |
| 11323 | |
| 11324 | int nl80211_init(void) |
| 11325 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11326 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11327 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11328 | err = genl_register_family_with_ops(&nl80211_fam, |
| 11329 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11330 | if (err) |
| 11331 | return err; |
| 11332 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11333 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 11334 | if (err) |
| 11335 | goto err_out; |
| 11336 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11337 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 11338 | if (err) |
| 11339 | goto err_out; |
| 11340 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11341 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 11342 | if (err) |
| 11343 | goto err_out; |
| 11344 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11345 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 11346 | if (err) |
| 11347 | goto err_out; |
| 11348 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11349 | #ifdef CONFIG_NL80211_TESTMODE |
| 11350 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 11351 | if (err) |
| 11352 | goto err_out; |
| 11353 | #endif |
| 11354 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11355 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11356 | if (err) |
| 11357 | goto err_out; |
| 11358 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11359 | return 0; |
| 11360 | err_out: |
| 11361 | genl_unregister_family(&nl80211_fam); |
| 11362 | return err; |
| 11363 | } |
| 11364 | |
| 11365 | void nl80211_exit(void) |
| 11366 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11367 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11368 | genl_unregister_family(&nl80211_fam); |
| 11369 | } |