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 | dc6382ce | 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 }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 359 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 360 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 361 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 362 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 363 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 364 | }; |
| 365 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 366 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 367 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 368 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 369 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 370 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 371 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 372 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 373 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 374 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 375 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 376 | }; |
| 377 | |
| 378 | /* policy for the key default flags */ |
| 379 | static const struct nla_policy |
| 380 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 381 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 382 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 383 | }; |
| 384 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 385 | /* policy for WoWLAN attributes */ |
| 386 | static const struct nla_policy |
| 387 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 388 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 389 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 390 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 391 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 392 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 393 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 394 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 395 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 396 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 397 | }; |
| 398 | |
| 399 | static const struct nla_policy |
| 400 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 401 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 402 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 403 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 404 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 405 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 406 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 407 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 408 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 409 | }, |
| 410 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 411 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 412 | }, |
| 413 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 414 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 415 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 416 | }; |
| 417 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 418 | /* policy for coalesce rule attributes */ |
| 419 | static const struct nla_policy |
| 420 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 421 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 422 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 423 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 424 | }; |
| 425 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 426 | /* policy for GTK rekey offload attributes */ |
| 427 | static const struct nla_policy |
| 428 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 429 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 430 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 431 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 432 | }; |
| 433 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 434 | static const struct nla_policy |
| 435 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 436 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 437 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 438 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 439 | }; |
| 440 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 441 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 442 | struct netlink_callback *cb, |
| 443 | struct cfg80211_registered_device **rdev, |
| 444 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 445 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 446 | int err; |
| 447 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 448 | rtnl_lock(); |
| 449 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 450 | if (!cb->args[0]) { |
| 451 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 452 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 453 | nl80211_policy); |
| 454 | if (err) |
| 455 | goto out_unlock; |
| 456 | |
| 457 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 458 | nl80211_fam.attrbuf); |
| 459 | if (IS_ERR(*wdev)) { |
| 460 | err = PTR_ERR(*wdev); |
| 461 | goto out_unlock; |
| 462 | } |
| 463 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 464 | /* 0 is the first index - add 1 to parse only once */ |
| 465 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 466 | cb->args[1] = (*wdev)->identifier; |
| 467 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 468 | /* subtract the 1 again here */ |
| 469 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 470 | struct wireless_dev *tmp; |
| 471 | |
| 472 | if (!wiphy) { |
| 473 | err = -ENODEV; |
| 474 | goto out_unlock; |
| 475 | } |
| 476 | *rdev = wiphy_to_dev(wiphy); |
| 477 | *wdev = NULL; |
| 478 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 479 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 480 | if (tmp->identifier == cb->args[1]) { |
| 481 | *wdev = tmp; |
| 482 | break; |
| 483 | } |
| 484 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 485 | |
| 486 | if (!*wdev) { |
| 487 | err = -ENODEV; |
| 488 | goto out_unlock; |
| 489 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 492 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 493 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 494 | rtnl_unlock(); |
| 495 | return err; |
| 496 | } |
| 497 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 498 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 499 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 500 | rtnl_unlock(); |
| 501 | } |
| 502 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 503 | /* IE validation */ |
| 504 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 505 | { |
| 506 | const u8 *pos; |
| 507 | int len; |
| 508 | |
| 509 | if (!attr) |
| 510 | return true; |
| 511 | |
| 512 | pos = nla_data(attr); |
| 513 | len = nla_len(attr); |
| 514 | |
| 515 | while (len) { |
| 516 | u8 elemlen; |
| 517 | |
| 518 | if (len < 2) |
| 519 | return false; |
| 520 | len -= 2; |
| 521 | |
| 522 | elemlen = pos[1]; |
| 523 | if (elemlen > len) |
| 524 | return false; |
| 525 | |
| 526 | len -= elemlen; |
| 527 | pos += 2 + elemlen; |
| 528 | } |
| 529 | |
| 530 | return true; |
| 531 | } |
| 532 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 533 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 534 | 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] | 535 | int flags, u8 cmd) |
| 536 | { |
| 537 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 538 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 539 | } |
| 540 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 541 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 542 | struct ieee80211_channel *chan, |
| 543 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 544 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 545 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 546 | chan->center_freq)) |
| 547 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 548 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 549 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 550 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 551 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 552 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 553 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 554 | goto nla_put_failure; |
| 555 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 556 | goto nla_put_failure; |
| 557 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 558 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 559 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 560 | goto nla_put_failure; |
| 561 | if (large) { |
| 562 | u32 time; |
| 563 | |
| 564 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 565 | |
| 566 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 567 | chan->dfs_state)) |
| 568 | goto nla_put_failure; |
| 569 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 570 | time)) |
| 571 | goto nla_put_failure; |
| 572 | } |
| 573 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 574 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 575 | if (large) { |
| 576 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 577 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 578 | goto nla_put_failure; |
| 579 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 580 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 581 | goto nla_put_failure; |
| 582 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 583 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 584 | goto nla_put_failure; |
| 585 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 586 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 587 | goto nla_put_failure; |
| 588 | } |
| 589 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 590 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 591 | DBM_TO_MBM(chan->max_power))) |
| 592 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 593 | |
| 594 | return 0; |
| 595 | |
| 596 | nla_put_failure: |
| 597 | return -ENOBUFS; |
| 598 | } |
| 599 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 600 | /* netlink command implementations */ |
| 601 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 602 | struct key_parse { |
| 603 | struct key_params p; |
| 604 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 605 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 606 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 607 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 608 | }; |
| 609 | |
| 610 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 611 | { |
| 612 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 613 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 614 | nl80211_key_policy); |
| 615 | if (err) |
| 616 | return err; |
| 617 | |
| 618 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 619 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 620 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 621 | if (k->def) { |
| 622 | k->def_uni = true; |
| 623 | k->def_multi = true; |
| 624 | } |
| 625 | if (k->defmgmt) |
| 626 | k->def_multi = true; |
| 627 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 628 | if (tb[NL80211_KEY_IDX]) |
| 629 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 630 | |
| 631 | if (tb[NL80211_KEY_DATA]) { |
| 632 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 633 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 634 | } |
| 635 | |
| 636 | if (tb[NL80211_KEY_SEQ]) { |
| 637 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 638 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 639 | } |
| 640 | |
| 641 | if (tb[NL80211_KEY_CIPHER]) |
| 642 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 643 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 644 | if (tb[NL80211_KEY_TYPE]) { |
| 645 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 646 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 647 | return -EINVAL; |
| 648 | } |
| 649 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 650 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 651 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 652 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 653 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 654 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 655 | if (err) |
| 656 | return err; |
| 657 | |
| 658 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 659 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 660 | } |
| 661 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 666 | { |
| 667 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 668 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 669 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 670 | } |
| 671 | |
| 672 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 673 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 674 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 675 | } |
| 676 | |
| 677 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 678 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 679 | |
| 680 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 681 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 682 | |
| 683 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 684 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 685 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 686 | if (k->def) { |
| 687 | k->def_uni = true; |
| 688 | k->def_multi = true; |
| 689 | } |
| 690 | if (k->defmgmt) |
| 691 | k->def_multi = true; |
| 692 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 693 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 694 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 695 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 696 | return -EINVAL; |
| 697 | } |
| 698 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 699 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 700 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 701 | int err = nla_parse_nested( |
| 702 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 703 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 704 | nl80211_key_default_policy); |
| 705 | if (err) |
| 706 | return err; |
| 707 | |
| 708 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 709 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 710 | } |
| 711 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 716 | { |
| 717 | int err; |
| 718 | |
| 719 | memset(k, 0, sizeof(*k)); |
| 720 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 721 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 722 | |
| 723 | if (info->attrs[NL80211_ATTR_KEY]) |
| 724 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 725 | else |
| 726 | err = nl80211_parse_key_old(info, k); |
| 727 | |
| 728 | if (err) |
| 729 | return err; |
| 730 | |
| 731 | if (k->def && k->defmgmt) |
| 732 | return -EINVAL; |
| 733 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 734 | if (k->defmgmt) { |
| 735 | if (k->def_uni || !k->def_multi) |
| 736 | return -EINVAL; |
| 737 | } |
| 738 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 739 | if (k->idx != -1) { |
| 740 | if (k->defmgmt) { |
| 741 | if (k->idx < 4 || k->idx > 5) |
| 742 | return -EINVAL; |
| 743 | } else if (k->def) { |
| 744 | if (k->idx < 0 || k->idx > 3) |
| 745 | return -EINVAL; |
| 746 | } else { |
| 747 | if (k->idx < 0 || k->idx > 5) |
| 748 | return -EINVAL; |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | return 0; |
| 753 | } |
| 754 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 755 | static struct cfg80211_cached_keys * |
| 756 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 757 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 758 | { |
| 759 | struct key_parse parse; |
| 760 | struct nlattr *key; |
| 761 | struct cfg80211_cached_keys *result; |
| 762 | int rem, err, def = 0; |
| 763 | |
| 764 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 765 | if (!result) |
| 766 | return ERR_PTR(-ENOMEM); |
| 767 | |
| 768 | result->def = -1; |
| 769 | result->defmgmt = -1; |
| 770 | |
| 771 | nla_for_each_nested(key, keys, rem) { |
| 772 | memset(&parse, 0, sizeof(parse)); |
| 773 | parse.idx = -1; |
| 774 | |
| 775 | err = nl80211_parse_key_new(key, &parse); |
| 776 | if (err) |
| 777 | goto error; |
| 778 | err = -EINVAL; |
| 779 | if (!parse.p.key) |
| 780 | goto error; |
| 781 | if (parse.idx < 0 || parse.idx > 4) |
| 782 | goto error; |
| 783 | if (parse.def) { |
| 784 | if (def) |
| 785 | goto error; |
| 786 | def = 1; |
| 787 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 788 | if (!parse.def_uni || !parse.def_multi) |
| 789 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 790 | } else if (parse.defmgmt) |
| 791 | goto error; |
| 792 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 793 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 794 | if (err) |
| 795 | goto error; |
| 796 | result->params[parse.idx].cipher = parse.p.cipher; |
| 797 | result->params[parse.idx].key_len = parse.p.key_len; |
| 798 | result->params[parse.idx].key = result->data[parse.idx]; |
| 799 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 800 | |
| 801 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 802 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 803 | if (no_ht) |
| 804 | *no_ht = true; |
| 805 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | return result; |
| 809 | error: |
| 810 | kfree(result); |
| 811 | return ERR_PTR(err); |
| 812 | } |
| 813 | |
| 814 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 815 | { |
| 816 | ASSERT_WDEV_LOCK(wdev); |
| 817 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 818 | switch (wdev->iftype) { |
| 819 | case NL80211_IFTYPE_AP: |
| 820 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 821 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 822 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 823 | break; |
| 824 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 825 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 826 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 827 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 828 | return -ENOLINK; |
| 829 | break; |
| 830 | default: |
| 831 | return -EINVAL; |
| 832 | } |
| 833 | |
| 834 | return 0; |
| 835 | } |
| 836 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 837 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 838 | { |
| 839 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 840 | int i; |
| 841 | |
| 842 | if (!nl_modes) |
| 843 | goto nla_put_failure; |
| 844 | |
| 845 | i = 0; |
| 846 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 847 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 848 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 849 | ifmodes >>= 1; |
| 850 | i++; |
| 851 | } |
| 852 | |
| 853 | nla_nest_end(msg, nl_modes); |
| 854 | return 0; |
| 855 | |
| 856 | nla_put_failure: |
| 857 | return -ENOBUFS; |
| 858 | } |
| 859 | |
| 860 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 861 | struct sk_buff *msg, |
| 862 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 863 | { |
| 864 | struct nlattr *nl_combis; |
| 865 | int i, j; |
| 866 | |
| 867 | nl_combis = nla_nest_start(msg, |
| 868 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 869 | if (!nl_combis) |
| 870 | goto nla_put_failure; |
| 871 | |
| 872 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 873 | const struct ieee80211_iface_combination *c; |
| 874 | struct nlattr *nl_combi, *nl_limits; |
| 875 | |
| 876 | c = &wiphy->iface_combinations[i]; |
| 877 | |
| 878 | nl_combi = nla_nest_start(msg, i + 1); |
| 879 | if (!nl_combi) |
| 880 | goto nla_put_failure; |
| 881 | |
| 882 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 883 | if (!nl_limits) |
| 884 | goto nla_put_failure; |
| 885 | |
| 886 | for (j = 0; j < c->n_limits; j++) { |
| 887 | struct nlattr *nl_limit; |
| 888 | |
| 889 | nl_limit = nla_nest_start(msg, j + 1); |
| 890 | if (!nl_limit) |
| 891 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 892 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 893 | c->limits[j].max)) |
| 894 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 895 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 896 | c->limits[j].types)) |
| 897 | goto nla_put_failure; |
| 898 | nla_nest_end(msg, nl_limit); |
| 899 | } |
| 900 | |
| 901 | nla_nest_end(msg, nl_limits); |
| 902 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 903 | if (c->beacon_int_infra_match && |
| 904 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 905 | goto nla_put_failure; |
| 906 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 907 | c->num_different_channels) || |
| 908 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 909 | c->max_interfaces)) |
| 910 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 911 | if (large && |
| 912 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 913 | c->radar_detect_widths)) |
| 914 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 915 | |
| 916 | nla_nest_end(msg, nl_combi); |
| 917 | } |
| 918 | |
| 919 | nla_nest_end(msg, nl_combis); |
| 920 | |
| 921 | return 0; |
| 922 | nla_put_failure: |
| 923 | return -ENOBUFS; |
| 924 | } |
| 925 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 926 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 927 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 928 | struct sk_buff *msg) |
| 929 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 930 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 931 | struct nlattr *nl_tcp; |
| 932 | |
| 933 | if (!tcp) |
| 934 | return 0; |
| 935 | |
| 936 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 937 | if (!nl_tcp) |
| 938 | return -ENOBUFS; |
| 939 | |
| 940 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 941 | tcp->data_payload_max)) |
| 942 | return -ENOBUFS; |
| 943 | |
| 944 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 945 | tcp->data_payload_max)) |
| 946 | return -ENOBUFS; |
| 947 | |
| 948 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 949 | return -ENOBUFS; |
| 950 | |
| 951 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 952 | sizeof(*tcp->tok), tcp->tok)) |
| 953 | return -ENOBUFS; |
| 954 | |
| 955 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 956 | tcp->data_interval_max)) |
| 957 | return -ENOBUFS; |
| 958 | |
| 959 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 960 | tcp->wake_payload_max)) |
| 961 | return -ENOBUFS; |
| 962 | |
| 963 | nla_nest_end(msg, nl_tcp); |
| 964 | return 0; |
| 965 | } |
| 966 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 967 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 968 | struct cfg80211_registered_device *dev, |
| 969 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 970 | { |
| 971 | struct nlattr *nl_wowlan; |
| 972 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 973 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 974 | return 0; |
| 975 | |
| 976 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 977 | if (!nl_wowlan) |
| 978 | return -ENOBUFS; |
| 979 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 980 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 981 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 982 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 983 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 984 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 985 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 986 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 987 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 988 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 989 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 990 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 991 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 992 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 993 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 994 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 995 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 996 | return -ENOBUFS; |
| 997 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 998 | if (dev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 999 | struct nl80211_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1000 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 1001 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 1002 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 1003 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1004 | }; |
| 1005 | |
| 1006 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1007 | sizeof(pat), &pat)) |
| 1008 | return -ENOBUFS; |
| 1009 | } |
| 1010 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1011 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1012 | return -ENOBUFS; |
| 1013 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1014 | nla_nest_end(msg, nl_wowlan); |
| 1015 | |
| 1016 | return 0; |
| 1017 | } |
| 1018 | #endif |
| 1019 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1020 | static int nl80211_send_coalesce(struct sk_buff *msg, |
| 1021 | struct cfg80211_registered_device *dev) |
| 1022 | { |
| 1023 | struct nl80211_coalesce_rule_support rule; |
| 1024 | |
| 1025 | if (!dev->wiphy.coalesce) |
| 1026 | return 0; |
| 1027 | |
| 1028 | rule.max_rules = dev->wiphy.coalesce->n_rules; |
| 1029 | rule.max_delay = dev->wiphy.coalesce->max_delay; |
| 1030 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; |
| 1031 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; |
| 1032 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; |
| 1033 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; |
| 1034 | |
| 1035 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1036 | return -ENOBUFS; |
| 1037 | |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1041 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1042 | struct ieee80211_supported_band *sband) |
| 1043 | { |
| 1044 | struct nlattr *nl_rates, *nl_rate; |
| 1045 | struct ieee80211_rate *rate; |
| 1046 | int i; |
| 1047 | |
| 1048 | /* add HT info */ |
| 1049 | if (sband->ht_cap.ht_supported && |
| 1050 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1051 | sizeof(sband->ht_cap.mcs), |
| 1052 | &sband->ht_cap.mcs) || |
| 1053 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1054 | sband->ht_cap.cap) || |
| 1055 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1056 | sband->ht_cap.ampdu_factor) || |
| 1057 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1058 | sband->ht_cap.ampdu_density))) |
| 1059 | return -ENOBUFS; |
| 1060 | |
| 1061 | /* add VHT info */ |
| 1062 | if (sband->vht_cap.vht_supported && |
| 1063 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1064 | sizeof(sband->vht_cap.vht_mcs), |
| 1065 | &sband->vht_cap.vht_mcs) || |
| 1066 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1067 | sband->vht_cap.cap))) |
| 1068 | return -ENOBUFS; |
| 1069 | |
| 1070 | /* add bitrates */ |
| 1071 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1072 | if (!nl_rates) |
| 1073 | return -ENOBUFS; |
| 1074 | |
| 1075 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1076 | nl_rate = nla_nest_start(msg, i); |
| 1077 | if (!nl_rate) |
| 1078 | return -ENOBUFS; |
| 1079 | |
| 1080 | rate = &sband->bitrates[i]; |
| 1081 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1082 | rate->bitrate)) |
| 1083 | return -ENOBUFS; |
| 1084 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1085 | nla_put_flag(msg, |
| 1086 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1087 | return -ENOBUFS; |
| 1088 | |
| 1089 | nla_nest_end(msg, nl_rate); |
| 1090 | } |
| 1091 | |
| 1092 | nla_nest_end(msg, nl_rates); |
| 1093 | |
| 1094 | return 0; |
| 1095 | } |
| 1096 | |
| 1097 | static int |
| 1098 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1099 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1100 | { |
| 1101 | u16 stypes; |
| 1102 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1103 | enum nl80211_iftype ift; |
| 1104 | int i; |
| 1105 | |
| 1106 | if (!mgmt_stypes) |
| 1107 | return 0; |
| 1108 | |
| 1109 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1110 | if (!nl_ifs) |
| 1111 | return -ENOBUFS; |
| 1112 | |
| 1113 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1114 | nl_ftypes = nla_nest_start(msg, ift); |
| 1115 | if (!nl_ftypes) |
| 1116 | return -ENOBUFS; |
| 1117 | i = 0; |
| 1118 | stypes = mgmt_stypes[ift].tx; |
| 1119 | while (stypes) { |
| 1120 | if ((stypes & 1) && |
| 1121 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1122 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1123 | return -ENOBUFS; |
| 1124 | stypes >>= 1; |
| 1125 | i++; |
| 1126 | } |
| 1127 | nla_nest_end(msg, nl_ftypes); |
| 1128 | } |
| 1129 | |
| 1130 | nla_nest_end(msg, nl_ifs); |
| 1131 | |
| 1132 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1133 | if (!nl_ifs) |
| 1134 | return -ENOBUFS; |
| 1135 | |
| 1136 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1137 | nl_ftypes = nla_nest_start(msg, ift); |
| 1138 | if (!nl_ftypes) |
| 1139 | return -ENOBUFS; |
| 1140 | i = 0; |
| 1141 | stypes = mgmt_stypes[ift].rx; |
| 1142 | while (stypes) { |
| 1143 | if ((stypes & 1) && |
| 1144 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1145 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1146 | return -ENOBUFS; |
| 1147 | stypes >>= 1; |
| 1148 | i++; |
| 1149 | } |
| 1150 | nla_nest_end(msg, nl_ftypes); |
| 1151 | } |
| 1152 | nla_nest_end(msg, nl_ifs); |
| 1153 | |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1157 | struct nl80211_dump_wiphy_state { |
| 1158 | s64 filter_wiphy; |
| 1159 | long start; |
| 1160 | long split_start, band_start, chan_start; |
| 1161 | bool split; |
| 1162 | }; |
| 1163 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1164 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1165 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1166 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1167 | { |
| 1168 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1169 | struct nlattr *nl_bands, *nl_band; |
| 1170 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1171 | struct nlattr *nl_cmds; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1172 | struct nlattr *nl_vendor_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1173 | enum ieee80211_band band; |
| 1174 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1175 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1176 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1177 | dev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1178 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1179 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1180 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1181 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1182 | return -ENOBUFS; |
| 1183 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1184 | if (WARN_ON(!state)) |
| 1185 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1186 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1187 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1188 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1189 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1190 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1191 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1192 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1193 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1194 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1195 | case 0: |
| 1196 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1197 | dev->wiphy.retry_short) || |
| 1198 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1199 | dev->wiphy.retry_long) || |
| 1200 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1201 | dev->wiphy.frag_threshold) || |
| 1202 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1203 | dev->wiphy.rts_threshold) || |
| 1204 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1205 | dev->wiphy.coverage_class) || |
| 1206 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1207 | dev->wiphy.max_scan_ssids) || |
| 1208 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1209 | dev->wiphy.max_sched_scan_ssids) || |
| 1210 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1211 | dev->wiphy.max_scan_ie_len) || |
| 1212 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1213 | dev->wiphy.max_sched_scan_ie_len) || |
| 1214 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1215 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1216 | goto nla_put_failure; |
| 1217 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1218 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1219 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1220 | goto nla_put_failure; |
| 1221 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1222 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1223 | goto nla_put_failure; |
| 1224 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1225 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1226 | goto nla_put_failure; |
| 1227 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1228 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1229 | goto nla_put_failure; |
| 1230 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1231 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1232 | goto nla_put_failure; |
| 1233 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1234 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1235 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1236 | state->split_start++; |
| 1237 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1238 | break; |
| 1239 | case 1: |
| 1240 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1241 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1242 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1243 | goto nla_put_failure; |
| 1244 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1245 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1246 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1247 | goto nla_put_failure; |
| 1248 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1249 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1250 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1251 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1252 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1253 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1254 | dev->wiphy.available_antennas_tx) || |
| 1255 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1256 | dev->wiphy.available_antennas_rx)) |
| 1257 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1258 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1259 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1260 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1261 | dev->wiphy.probe_resp_offload)) |
| 1262 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1263 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1264 | if ((dev->wiphy.available_antennas_tx || |
| 1265 | dev->wiphy.available_antennas_rx) && |
| 1266 | dev->ops->get_antenna) { |
| 1267 | u32 tx_ant = 0, rx_ant = 0; |
| 1268 | int res; |
| 1269 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1270 | if (!res) { |
| 1271 | if (nla_put_u32(msg, |
| 1272 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1273 | tx_ant) || |
| 1274 | nla_put_u32(msg, |
| 1275 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1276 | rx_ant)) |
| 1277 | goto nla_put_failure; |
| 1278 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1279 | } |
| 1280 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1281 | state->split_start++; |
| 1282 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1283 | break; |
| 1284 | case 2: |
| 1285 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1286 | dev->wiphy.interface_modes)) |
| 1287 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1288 | state->split_start++; |
| 1289 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1290 | break; |
| 1291 | case 3: |
| 1292 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1293 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1294 | goto nla_put_failure; |
| 1295 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1296 | for (band = state->band_start; |
| 1297 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1298 | struct ieee80211_supported_band *sband; |
| 1299 | |
| 1300 | sband = dev->wiphy.bands[band]; |
| 1301 | |
| 1302 | if (!sband) |
| 1303 | continue; |
| 1304 | |
| 1305 | nl_band = nla_nest_start(msg, band); |
| 1306 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1307 | goto nla_put_failure; |
| 1308 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1309 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1310 | case 0: |
| 1311 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1312 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1313 | state->chan_start++; |
| 1314 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1315 | break; |
| 1316 | default: |
| 1317 | /* add frequencies */ |
| 1318 | nl_freqs = nla_nest_start( |
| 1319 | msg, NL80211_BAND_ATTR_FREQS); |
| 1320 | if (!nl_freqs) |
| 1321 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1322 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1323 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1324 | i < sband->n_channels; |
| 1325 | i++) { |
| 1326 | nl_freq = nla_nest_start(msg, i); |
| 1327 | if (!nl_freq) |
| 1328 | goto nla_put_failure; |
| 1329 | |
| 1330 | chan = &sband->channels[i]; |
| 1331 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1332 | if (nl80211_msg_put_channel( |
| 1333 | msg, chan, |
| 1334 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1335 | goto nla_put_failure; |
| 1336 | |
| 1337 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1338 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1339 | break; |
| 1340 | } |
| 1341 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1342 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1343 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1344 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1345 | nla_nest_end(msg, nl_freqs); |
| 1346 | } |
| 1347 | |
| 1348 | nla_nest_end(msg, nl_band); |
| 1349 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1350 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1351 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1352 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1353 | band--; |
| 1354 | break; |
| 1355 | } |
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 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1358 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1359 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1360 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1361 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1362 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1363 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1364 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1365 | if (state->band_start == 0 && state->chan_start == 0) |
| 1366 | state->split_start++; |
| 1367 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1368 | break; |
| 1369 | case 4: |
| 1370 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1371 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1372 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1373 | |
| 1374 | i = 0; |
| 1375 | #define CMD(op, n) \ |
| 1376 | do { \ |
| 1377 | if (dev->ops->op) { \ |
| 1378 | i++; \ |
| 1379 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1380 | goto nla_put_failure; \ |
| 1381 | } \ |
| 1382 | } while (0) |
| 1383 | |
| 1384 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1385 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1386 | CMD(add_key, NEW_KEY); |
| 1387 | CMD(start_ap, START_AP); |
| 1388 | CMD(add_station, NEW_STATION); |
| 1389 | CMD(add_mpath, NEW_MPATH); |
| 1390 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1391 | CMD(change_bss, SET_BSS); |
| 1392 | CMD(auth, AUTHENTICATE); |
| 1393 | CMD(assoc, ASSOCIATE); |
| 1394 | CMD(deauth, DEAUTHENTICATE); |
| 1395 | CMD(disassoc, DISASSOCIATE); |
| 1396 | CMD(join_ibss, JOIN_IBSS); |
| 1397 | CMD(join_mesh, JOIN_MESH); |
| 1398 | CMD(set_pmksa, SET_PMKSA); |
| 1399 | CMD(del_pmksa, DEL_PMKSA); |
| 1400 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1401 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1402 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1403 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1404 | CMD(mgmt_tx, FRAME); |
| 1405 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1406 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1407 | i++; |
| 1408 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1409 | goto nla_put_failure; |
| 1410 | } |
| 1411 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1412 | dev->ops->join_mesh) { |
| 1413 | i++; |
| 1414 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1415 | goto nla_put_failure; |
| 1416 | } |
| 1417 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1418 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1419 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1420 | CMD(tdls_oper, TDLS_OPER); |
| 1421 | } |
| 1422 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1423 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1424 | CMD(probe_client, PROBE_CLIENT); |
| 1425 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1426 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1427 | i++; |
| 1428 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1429 | goto nla_put_failure; |
| 1430 | } |
| 1431 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1432 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1433 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1434 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1435 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1436 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
| 1437 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1438 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1439 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1440 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1441 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1442 | #endif |
| 1443 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1444 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1445 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1446 | if (dev->ops->connect || dev->ops->auth) { |
| 1447 | i++; |
| 1448 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1449 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1450 | } |
| 1451 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1452 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1453 | i++; |
| 1454 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1455 | goto nla_put_failure; |
| 1456 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1457 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1458 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1459 | state->split_start++; |
| 1460 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1461 | break; |
| 1462 | case 5: |
| 1463 | if (dev->ops->remain_on_channel && |
| 1464 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1465 | nla_put_u32(msg, |
| 1466 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1467 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1468 | goto nla_put_failure; |
| 1469 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1470 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1471 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1472 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1473 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1474 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1475 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1476 | state->split_start++; |
| 1477 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1478 | break; |
| 1479 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1480 | #ifdef CONFIG_PM |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1481 | if (nl80211_send_wowlan(msg, dev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1482 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1483 | state->split_start++; |
| 1484 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1485 | break; |
| 1486 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1487 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1488 | #endif |
| 1489 | case 7: |
| 1490 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1491 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1492 | goto nla_put_failure; |
| 1493 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1494 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
| 1495 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1496 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1497 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1498 | state->split_start++; |
| 1499 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1500 | break; |
| 1501 | case 8: |
| 1502 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1503 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1504 | dev->wiphy.ap_sme_capa)) |
| 1505 | goto nla_put_failure; |
| 1506 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1507 | features = dev->wiphy.features; |
| 1508 | /* |
| 1509 | * We can only add the per-channel limit information if the |
| 1510 | * dump is split, otherwise it makes it too big. Therefore |
| 1511 | * only advertise it in that case. |
| 1512 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1513 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1514 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1515 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1516 | goto nla_put_failure; |
| 1517 | |
| 1518 | if (dev->wiphy.ht_capa_mod_mask && |
| 1519 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1520 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1521 | dev->wiphy.ht_capa_mod_mask)) |
| 1522 | goto nla_put_failure; |
| 1523 | |
| 1524 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1525 | dev->wiphy.max_acl_mac_addrs && |
| 1526 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1527 | dev->wiphy.max_acl_mac_addrs)) |
| 1528 | goto nla_put_failure; |
| 1529 | |
| 1530 | /* |
| 1531 | * Any information below this point is only available to |
| 1532 | * applications that can deal with it being split. This |
| 1533 | * helps ensure that newly added capabilities don't break |
| 1534 | * older tools by overrunning their buffers. |
| 1535 | * |
| 1536 | * We still increment split_start so that in the split |
| 1537 | * case we'll continue with more data in the next round, |
| 1538 | * but break unconditionally so unsplit data stops here. |
| 1539 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1540 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1541 | break; |
| 1542 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1543 | if (dev->wiphy.extended_capabilities && |
| 1544 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1545 | dev->wiphy.extended_capabilities_len, |
| 1546 | dev->wiphy.extended_capabilities) || |
| 1547 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1548 | dev->wiphy.extended_capabilities_len, |
| 1549 | dev->wiphy.extended_capabilities_mask))) |
| 1550 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1551 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1552 | if (dev->wiphy.vht_capa_mod_mask && |
| 1553 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1554 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1555 | dev->wiphy.vht_capa_mod_mask)) |
| 1556 | goto nla_put_failure; |
| 1557 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1558 | state->split_start++; |
| 1559 | break; |
| 1560 | case 10: |
| 1561 | if (nl80211_send_coalesce(msg, dev)) |
| 1562 | goto nla_put_failure; |
| 1563 | |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1564 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1565 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1566 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1567 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1568 | state->split_start++; |
| 1569 | break; |
| 1570 | case 11: |
| 1571 | nl_vendor_cmds = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1572 | if (!nl_vendor_cmds) |
| 1573 | goto nla_put_failure; |
| 1574 | |
| 1575 | for (i = 0; i < dev->wiphy.n_vendor_commands; i++) |
| 1576 | if (nla_put(msg, i + 1, |
| 1577 | sizeof(struct nl80211_vendor_cmd_info), |
| 1578 | &dev->wiphy.vendor_commands[i].info)) |
| 1579 | goto nla_put_failure; |
| 1580 | nla_nest_end(msg, nl_vendor_cmds); |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1581 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1582 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1583 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1584 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1585 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1586 | return genlmsg_end(msg, hdr); |
| 1587 | |
| 1588 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1589 | genlmsg_cancel(msg, hdr); |
| 1590 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1591 | } |
| 1592 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1593 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1594 | struct netlink_callback *cb, |
| 1595 | struct nl80211_dump_wiphy_state *state) |
| 1596 | { |
| 1597 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1598 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1599 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1600 | /* ignore parse errors for backward compatibility */ |
| 1601 | if (ret) |
| 1602 | return 0; |
| 1603 | |
| 1604 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1605 | if (tb[NL80211_ATTR_WIPHY]) |
| 1606 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1607 | if (tb[NL80211_ATTR_WDEV]) |
| 1608 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1609 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1610 | struct net_device *netdev; |
| 1611 | struct cfg80211_registered_device *rdev; |
| 1612 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1613 | |
| 1614 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1615 | if (!netdev) |
| 1616 | return -ENODEV; |
| 1617 | if (netdev->ieee80211_ptr) { |
| 1618 | rdev = wiphy_to_dev( |
| 1619 | netdev->ieee80211_ptr->wiphy); |
| 1620 | state->filter_wiphy = rdev->wiphy_idx; |
| 1621 | } |
| 1622 | dev_put(netdev); |
| 1623 | } |
| 1624 | |
| 1625 | return 0; |
| 1626 | } |
| 1627 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1628 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1629 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1630 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1631 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1632 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1633 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1634 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1635 | if (!state) { |
| 1636 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1637 | if (!state) { |
| 1638 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1639 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1640 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1641 | state->filter_wiphy = -1; |
| 1642 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1643 | if (ret) { |
| 1644 | kfree(state); |
| 1645 | rtnl_unlock(); |
| 1646 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1647 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1648 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1649 | } |
| 1650 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1651 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1652 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1653 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1654 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1655 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1656 | if (state->filter_wiphy != -1 && |
| 1657 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1658 | continue; |
| 1659 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1660 | do { |
| 1661 | ret = nl80211_send_wiphy(dev, skb, |
| 1662 | NETLINK_CB(cb->skb).portid, |
| 1663 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1664 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1665 | if (ret < 0) { |
| 1666 | /* |
| 1667 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1668 | * or EMSGSIZE returned), this SKB is still |
| 1669 | * empty (so it's not too big because another |
| 1670 | * wiphy dataset is already in the skb) and |
| 1671 | * we've not tried to adjust the dump allocation |
| 1672 | * yet ... then adjust the alloc size to be |
| 1673 | * bigger, and return 1 but with the empty skb. |
| 1674 | * This results in an empty message being RX'ed |
| 1675 | * in userspace, but that is ignored. |
| 1676 | * |
| 1677 | * We can then retry with the larger buffer. |
| 1678 | */ |
| 1679 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1680 | !skb->len && |
| 1681 | cb->min_dump_alloc < 4096) { |
| 1682 | cb->min_dump_alloc = 4096; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1683 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1684 | return 1; |
| 1685 | } |
| 1686 | idx--; |
| 1687 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1688 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1689 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1690 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1691 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1692 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1693 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1694 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1695 | |
| 1696 | return skb->len; |
| 1697 | } |
| 1698 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1699 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1700 | { |
| 1701 | kfree((void *)cb->args[0]); |
| 1702 | return 0; |
| 1703 | } |
| 1704 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1705 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1706 | { |
| 1707 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1708 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1709 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1710 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1711 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1712 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1713 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1714 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1715 | 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] | 1716 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1717 | nlmsg_free(msg); |
| 1718 | return -ENOBUFS; |
| 1719 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1720 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1721 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1722 | } |
| 1723 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1724 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1725 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1726 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1727 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1728 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1729 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1730 | }; |
| 1731 | |
| 1732 | static int parse_txq_params(struct nlattr *tb[], |
| 1733 | struct ieee80211_txq_params *txq_params) |
| 1734 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1735 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1736 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1737 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1738 | return -EINVAL; |
| 1739 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1740 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1741 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1742 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1743 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1744 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1745 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1746 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1747 | return -EINVAL; |
| 1748 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1749 | return 0; |
| 1750 | } |
| 1751 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1752 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1753 | { |
| 1754 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1755 | * You can only set the channel explicitly for WDS interfaces, |
| 1756 | * all others have their channel managed via their respective |
| 1757 | * "establish a connection" command (connect, join, ...) |
| 1758 | * |
| 1759 | * For AP/GO and mesh mode, the channel can be set with the |
| 1760 | * channel userspace API, but is only stored and passed to the |
| 1761 | * low-level driver when the AP starts or the mesh is joined. |
| 1762 | * This is for backward compatibility, userspace can also give |
| 1763 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1764 | * |
| 1765 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1766 | * whatever else is going on, so they have their own special |
| 1767 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1768 | */ |
| 1769 | return !wdev || |
| 1770 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1771 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1772 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1773 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1774 | } |
| 1775 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1776 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1777 | struct genl_info *info, |
| 1778 | struct cfg80211_chan_def *chandef) |
| 1779 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1780 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1781 | |
| 1782 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1783 | return -EINVAL; |
| 1784 | |
| 1785 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1786 | |
| 1787 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1788 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1789 | chandef->center_freq1 = control_freq; |
| 1790 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1791 | |
| 1792 | /* Primary channel not allowed */ |
| 1793 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1794 | return -EINVAL; |
| 1795 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1796 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1797 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1798 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1799 | chantype = nla_get_u32( |
| 1800 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1801 | |
| 1802 | switch (chantype) { |
| 1803 | case NL80211_CHAN_NO_HT: |
| 1804 | case NL80211_CHAN_HT20: |
| 1805 | case NL80211_CHAN_HT40PLUS: |
| 1806 | case NL80211_CHAN_HT40MINUS: |
| 1807 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1808 | chantype); |
| 1809 | break; |
| 1810 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1811 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1812 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1813 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1814 | chandef->width = |
| 1815 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1816 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1817 | chandef->center_freq1 = |
| 1818 | nla_get_u32( |
| 1819 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1820 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1821 | chandef->center_freq2 = |
| 1822 | nla_get_u32( |
| 1823 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1824 | } |
| 1825 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1826 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1827 | return -EINVAL; |
| 1828 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1829 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1830 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1831 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1832 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1833 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1834 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1835 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1836 | return -EINVAL; |
| 1837 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1838 | return 0; |
| 1839 | } |
| 1840 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1841 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1842 | struct wireless_dev *wdev, |
| 1843 | struct genl_info *info) |
| 1844 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1845 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1846 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1847 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1848 | |
| 1849 | if (wdev) |
| 1850 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1851 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1852 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1853 | return -EOPNOTSUPP; |
| 1854 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1855 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1856 | if (result) |
| 1857 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1858 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1859 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1860 | case NL80211_IFTYPE_AP: |
| 1861 | case NL80211_IFTYPE_P2P_GO: |
| 1862 | if (wdev->beacon_interval) { |
| 1863 | result = -EBUSY; |
| 1864 | break; |
| 1865 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1866 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1867 | result = -EINVAL; |
| 1868 | break; |
| 1869 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1870 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1871 | result = 0; |
| 1872 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1873 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1874 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1875 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1876 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1877 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1878 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1879 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1880 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1881 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1882 | |
| 1883 | return result; |
| 1884 | } |
| 1885 | |
| 1886 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1887 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1888 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1889 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1890 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1891 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1892 | } |
| 1893 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1894 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1895 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1896 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1897 | struct net_device *dev = info->user_ptr[1]; |
| 1898 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1899 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1900 | |
| 1901 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1902 | return -EINVAL; |
| 1903 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1904 | if (netif_running(dev)) |
| 1905 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1906 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1907 | if (!rdev->ops->set_wds_peer) |
| 1908 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1909 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1910 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1911 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1912 | |
| 1913 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1914 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1918 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1919 | { |
| 1920 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1921 | struct net_device *netdev = NULL; |
| 1922 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1923 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1924 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1925 | u32 changed; |
| 1926 | u8 retry_short = 0, retry_long = 0; |
| 1927 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1928 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1929 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1930 | ASSERT_RTNL(); |
| 1931 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1932 | /* |
| 1933 | * Try to find the wiphy and netdev. Normally this |
| 1934 | * function shouldn't need the netdev, but this is |
| 1935 | * done for backward compatibility -- previously |
| 1936 | * setting the channel was done per wiphy, but now |
| 1937 | * it is per netdev. Previous userland like hostapd |
| 1938 | * also passed a netdev to set_wiphy, so that it is |
| 1939 | * possible to let that go to the right netdev! |
| 1940 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1941 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1942 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1943 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1944 | |
| 1945 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1946 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1947 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1948 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1949 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1950 | } |
| 1951 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1952 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1953 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1954 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1955 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1956 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1957 | wdev = NULL; |
| 1958 | netdev = NULL; |
| 1959 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1960 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1961 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1962 | |
| 1963 | /* |
| 1964 | * end workaround code, by now the rdev is available |
| 1965 | * and locked, and wdev may or may not be NULL. |
| 1966 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1967 | |
| 1968 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1969 | result = cfg80211_dev_rename( |
| 1970 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1971 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1972 | if (result) |
| 1973 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1974 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1975 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1976 | struct ieee80211_txq_params txq_params; |
| 1977 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1978 | |
| 1979 | if (!rdev->ops->set_txq_params) { |
| 1980 | result = -EOPNOTSUPP; |
| 1981 | goto bad_res; |
| 1982 | } |
| 1983 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1984 | if (!netdev) { |
| 1985 | result = -EINVAL; |
| 1986 | goto bad_res; |
| 1987 | } |
| 1988 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1989 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1990 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1991 | result = -EINVAL; |
| 1992 | goto bad_res; |
| 1993 | } |
| 1994 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1995 | if (!netif_running(netdev)) { |
| 1996 | result = -ENETDOWN; |
| 1997 | goto bad_res; |
| 1998 | } |
| 1999 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2000 | nla_for_each_nested(nl_txq_params, |
| 2001 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2002 | rem_txq_params) { |
| 2003 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2004 | nla_data(nl_txq_params), |
| 2005 | nla_len(nl_txq_params), |
| 2006 | txq_params_policy); |
| 2007 | result = parse_txq_params(tb, &txq_params); |
| 2008 | if (result) |
| 2009 | goto bad_res; |
| 2010 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2011 | result = rdev_set_txq_params(rdev, netdev, |
| 2012 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2013 | if (result) |
| 2014 | goto bad_res; |
| 2015 | } |
| 2016 | } |
| 2017 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2018 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2019 | result = __nl80211_set_channel(rdev, |
| 2020 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 2021 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2022 | if (result) |
| 2023 | goto bad_res; |
| 2024 | } |
| 2025 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2026 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2027 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2028 | enum nl80211_tx_power_setting type; |
| 2029 | int idx, mbm = 0; |
| 2030 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2031 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2032 | txp_wdev = NULL; |
| 2033 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2034 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 2035 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2036 | goto bad_res; |
| 2037 | } |
| 2038 | |
| 2039 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2040 | type = nla_get_u32(info->attrs[idx]); |
| 2041 | |
| 2042 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 2043 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 2044 | result = -EINVAL; |
| 2045 | goto bad_res; |
| 2046 | } |
| 2047 | |
| 2048 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2049 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2050 | mbm = nla_get_u32(info->attrs[idx]); |
| 2051 | } |
| 2052 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2053 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2054 | if (result) |
| 2055 | goto bad_res; |
| 2056 | } |
| 2057 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2058 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2059 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2060 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2061 | if ((!rdev->wiphy.available_antennas_tx && |
| 2062 | !rdev->wiphy.available_antennas_rx) || |
| 2063 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2064 | result = -EOPNOTSUPP; |
| 2065 | goto bad_res; |
| 2066 | } |
| 2067 | |
| 2068 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2069 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2070 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2071 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2072 | * available antenna masks, except for the "all" mask */ |
| 2073 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2074 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2075 | result = -EINVAL; |
| 2076 | goto bad_res; |
| 2077 | } |
| 2078 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2079 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2080 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2081 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2082 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2083 | if (result) |
| 2084 | goto bad_res; |
| 2085 | } |
| 2086 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2087 | changed = 0; |
| 2088 | |
| 2089 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2090 | retry_short = nla_get_u8( |
| 2091 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2092 | if (retry_short == 0) { |
| 2093 | result = -EINVAL; |
| 2094 | goto bad_res; |
| 2095 | } |
| 2096 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2097 | } |
| 2098 | |
| 2099 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2100 | retry_long = nla_get_u8( |
| 2101 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2102 | if (retry_long == 0) { |
| 2103 | result = -EINVAL; |
| 2104 | goto bad_res; |
| 2105 | } |
| 2106 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2107 | } |
| 2108 | |
| 2109 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2110 | frag_threshold = nla_get_u32( |
| 2111 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2112 | if (frag_threshold < 256) { |
| 2113 | result = -EINVAL; |
| 2114 | goto bad_res; |
| 2115 | } |
| 2116 | if (frag_threshold != (u32) -1) { |
| 2117 | /* |
| 2118 | * Fragments (apart from the last one) are required to |
| 2119 | * have even length. Make the fragmentation code |
| 2120 | * simpler by stripping LSB should someone try to use |
| 2121 | * odd threshold value. |
| 2122 | */ |
| 2123 | frag_threshold &= ~0x1; |
| 2124 | } |
| 2125 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2126 | } |
| 2127 | |
| 2128 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2129 | rts_threshold = nla_get_u32( |
| 2130 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2131 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2132 | } |
| 2133 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2134 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2135 | coverage_class = nla_get_u8( |
| 2136 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2137 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2138 | } |
| 2139 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2140 | if (changed) { |
| 2141 | u8 old_retry_short, old_retry_long; |
| 2142 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2143 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2144 | |
| 2145 | if (!rdev->ops->set_wiphy_params) { |
| 2146 | result = -EOPNOTSUPP; |
| 2147 | goto bad_res; |
| 2148 | } |
| 2149 | |
| 2150 | old_retry_short = rdev->wiphy.retry_short; |
| 2151 | old_retry_long = rdev->wiphy.retry_long; |
| 2152 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2153 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2154 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2155 | |
| 2156 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2157 | rdev->wiphy.retry_short = retry_short; |
| 2158 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2159 | rdev->wiphy.retry_long = retry_long; |
| 2160 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2161 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2162 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2163 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2164 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2165 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2166 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2167 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2168 | if (result) { |
| 2169 | rdev->wiphy.retry_short = old_retry_short; |
| 2170 | rdev->wiphy.retry_long = old_retry_long; |
| 2171 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2172 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2173 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2174 | } |
| 2175 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2176 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2177 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2178 | if (netdev) |
| 2179 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2180 | return result; |
| 2181 | } |
| 2182 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2183 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2184 | { |
| 2185 | return (u64)wdev->identifier | |
| 2186 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2187 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2188 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2189 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2190 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2191 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2192 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2193 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2194 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2195 | chandef->chan->center_freq)) |
| 2196 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2197 | switch (chandef->width) { |
| 2198 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2199 | case NL80211_CHAN_WIDTH_20: |
| 2200 | case NL80211_CHAN_WIDTH_40: |
| 2201 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2202 | cfg80211_get_chandef_type(chandef))) |
| 2203 | return -ENOBUFS; |
| 2204 | break; |
| 2205 | default: |
| 2206 | break; |
| 2207 | } |
| 2208 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2209 | return -ENOBUFS; |
| 2210 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2211 | return -ENOBUFS; |
| 2212 | if (chandef->center_freq2 && |
| 2213 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2214 | return -ENOBUFS; |
| 2215 | return 0; |
| 2216 | } |
| 2217 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2218 | 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] | 2219 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2220 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2221 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2222 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2223 | void *hdr; |
| 2224 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2225 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2226 | if (!hdr) |
| 2227 | return -1; |
| 2228 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2229 | if (dev && |
| 2230 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2231 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2232 | goto nla_put_failure; |
| 2233 | |
| 2234 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2235 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2236 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2237 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2238 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2239 | rdev->devlist_generation ^ |
| 2240 | (cfg80211_rdev_list_generation << 2))) |
| 2241 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2242 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2243 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2244 | int ret; |
| 2245 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2246 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2247 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2248 | if (ret == 0) { |
| 2249 | if (nl80211_send_chandef(msg, &chandef)) |
| 2250 | goto nla_put_failure; |
| 2251 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2252 | } |
| 2253 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2254 | if (wdev->ssid_len) { |
| 2255 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2256 | goto nla_put_failure; |
| 2257 | } |
| 2258 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2259 | return genlmsg_end(msg, hdr); |
| 2260 | |
| 2261 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2262 | genlmsg_cancel(msg, hdr); |
| 2263 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2267 | { |
| 2268 | int wp_idx = 0; |
| 2269 | int if_idx = 0; |
| 2270 | int wp_start = cb->args[0]; |
| 2271 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2272 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2273 | struct wireless_dev *wdev; |
| 2274 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2275 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2276 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2277 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2278 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2279 | if (wp_idx < wp_start) { |
| 2280 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2281 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2282 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2283 | if_idx = 0; |
| 2284 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2285 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2286 | if (if_idx < if_start) { |
| 2287 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2288 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2289 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2290 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2291 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2292 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2293 | goto out; |
| 2294 | } |
| 2295 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2296 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2297 | |
| 2298 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2299 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2300 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2301 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2302 | |
| 2303 | cb->args[0] = wp_idx; |
| 2304 | cb->args[1] = if_idx; |
| 2305 | |
| 2306 | return skb->len; |
| 2307 | } |
| 2308 | |
| 2309 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2310 | { |
| 2311 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2312 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2313 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2314 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2315 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2316 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2317 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2318 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2319 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2320 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2321 | nlmsg_free(msg); |
| 2322 | return -ENOBUFS; |
| 2323 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2324 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2325 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2326 | } |
| 2327 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2328 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2329 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2330 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2331 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2332 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2333 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2334 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2335 | }; |
| 2336 | |
| 2337 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2338 | { |
| 2339 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2340 | int flag; |
| 2341 | |
| 2342 | *mntrflags = 0; |
| 2343 | |
| 2344 | if (!nla) |
| 2345 | return -EINVAL; |
| 2346 | |
| 2347 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2348 | nla, mntr_flags_policy)) |
| 2349 | return -EINVAL; |
| 2350 | |
| 2351 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2352 | if (flags[flag]) |
| 2353 | *mntrflags |= (1<<flag); |
| 2354 | |
| 2355 | return 0; |
| 2356 | } |
| 2357 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2358 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2359 | struct net_device *netdev, u8 use_4addr, |
| 2360 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2361 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2362 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2363 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2364 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2365 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2366 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2367 | |
| 2368 | switch (iftype) { |
| 2369 | case NL80211_IFTYPE_AP_VLAN: |
| 2370 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2371 | return 0; |
| 2372 | break; |
| 2373 | case NL80211_IFTYPE_STATION: |
| 2374 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2375 | return 0; |
| 2376 | break; |
| 2377 | default: |
| 2378 | break; |
| 2379 | } |
| 2380 | |
| 2381 | return -EOPNOTSUPP; |
| 2382 | } |
| 2383 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2384 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2385 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2386 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2387 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2388 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2389 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2390 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2391 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2392 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2393 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2394 | memset(¶ms, 0, sizeof(params)); |
| 2395 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2396 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2397 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2398 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2399 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2400 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2401 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2402 | if (ntype > NL80211_IFTYPE_MAX) |
| 2403 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2404 | } |
| 2405 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2406 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2407 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2408 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2409 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2410 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2411 | if (netif_running(dev)) |
| 2412 | return -EBUSY; |
| 2413 | |
| 2414 | wdev_lock(wdev); |
| 2415 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2416 | IEEE80211_MAX_MESH_ID_LEN); |
| 2417 | wdev->mesh_id_up_len = |
| 2418 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2419 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2420 | wdev->mesh_id_up_len); |
| 2421 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2422 | } |
| 2423 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2424 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2425 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2426 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2427 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2428 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2429 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2430 | } else { |
| 2431 | params.use_4addr = -1; |
| 2432 | } |
| 2433 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2434 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2435 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2436 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2437 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2438 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2439 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2440 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2441 | |
| 2442 | flags = &_flags; |
| 2443 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2444 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2445 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2446 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2447 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2448 | return -EOPNOTSUPP; |
| 2449 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2450 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2451 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2452 | else |
| 2453 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2454 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2455 | if (!err && params.use_4addr != -1) |
| 2456 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2457 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2458 | return err; |
| 2459 | } |
| 2460 | |
| 2461 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2462 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2463 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2464 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2465 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2466 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2467 | int err; |
| 2468 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2469 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2470 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2471 | memset(¶ms, 0, sizeof(params)); |
| 2472 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2473 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2474 | return -EINVAL; |
| 2475 | |
| 2476 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2477 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2478 | if (type > NL80211_IFTYPE_MAX) |
| 2479 | return -EINVAL; |
| 2480 | } |
| 2481 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2482 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2483 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2484 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2485 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2486 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2487 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2488 | ETH_ALEN); |
| 2489 | if (!is_valid_ether_addr(params.macaddr)) |
| 2490 | return -EADDRNOTAVAIL; |
| 2491 | } |
| 2492 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2493 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2494 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2495 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2496 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2497 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2498 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2499 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2500 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2501 | if (!msg) |
| 2502 | return -ENOMEM; |
| 2503 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2504 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2505 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2506 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2507 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2508 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2509 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2510 | return -EOPNOTSUPP; |
| 2511 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2512 | wdev = rdev_add_virtual_intf(rdev, |
| 2513 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2514 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2515 | if (IS_ERR(wdev)) { |
| 2516 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2517 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2518 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2519 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2520 | switch (type) { |
| 2521 | case NL80211_IFTYPE_MESH_POINT: |
| 2522 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2523 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2524 | wdev_lock(wdev); |
| 2525 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2526 | IEEE80211_MAX_MESH_ID_LEN); |
| 2527 | wdev->mesh_id_up_len = |
| 2528 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2529 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2530 | wdev->mesh_id_up_len); |
| 2531 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2532 | break; |
| 2533 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2534 | /* |
| 2535 | * P2P Device doesn't have a netdev, so doesn't go |
| 2536 | * through the netdev notifier and must be added here |
| 2537 | */ |
| 2538 | mutex_init(&wdev->mtx); |
| 2539 | INIT_LIST_HEAD(&wdev->event_list); |
| 2540 | spin_lock_init(&wdev->event_lock); |
| 2541 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2542 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2543 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2544 | wdev->identifier = ++rdev->wdev_id; |
| 2545 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2546 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2547 | break; |
| 2548 | default: |
| 2549 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2550 | } |
| 2551 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2552 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2553 | rdev, wdev) < 0) { |
| 2554 | nlmsg_free(msg); |
| 2555 | return -ENOBUFS; |
| 2556 | } |
| 2557 | |
| 2558 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2562 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2563 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2564 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2565 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2566 | if (!rdev->ops->del_virtual_intf) |
| 2567 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2568 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2569 | /* |
| 2570 | * If we remove a wireless device without a netdev then clear |
| 2571 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2572 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2573 | * since the wdev has been freed, unlike with a netdev where |
| 2574 | * we need the dev_put() for the netdev to really be freed. |
| 2575 | */ |
| 2576 | if (!wdev->netdev) |
| 2577 | info->user_ptr[1] = NULL; |
| 2578 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2579 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2580 | } |
| 2581 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2582 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2583 | { |
| 2584 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2585 | struct net_device *dev = info->user_ptr[1]; |
| 2586 | u16 noack_map; |
| 2587 | |
| 2588 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2589 | return -EINVAL; |
| 2590 | |
| 2591 | if (!rdev->ops->set_noack_map) |
| 2592 | return -EOPNOTSUPP; |
| 2593 | |
| 2594 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2595 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2596 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2597 | } |
| 2598 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2599 | struct get_key_cookie { |
| 2600 | struct sk_buff *msg; |
| 2601 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2602 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2603 | }; |
| 2604 | |
| 2605 | static void get_key_callback(void *c, struct key_params *params) |
| 2606 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2607 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2608 | struct get_key_cookie *cookie = c; |
| 2609 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2610 | if ((params->key && |
| 2611 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2612 | params->key_len, params->key)) || |
| 2613 | (params->seq && |
| 2614 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2615 | params->seq_len, params->seq)) || |
| 2616 | (params->cipher && |
| 2617 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2618 | params->cipher))) |
| 2619 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2620 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2621 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2622 | if (!key) |
| 2623 | goto nla_put_failure; |
| 2624 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2625 | if ((params->key && |
| 2626 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2627 | params->key_len, params->key)) || |
| 2628 | (params->seq && |
| 2629 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2630 | params->seq_len, params->seq)) || |
| 2631 | (params->cipher && |
| 2632 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2633 | params->cipher))) |
| 2634 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2635 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2636 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2637 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2638 | |
| 2639 | nla_nest_end(cookie->msg, key); |
| 2640 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2641 | return; |
| 2642 | nla_put_failure: |
| 2643 | cookie->error = 1; |
| 2644 | } |
| 2645 | |
| 2646 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2647 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2648 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2649 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2650 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2651 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2652 | const u8 *mac_addr = NULL; |
| 2653 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2654 | struct get_key_cookie cookie = { |
| 2655 | .error = 0, |
| 2656 | }; |
| 2657 | void *hdr; |
| 2658 | struct sk_buff *msg; |
| 2659 | |
| 2660 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2661 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2662 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2663 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2664 | return -EINVAL; |
| 2665 | |
| 2666 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2667 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2668 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2669 | pairwise = !!mac_addr; |
| 2670 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2671 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2672 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2673 | return -EINVAL; |
| 2674 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2675 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2676 | return -EINVAL; |
| 2677 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2678 | } |
| 2679 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2680 | if (!rdev->ops->get_key) |
| 2681 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2682 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2683 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2684 | if (!msg) |
| 2685 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2686 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2687 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2688 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2689 | if (!hdr) |
| 2690 | return -ENOBUFS; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2691 | |
| 2692 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2693 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2694 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2695 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2696 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2697 | goto nla_put_failure; |
| 2698 | if (mac_addr && |
| 2699 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2700 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2701 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2702 | if (pairwise && mac_addr && |
| 2703 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2704 | return -ENOENT; |
| 2705 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2706 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2707 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2708 | |
| 2709 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2710 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2711 | |
| 2712 | if (cookie.error) |
| 2713 | goto nla_put_failure; |
| 2714 | |
| 2715 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2716 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2717 | |
| 2718 | nla_put_failure: |
| 2719 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2720 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2721 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2722 | return err; |
| 2723 | } |
| 2724 | |
| 2725 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2726 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2727 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2728 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2729 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2730 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2731 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2732 | err = nl80211_parse_key(info, &key); |
| 2733 | if (err) |
| 2734 | return err; |
| 2735 | |
| 2736 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2737 | return -EINVAL; |
| 2738 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2739 | /* only support setting default key */ |
| 2740 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2741 | return -EINVAL; |
| 2742 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2743 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2744 | |
| 2745 | if (key.def) { |
| 2746 | if (!rdev->ops->set_default_key) { |
| 2747 | err = -EOPNOTSUPP; |
| 2748 | goto out; |
| 2749 | } |
| 2750 | |
| 2751 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2752 | if (err) |
| 2753 | goto out; |
| 2754 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2755 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2756 | key.def_uni, key.def_multi); |
| 2757 | |
| 2758 | if (err) |
| 2759 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2760 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2761 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2762 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2763 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2764 | } else { |
| 2765 | if (key.def_uni || !key.def_multi) { |
| 2766 | err = -EINVAL; |
| 2767 | goto out; |
| 2768 | } |
| 2769 | |
| 2770 | if (!rdev->ops->set_default_mgmt_key) { |
| 2771 | err = -EOPNOTSUPP; |
| 2772 | goto out; |
| 2773 | } |
| 2774 | |
| 2775 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2776 | if (err) |
| 2777 | goto out; |
| 2778 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2779 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2780 | if (err) |
| 2781 | goto out; |
| 2782 | |
| 2783 | #ifdef CONFIG_CFG80211_WEXT |
| 2784 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2785 | #endif |
| 2786 | } |
| 2787 | |
| 2788 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2789 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2790 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2791 | return err; |
| 2792 | } |
| 2793 | |
| 2794 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2795 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2796 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2797 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2798 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2799 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2800 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2801 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2802 | err = nl80211_parse_key(info, &key); |
| 2803 | if (err) |
| 2804 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2805 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2806 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2807 | return -EINVAL; |
| 2808 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2809 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2810 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2811 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2812 | if (key.type == -1) { |
| 2813 | if (mac_addr) |
| 2814 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2815 | else |
| 2816 | key.type = NL80211_KEYTYPE_GROUP; |
| 2817 | } |
| 2818 | |
| 2819 | /* for now */ |
| 2820 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2821 | key.type != NL80211_KEYTYPE_GROUP) |
| 2822 | return -EINVAL; |
| 2823 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2824 | if (!rdev->ops->add_key) |
| 2825 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2826 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2827 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2828 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2829 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2830 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2831 | |
| 2832 | wdev_lock(dev->ieee80211_ptr); |
| 2833 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2834 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2835 | err = rdev_add_key(rdev, dev, key.idx, |
| 2836 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2837 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2838 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2839 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2840 | return err; |
| 2841 | } |
| 2842 | |
| 2843 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2844 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2846 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2847 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2848 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2849 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2850 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2851 | err = nl80211_parse_key(info, &key); |
| 2852 | if (err) |
| 2853 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2854 | |
| 2855 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2856 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2857 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2858 | if (key.type == -1) { |
| 2859 | if (mac_addr) |
| 2860 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2861 | else |
| 2862 | key.type = NL80211_KEYTYPE_GROUP; |
| 2863 | } |
| 2864 | |
| 2865 | /* for now */ |
| 2866 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2867 | key.type != NL80211_KEYTYPE_GROUP) |
| 2868 | return -EINVAL; |
| 2869 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2870 | if (!rdev->ops->del_key) |
| 2871 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2872 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2873 | wdev_lock(dev->ieee80211_ptr); |
| 2874 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2875 | |
| 2876 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2877 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2878 | err = -ENOENT; |
| 2879 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2880 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2881 | err = rdev_del_key(rdev, dev, key.idx, |
| 2882 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2883 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2884 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2885 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2886 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2887 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2888 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2889 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2890 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2891 | } |
| 2892 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2893 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2894 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2895 | return err; |
| 2896 | } |
| 2897 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2898 | /* This function returns an error or the number of nested attributes */ |
| 2899 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2900 | { |
| 2901 | struct nlattr *attr; |
| 2902 | int n_entries = 0, tmp; |
| 2903 | |
| 2904 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2905 | if (nla_len(attr) != ETH_ALEN) |
| 2906 | return -EINVAL; |
| 2907 | |
| 2908 | n_entries++; |
| 2909 | } |
| 2910 | |
| 2911 | return n_entries; |
| 2912 | } |
| 2913 | |
| 2914 | /* |
| 2915 | * This function parses ACL information and allocates memory for ACL data. |
| 2916 | * On successful return, the calling function is responsible to free the |
| 2917 | * ACL buffer returned by this function. |
| 2918 | */ |
| 2919 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2920 | struct genl_info *info) |
| 2921 | { |
| 2922 | enum nl80211_acl_policy acl_policy; |
| 2923 | struct nlattr *attr; |
| 2924 | struct cfg80211_acl_data *acl; |
| 2925 | int i = 0, n_entries, tmp; |
| 2926 | |
| 2927 | if (!wiphy->max_acl_mac_addrs) |
| 2928 | return ERR_PTR(-EOPNOTSUPP); |
| 2929 | |
| 2930 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2931 | return ERR_PTR(-EINVAL); |
| 2932 | |
| 2933 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2934 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2935 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2936 | return ERR_PTR(-EINVAL); |
| 2937 | |
| 2938 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2939 | return ERR_PTR(-EINVAL); |
| 2940 | |
| 2941 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2942 | if (n_entries < 0) |
| 2943 | return ERR_PTR(n_entries); |
| 2944 | |
| 2945 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2946 | return ERR_PTR(-ENOTSUPP); |
| 2947 | |
| 2948 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2949 | GFP_KERNEL); |
| 2950 | if (!acl) |
| 2951 | return ERR_PTR(-ENOMEM); |
| 2952 | |
| 2953 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2954 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2955 | i++; |
| 2956 | } |
| 2957 | |
| 2958 | acl->n_acl_entries = n_entries; |
| 2959 | acl->acl_policy = acl_policy; |
| 2960 | |
| 2961 | return acl; |
| 2962 | } |
| 2963 | |
| 2964 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2965 | { |
| 2966 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2967 | struct net_device *dev = info->user_ptr[1]; |
| 2968 | struct cfg80211_acl_data *acl; |
| 2969 | int err; |
| 2970 | |
| 2971 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2972 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2973 | return -EOPNOTSUPP; |
| 2974 | |
| 2975 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2976 | return -EINVAL; |
| 2977 | |
| 2978 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2979 | if (IS_ERR(acl)) |
| 2980 | return PTR_ERR(acl); |
| 2981 | |
| 2982 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2983 | |
| 2984 | kfree(acl); |
| 2985 | |
| 2986 | return err; |
| 2987 | } |
| 2988 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2989 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2990 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2991 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2992 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2993 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2994 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2995 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 2996 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2997 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2998 | return -EINVAL; |
| 2999 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3000 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3001 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3002 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3003 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3004 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3005 | if (!bcn->head_len) |
| 3006 | return -EINVAL; |
| 3007 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3008 | } |
| 3009 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3010 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3011 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3012 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3013 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3014 | } |
| 3015 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3016 | if (!haveinfo) |
| 3017 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3018 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3019 | if (attrs[NL80211_ATTR_IE]) { |
| 3020 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3021 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3022 | } |
| 3023 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3024 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3025 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3026 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3027 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3028 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3029 | } |
| 3030 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3031 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3032 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3033 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3034 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3035 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3036 | } |
| 3037 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3038 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3039 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3040 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3041 | } |
| 3042 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3043 | return 0; |
| 3044 | } |
| 3045 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3046 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3047 | struct cfg80211_ap_settings *params) |
| 3048 | { |
| 3049 | struct wireless_dev *wdev; |
| 3050 | bool ret = false; |
| 3051 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3052 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3053 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3054 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3055 | continue; |
| 3056 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3057 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3058 | continue; |
| 3059 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3060 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3061 | ret = true; |
| 3062 | break; |
| 3063 | } |
| 3064 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3065 | return ret; |
| 3066 | } |
| 3067 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3068 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3069 | enum nl80211_auth_type auth_type, |
| 3070 | enum nl80211_commands cmd) |
| 3071 | { |
| 3072 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3073 | return false; |
| 3074 | |
| 3075 | switch (cmd) { |
| 3076 | case NL80211_CMD_AUTHENTICATE: |
| 3077 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3078 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3079 | return false; |
| 3080 | return true; |
| 3081 | case NL80211_CMD_CONNECT: |
| 3082 | case NL80211_CMD_START_AP: |
| 3083 | /* SAE not supported yet */ |
| 3084 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3085 | return false; |
| 3086 | return true; |
| 3087 | default: |
| 3088 | return false; |
| 3089 | } |
| 3090 | } |
| 3091 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3092 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3093 | { |
| 3094 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3095 | struct net_device *dev = info->user_ptr[1]; |
| 3096 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3097 | struct cfg80211_ap_settings params; |
| 3098 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3099 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3100 | |
| 3101 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3102 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3103 | return -EOPNOTSUPP; |
| 3104 | |
| 3105 | if (!rdev->ops->start_ap) |
| 3106 | return -EOPNOTSUPP; |
| 3107 | |
| 3108 | if (wdev->beacon_interval) |
| 3109 | return -EALREADY; |
| 3110 | |
| 3111 | memset(¶ms, 0, sizeof(params)); |
| 3112 | |
| 3113 | /* these are required for START_AP */ |
| 3114 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3115 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3116 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3117 | return -EINVAL; |
| 3118 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3119 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3120 | if (err) |
| 3121 | return err; |
| 3122 | |
| 3123 | params.beacon_interval = |
| 3124 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3125 | params.dtim_period = |
| 3126 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3127 | |
| 3128 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3129 | if (err) |
| 3130 | return err; |
| 3131 | |
| 3132 | /* |
| 3133 | * In theory, some of these attributes should be required here |
| 3134 | * but since they were not used when the command was originally |
| 3135 | * added, keep them optional for old user space programs to let |
| 3136 | * them continue to work with drivers that do not need the |
| 3137 | * additional information -- drivers must check! |
| 3138 | */ |
| 3139 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3140 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3141 | params.ssid_len = |
| 3142 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3143 | if (params.ssid_len == 0 || |
| 3144 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3145 | return -EINVAL; |
| 3146 | } |
| 3147 | |
| 3148 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3149 | params.hidden_ssid = nla_get_u32( |
| 3150 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3151 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3152 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3153 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3154 | return -EINVAL; |
| 3155 | } |
| 3156 | |
| 3157 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3158 | |
| 3159 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3160 | params.auth_type = nla_get_u32( |
| 3161 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3162 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3163 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3164 | return -EINVAL; |
| 3165 | } else |
| 3166 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3167 | |
| 3168 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3169 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3170 | if (err) |
| 3171 | return err; |
| 3172 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3173 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3174 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3175 | return -EOPNOTSUPP; |
| 3176 | params.inactivity_timeout = nla_get_u16( |
| 3177 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3178 | } |
| 3179 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3180 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3181 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3182 | return -EINVAL; |
| 3183 | params.p2p_ctwindow = |
| 3184 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3185 | if (params.p2p_ctwindow > 127) |
| 3186 | return -EINVAL; |
| 3187 | if (params.p2p_ctwindow != 0 && |
| 3188 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3189 | return -EINVAL; |
| 3190 | } |
| 3191 | |
| 3192 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3193 | u8 tmp; |
| 3194 | |
| 3195 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3196 | return -EINVAL; |
| 3197 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3198 | if (tmp > 1) |
| 3199 | return -EINVAL; |
| 3200 | params.p2p_opp_ps = tmp; |
| 3201 | if (params.p2p_opp_ps != 0 && |
| 3202 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3203 | return -EINVAL; |
| 3204 | } |
| 3205 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3206 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3207 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3208 | if (err) |
| 3209 | return err; |
| 3210 | } else if (wdev->preset_chandef.chan) { |
| 3211 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3212 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3213 | return -EINVAL; |
| 3214 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3215 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3216 | return -EINVAL; |
| 3217 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3218 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3219 | if (err < 0) |
| 3220 | return err; |
| 3221 | if (err) { |
| 3222 | radar_detect_width = BIT(params.chandef.width); |
| 3223 | params.radar_required = true; |
| 3224 | } |
| 3225 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3226 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3227 | params.chandef.chan, |
| 3228 | CHAN_MODE_SHARED, |
| 3229 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3230 | if (err) |
| 3231 | return err; |
| 3232 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3233 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3234 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3235 | if (IS_ERR(params.acl)) |
| 3236 | return PTR_ERR(params.acl); |
| 3237 | } |
| 3238 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3239 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3240 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3241 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3242 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3243 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3244 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3245 | wdev->ssid_len = params.ssid_len; |
| 3246 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3247 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3248 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3249 | |
| 3250 | kfree(params.acl); |
| 3251 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3252 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3253 | } |
| 3254 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3255 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3256 | { |
| 3257 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3258 | struct net_device *dev = info->user_ptr[1]; |
| 3259 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3260 | struct cfg80211_beacon_data params; |
| 3261 | int err; |
| 3262 | |
| 3263 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3264 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3265 | return -EOPNOTSUPP; |
| 3266 | |
| 3267 | if (!rdev->ops->change_beacon) |
| 3268 | return -EOPNOTSUPP; |
| 3269 | |
| 3270 | if (!wdev->beacon_interval) |
| 3271 | return -EINVAL; |
| 3272 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3273 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3274 | if (err) |
| 3275 | return err; |
| 3276 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3277 | wdev_lock(wdev); |
| 3278 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3279 | wdev_unlock(wdev); |
| 3280 | |
| 3281 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | 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] | 3285 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3286 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3287 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3288 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3289 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3290 | } |
| 3291 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3292 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3293 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3294 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3295 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3296 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3297 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3298 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3299 | }; |
| 3300 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3301 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3302 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3303 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3304 | { |
| 3305 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3306 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3307 | int flag; |
| 3308 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3309 | /* |
| 3310 | * Try parsing the new attribute first so userspace |
| 3311 | * can specify both for older kernels. |
| 3312 | */ |
| 3313 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3314 | if (nla) { |
| 3315 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3316 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3317 | sta_flags = nla_data(nla); |
| 3318 | params->sta_flags_mask = sta_flags->mask; |
| 3319 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3320 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3321 | if ((params->sta_flags_mask | |
| 3322 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3323 | return -EINVAL; |
| 3324 | return 0; |
| 3325 | } |
| 3326 | |
| 3327 | /* if present, parse the old attribute */ |
| 3328 | |
| 3329 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3330 | if (!nla) |
| 3331 | return 0; |
| 3332 | |
| 3333 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3334 | nla, sta_flags_policy)) |
| 3335 | return -EINVAL; |
| 3336 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3337 | /* |
| 3338 | * Only allow certain flags for interface types so that |
| 3339 | * other attributes are silently ignored. Remember that |
| 3340 | * this is backward compatibility code with old userspace |
| 3341 | * and shouldn't be hit in other cases anyway. |
| 3342 | */ |
| 3343 | switch (iftype) { |
| 3344 | case NL80211_IFTYPE_AP: |
| 3345 | case NL80211_IFTYPE_AP_VLAN: |
| 3346 | case NL80211_IFTYPE_P2P_GO: |
| 3347 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3348 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3349 | BIT(NL80211_STA_FLAG_WME) | |
| 3350 | BIT(NL80211_STA_FLAG_MFP); |
| 3351 | break; |
| 3352 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3353 | case NL80211_IFTYPE_STATION: |
| 3354 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3355 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3356 | break; |
| 3357 | case NL80211_IFTYPE_MESH_POINT: |
| 3358 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3359 | BIT(NL80211_STA_FLAG_MFP) | |
| 3360 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3361 | default: |
| 3362 | return -EINVAL; |
| 3363 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3364 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3365 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3366 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3367 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3368 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3369 | /* no longer support new API additions in old API */ |
| 3370 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3371 | return -EINVAL; |
| 3372 | } |
| 3373 | } |
| 3374 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3375 | return 0; |
| 3376 | } |
| 3377 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3378 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3379 | int attr) |
| 3380 | { |
| 3381 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3382 | u32 bitrate; |
| 3383 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3384 | |
| 3385 | rate = nla_nest_start(msg, attr); |
| 3386 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3387 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3388 | |
| 3389 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3390 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3391 | /* report 16-bit bitrate only if we can */ |
| 3392 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3393 | if (bitrate > 0 && |
| 3394 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3395 | return false; |
| 3396 | if (bitrate_compat > 0 && |
| 3397 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3398 | return false; |
| 3399 | |
| 3400 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3401 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3402 | return false; |
| 3403 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3404 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3405 | return false; |
| 3406 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3407 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3408 | return false; |
| 3409 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3410 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3411 | return false; |
| 3412 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3413 | return false; |
| 3414 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3415 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3416 | return false; |
| 3417 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3418 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3419 | return false; |
| 3420 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3421 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3422 | return false; |
| 3423 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3424 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3425 | return false; |
| 3426 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3427 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3428 | return false; |
| 3429 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3430 | |
| 3431 | nla_nest_end(msg, rate); |
| 3432 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3433 | } |
| 3434 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3435 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3436 | int id) |
| 3437 | { |
| 3438 | void *attr; |
| 3439 | int i = 0; |
| 3440 | |
| 3441 | if (!mask) |
| 3442 | return true; |
| 3443 | |
| 3444 | attr = nla_nest_start(msg, id); |
| 3445 | if (!attr) |
| 3446 | return false; |
| 3447 | |
| 3448 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3449 | if (!(mask & BIT(i))) |
| 3450 | continue; |
| 3451 | |
| 3452 | if (nla_put_u8(msg, i, signal[i])) |
| 3453 | return false; |
| 3454 | } |
| 3455 | |
| 3456 | nla_nest_end(msg, attr); |
| 3457 | |
| 3458 | return true; |
| 3459 | } |
| 3460 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3461 | 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] | 3462 | int flags, |
| 3463 | struct cfg80211_registered_device *rdev, |
| 3464 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3465 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3466 | { |
| 3467 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3468 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3469 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3470 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3471 | if (!hdr) |
| 3472 | return -1; |
| 3473 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3474 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3475 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3476 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3477 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3478 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3479 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3480 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3481 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3482 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3483 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3484 | sinfo->connected_time)) |
| 3485 | goto nla_put_failure; |
| 3486 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3487 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3488 | sinfo->inactive_time)) |
| 3489 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3490 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3491 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3492 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3493 | (u32)sinfo->rx_bytes)) |
| 3494 | goto nla_put_failure; |
| 3495 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3496 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3497 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3498 | (u32)sinfo->tx_bytes)) |
| 3499 | goto nla_put_failure; |
| 3500 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3501 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3502 | sinfo->rx_bytes)) |
| 3503 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3504 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3505 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3506 | sinfo->tx_bytes)) |
| 3507 | goto nla_put_failure; |
| 3508 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3509 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3510 | goto nla_put_failure; |
| 3511 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3512 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3513 | goto nla_put_failure; |
| 3514 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3515 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3516 | sinfo->plink_state)) |
| 3517 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3518 | switch (rdev->wiphy.signal_type) { |
| 3519 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3520 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3521 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3522 | sinfo->signal)) |
| 3523 | goto nla_put_failure; |
| 3524 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3525 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3526 | sinfo->signal_avg)) |
| 3527 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3528 | break; |
| 3529 | default: |
| 3530 | break; |
| 3531 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3532 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3533 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3534 | sinfo->chain_signal, |
| 3535 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3536 | goto nla_put_failure; |
| 3537 | } |
| 3538 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3539 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3540 | sinfo->chain_signal_avg, |
| 3541 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3542 | goto nla_put_failure; |
| 3543 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3544 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3545 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3546 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3547 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3548 | } |
| 3549 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3550 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3551 | NL80211_STA_INFO_RX_BITRATE)) |
| 3552 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3553 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3554 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3555 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3556 | sinfo->rx_packets)) |
| 3557 | goto nla_put_failure; |
| 3558 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3559 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3560 | sinfo->tx_packets)) |
| 3561 | goto nla_put_failure; |
| 3562 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3563 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3564 | sinfo->tx_retries)) |
| 3565 | goto nla_put_failure; |
| 3566 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3567 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3568 | sinfo->tx_failed)) |
| 3569 | goto nla_put_failure; |
| 3570 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3571 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3572 | sinfo->beacon_loss_count)) |
| 3573 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3574 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3575 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3576 | sinfo->local_pm)) |
| 3577 | goto nla_put_failure; |
| 3578 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3579 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3580 | sinfo->peer_pm)) |
| 3581 | goto nla_put_failure; |
| 3582 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3583 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3584 | sinfo->nonpeer_pm)) |
| 3585 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3586 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3587 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3588 | if (!bss_param) |
| 3589 | goto nla_put_failure; |
| 3590 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3591 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3592 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3593 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3594 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3595 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3596 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3597 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3598 | sinfo->bss_param.dtim_period) || |
| 3599 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3600 | sinfo->bss_param.beacon_interval)) |
| 3601 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3602 | |
| 3603 | nla_nest_end(msg, bss_param); |
| 3604 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3605 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3606 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3607 | sizeof(struct nl80211_sta_flag_update), |
| 3608 | &sinfo->sta_flags)) |
| 3609 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3610 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3611 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3612 | sinfo->t_offset)) |
| 3613 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3614 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3615 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3616 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3617 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3618 | sinfo->assoc_req_ies)) |
| 3619 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3620 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3621 | return genlmsg_end(msg, hdr); |
| 3622 | |
| 3623 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3624 | genlmsg_cancel(msg, hdr); |
| 3625 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3626 | } |
| 3627 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3628 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3629 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3630 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3631 | struct station_info sinfo; |
| 3632 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3633 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3634 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3635 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3636 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3637 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3638 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3639 | if (err) |
| 3640 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3641 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3642 | if (!wdev->netdev) { |
| 3643 | err = -EINVAL; |
| 3644 | goto out_err; |
| 3645 | } |
| 3646 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3647 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3648 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3649 | goto out_err; |
| 3650 | } |
| 3651 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3652 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3653 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3654 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3655 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3656 | if (err == -ENOENT) |
| 3657 | break; |
| 3658 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3659 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3660 | |
| 3661 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3662 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3663 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3664 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3665 | &sinfo) < 0) |
| 3666 | goto out; |
| 3667 | |
| 3668 | sta_idx++; |
| 3669 | } |
| 3670 | |
| 3671 | |
| 3672 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3673 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3674 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3675 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3676 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3677 | |
| 3678 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3679 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3680 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3681 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3682 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3683 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3684 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3685 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3686 | struct sk_buff *msg; |
| 3687 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3688 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3689 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3690 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3691 | |
| 3692 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3693 | return -EINVAL; |
| 3694 | |
| 3695 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3696 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3697 | if (!rdev->ops->get_station) |
| 3698 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3699 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3700 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3701 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3702 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3703 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3704 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3705 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3706 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3707 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3708 | 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] | 3709 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3710 | nlmsg_free(msg); |
| 3711 | return -ENOBUFS; |
| 3712 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3713 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3714 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3715 | } |
| 3716 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3717 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3718 | struct station_parameters *params, |
| 3719 | enum cfg80211_station_type statype) |
| 3720 | { |
| 3721 | if (params->listen_interval != -1) |
| 3722 | return -EINVAL; |
| 3723 | if (params->aid) |
| 3724 | return -EINVAL; |
| 3725 | |
| 3726 | /* When you run into this, adjust the code below for the new flag */ |
| 3727 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3728 | |
| 3729 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3730 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3731 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3732 | /* |
| 3733 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3734 | * code doesn't have the bug of including TDLS in the |
| 3735 | * mask everywhere. |
| 3736 | */ |
| 3737 | if (params->sta_flags_mask & |
| 3738 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3739 | BIT(NL80211_STA_FLAG_MFP) | |
| 3740 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3741 | return -EINVAL; |
| 3742 | break; |
| 3743 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3744 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3745 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3746 | return -EINVAL; |
| 3747 | /* ignore since it can't change */ |
| 3748 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3749 | break; |
| 3750 | default: |
| 3751 | /* disallow mesh-specific things */ |
| 3752 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3753 | return -EINVAL; |
| 3754 | if (params->local_pm) |
| 3755 | return -EINVAL; |
| 3756 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3757 | return -EINVAL; |
| 3758 | } |
| 3759 | |
| 3760 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3761 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3762 | /* TDLS can't be set, ... */ |
| 3763 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3764 | return -EINVAL; |
| 3765 | /* |
| 3766 | * ... but don't bother the driver with it. This works around |
| 3767 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3768 | * TLDS_PEER flag in the mask even for AP mode. |
| 3769 | */ |
| 3770 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3771 | } |
| 3772 | |
| 3773 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3774 | /* reject other things that can't change */ |
| 3775 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3776 | return -EINVAL; |
| 3777 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3778 | return -EINVAL; |
| 3779 | if (params->supported_rates) |
| 3780 | return -EINVAL; |
| 3781 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3782 | return -EINVAL; |
| 3783 | } |
| 3784 | |
| 3785 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3786 | if (params->vlan) |
| 3787 | return -EINVAL; |
| 3788 | } |
| 3789 | |
| 3790 | switch (statype) { |
| 3791 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3792 | /* Use this only for authorizing/unauthorizing a station */ |
| 3793 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3794 | return -EOPNOTSUPP; |
| 3795 | break; |
| 3796 | case CFG80211_STA_AP_CLIENT: |
| 3797 | /* accept only the listed bits */ |
| 3798 | if (params->sta_flags_mask & |
| 3799 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3800 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3801 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3802 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3803 | BIT(NL80211_STA_FLAG_WME) | |
| 3804 | BIT(NL80211_STA_FLAG_MFP))) |
| 3805 | return -EINVAL; |
| 3806 | |
| 3807 | /* but authenticated/associated only if driver handles it */ |
| 3808 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3809 | params->sta_flags_mask & |
| 3810 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3811 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3812 | return -EINVAL; |
| 3813 | break; |
| 3814 | case CFG80211_STA_IBSS: |
| 3815 | case CFG80211_STA_AP_STA: |
| 3816 | /* reject any changes other than AUTHORIZED */ |
| 3817 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3818 | return -EINVAL; |
| 3819 | break; |
| 3820 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3821 | /* reject any changes other than AUTHORIZED or WME */ |
| 3822 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3823 | BIT(NL80211_STA_FLAG_WME))) |
| 3824 | return -EINVAL; |
| 3825 | /* force (at least) rates when authorizing */ |
| 3826 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3827 | !params->supported_rates) |
| 3828 | return -EINVAL; |
| 3829 | break; |
| 3830 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3831 | /* reject any changes */ |
| 3832 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3833 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3834 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3835 | return -EINVAL; |
| 3836 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3837 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3838 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3839 | return -EINVAL; |
| 3840 | break; |
| 3841 | } |
| 3842 | |
| 3843 | return 0; |
| 3844 | } |
| 3845 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3846 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3847 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3848 | * 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] | 3849 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3850 | static struct net_device *get_vlan(struct genl_info *info, |
| 3851 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3852 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3853 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3854 | struct net_device *v; |
| 3855 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3856 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3857 | if (!vlanattr) |
| 3858 | return NULL; |
| 3859 | |
| 3860 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3861 | if (!v) |
| 3862 | return ERR_PTR(-ENODEV); |
| 3863 | |
| 3864 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3865 | ret = -EINVAL; |
| 3866 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3867 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3868 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3869 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3870 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3871 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3872 | ret = -EINVAL; |
| 3873 | goto error; |
| 3874 | } |
| 3875 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3876 | if (!netif_running(v)) { |
| 3877 | ret = -ENETDOWN; |
| 3878 | goto error; |
| 3879 | } |
| 3880 | |
| 3881 | return v; |
| 3882 | error: |
| 3883 | dev_put(v); |
| 3884 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3885 | } |
| 3886 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3887 | static struct nla_policy |
| 3888 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3889 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3890 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3891 | }; |
| 3892 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3893 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3894 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3895 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3896 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3897 | struct nlattr *nla; |
| 3898 | int err; |
| 3899 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3900 | /* parse WME attributes if present */ |
| 3901 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3902 | return 0; |
| 3903 | |
| 3904 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3905 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3906 | nl80211_sta_wme_policy); |
| 3907 | if (err) |
| 3908 | return err; |
| 3909 | |
| 3910 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3911 | params->uapsd_queues = nla_get_u8( |
| 3912 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3913 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3914 | return -EINVAL; |
| 3915 | |
| 3916 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3917 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3918 | |
| 3919 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3920 | return -EINVAL; |
| 3921 | |
| 3922 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3923 | |
| 3924 | return 0; |
| 3925 | } |
| 3926 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3927 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 3928 | struct station_parameters *params) |
| 3929 | { |
| 3930 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 3931 | params->supported_channels = |
| 3932 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3933 | params->supported_channels_len = |
| 3934 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3935 | /* |
| 3936 | * Need to include at least one (first channel, number of |
| 3937 | * channels) tuple for each subband, and must have proper |
| 3938 | * tuples for the rest of the data as well. |
| 3939 | */ |
| 3940 | if (params->supported_channels_len < 2) |
| 3941 | return -EINVAL; |
| 3942 | if (params->supported_channels_len % 2) |
| 3943 | return -EINVAL; |
| 3944 | } |
| 3945 | |
| 3946 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 3947 | params->supported_oper_classes = |
| 3948 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3949 | params->supported_oper_classes_len = |
| 3950 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3951 | /* |
| 3952 | * The value of the Length field of the Supported Operating |
| 3953 | * Classes element is between 2 and 253. |
| 3954 | */ |
| 3955 | if (params->supported_oper_classes_len < 2 || |
| 3956 | params->supported_oper_classes_len > 253) |
| 3957 | return -EINVAL; |
| 3958 | } |
| 3959 | return 0; |
| 3960 | } |
| 3961 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3962 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3963 | struct station_parameters *params) |
| 3964 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3965 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3966 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3967 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3968 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3969 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3970 | params->ht_capa = |
| 3971 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3972 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3973 | params->vht_capa = |
| 3974 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3975 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3976 | err = nl80211_parse_sta_channel_info(info, params); |
| 3977 | if (err) |
| 3978 | return err; |
| 3979 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3980 | return nl80211_parse_sta_wme(info, params); |
| 3981 | } |
| 3982 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3983 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3984 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3986 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3987 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3988 | u8 *mac_addr; |
| 3989 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3990 | |
| 3991 | memset(¶ms, 0, sizeof(params)); |
| 3992 | |
| 3993 | params.listen_interval = -1; |
| 3994 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3995 | if (!rdev->ops->change_station) |
| 3996 | return -EOPNOTSUPP; |
| 3997 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3998 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3999 | return -EINVAL; |
| 4000 | |
| 4001 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4002 | return -EINVAL; |
| 4003 | |
| 4004 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4005 | |
| 4006 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4007 | params.supported_rates = |
| 4008 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4009 | params.supported_rates_len = |
| 4010 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4011 | } |
| 4012 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4013 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4014 | params.capability = |
| 4015 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4016 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4017 | } |
| 4018 | |
| 4019 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4020 | params.ext_capab = |
| 4021 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4022 | params.ext_capab_len = |
| 4023 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4024 | } |
| 4025 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4026 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4027 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4028 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4029 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4030 | return -EINVAL; |
| 4031 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4032 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4033 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4034 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4035 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4036 | return -EINVAL; |
| 4037 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4038 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4039 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4040 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4041 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4042 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4043 | return -EINVAL; |
| 4044 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4045 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4046 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4047 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4048 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4049 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4050 | |
| 4051 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4052 | pm > NL80211_MESH_POWER_MAX) |
| 4053 | return -EINVAL; |
| 4054 | |
| 4055 | params.local_pm = pm; |
| 4056 | } |
| 4057 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4058 | /* Include parameters for TDLS peer (will check later) */ |
| 4059 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4060 | if (err) |
| 4061 | return err; |
| 4062 | |
| 4063 | params.vlan = get_vlan(info, rdev); |
| 4064 | if (IS_ERR(params.vlan)) |
| 4065 | return PTR_ERR(params.vlan); |
| 4066 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4067 | switch (dev->ieee80211_ptr->iftype) { |
| 4068 | case NL80211_IFTYPE_AP: |
| 4069 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4070 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4071 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4072 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4073 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4074 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4075 | break; |
| 4076 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4077 | err = -EOPNOTSUPP; |
| 4078 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4079 | } |
| 4080 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4081 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4082 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4083 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4084 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4085 | if (params.vlan) |
| 4086 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4087 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4088 | return err; |
| 4089 | } |
| 4090 | |
| 4091 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4092 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4094 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4095 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4096 | struct station_parameters params; |
| 4097 | u8 *mac_addr = NULL; |
| 4098 | |
| 4099 | memset(¶ms, 0, sizeof(params)); |
| 4100 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4101 | if (!rdev->ops->add_station) |
| 4102 | return -EOPNOTSUPP; |
| 4103 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4104 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4105 | return -EINVAL; |
| 4106 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4107 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4108 | return -EINVAL; |
| 4109 | |
| 4110 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4111 | return -EINVAL; |
| 4112 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4113 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4114 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4115 | return -EINVAL; |
| 4116 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4117 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4118 | params.supported_rates = |
| 4119 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4120 | params.supported_rates_len = |
| 4121 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4122 | params.listen_interval = |
| 4123 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4124 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4125 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4126 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4127 | else |
| 4128 | 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] | 4129 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4130 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4131 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4132 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4133 | params.capability = |
| 4134 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4135 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4136 | } |
| 4137 | |
| 4138 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4139 | params.ext_capab = |
| 4140 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4141 | params.ext_capab_len = |
| 4142 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4143 | } |
| 4144 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4145 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4146 | params.ht_capa = |
| 4147 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4148 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4149 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4150 | params.vht_capa = |
| 4151 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4152 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4153 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4154 | params.opmode_notif_used = true; |
| 4155 | params.opmode_notif = |
| 4156 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4157 | } |
| 4158 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4159 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4160 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4161 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4162 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4163 | return -EINVAL; |
| 4164 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4165 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4166 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4167 | if (err) |
| 4168 | return err; |
| 4169 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4170 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4171 | if (err) |
| 4172 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4173 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4174 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4175 | return -EINVAL; |
| 4176 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4177 | /* When you run into this, adjust the code below for the new flag */ |
| 4178 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4179 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4180 | switch (dev->ieee80211_ptr->iftype) { |
| 4181 | case NL80211_IFTYPE_AP: |
| 4182 | case NL80211_IFTYPE_AP_VLAN: |
| 4183 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4184 | /* ignore WME attributes if iface/sta is not capable */ |
| 4185 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4186 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4187 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4188 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4189 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4190 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4191 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4192 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4193 | /* but don't bother the driver with it */ |
| 4194 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4195 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4196 | /* allow authenticated/associated only if driver handles it */ |
| 4197 | if (!(rdev->wiphy.features & |
| 4198 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4199 | params.sta_flags_mask & |
| 4200 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4201 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4202 | return -EINVAL; |
| 4203 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4204 | /* must be last in here for error handling */ |
| 4205 | params.vlan = get_vlan(info, rdev); |
| 4206 | if (IS_ERR(params.vlan)) |
| 4207 | return PTR_ERR(params.vlan); |
| 4208 | break; |
| 4209 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4210 | /* ignore uAPSD data */ |
| 4211 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4212 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4213 | /* associated is disallowed */ |
| 4214 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4215 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4216 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4217 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4218 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4219 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4220 | break; |
| 4221 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4222 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4223 | /* ignore uAPSD data */ |
| 4224 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4225 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4226 | /* these are disallowed */ |
| 4227 | if (params.sta_flags_mask & |
| 4228 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4229 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4230 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4231 | /* Only TDLS peers can be added */ |
| 4232 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4233 | return -EINVAL; |
| 4234 | /* Can only add if TDLS ... */ |
| 4235 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4236 | return -EOPNOTSUPP; |
| 4237 | /* ... with external setup is supported */ |
| 4238 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4239 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4240 | /* |
| 4241 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4242 | * as authorized, but it shouldn't yet be. |
| 4243 | */ |
| 4244 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4245 | break; |
| 4246 | default: |
| 4247 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4248 | } |
| 4249 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4250 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4251 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4252 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4253 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4254 | if (params.vlan) |
| 4255 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4256 | return err; |
| 4257 | } |
| 4258 | |
| 4259 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4260 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4261 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4262 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4263 | u8 *mac_addr = NULL; |
| 4264 | |
| 4265 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4266 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4267 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4268 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4269 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4270 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4271 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4272 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4273 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4274 | if (!rdev->ops->del_station) |
| 4275 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4276 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4277 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4278 | } |
| 4279 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4280 | 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] | 4281 | int flags, struct net_device *dev, |
| 4282 | u8 *dst, u8 *next_hop, |
| 4283 | struct mpath_info *pinfo) |
| 4284 | { |
| 4285 | void *hdr; |
| 4286 | struct nlattr *pinfoattr; |
| 4287 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4288 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4289 | if (!hdr) |
| 4290 | return -1; |
| 4291 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4292 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4293 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4294 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4295 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4296 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4297 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4298 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4299 | if (!pinfoattr) |
| 4300 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4301 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4302 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4303 | pinfo->frame_qlen)) |
| 4304 | goto nla_put_failure; |
| 4305 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4306 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4307 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4308 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4309 | pinfo->metric)) || |
| 4310 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4311 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4312 | pinfo->exptime)) || |
| 4313 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4314 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4315 | pinfo->flags)) || |
| 4316 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4317 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4318 | pinfo->discovery_timeout)) || |
| 4319 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4320 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4321 | pinfo->discovery_retries))) |
| 4322 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4323 | |
| 4324 | nla_nest_end(msg, pinfoattr); |
| 4325 | |
| 4326 | return genlmsg_end(msg, hdr); |
| 4327 | |
| 4328 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4329 | genlmsg_cancel(msg, hdr); |
| 4330 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4331 | } |
| 4332 | |
| 4333 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4334 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4335 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4336 | struct mpath_info pinfo; |
| 4337 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4338 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4339 | u8 dst[ETH_ALEN]; |
| 4340 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4341 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4342 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4343 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4344 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4345 | if (err) |
| 4346 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4347 | |
| 4348 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4349 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4350 | goto out_err; |
| 4351 | } |
| 4352 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4353 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4354 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4355 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4356 | } |
| 4357 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4358 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4359 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4360 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4361 | if (err == -ENOENT) |
| 4362 | break; |
| 4363 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4364 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4365 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4366 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4367 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4368 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4369 | &pinfo) < 0) |
| 4370 | goto out; |
| 4371 | |
| 4372 | path_idx++; |
| 4373 | } |
| 4374 | |
| 4375 | |
| 4376 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4377 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4378 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4379 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4380 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4381 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4382 | } |
| 4383 | |
| 4384 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4385 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4386 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4387 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4388 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4389 | struct mpath_info pinfo; |
| 4390 | struct sk_buff *msg; |
| 4391 | u8 *dst = NULL; |
| 4392 | u8 next_hop[ETH_ALEN]; |
| 4393 | |
| 4394 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4395 | |
| 4396 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4397 | return -EINVAL; |
| 4398 | |
| 4399 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4400 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4401 | if (!rdev->ops->get_mpath) |
| 4402 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4403 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4404 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4405 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4406 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4407 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4408 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4409 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4410 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4411 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4412 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4413 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4414 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4415 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4416 | dev, dst, next_hop, &pinfo) < 0) { |
| 4417 | nlmsg_free(msg); |
| 4418 | return -ENOBUFS; |
| 4419 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4420 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4421 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4422 | } |
| 4423 | |
| 4424 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4425 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4426 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4427 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4428 | u8 *dst = NULL; |
| 4429 | u8 *next_hop = NULL; |
| 4430 | |
| 4431 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4432 | return -EINVAL; |
| 4433 | |
| 4434 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4435 | return -EINVAL; |
| 4436 | |
| 4437 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4438 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4439 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4440 | if (!rdev->ops->change_mpath) |
| 4441 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4442 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4443 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4444 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4445 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4446 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4447 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4448 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4449 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4450 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4451 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4452 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4453 | u8 *dst = NULL; |
| 4454 | u8 *next_hop = NULL; |
| 4455 | |
| 4456 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4457 | return -EINVAL; |
| 4458 | |
| 4459 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4460 | return -EINVAL; |
| 4461 | |
| 4462 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4463 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4464 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4465 | if (!rdev->ops->add_mpath) |
| 4466 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4467 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4468 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4469 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4470 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4471 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4475 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4476 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4477 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4478 | u8 *dst = NULL; |
| 4479 | |
| 4480 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4481 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4482 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4483 | if (!rdev->ops->del_mpath) |
| 4484 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4485 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4486 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4487 | } |
| 4488 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4489 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4490 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4491 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4492 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4493 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4494 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4495 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4496 | |
| 4497 | memset(¶ms, 0, sizeof(params)); |
| 4498 | /* default to not changing parameters */ |
| 4499 | params.use_cts_prot = -1; |
| 4500 | params.use_short_preamble = -1; |
| 4501 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4502 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4503 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4504 | params.p2p_ctwindow = -1; |
| 4505 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4506 | |
| 4507 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4508 | params.use_cts_prot = |
| 4509 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4510 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4511 | params.use_short_preamble = |
| 4512 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4513 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4514 | params.use_short_slot_time = |
| 4515 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4516 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4517 | params.basic_rates = |
| 4518 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4519 | params.basic_rates_len = |
| 4520 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4521 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4522 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4523 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4524 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4525 | params.ht_opmode = |
| 4526 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4527 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4528 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4529 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4530 | return -EINVAL; |
| 4531 | params.p2p_ctwindow = |
| 4532 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4533 | if (params.p2p_ctwindow < 0) |
| 4534 | return -EINVAL; |
| 4535 | if (params.p2p_ctwindow != 0 && |
| 4536 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4537 | return -EINVAL; |
| 4538 | } |
| 4539 | |
| 4540 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4541 | u8 tmp; |
| 4542 | |
| 4543 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4544 | return -EINVAL; |
| 4545 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4546 | if (tmp > 1) |
| 4547 | return -EINVAL; |
| 4548 | params.p2p_opp_ps = tmp; |
| 4549 | if (params.p2p_opp_ps && |
| 4550 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4551 | return -EINVAL; |
| 4552 | } |
| 4553 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4554 | if (!rdev->ops->change_bss) |
| 4555 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4556 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4557 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4558 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4559 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4560 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4561 | wdev_lock(wdev); |
| 4562 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4563 | wdev_unlock(wdev); |
| 4564 | |
| 4565 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4566 | } |
| 4567 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4568 | 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] | 4569 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4570 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4571 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4572 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4573 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4574 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4575 | }; |
| 4576 | |
| 4577 | static int parse_reg_rule(struct nlattr *tb[], |
| 4578 | struct ieee80211_reg_rule *reg_rule) |
| 4579 | { |
| 4580 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4581 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4582 | |
| 4583 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4584 | return -EINVAL; |
| 4585 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4586 | return -EINVAL; |
| 4587 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4588 | return -EINVAL; |
| 4589 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4590 | return -EINVAL; |
| 4591 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4592 | return -EINVAL; |
| 4593 | |
| 4594 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4595 | |
| 4596 | freq_range->start_freq_khz = |
| 4597 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4598 | freq_range->end_freq_khz = |
| 4599 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4600 | freq_range->max_bandwidth_khz = |
| 4601 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4602 | |
| 4603 | power_rule->max_eirp = |
| 4604 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4605 | |
| 4606 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4607 | power_rule->max_antenna_gain = |
| 4608 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4609 | |
| 4610 | return 0; |
| 4611 | } |
| 4612 | |
| 4613 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4614 | { |
| 4615 | int r; |
| 4616 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4617 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4618 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4619 | /* |
| 4620 | * You should only get this when cfg80211 hasn't yet initialized |
| 4621 | * completely when built-in to the kernel right between the time |
| 4622 | * window between nl80211_init() and regulatory_init(), if that is |
| 4623 | * even possible. |
| 4624 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4625 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4626 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4627 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4628 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4629 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4630 | |
| 4631 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4632 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4633 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4634 | user_reg_hint_type = |
| 4635 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4636 | else |
| 4637 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4638 | |
| 4639 | switch (user_reg_hint_type) { |
| 4640 | case NL80211_USER_REG_HINT_USER: |
| 4641 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4642 | break; |
| 4643 | default: |
| 4644 | return -EINVAL; |
| 4645 | } |
| 4646 | |
| 4647 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4648 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4649 | return r; |
| 4650 | } |
| 4651 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4652 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4653 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4654 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4656 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4657 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4658 | struct mesh_config cur_params; |
| 4659 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4660 | void *hdr; |
| 4661 | struct nlattr *pinfoattr; |
| 4662 | struct sk_buff *msg; |
| 4663 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4664 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4665 | return -EOPNOTSUPP; |
| 4666 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4667 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4668 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4669 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4670 | wdev_lock(wdev); |
| 4671 | /* If not connected, get default parameters */ |
| 4672 | if (!wdev->mesh_id_len) |
| 4673 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4674 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4675 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4676 | wdev_unlock(wdev); |
| 4677 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4678 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4679 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4680 | |
| 4681 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4682 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4683 | if (!msg) |
| 4684 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4685 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4686 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4687 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4688 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4689 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4690 | if (!pinfoattr) |
| 4691 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4692 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4693 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4694 | cur_params.dot11MeshRetryTimeout) || |
| 4695 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4696 | cur_params.dot11MeshConfirmTimeout) || |
| 4697 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4698 | cur_params.dot11MeshHoldingTimeout) || |
| 4699 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4700 | cur_params.dot11MeshMaxPeerLinks) || |
| 4701 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4702 | cur_params.dot11MeshMaxRetries) || |
| 4703 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4704 | cur_params.dot11MeshTTL) || |
| 4705 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4706 | cur_params.element_ttl) || |
| 4707 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4708 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4709 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4710 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4711 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4712 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4713 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4714 | cur_params.path_refresh_time) || |
| 4715 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4716 | cur_params.min_discovery_timeout) || |
| 4717 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4718 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4719 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4720 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4721 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4722 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4723 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4724 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4725 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4726 | cur_params.dot11MeshHWMPRootMode) || |
| 4727 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4728 | cur_params.dot11MeshHWMPRannInterval) || |
| 4729 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4730 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4731 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4732 | cur_params.dot11MeshForwarding) || |
| 4733 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4734 | cur_params.rssi_threshold) || |
| 4735 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4736 | cur_params.ht_opmode) || |
| 4737 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4738 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4739 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4740 | cur_params.dot11MeshHWMProotInterval) || |
| 4741 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4742 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4743 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4744 | cur_params.power_mode) || |
| 4745 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4746 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4747 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4748 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4749 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4750 | nla_nest_end(msg, pinfoattr); |
| 4751 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4752 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4753 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4754 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4755 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4756 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4757 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4758 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4759 | } |
| 4760 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4761 | 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] | 4762 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4763 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4764 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4765 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4766 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4767 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4768 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4769 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4770 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4771 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4772 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4773 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4774 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4775 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4776 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4777 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4778 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4779 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4780 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4781 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4782 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4783 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4784 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4785 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4786 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4787 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4788 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4789 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4790 | }; |
| 4791 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4792 | static const struct nla_policy |
| 4793 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4794 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4795 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4796 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4797 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4798 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4799 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4800 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4801 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4802 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4803 | }; |
| 4804 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4805 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4806 | struct mesh_config *cfg, |
| 4807 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4808 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4809 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4810 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4811 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4812 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4813 | do { \ |
| 4814 | if (tb[attr]) { \ |
| 4815 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4816 | return -EINVAL; \ |
| 4817 | cfg->param = fn(tb[attr]); \ |
| 4818 | mask |= (1 << (attr - 1)); \ |
| 4819 | } \ |
| 4820 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4821 | |
| 4822 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4823 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4824 | return -EINVAL; |
| 4825 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4826 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4827 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4828 | return -EINVAL; |
| 4829 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4830 | /* This makes sure that there aren't more than 32 mesh config |
| 4831 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4832 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4833 | |
| 4834 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4835 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4836 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4837 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4838 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4839 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4840 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4841 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4842 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4843 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4844 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4845 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4846 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4847 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4848 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4849 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4850 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4851 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4852 | 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] | 4853 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4854 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4855 | 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] | 4856 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4857 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4858 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4859 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4860 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4861 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4862 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4863 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4864 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4865 | 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] | 4866 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4867 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4868 | 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] | 4869 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4870 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4871 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4872 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4873 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4874 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4875 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4876 | 1, 65535, mask, |
| 4877 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4878 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4879 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4880 | 1, 65535, mask, |
| 4881 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4882 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4883 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4884 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4885 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4886 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4887 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4888 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4889 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4890 | nla_get_u8); |
| 4891 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4892 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4893 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4894 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4895 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4896 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4897 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4898 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4899 | mask, NL80211_MESHCONF_FORWARDING, |
| 4900 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4901 | 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] | 4902 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4903 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4904 | 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] | 4905 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4906 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4907 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4908 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4909 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4910 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4911 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4912 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4913 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4914 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4915 | dot11MeshHWMPconfirmationInterval, |
| 4916 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4917 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4918 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4919 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4920 | NL80211_MESH_POWER_ACTIVE, |
| 4921 | NL80211_MESH_POWER_MAX, |
| 4922 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4923 | nla_get_u32); |
| 4924 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4925 | 0, 65535, mask, |
| 4926 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4927 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4928 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4929 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4930 | if (mask_out) |
| 4931 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4932 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4933 | return 0; |
| 4934 | |
| 4935 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4936 | } |
| 4937 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4938 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4939 | struct mesh_setup *setup) |
| 4940 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4942 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4943 | |
| 4944 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4945 | return -EINVAL; |
| 4946 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4947 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4948 | nl80211_mesh_setup_params_policy)) |
| 4949 | return -EINVAL; |
| 4950 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4951 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4952 | setup->sync_method = |
| 4953 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4954 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4955 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4956 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4957 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4958 | setup->path_sel_proto = |
| 4959 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4960 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4961 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4962 | |
| 4963 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4964 | setup->path_metric = |
| 4965 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4966 | IEEE80211_PATH_METRIC_VENDOR : |
| 4967 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4968 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4969 | |
| 4970 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4971 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4972 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4973 | if (!is_valid_ie_attr(ieattr)) |
| 4974 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4975 | setup->ie = nla_data(ieattr); |
| 4976 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4977 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4978 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4979 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4980 | return -EINVAL; |
| 4981 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4982 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4983 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4984 | if (setup->is_secure) |
| 4985 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4986 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4987 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 4988 | if (!setup->user_mpm) |
| 4989 | return -EINVAL; |
| 4990 | setup->auth_id = |
| 4991 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 4992 | } |
| 4993 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4994 | return 0; |
| 4995 | } |
| 4996 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4997 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4998 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4999 | { |
| 5000 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5001 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5002 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5003 | struct mesh_config cfg; |
| 5004 | u32 mask; |
| 5005 | int err; |
| 5006 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5007 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5008 | return -EOPNOTSUPP; |
| 5009 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5010 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5011 | return -EOPNOTSUPP; |
| 5012 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5013 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5014 | if (err) |
| 5015 | return err; |
| 5016 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5017 | wdev_lock(wdev); |
| 5018 | if (!wdev->mesh_id_len) |
| 5019 | err = -ENOLINK; |
| 5020 | |
| 5021 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5022 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5023 | |
| 5024 | wdev_unlock(wdev); |
| 5025 | |
| 5026 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5027 | } |
| 5028 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5029 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5030 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5031 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5032 | struct sk_buff *msg; |
| 5033 | void *hdr = NULL; |
| 5034 | struct nlattr *nl_reg_rules; |
| 5035 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5036 | |
| 5037 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5038 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5039 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5040 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5041 | if (!msg) |
| 5042 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5043 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5044 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5045 | NL80211_CMD_GET_REG); |
| 5046 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5047 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5048 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5049 | if (reg_last_request_cell_base() && |
| 5050 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5051 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5052 | goto nla_put_failure; |
| 5053 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5054 | rcu_read_lock(); |
| 5055 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5056 | |
| 5057 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5058 | (regdom->dfs_region && |
| 5059 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5060 | goto nla_put_failure_rcu; |
| 5061 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5062 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5063 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5064 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5065 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5066 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5067 | struct nlattr *nl_reg_rule; |
| 5068 | const struct ieee80211_reg_rule *reg_rule; |
| 5069 | const struct ieee80211_freq_range *freq_range; |
| 5070 | const struct ieee80211_power_rule *power_rule; |
| 5071 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5072 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5073 | freq_range = ®_rule->freq_range; |
| 5074 | power_rule = ®_rule->power_rule; |
| 5075 | |
| 5076 | nl_reg_rule = nla_nest_start(msg, i); |
| 5077 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5078 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5079 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5080 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5081 | reg_rule->flags) || |
| 5082 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5083 | freq_range->start_freq_khz) || |
| 5084 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5085 | freq_range->end_freq_khz) || |
| 5086 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 5087 | freq_range->max_bandwidth_khz) || |
| 5088 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5089 | power_rule->max_antenna_gain) || |
| 5090 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 5091 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5092 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5093 | |
| 5094 | nla_nest_end(msg, nl_reg_rule); |
| 5095 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5096 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5097 | |
| 5098 | nla_nest_end(msg, nl_reg_rules); |
| 5099 | |
| 5100 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5101 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5102 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5103 | nla_put_failure_rcu: |
| 5104 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5105 | nla_put_failure: |
| 5106 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5107 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5108 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5109 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5110 | } |
| 5111 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5112 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5113 | { |
| 5114 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5115 | struct nlattr *nl_reg_rule; |
| 5116 | char *alpha2 = NULL; |
| 5117 | int rem_reg_rules = 0, r = 0; |
| 5118 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5119 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5120 | struct ieee80211_regdomain *rd = NULL; |
| 5121 | |
| 5122 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5123 | return -EINVAL; |
| 5124 | |
| 5125 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5126 | return -EINVAL; |
| 5127 | |
| 5128 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5129 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5130 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5131 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5132 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5133 | 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] | 5134 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5135 | num_rules++; |
| 5136 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5137 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5138 | } |
| 5139 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5140 | if (!reg_is_valid_request(alpha2)) |
| 5141 | return -EINVAL; |
| 5142 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5143 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5144 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5145 | |
| 5146 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5147 | if (!rd) |
| 5148 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5149 | |
| 5150 | rd->n_reg_rules = num_rules; |
| 5151 | rd->alpha2[0] = alpha2[0]; |
| 5152 | rd->alpha2[1] = alpha2[1]; |
| 5153 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5154 | /* |
| 5155 | * Disable DFS master mode if the DFS region was |
| 5156 | * not supported or known on this kernel. |
| 5157 | */ |
| 5158 | if (reg_supported_dfs_region(dfs_region)) |
| 5159 | rd->dfs_region = dfs_region; |
| 5160 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5161 | 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] | 5162 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5163 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5164 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5165 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5166 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5167 | if (r) |
| 5168 | goto bad_reg; |
| 5169 | |
| 5170 | rule_idx++; |
| 5171 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5172 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5173 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5174 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5175 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5176 | } |
| 5177 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5178 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5179 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5180 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5181 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5182 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5183 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5184 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5185 | } |
| 5186 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5187 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5188 | { |
| 5189 | struct nlattr *attr1, *attr2; |
| 5190 | int n_channels = 0, tmp1, tmp2; |
| 5191 | |
| 5192 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5193 | n_channels++; |
| 5194 | /* |
| 5195 | * Some hardware has a limited channel list for |
| 5196 | * scanning, and it is pretty much nonsensical |
| 5197 | * to scan for a channel twice, so disallow that |
| 5198 | * and don't require drivers to check that the |
| 5199 | * channel list they get isn't longer than what |
| 5200 | * they can scan, as long as they can scan all |
| 5201 | * the channels they registered at once. |
| 5202 | */ |
| 5203 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5204 | if (attr1 != attr2 && |
| 5205 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5206 | return 0; |
| 5207 | } |
| 5208 | |
| 5209 | return n_channels; |
| 5210 | } |
| 5211 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5212 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5213 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5215 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5216 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5217 | struct nlattr *attr; |
| 5218 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5219 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5220 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5221 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5222 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5223 | return -EINVAL; |
| 5224 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5225 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5226 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5227 | if (!rdev->ops->scan) |
| 5228 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5229 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5230 | if (rdev->scan_req) { |
| 5231 | err = -EBUSY; |
| 5232 | goto unlock; |
| 5233 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5234 | |
| 5235 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5236 | n_channels = validate_scan_freqs( |
| 5237 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5238 | if (!n_channels) { |
| 5239 | err = -EINVAL; |
| 5240 | goto unlock; |
| 5241 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5242 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5243 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5244 | n_channels = 0; |
| 5245 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5246 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5247 | if (wiphy->bands[band]) |
| 5248 | n_channels += wiphy->bands[band]->n_channels; |
| 5249 | } |
| 5250 | |
| 5251 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5252 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5253 | n_ssids++; |
| 5254 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5255 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5256 | err = -EINVAL; |
| 5257 | goto unlock; |
| 5258 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5259 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5260 | if (info->attrs[NL80211_ATTR_IE]) |
| 5261 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5262 | else |
| 5263 | ie_len = 0; |
| 5264 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5265 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5266 | err = -EINVAL; |
| 5267 | goto unlock; |
| 5268 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5269 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5270 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5271 | + sizeof(*request->ssids) * n_ssids |
| 5272 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5273 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5274 | if (!request) { |
| 5275 | err = -ENOMEM; |
| 5276 | goto unlock; |
| 5277 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5278 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5279 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5280 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5281 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5282 | if (ie_len) { |
| 5283 | if (request->ssids) |
| 5284 | request->ie = (void *)(request->ssids + n_ssids); |
| 5285 | else |
| 5286 | request->ie = (void *)(request->channels + n_channels); |
| 5287 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5288 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5289 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5290 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5291 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5292 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5293 | struct ieee80211_channel *chan; |
| 5294 | |
| 5295 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5296 | |
| 5297 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5298 | err = -EINVAL; |
| 5299 | goto out_free; |
| 5300 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5301 | |
| 5302 | /* ignore disabled channels */ |
| 5303 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5304 | continue; |
| 5305 | |
| 5306 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5307 | i++; |
| 5308 | } |
| 5309 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5310 | enum ieee80211_band band; |
| 5311 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5312 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5313 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5314 | int j; |
| 5315 | if (!wiphy->bands[band]) |
| 5316 | continue; |
| 5317 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5318 | struct ieee80211_channel *chan; |
| 5319 | |
| 5320 | chan = &wiphy->bands[band]->channels[j]; |
| 5321 | |
| 5322 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5323 | continue; |
| 5324 | |
| 5325 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5326 | i++; |
| 5327 | } |
| 5328 | } |
| 5329 | } |
| 5330 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5331 | if (!i) { |
| 5332 | err = -EINVAL; |
| 5333 | goto out_free; |
| 5334 | } |
| 5335 | |
| 5336 | request->n_channels = i; |
| 5337 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5338 | i = 0; |
| 5339 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5340 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5341 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5342 | err = -EINVAL; |
| 5343 | goto out_free; |
| 5344 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5345 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5346 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5347 | i++; |
| 5348 | } |
| 5349 | } |
| 5350 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5351 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5352 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5353 | memcpy((void *)request->ie, |
| 5354 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5355 | request->ie_len); |
| 5356 | } |
| 5357 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5358 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5359 | if (wiphy->bands[i]) |
| 5360 | request->rates[i] = |
| 5361 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5362 | |
| 5363 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5364 | nla_for_each_nested(attr, |
| 5365 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5366 | tmp) { |
| 5367 | enum ieee80211_band band = nla_type(attr); |
| 5368 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5369 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5370 | err = -EINVAL; |
| 5371 | goto out_free; |
| 5372 | } |
| 5373 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5374 | nla_data(attr), |
| 5375 | nla_len(attr), |
| 5376 | &request->rates[band]); |
| 5377 | if (err) |
| 5378 | goto out_free; |
| 5379 | } |
| 5380 | } |
| 5381 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5382 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5383 | request->flags = nla_get_u32( |
| 5384 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5385 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5386 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5387 | err = -EOPNOTSUPP; |
| 5388 | goto out_free; |
| 5389 | } |
| 5390 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5391 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5392 | request->no_cck = |
| 5393 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5394 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5395 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5396 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5397 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5398 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5399 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5400 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5401 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5402 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5403 | nl80211_send_scan_start(rdev, wdev); |
| 5404 | if (wdev->netdev) |
| 5405 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5406 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5407 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5408 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5409 | kfree(request); |
| 5410 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5411 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5412 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5413 | return err; |
| 5414 | } |
| 5415 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5416 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5417 | struct genl_info *info) |
| 5418 | { |
| 5419 | struct cfg80211_sched_scan_request *request; |
| 5420 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5421 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5422 | struct nlattr *attr; |
| 5423 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5424 | 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] | 5425 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5426 | enum ieee80211_band band; |
| 5427 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5428 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5429 | |
| 5430 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5431 | !rdev->ops->sched_scan_start) |
| 5432 | return -EOPNOTSUPP; |
| 5433 | |
| 5434 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5435 | return -EINVAL; |
| 5436 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5437 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5438 | return -EINVAL; |
| 5439 | |
| 5440 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5441 | if (interval == 0) |
| 5442 | return -EINVAL; |
| 5443 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5444 | wiphy = &rdev->wiphy; |
| 5445 | |
| 5446 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5447 | n_channels = validate_scan_freqs( |
| 5448 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5449 | if (!n_channels) |
| 5450 | return -EINVAL; |
| 5451 | } else { |
| 5452 | n_channels = 0; |
| 5453 | |
| 5454 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5455 | if (wiphy->bands[band]) |
| 5456 | n_channels += wiphy->bands[band]->n_channels; |
| 5457 | } |
| 5458 | |
| 5459 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5460 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5461 | tmp) |
| 5462 | n_ssids++; |
| 5463 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5464 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5465 | return -EINVAL; |
| 5466 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5467 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5468 | nla_for_each_nested(attr, |
| 5469 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5470 | tmp) |
| 5471 | n_match_sets++; |
| 5472 | |
| 5473 | if (n_match_sets > wiphy->max_match_sets) |
| 5474 | return -EINVAL; |
| 5475 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5476 | if (info->attrs[NL80211_ATTR_IE]) |
| 5477 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5478 | else |
| 5479 | ie_len = 0; |
| 5480 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5481 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5482 | return -EINVAL; |
| 5483 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5484 | if (rdev->sched_scan_req) { |
| 5485 | err = -EINPROGRESS; |
| 5486 | goto out; |
| 5487 | } |
| 5488 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5489 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5490 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5491 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5492 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5493 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5494 | if (!request) { |
| 5495 | err = -ENOMEM; |
| 5496 | goto out; |
| 5497 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5498 | |
| 5499 | if (n_ssids) |
| 5500 | request->ssids = (void *)&request->channels[n_channels]; |
| 5501 | request->n_ssids = n_ssids; |
| 5502 | if (ie_len) { |
| 5503 | if (request->ssids) |
| 5504 | request->ie = (void *)(request->ssids + n_ssids); |
| 5505 | else |
| 5506 | request->ie = (void *)(request->channels + n_channels); |
| 5507 | } |
| 5508 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5509 | if (n_match_sets) { |
| 5510 | if (request->ie) |
| 5511 | request->match_sets = (void *)(request->ie + ie_len); |
| 5512 | else if (request->ssids) |
| 5513 | request->match_sets = |
| 5514 | (void *)(request->ssids + n_ssids); |
| 5515 | else |
| 5516 | request->match_sets = |
| 5517 | (void *)(request->channels + n_channels); |
| 5518 | } |
| 5519 | request->n_match_sets = n_match_sets; |
| 5520 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5521 | i = 0; |
| 5522 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5523 | /* user specified, bail out if channel not found */ |
| 5524 | nla_for_each_nested(attr, |
| 5525 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5526 | tmp) { |
| 5527 | struct ieee80211_channel *chan; |
| 5528 | |
| 5529 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5530 | |
| 5531 | if (!chan) { |
| 5532 | err = -EINVAL; |
| 5533 | goto out_free; |
| 5534 | } |
| 5535 | |
| 5536 | /* ignore disabled channels */ |
| 5537 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5538 | continue; |
| 5539 | |
| 5540 | request->channels[i] = chan; |
| 5541 | i++; |
| 5542 | } |
| 5543 | } else { |
| 5544 | /* all channels */ |
| 5545 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5546 | int j; |
| 5547 | if (!wiphy->bands[band]) |
| 5548 | continue; |
| 5549 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5550 | struct ieee80211_channel *chan; |
| 5551 | |
| 5552 | chan = &wiphy->bands[band]->channels[j]; |
| 5553 | |
| 5554 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5555 | continue; |
| 5556 | |
| 5557 | request->channels[i] = chan; |
| 5558 | i++; |
| 5559 | } |
| 5560 | } |
| 5561 | } |
| 5562 | |
| 5563 | if (!i) { |
| 5564 | err = -EINVAL; |
| 5565 | goto out_free; |
| 5566 | } |
| 5567 | |
| 5568 | request->n_channels = i; |
| 5569 | |
| 5570 | i = 0; |
| 5571 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5572 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5573 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5574 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5575 | err = -EINVAL; |
| 5576 | goto out_free; |
| 5577 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5578 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5579 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5580 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5581 | i++; |
| 5582 | } |
| 5583 | } |
| 5584 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5585 | i = 0; |
| 5586 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5587 | nla_for_each_nested(attr, |
| 5588 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5589 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5590 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5591 | |
| 5592 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5593 | nla_data(attr), nla_len(attr), |
| 5594 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5595 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5596 | if (ssid) { |
| 5597 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5598 | err = -EINVAL; |
| 5599 | goto out_free; |
| 5600 | } |
| 5601 | memcpy(request->match_sets[i].ssid.ssid, |
| 5602 | nla_data(ssid), nla_len(ssid)); |
| 5603 | request->match_sets[i].ssid.ssid_len = |
| 5604 | nla_len(ssid); |
| 5605 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5606 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5607 | if (rssi) |
| 5608 | request->rssi_thold = nla_get_u32(rssi); |
| 5609 | else |
| 5610 | request->rssi_thold = |
| 5611 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5612 | i++; |
| 5613 | } |
| 5614 | } |
| 5615 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5616 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5617 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5618 | memcpy((void *)request->ie, |
| 5619 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5620 | request->ie_len); |
| 5621 | } |
| 5622 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5623 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5624 | request->flags = nla_get_u32( |
| 5625 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5626 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5627 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5628 | err = -EOPNOTSUPP; |
| 5629 | goto out_free; |
| 5630 | } |
| 5631 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5632 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5633 | request->dev = dev; |
| 5634 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5635 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5636 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5637 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5638 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5639 | if (!err) { |
| 5640 | rdev->sched_scan_req = request; |
| 5641 | nl80211_send_sched_scan(rdev, dev, |
| 5642 | NL80211_CMD_START_SCHED_SCAN); |
| 5643 | goto out; |
| 5644 | } |
| 5645 | |
| 5646 | out_free: |
| 5647 | kfree(request); |
| 5648 | out: |
| 5649 | return err; |
| 5650 | } |
| 5651 | |
| 5652 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5653 | struct genl_info *info) |
| 5654 | { |
| 5655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5656 | |
| 5657 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5658 | !rdev->ops->sched_scan_stop) |
| 5659 | return -EOPNOTSUPP; |
| 5660 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5661 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5662 | } |
| 5663 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5664 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5665 | struct genl_info *info) |
| 5666 | { |
| 5667 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5668 | struct net_device *dev = info->user_ptr[1]; |
| 5669 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5670 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5671 | enum nl80211_dfs_regions dfs_region; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5672 | int err; |
| 5673 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5674 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5675 | if (dfs_region == NL80211_DFS_UNSET) |
| 5676 | return -EINVAL; |
| 5677 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5678 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5679 | if (err) |
| 5680 | return err; |
| 5681 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5682 | if (netif_carrier_ok(dev)) |
| 5683 | return -EBUSY; |
| 5684 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5685 | if (wdev->cac_started) |
| 5686 | return -EBUSY; |
| 5687 | |
| 5688 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5689 | if (err < 0) |
| 5690 | return err; |
| 5691 | |
| 5692 | if (err == 0) |
| 5693 | return -EINVAL; |
| 5694 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5695 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5696 | return -EINVAL; |
| 5697 | |
| 5698 | if (!rdev->ops->start_radar_detection) |
| 5699 | return -EOPNOTSUPP; |
| 5700 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5701 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5702 | chandef.chan, CHAN_MODE_SHARED, |
| 5703 | BIT(chandef.width)); |
| 5704 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5705 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5706 | |
| 5707 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5708 | if (!err) { |
| 5709 | wdev->channel = chandef.chan; |
| 5710 | wdev->cac_started = true; |
| 5711 | wdev->cac_start_time = jiffies; |
| 5712 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5713 | return err; |
| 5714 | } |
| 5715 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5716 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5717 | { |
| 5718 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5719 | struct net_device *dev = info->user_ptr[1]; |
| 5720 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5721 | struct cfg80211_csa_settings params; |
| 5722 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5723 | * function is called under RTNL lock, so this should not be a problem. |
| 5724 | */ |
| 5725 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5726 | u8 radar_detect_width = 0; |
| 5727 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5728 | bool need_new_beacon = false; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5729 | |
| 5730 | if (!rdev->ops->channel_switch || |
| 5731 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5732 | return -EOPNOTSUPP; |
| 5733 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5734 | switch (dev->ieee80211_ptr->iftype) { |
| 5735 | case NL80211_IFTYPE_AP: |
| 5736 | case NL80211_IFTYPE_P2P_GO: |
| 5737 | need_new_beacon = true; |
| 5738 | |
| 5739 | /* useless if AP is not running */ |
| 5740 | if (!wdev->beacon_interval) |
| 5741 | return -EINVAL; |
| 5742 | break; |
| 5743 | case NL80211_IFTYPE_ADHOC: |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5744 | case NL80211_IFTYPE_MESH_POINT: |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5745 | break; |
| 5746 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5747 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5748 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5749 | |
| 5750 | memset(¶ms, 0, sizeof(params)); |
| 5751 | |
| 5752 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5753 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5754 | return -EINVAL; |
| 5755 | |
| 5756 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5757 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5758 | return -EINVAL; |
| 5759 | |
| 5760 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5761 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5762 | if (!need_new_beacon) |
| 5763 | goto skip_beacons; |
| 5764 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5765 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5766 | if (err) |
| 5767 | return err; |
| 5768 | |
| 5769 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5770 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5771 | nl80211_policy); |
| 5772 | if (err) |
| 5773 | return err; |
| 5774 | |
| 5775 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5776 | if (err) |
| 5777 | return err; |
| 5778 | |
| 5779 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5780 | return -EINVAL; |
| 5781 | |
| 5782 | params.counter_offset_beacon = |
| 5783 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5784 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5785 | return -EINVAL; |
| 5786 | |
| 5787 | /* sanity check - counters should be the same */ |
| 5788 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5789 | params.count) |
| 5790 | return -EINVAL; |
| 5791 | |
| 5792 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5793 | params.counter_offset_presp = |
| 5794 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5795 | if (params.counter_offset_presp >= |
| 5796 | params.beacon_csa.probe_resp_len) |
| 5797 | return -EINVAL; |
| 5798 | |
| 5799 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5800 | params.count) |
| 5801 | return -EINVAL; |
| 5802 | } |
| 5803 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5804 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5805 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5806 | if (err) |
| 5807 | return err; |
| 5808 | |
| 5809 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5810 | return -EINVAL; |
| 5811 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5812 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 5813 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO || |
| 5814 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) { |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5815 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 5816 | ¶ms.chandef); |
| 5817 | if (err < 0) { |
| 5818 | return err; |
| 5819 | } else if (err) { |
| 5820 | radar_detect_width = BIT(params.chandef.width); |
| 5821 | params.radar_required = true; |
| 5822 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5823 | } |
| 5824 | |
| 5825 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5826 | params.chandef.chan, |
| 5827 | CHAN_MODE_SHARED, |
| 5828 | radar_detect_width); |
| 5829 | if (err) |
| 5830 | return err; |
| 5831 | |
| 5832 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5833 | params.block_tx = true; |
| 5834 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5835 | wdev_lock(wdev); |
| 5836 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 5837 | wdev_unlock(wdev); |
| 5838 | |
| 5839 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5840 | } |
| 5841 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5842 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5843 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5844 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5845 | struct wireless_dev *wdev, |
| 5846 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5847 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5848 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5849 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5850 | void *hdr; |
| 5851 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5852 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5853 | |
| 5854 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5855 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5856 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5857 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5858 | if (!hdr) |
| 5859 | return -1; |
| 5860 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5861 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5862 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5863 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5864 | goto nla_put_failure; |
| 5865 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5866 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5867 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5868 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5869 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5870 | |
| 5871 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5872 | if (!bss) |
| 5873 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5874 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5875 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5876 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5877 | |
| 5878 | rcu_read_lock(); |
| 5879 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5880 | if (ies) { |
| 5881 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5882 | goto fail_unlock_rcu; |
| 5883 | tsf = true; |
| 5884 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5885 | ies->len, ies->data)) |
| 5886 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5887 | } |
| 5888 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5889 | if (ies) { |
| 5890 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5891 | goto fail_unlock_rcu; |
| 5892 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5893 | ies->len, ies->data)) |
| 5894 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5895 | } |
| 5896 | rcu_read_unlock(); |
| 5897 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5898 | if (res->beacon_interval && |
| 5899 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5900 | goto nla_put_failure; |
| 5901 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5902 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 5903 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5904 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5905 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5906 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5907 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5908 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5909 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5910 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5911 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5912 | break; |
| 5913 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5914 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5915 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5916 | break; |
| 5917 | default: |
| 5918 | break; |
| 5919 | } |
| 5920 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5921 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5922 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5923 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5924 | if (intbss == wdev->current_bss && |
| 5925 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5926 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5927 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5928 | break; |
| 5929 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5930 | if (intbss == wdev->current_bss && |
| 5931 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5932 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5933 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5934 | break; |
| 5935 | default: |
| 5936 | break; |
| 5937 | } |
| 5938 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5939 | nla_nest_end(msg, bss); |
| 5940 | |
| 5941 | return genlmsg_end(msg, hdr); |
| 5942 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5943 | fail_unlock_rcu: |
| 5944 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5945 | nla_put_failure: |
| 5946 | genlmsg_cancel(msg, hdr); |
| 5947 | return -EMSGSIZE; |
| 5948 | } |
| 5949 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5950 | 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] | 5951 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5952 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5953 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5954 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5955 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5956 | int err; |
| 5957 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5958 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5959 | if (err) |
| 5960 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5961 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5962 | wdev_lock(wdev); |
| 5963 | spin_lock_bh(&rdev->bss_lock); |
| 5964 | cfg80211_bss_expire(rdev); |
| 5965 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5966 | cb->seq = rdev->bss_generation; |
| 5967 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5968 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5969 | if (++idx <= start) |
| 5970 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5971 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5972 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5973 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5974 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5975 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5976 | } |
| 5977 | } |
| 5978 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5979 | spin_unlock_bh(&rdev->bss_lock); |
| 5980 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5981 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5982 | cb->args[2] = idx; |
| 5983 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5984 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5985 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5986 | } |
| 5987 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5988 | 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] | 5989 | int flags, struct net_device *dev, |
| 5990 | struct survey_info *survey) |
| 5991 | { |
| 5992 | void *hdr; |
| 5993 | struct nlattr *infoattr; |
| 5994 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5995 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5996 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5997 | if (!hdr) |
| 5998 | return -ENOMEM; |
| 5999 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6000 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6001 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6002 | |
| 6003 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6004 | if (!infoattr) |
| 6005 | goto nla_put_failure; |
| 6006 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6007 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6008 | survey->channel->center_freq)) |
| 6009 | goto nla_put_failure; |
| 6010 | |
| 6011 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6012 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6013 | goto nla_put_failure; |
| 6014 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6015 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6016 | goto nla_put_failure; |
| 6017 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6018 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6019 | survey->channel_time)) |
| 6020 | goto nla_put_failure; |
| 6021 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6022 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6023 | survey->channel_time_busy)) |
| 6024 | goto nla_put_failure; |
| 6025 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6026 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6027 | survey->channel_time_ext_busy)) |
| 6028 | goto nla_put_failure; |
| 6029 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6030 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6031 | survey->channel_time_rx)) |
| 6032 | goto nla_put_failure; |
| 6033 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6034 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6035 | survey->channel_time_tx)) |
| 6036 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6037 | |
| 6038 | nla_nest_end(msg, infoattr); |
| 6039 | |
| 6040 | return genlmsg_end(msg, hdr); |
| 6041 | |
| 6042 | nla_put_failure: |
| 6043 | genlmsg_cancel(msg, hdr); |
| 6044 | return -EMSGSIZE; |
| 6045 | } |
| 6046 | |
| 6047 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6048 | struct netlink_callback *cb) |
| 6049 | { |
| 6050 | struct survey_info survey; |
| 6051 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6052 | struct wireless_dev *wdev; |
| 6053 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6054 | int res; |
| 6055 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6056 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6057 | if (res) |
| 6058 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6059 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6060 | if (!wdev->netdev) { |
| 6061 | res = -EINVAL; |
| 6062 | goto out_err; |
| 6063 | } |
| 6064 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6065 | if (!dev->ops->dump_survey) { |
| 6066 | res = -EOPNOTSUPP; |
| 6067 | goto out_err; |
| 6068 | } |
| 6069 | |
| 6070 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6071 | struct ieee80211_channel *chan; |
| 6072 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6073 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6074 | if (res == -ENOENT) |
| 6075 | break; |
| 6076 | if (res) |
| 6077 | goto out_err; |
| 6078 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6079 | /* Survey without a channel doesn't make sense */ |
| 6080 | if (!survey.channel) { |
| 6081 | res = -EINVAL; |
| 6082 | goto out; |
| 6083 | } |
| 6084 | |
| 6085 | chan = ieee80211_get_channel(&dev->wiphy, |
| 6086 | survey.channel->center_freq); |
| 6087 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6088 | survey_idx++; |
| 6089 | continue; |
| 6090 | } |
| 6091 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6092 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6093 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6094 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6095 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6096 | goto out; |
| 6097 | survey_idx++; |
| 6098 | } |
| 6099 | |
| 6100 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6101 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6102 | res = skb->len; |
| 6103 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6104 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6105 | return res; |
| 6106 | } |
| 6107 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6108 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6109 | { |
| 6110 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6111 | NL80211_WPA_VERSION_2)); |
| 6112 | } |
| 6113 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6114 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6115 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6117 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6118 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6119 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6120 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6121 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6122 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6123 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6124 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6125 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6126 | return -EINVAL; |
| 6127 | |
| 6128 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6129 | return -EINVAL; |
| 6130 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6131 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6132 | return -EINVAL; |
| 6133 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6134 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6135 | return -EINVAL; |
| 6136 | |
| 6137 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6138 | return -EINVAL; |
| 6139 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6140 | err = nl80211_parse_key(info, &key); |
| 6141 | if (err) |
| 6142 | return err; |
| 6143 | |
| 6144 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6145 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6146 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6147 | if (!key.p.key || !key.p.key_len) |
| 6148 | return -EINVAL; |
| 6149 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6150 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6151 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6152 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6153 | return -EINVAL; |
| 6154 | if (key.idx > 4) |
| 6155 | return -EINVAL; |
| 6156 | } else { |
| 6157 | key.p.key_len = 0; |
| 6158 | key.p.key = NULL; |
| 6159 | } |
| 6160 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6161 | if (key.idx >= 0) { |
| 6162 | int i; |
| 6163 | bool ok = false; |
| 6164 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6165 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6166 | ok = true; |
| 6167 | break; |
| 6168 | } |
| 6169 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6170 | if (!ok) |
| 6171 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6172 | } |
| 6173 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6174 | if (!rdev->ops->auth) |
| 6175 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6176 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6177 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6178 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6179 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6180 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6181 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6182 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6183 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6184 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6185 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6186 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6187 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6188 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6189 | |
| 6190 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6191 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6192 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6193 | } |
| 6194 | |
| 6195 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6196 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6197 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6198 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6199 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6200 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6201 | return -EINVAL; |
| 6202 | |
| 6203 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6204 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6205 | return -EINVAL; |
| 6206 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6207 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6208 | /* need to include at least Auth Transaction and Status Code */ |
| 6209 | if (sae_data_len < 4) |
| 6210 | return -EINVAL; |
| 6211 | } |
| 6212 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6213 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6214 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6215 | /* |
| 6216 | * Since we no longer track auth state, ignore |
| 6217 | * requests to only change local state. |
| 6218 | */ |
| 6219 | if (local_state_change) |
| 6220 | return 0; |
| 6221 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6222 | wdev_lock(dev->ieee80211_ptr); |
| 6223 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6224 | ssid, ssid_len, ie, ie_len, |
| 6225 | key.p.key, key.p.key_len, key.idx, |
| 6226 | sae_data, sae_data_len); |
| 6227 | wdev_unlock(dev->ieee80211_ptr); |
| 6228 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6229 | } |
| 6230 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6231 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6232 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6233 | struct cfg80211_crypto_settings *settings, |
| 6234 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6235 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6236 | memset(settings, 0, sizeof(*settings)); |
| 6237 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6238 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6239 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6240 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6241 | u16 proto; |
| 6242 | proto = nla_get_u16( |
| 6243 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6244 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6245 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6246 | proto != ETH_P_PAE) |
| 6247 | return -EINVAL; |
| 6248 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6249 | settings->control_port_no_encrypt = true; |
| 6250 | } else |
| 6251 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6252 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6253 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6254 | void *data; |
| 6255 | int len, i; |
| 6256 | |
| 6257 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6258 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6259 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6260 | |
| 6261 | if (len % sizeof(u32)) |
| 6262 | return -EINVAL; |
| 6263 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6264 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6265 | return -EINVAL; |
| 6266 | |
| 6267 | memcpy(settings->ciphers_pairwise, data, len); |
| 6268 | |
| 6269 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6270 | if (!cfg80211_supported_cipher_suite( |
| 6271 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6272 | settings->ciphers_pairwise[i])) |
| 6273 | return -EINVAL; |
| 6274 | } |
| 6275 | |
| 6276 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6277 | settings->cipher_group = |
| 6278 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6279 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6280 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6281 | return -EINVAL; |
| 6282 | } |
| 6283 | |
| 6284 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6285 | settings->wpa_versions = |
| 6286 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6287 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6288 | return -EINVAL; |
| 6289 | } |
| 6290 | |
| 6291 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6292 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6293 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6294 | |
| 6295 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6296 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6297 | settings->n_akm_suites = len / sizeof(u32); |
| 6298 | |
| 6299 | if (len % sizeof(u32)) |
| 6300 | return -EINVAL; |
| 6301 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6302 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6303 | return -EINVAL; |
| 6304 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6305 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6306 | } |
| 6307 | |
| 6308 | return 0; |
| 6309 | } |
| 6310 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6311 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6312 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6313 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6314 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6315 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6316 | struct cfg80211_assoc_request req = {}; |
| 6317 | const u8 *bssid, *ssid; |
| 6318 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6319 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6320 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6321 | return -EINVAL; |
| 6322 | |
| 6323 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6324 | !info->attrs[NL80211_ATTR_SSID] || |
| 6325 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6326 | return -EINVAL; |
| 6327 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6328 | if (!rdev->ops->assoc) |
| 6329 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6330 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6331 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6332 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6333 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6334 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6335 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6336 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6337 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6338 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6339 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6340 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6341 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6342 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6343 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6344 | |
| 6345 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6346 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6347 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6348 | } |
| 6349 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6350 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6351 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6352 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6353 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6354 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6355 | else if (mfp != NL80211_MFP_NO) |
| 6356 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6357 | } |
| 6358 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6359 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6360 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6361 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6362 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6363 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6364 | |
| 6365 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6366 | memcpy(&req.ht_capa_mask, |
| 6367 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6368 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6369 | |
| 6370 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6371 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6372 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6373 | memcpy(&req.ht_capa, |
| 6374 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6375 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6376 | } |
| 6377 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6378 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6379 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6380 | |
| 6381 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6382 | memcpy(&req.vht_capa_mask, |
| 6383 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6384 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6385 | |
| 6386 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6387 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6388 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6389 | memcpy(&req.vht_capa, |
| 6390 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6391 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6392 | } |
| 6393 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6394 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6395 | if (!err) { |
| 6396 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6397 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6398 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6399 | wdev_unlock(dev->ieee80211_ptr); |
| 6400 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6401 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6402 | return err; |
| 6403 | } |
| 6404 | |
| 6405 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6406 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6407 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6408 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6409 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6410 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6411 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6412 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6413 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6414 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6415 | return -EINVAL; |
| 6416 | |
| 6417 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6418 | return -EINVAL; |
| 6419 | |
| 6420 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6421 | return -EINVAL; |
| 6422 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6423 | if (!rdev->ops->deauth) |
| 6424 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6425 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6426 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6427 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6428 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6429 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6430 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6431 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6432 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6433 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6434 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6435 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6436 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6437 | |
| 6438 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6439 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6440 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6441 | } |
| 6442 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6443 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6444 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6445 | wdev_lock(dev->ieee80211_ptr); |
| 6446 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6447 | local_state_change); |
| 6448 | wdev_unlock(dev->ieee80211_ptr); |
| 6449 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6450 | } |
| 6451 | |
| 6452 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6453 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6454 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6455 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6456 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6457 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6458 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6459 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6460 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6461 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6462 | return -EINVAL; |
| 6463 | |
| 6464 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6465 | return -EINVAL; |
| 6466 | |
| 6467 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6468 | return -EINVAL; |
| 6469 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6470 | if (!rdev->ops->disassoc) |
| 6471 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6472 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6473 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6474 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6475 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6476 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6477 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6478 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6479 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6480 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6481 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6482 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6483 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6484 | |
| 6485 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6486 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6487 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6488 | } |
| 6489 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6490 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6491 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6492 | wdev_lock(dev->ieee80211_ptr); |
| 6493 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6494 | local_state_change); |
| 6495 | wdev_unlock(dev->ieee80211_ptr); |
| 6496 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6497 | } |
| 6498 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6499 | static bool |
| 6500 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6501 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6502 | int rateval) |
| 6503 | { |
| 6504 | struct wiphy *wiphy = &rdev->wiphy; |
| 6505 | bool found = false; |
| 6506 | int band, i; |
| 6507 | |
| 6508 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6509 | struct ieee80211_supported_band *sband; |
| 6510 | |
| 6511 | sband = wiphy->bands[band]; |
| 6512 | if (!sband) |
| 6513 | continue; |
| 6514 | |
| 6515 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6516 | if (sband->bitrates[i].bitrate == rateval) { |
| 6517 | mcast_rate[band] = i + 1; |
| 6518 | found = true; |
| 6519 | break; |
| 6520 | } |
| 6521 | } |
| 6522 | } |
| 6523 | |
| 6524 | return found; |
| 6525 | } |
| 6526 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6527 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6528 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6529 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6530 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6531 | struct cfg80211_ibss_params ibss; |
| 6532 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6533 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6534 | int err; |
| 6535 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6536 | memset(&ibss, 0, sizeof(ibss)); |
| 6537 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6538 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6539 | return -EINVAL; |
| 6540 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6541 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6542 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6543 | return -EINVAL; |
| 6544 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6545 | ibss.beacon_interval = 100; |
| 6546 | |
| 6547 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6548 | ibss.beacon_interval = |
| 6549 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6550 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6551 | return -EINVAL; |
| 6552 | } |
| 6553 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6554 | if (!rdev->ops->join_ibss) |
| 6555 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6556 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6557 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6558 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6559 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6560 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6561 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6562 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6563 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6564 | |
| 6565 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6566 | return -EINVAL; |
| 6567 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6568 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6569 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6570 | |
| 6571 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6572 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6573 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6574 | } |
| 6575 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6576 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6577 | if (err) |
| 6578 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6579 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6580 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6581 | return -EINVAL; |
| 6582 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6583 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6584 | case NL80211_CHAN_WIDTH_5: |
| 6585 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6586 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6587 | break; |
| 6588 | case NL80211_CHAN_WIDTH_20: |
| 6589 | case NL80211_CHAN_WIDTH_40: |
| 6590 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6591 | break; |
| 6592 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6593 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6594 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6595 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6596 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6597 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6598 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6599 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6600 | u8 *rates = |
| 6601 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6602 | int n_rates = |
| 6603 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6604 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6605 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6606 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6607 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6608 | &ibss.basic_rates); |
| 6609 | if (err) |
| 6610 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6611 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6612 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6613 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6614 | memcpy(&ibss.ht_capa_mask, |
| 6615 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6616 | sizeof(ibss.ht_capa_mask)); |
| 6617 | |
| 6618 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6619 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6620 | return -EINVAL; |
| 6621 | memcpy(&ibss.ht_capa, |
| 6622 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6623 | sizeof(ibss.ht_capa)); |
| 6624 | } |
| 6625 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6626 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6627 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6628 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6629 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6630 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6631 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6632 | bool no_ht = false; |
| 6633 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6634 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6635 | info->attrs[NL80211_ATTR_KEYS], |
| 6636 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6637 | if (IS_ERR(connkeys)) |
| 6638 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6639 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6640 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6641 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6642 | kfree(connkeys); |
| 6643 | return -EINVAL; |
| 6644 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6645 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6646 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6647 | ibss.control_port = |
| 6648 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6649 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6650 | ibss.userspace_handles_dfs = |
| 6651 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6652 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6653 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6654 | if (err) |
| 6655 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6656 | return err; |
| 6657 | } |
| 6658 | |
| 6659 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6660 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6661 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6662 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6663 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6664 | if (!rdev->ops->leave_ibss) |
| 6665 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6666 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6667 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6668 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6669 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6670 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6671 | } |
| 6672 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6673 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6674 | { |
| 6675 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6676 | struct net_device *dev = info->user_ptr[1]; |
| 6677 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6678 | u32 nla_rate; |
| 6679 | int err; |
| 6680 | |
| 6681 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6682 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6683 | return -EOPNOTSUPP; |
| 6684 | |
| 6685 | if (!rdev->ops->set_mcast_rate) |
| 6686 | return -EOPNOTSUPP; |
| 6687 | |
| 6688 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6689 | |
| 6690 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6691 | return -EINVAL; |
| 6692 | |
| 6693 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6694 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6695 | return -EINVAL; |
| 6696 | |
| 6697 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6698 | |
| 6699 | return err; |
| 6700 | } |
| 6701 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6702 | static struct sk_buff * |
| 6703 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 6704 | int approxlen, u32 portid, u32 seq, |
| 6705 | enum nl80211_commands cmd, |
| 6706 | enum nl80211_attrs attr, gfp_t gfp) |
| 6707 | { |
| 6708 | struct sk_buff *skb; |
| 6709 | void *hdr; |
| 6710 | struct nlattr *data; |
| 6711 | |
| 6712 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6713 | if (!skb) |
| 6714 | return NULL; |
| 6715 | |
| 6716 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 6717 | if (!hdr) { |
| 6718 | kfree_skb(skb); |
| 6719 | return NULL; |
| 6720 | } |
| 6721 | |
| 6722 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6723 | goto nla_put_failure; |
| 6724 | data = nla_nest_start(skb, attr); |
| 6725 | |
| 6726 | ((void **)skb->cb)[0] = rdev; |
| 6727 | ((void **)skb->cb)[1] = hdr; |
| 6728 | ((void **)skb->cb)[2] = data; |
| 6729 | |
| 6730 | return skb; |
| 6731 | |
| 6732 | nla_put_failure: |
| 6733 | kfree_skb(skb); |
| 6734 | return NULL; |
| 6735 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6736 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6737 | #ifdef CONFIG_NL80211_TESTMODE |
| 6738 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6739 | .name = "testmode", |
| 6740 | }; |
| 6741 | |
| 6742 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6743 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6745 | struct wireless_dev *wdev = |
| 6746 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6747 | int err; |
| 6748 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6749 | if (!rdev->ops->testmode_cmd) |
| 6750 | return -EOPNOTSUPP; |
| 6751 | |
| 6752 | if (IS_ERR(wdev)) { |
| 6753 | err = PTR_ERR(wdev); |
| 6754 | if (err != -EINVAL) |
| 6755 | return err; |
| 6756 | wdev = NULL; |
| 6757 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6758 | return -EINVAL; |
| 6759 | } |
| 6760 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6761 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6762 | return -EINVAL; |
| 6763 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6764 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6765 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6766 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6767 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6768 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6769 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6770 | return err; |
| 6771 | } |
| 6772 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6773 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6774 | struct netlink_callback *cb) |
| 6775 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6776 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6777 | int err; |
| 6778 | long phy_idx; |
| 6779 | void *data = NULL; |
| 6780 | int data_len = 0; |
| 6781 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6782 | rtnl_lock(); |
| 6783 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6784 | if (cb->args[0]) { |
| 6785 | /* |
| 6786 | * 0 is a valid index, but not valid for args[0], |
| 6787 | * so we need to offset by 1. |
| 6788 | */ |
| 6789 | phy_idx = cb->args[0] - 1; |
| 6790 | } else { |
| 6791 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6792 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6793 | nl80211_policy); |
| 6794 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6795 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6796 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6797 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6798 | nl80211_fam.attrbuf); |
| 6799 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6800 | err = PTR_ERR(rdev); |
| 6801 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6802 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6803 | phy_idx = rdev->wiphy_idx; |
| 6804 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6805 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6806 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6807 | cb->args[1] = |
| 6808 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6809 | } |
| 6810 | |
| 6811 | if (cb->args[1]) { |
| 6812 | data = nla_data((void *)cb->args[1]); |
| 6813 | data_len = nla_len((void *)cb->args[1]); |
| 6814 | } |
| 6815 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6816 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6817 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6818 | err = -ENOENT; |
| 6819 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6820 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6821 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6822 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6823 | err = -EOPNOTSUPP; |
| 6824 | goto out_err; |
| 6825 | } |
| 6826 | |
| 6827 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6828 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6829 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6830 | NL80211_CMD_TESTMODE); |
| 6831 | struct nlattr *tmdata; |
| 6832 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 6833 | if (!hdr) |
| 6834 | break; |
| 6835 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6836 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6837 | genlmsg_cancel(skb, hdr); |
| 6838 | break; |
| 6839 | } |
| 6840 | |
| 6841 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6842 | if (!tmdata) { |
| 6843 | genlmsg_cancel(skb, hdr); |
| 6844 | break; |
| 6845 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6846 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6847 | nla_nest_end(skb, tmdata); |
| 6848 | |
| 6849 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6850 | genlmsg_cancel(skb, hdr); |
| 6851 | break; |
| 6852 | } else if (err) { |
| 6853 | genlmsg_cancel(skb, hdr); |
| 6854 | goto out_err; |
| 6855 | } |
| 6856 | |
| 6857 | genlmsg_end(skb, hdr); |
| 6858 | } |
| 6859 | |
| 6860 | err = skb->len; |
| 6861 | /* see above */ |
| 6862 | cb->args[0] = phy_idx + 1; |
| 6863 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6864 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6865 | return err; |
| 6866 | } |
| 6867 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6868 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6869 | int approxlen, gfp_t gfp) |
| 6870 | { |
| 6871 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6872 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6873 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 6874 | NL80211_CMD_TESTMODE, |
| 6875 | NL80211_ATTR_TESTDATA, gfp); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6876 | } |
| 6877 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6878 | |
| 6879 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6880 | { |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6881 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6882 | void *hdr = ((void **)skb->cb)[1]; |
| 6883 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6884 | |
| 6885 | nla_nest_end(skb, data); |
| 6886 | genlmsg_end(skb, hdr); |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6887 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0, |
| 6888 | nl80211_testmode_mcgrp.id, gfp); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6889 | } |
| 6890 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6891 | #endif |
| 6892 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6893 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6894 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6895 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6896 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6897 | struct cfg80211_connect_params connect; |
| 6898 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6899 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6900 | int err; |
| 6901 | |
| 6902 | memset(&connect, 0, sizeof(connect)); |
| 6903 | |
| 6904 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6905 | return -EINVAL; |
| 6906 | |
| 6907 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6908 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6909 | return -EINVAL; |
| 6910 | |
| 6911 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6912 | connect.auth_type = |
| 6913 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6914 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6915 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6916 | return -EINVAL; |
| 6917 | } else |
| 6918 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6919 | |
| 6920 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6921 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6922 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6923 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6924 | if (err) |
| 6925 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6926 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6927 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6928 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6929 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6930 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6931 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6932 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6933 | connect.bg_scan_period = -1; |
| 6934 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6935 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6936 | connect.bg_scan_period = |
| 6937 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6938 | } |
| 6939 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6940 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6941 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6942 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6943 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6944 | |
| 6945 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6946 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6947 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6948 | } |
| 6949 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6950 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6951 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6952 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6953 | connect.mfp != NL80211_MFP_NO) |
| 6954 | return -EINVAL; |
| 6955 | } else { |
| 6956 | connect.mfp = NL80211_MFP_NO; |
| 6957 | } |
| 6958 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6959 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6960 | connect.channel = |
| 6961 | ieee80211_get_channel(wiphy, |
| 6962 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6963 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6964 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6965 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6966 | } |
| 6967 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6968 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6969 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6970 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6971 | if (IS_ERR(connkeys)) |
| 6972 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6973 | } |
| 6974 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6975 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6976 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6977 | |
| 6978 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6979 | memcpy(&connect.ht_capa_mask, |
| 6980 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6981 | sizeof(connect.ht_capa_mask)); |
| 6982 | |
| 6983 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6984 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6985 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6986 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6987 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6988 | memcpy(&connect.ht_capa, |
| 6989 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6990 | sizeof(connect.ht_capa)); |
| 6991 | } |
| 6992 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6993 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6994 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6995 | |
| 6996 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6997 | memcpy(&connect.vht_capa_mask, |
| 6998 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6999 | sizeof(connect.vht_capa_mask)); |
| 7000 | |
| 7001 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7002 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 7003 | kfree(connkeys); |
| 7004 | return -EINVAL; |
| 7005 | } |
| 7006 | memcpy(&connect.vht_capa, |
| 7007 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7008 | sizeof(connect.vht_capa)); |
| 7009 | } |
| 7010 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7011 | wdev_lock(dev->ieee80211_ptr); |
| 7012 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7013 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7014 | if (err) |
| 7015 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7016 | return err; |
| 7017 | } |
| 7018 | |
| 7019 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7020 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7021 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7022 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7023 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7024 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7025 | |
| 7026 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7027 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7028 | else |
| 7029 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7030 | |
| 7031 | if (reason == 0) |
| 7032 | return -EINVAL; |
| 7033 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7034 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7035 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7036 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7037 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7038 | wdev_lock(dev->ieee80211_ptr); |
| 7039 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7040 | wdev_unlock(dev->ieee80211_ptr); |
| 7041 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7042 | } |
| 7043 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7044 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7045 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7046 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7047 | struct net *net; |
| 7048 | int err; |
| 7049 | u32 pid; |
| 7050 | |
| 7051 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7052 | return -EINVAL; |
| 7053 | |
| 7054 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7055 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7056 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7057 | if (IS_ERR(net)) |
| 7058 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7059 | |
| 7060 | err = 0; |
| 7061 | |
| 7062 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7063 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7064 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7065 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7066 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7067 | return err; |
| 7068 | } |
| 7069 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7070 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7071 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7072 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7073 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7074 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7075 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7076 | struct cfg80211_pmksa pmksa; |
| 7077 | |
| 7078 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7079 | |
| 7080 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7081 | return -EINVAL; |
| 7082 | |
| 7083 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7084 | return -EINVAL; |
| 7085 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7086 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7087 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7088 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7089 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7090 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7091 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7092 | |
| 7093 | switch (info->genlhdr->cmd) { |
| 7094 | case NL80211_CMD_SET_PMKSA: |
| 7095 | rdev_ops = rdev->ops->set_pmksa; |
| 7096 | break; |
| 7097 | case NL80211_CMD_DEL_PMKSA: |
| 7098 | rdev_ops = rdev->ops->del_pmksa; |
| 7099 | break; |
| 7100 | default: |
| 7101 | WARN_ON(1); |
| 7102 | break; |
| 7103 | } |
| 7104 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7105 | if (!rdev_ops) |
| 7106 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7107 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7108 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7109 | } |
| 7110 | |
| 7111 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7112 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7113 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7114 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7115 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7116 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7117 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7118 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7119 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7120 | if (!rdev->ops->flush_pmksa) |
| 7121 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7122 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7123 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7124 | } |
| 7125 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7126 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7127 | { |
| 7128 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7129 | struct net_device *dev = info->user_ptr[1]; |
| 7130 | u8 action_code, dialog_token; |
| 7131 | u16 status_code; |
| 7132 | u8 *peer; |
| 7133 | |
| 7134 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7135 | !rdev->ops->tdls_mgmt) |
| 7136 | return -EOPNOTSUPP; |
| 7137 | |
| 7138 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7139 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7140 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7141 | !info->attrs[NL80211_ATTR_IE] || |
| 7142 | !info->attrs[NL80211_ATTR_MAC]) |
| 7143 | return -EINVAL; |
| 7144 | |
| 7145 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7146 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7147 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7148 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 7149 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7150 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 7151 | dialog_token, status_code, |
| 7152 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7153 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7154 | } |
| 7155 | |
| 7156 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7157 | { |
| 7158 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7159 | struct net_device *dev = info->user_ptr[1]; |
| 7160 | enum nl80211_tdls_operation operation; |
| 7161 | u8 *peer; |
| 7162 | |
| 7163 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7164 | !rdev->ops->tdls_oper) |
| 7165 | return -EOPNOTSUPP; |
| 7166 | |
| 7167 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7168 | !info->attrs[NL80211_ATTR_MAC]) |
| 7169 | return -EINVAL; |
| 7170 | |
| 7171 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7172 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7173 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7174 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7175 | } |
| 7176 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7177 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7178 | struct genl_info *info) |
| 7179 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7180 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7181 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7182 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7183 | struct sk_buff *msg; |
| 7184 | void *hdr; |
| 7185 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7186 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7187 | int err; |
| 7188 | |
| 7189 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7190 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7191 | return -EINVAL; |
| 7192 | |
| 7193 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7194 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7195 | if (!rdev->ops->remain_on_channel || |
| 7196 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7197 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7198 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7199 | /* |
| 7200 | * We should be on that channel for at least a minimum amount of |
| 7201 | * time (10ms) but no longer than the driver supports. |
| 7202 | */ |
| 7203 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7204 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7205 | return -EINVAL; |
| 7206 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7207 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7208 | if (err) |
| 7209 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7210 | |
| 7211 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7212 | if (!msg) |
| 7213 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7214 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7215 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7216 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7217 | if (!hdr) { |
| 7218 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7219 | goto free_msg; |
| 7220 | } |
| 7221 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7222 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7223 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7224 | |
| 7225 | if (err) |
| 7226 | goto free_msg; |
| 7227 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7228 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7229 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7230 | |
| 7231 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7232 | |
| 7233 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7234 | |
| 7235 | nla_put_failure: |
| 7236 | err = -ENOBUFS; |
| 7237 | free_msg: |
| 7238 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7239 | return err; |
| 7240 | } |
| 7241 | |
| 7242 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7243 | struct genl_info *info) |
| 7244 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7245 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7246 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7247 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7248 | |
| 7249 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7250 | return -EINVAL; |
| 7251 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7252 | if (!rdev->ops->cancel_remain_on_channel) |
| 7253 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7254 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7255 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7256 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7257 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7258 | } |
| 7259 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7260 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7261 | u8 *rates, u8 rates_len) |
| 7262 | { |
| 7263 | u8 i; |
| 7264 | u32 mask = 0; |
| 7265 | |
| 7266 | for (i = 0; i < rates_len; i++) { |
| 7267 | int rate = (rates[i] & 0x7f) * 5; |
| 7268 | int ridx; |
| 7269 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7270 | struct ieee80211_rate *srate = |
| 7271 | &sband->bitrates[ridx]; |
| 7272 | if (rate == srate->bitrate) { |
| 7273 | mask |= 1 << ridx; |
| 7274 | break; |
| 7275 | } |
| 7276 | } |
| 7277 | if (ridx == sband->n_bitrates) |
| 7278 | return 0; /* rate not found */ |
| 7279 | } |
| 7280 | |
| 7281 | return mask; |
| 7282 | } |
| 7283 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7284 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7285 | u8 *rates, u8 rates_len, |
| 7286 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7287 | { |
| 7288 | u8 i; |
| 7289 | |
| 7290 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7291 | |
| 7292 | for (i = 0; i < rates_len; i++) { |
| 7293 | int ridx, rbit; |
| 7294 | |
| 7295 | ridx = rates[i] / 8; |
| 7296 | rbit = BIT(rates[i] % 8); |
| 7297 | |
| 7298 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7299 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7300 | return false; |
| 7301 | |
| 7302 | /* check availability */ |
| 7303 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7304 | mcs[ridx] |= rbit; |
| 7305 | else |
| 7306 | return false; |
| 7307 | } |
| 7308 | |
| 7309 | return true; |
| 7310 | } |
| 7311 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7312 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7313 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7314 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame^] | 7315 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7316 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7317 | }; |
| 7318 | |
| 7319 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7320 | struct genl_info *info) |
| 7321 | { |
| 7322 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7323 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7324 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7325 | int rem, i; |
| 7326 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7327 | struct nlattr *tx_rates; |
| 7328 | struct ieee80211_supported_band *sband; |
| 7329 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7330 | if (!rdev->ops->set_bitrate_mask) |
| 7331 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7332 | |
| 7333 | memset(&mask, 0, sizeof(mask)); |
| 7334 | /* Default to all rates enabled */ |
| 7335 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7336 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7337 | |
| 7338 | if (!sband) |
| 7339 | continue; |
| 7340 | |
| 7341 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame^] | 7342 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7343 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame^] | 7344 | sizeof(mask.control[i].ht_mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7345 | } |
| 7346 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7347 | /* if no rates are given set it back to the defaults */ |
| 7348 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7349 | goto out; |
| 7350 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7351 | /* |
| 7352 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7353 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7354 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7355 | 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] | 7356 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7357 | { |
| 7358 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7359 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7360 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7361 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7362 | if (sband == NULL) |
| 7363 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7364 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7365 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7366 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7367 | mask.control[band].legacy = rateset_to_mask( |
| 7368 | sband, |
| 7369 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7370 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7371 | if ((mask.control[band].legacy == 0) && |
| 7372 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7373 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7374 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame^] | 7375 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7376 | if (!ht_rateset_to_mask( |
| 7377 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame^] | 7378 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7379 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7380 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7381 | return -EINVAL; |
| 7382 | } |
| 7383 | |
| 7384 | if (mask.control[band].legacy == 0) { |
| 7385 | /* don't allow empty legacy rates if HT |
| 7386 | * is not even supported. */ |
| 7387 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7388 | return -EINVAL; |
| 7389 | |
| 7390 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame^] | 7391 | if (mask.control[band].ht_mcs[i]) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7392 | break; |
| 7393 | |
| 7394 | /* legacy and mcs rates may not be both empty */ |
| 7395 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7396 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7397 | } |
| 7398 | } |
| 7399 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7400 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7401 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7402 | } |
| 7403 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7404 | 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] | 7405 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7406 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7407 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7408 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7409 | |
| 7410 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7411 | return -EINVAL; |
| 7412 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7413 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7414 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7415 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7416 | switch (wdev->iftype) { |
| 7417 | case NL80211_IFTYPE_STATION: |
| 7418 | case NL80211_IFTYPE_ADHOC: |
| 7419 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7420 | case NL80211_IFTYPE_AP: |
| 7421 | case NL80211_IFTYPE_AP_VLAN: |
| 7422 | case NL80211_IFTYPE_MESH_POINT: |
| 7423 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7424 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7425 | break; |
| 7426 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7427 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7428 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7429 | |
| 7430 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7431 | if (!rdev->ops->mgmt_tx) |
| 7432 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7433 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7434 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7435 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7436 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7437 | } |
| 7438 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7439 | 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] | 7440 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7441 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7442 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7443 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7444 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7445 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7446 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7447 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7448 | struct cfg80211_mgmt_tx_params params = { |
| 7449 | .dont_wait_for_ack = |
| 7450 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7451 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7452 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7453 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7454 | return -EINVAL; |
| 7455 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7456 | if (!rdev->ops->mgmt_tx) |
| 7457 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7458 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7459 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7460 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7461 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7462 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7463 | case NL80211_IFTYPE_STATION: |
| 7464 | case NL80211_IFTYPE_ADHOC: |
| 7465 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7466 | case NL80211_IFTYPE_AP: |
| 7467 | case NL80211_IFTYPE_AP_VLAN: |
| 7468 | case NL80211_IFTYPE_MESH_POINT: |
| 7469 | case NL80211_IFTYPE_P2P_GO: |
| 7470 | break; |
| 7471 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7472 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7473 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7474 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7475 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7476 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7477 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7478 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7479 | |
| 7480 | /* |
| 7481 | * We should wait on the channel for at least a minimum amount |
| 7482 | * of time (10ms) but no longer than the driver supports. |
| 7483 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7484 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7485 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7486 | return -EINVAL; |
| 7487 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7488 | } |
| 7489 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7490 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7491 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7492 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7493 | return -EINVAL; |
| 7494 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7495 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7496 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7497 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7498 | * the driver. The latter will use the current one |
| 7499 | */ |
| 7500 | chandef.chan = NULL; |
| 7501 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7502 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7503 | if (err) |
| 7504 | return err; |
| 7505 | } |
| 7506 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7507 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7508 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7509 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7510 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7511 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7512 | if (!msg) |
| 7513 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7514 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7515 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7516 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7517 | if (!hdr) { |
| 7518 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7519 | goto free_msg; |
| 7520 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7521 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7522 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7523 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 7524 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 7525 | params.chan = chandef.chan; |
| 7526 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7527 | if (err) |
| 7528 | goto free_msg; |
| 7529 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7530 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7531 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7532 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7533 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7534 | genlmsg_end(msg, hdr); |
| 7535 | return genlmsg_reply(msg, info); |
| 7536 | } |
| 7537 | |
| 7538 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7539 | |
| 7540 | nla_put_failure: |
| 7541 | err = -ENOBUFS; |
| 7542 | free_msg: |
| 7543 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7544 | return err; |
| 7545 | } |
| 7546 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7547 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7548 | { |
| 7549 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7550 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7551 | u64 cookie; |
| 7552 | |
| 7553 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7554 | return -EINVAL; |
| 7555 | |
| 7556 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7557 | return -EOPNOTSUPP; |
| 7558 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7559 | switch (wdev->iftype) { |
| 7560 | case NL80211_IFTYPE_STATION: |
| 7561 | case NL80211_IFTYPE_ADHOC: |
| 7562 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7563 | case NL80211_IFTYPE_AP: |
| 7564 | case NL80211_IFTYPE_AP_VLAN: |
| 7565 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7566 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7567 | break; |
| 7568 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7569 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7570 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7571 | |
| 7572 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7573 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7574 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7575 | } |
| 7576 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7577 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7578 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7579 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7580 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7581 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7582 | u8 ps_state; |
| 7583 | bool state; |
| 7584 | int err; |
| 7585 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7586 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7587 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7588 | |
| 7589 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7590 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7591 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7592 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7593 | |
| 7594 | wdev = dev->ieee80211_ptr; |
| 7595 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7596 | if (!rdev->ops->set_power_mgmt) |
| 7597 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7598 | |
| 7599 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7600 | |
| 7601 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7602 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7603 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7604 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7605 | if (!err) |
| 7606 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7607 | return err; |
| 7608 | } |
| 7609 | |
| 7610 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7611 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7612 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7613 | enum nl80211_ps_state ps_state; |
| 7614 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7615 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7616 | struct sk_buff *msg; |
| 7617 | void *hdr; |
| 7618 | int err; |
| 7619 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7620 | wdev = dev->ieee80211_ptr; |
| 7621 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7622 | if (!rdev->ops->set_power_mgmt) |
| 7623 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7624 | |
| 7625 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7626 | if (!msg) |
| 7627 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7628 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7629 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7630 | NL80211_CMD_GET_POWER_SAVE); |
| 7631 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7632 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7633 | goto free_msg; |
| 7634 | } |
| 7635 | |
| 7636 | if (wdev->ps) |
| 7637 | ps_state = NL80211_PS_ENABLED; |
| 7638 | else |
| 7639 | ps_state = NL80211_PS_DISABLED; |
| 7640 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7641 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7642 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7643 | |
| 7644 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7645 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7646 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7647 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7648 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7649 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7650 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7651 | return err; |
| 7652 | } |
| 7653 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7654 | static struct nla_policy |
| 7655 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7656 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7657 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7658 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7659 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7660 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7661 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7662 | }; |
| 7663 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7664 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7665 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7666 | { |
| 7667 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [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; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7670 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7671 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7672 | return -EINVAL; |
| 7673 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7674 | if (!rdev->ops->set_cqm_txe_config) |
| 7675 | return -EOPNOTSUPP; |
| 7676 | |
| 7677 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7678 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7679 | return -EOPNOTSUPP; |
| 7680 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7681 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7682 | } |
| 7683 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7684 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7685 | s32 threshold, u32 hysteresis) |
| 7686 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7687 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7688 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7689 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7690 | |
| 7691 | if (threshold > 0) |
| 7692 | return -EINVAL; |
| 7693 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7694 | /* disabling - hysteresis should also be zero then */ |
| 7695 | if (threshold == 0) |
| 7696 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7697 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7698 | if (!rdev->ops->set_cqm_rssi_config) |
| 7699 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7700 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7701 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7702 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7703 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7704 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7705 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7706 | } |
| 7707 | |
| 7708 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7709 | { |
| 7710 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7711 | struct nlattr *cqm; |
| 7712 | int err; |
| 7713 | |
| 7714 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7715 | if (!cqm) |
| 7716 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7717 | |
| 7718 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7719 | nl80211_attr_cqm_policy); |
| 7720 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7721 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7722 | |
| 7723 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7724 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7725 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7726 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7727 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7728 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7729 | } |
| 7730 | |
| 7731 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7732 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7733 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7734 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7735 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7736 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7737 | |
| 7738 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 7739 | } |
| 7740 | |
| 7741 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7742 | } |
| 7743 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7744 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7745 | { |
| 7746 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7747 | struct net_device *dev = info->user_ptr[1]; |
| 7748 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7749 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7750 | int err; |
| 7751 | |
| 7752 | /* start with default */ |
| 7753 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7754 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7755 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7756 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7757 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7758 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7759 | if (err) |
| 7760 | return err; |
| 7761 | } |
| 7762 | |
| 7763 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7764 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7765 | return -EINVAL; |
| 7766 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7767 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7768 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7769 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7770 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7771 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7772 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7773 | return -EINVAL; |
| 7774 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7775 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7776 | setup.beacon_interval = |
| 7777 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7778 | if (setup.beacon_interval < 10 || |
| 7779 | setup.beacon_interval > 10000) |
| 7780 | return -EINVAL; |
| 7781 | } |
| 7782 | |
| 7783 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7784 | setup.dtim_period = |
| 7785 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7786 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7787 | return -EINVAL; |
| 7788 | } |
| 7789 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7790 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7791 | /* parse additional setup parameters if given */ |
| 7792 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7793 | if (err) |
| 7794 | return err; |
| 7795 | } |
| 7796 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7797 | if (setup.user_mpm) |
| 7798 | cfg.auto_open_plinks = false; |
| 7799 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7800 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7801 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7802 | if (err) |
| 7803 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7804 | } else { |
| 7805 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7806 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7807 | } |
| 7808 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7809 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7810 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7811 | int n_rates = |
| 7812 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7813 | struct ieee80211_supported_band *sband; |
| 7814 | |
| 7815 | if (!setup.chandef.chan) |
| 7816 | return -EINVAL; |
| 7817 | |
| 7818 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7819 | |
| 7820 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7821 | &setup.basic_rates); |
| 7822 | if (err) |
| 7823 | return err; |
| 7824 | } |
| 7825 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7826 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7827 | } |
| 7828 | |
| 7829 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7830 | { |
| 7831 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7832 | struct net_device *dev = info->user_ptr[1]; |
| 7833 | |
| 7834 | return cfg80211_leave_mesh(rdev, dev); |
| 7835 | } |
| 7836 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7837 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7838 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7839 | struct cfg80211_registered_device *rdev) |
| 7840 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7841 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7842 | struct nlattr *nl_pats, *nl_pat; |
| 7843 | int i, pat_len; |
| 7844 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7845 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7846 | return 0; |
| 7847 | |
| 7848 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7849 | if (!nl_pats) |
| 7850 | return -ENOBUFS; |
| 7851 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7852 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7853 | nl_pat = nla_nest_start(msg, i + 1); |
| 7854 | if (!nl_pat) |
| 7855 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7856 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7857 | 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] | 7858 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7859 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 7860 | wowlan->patterns[i].pattern) || |
| 7861 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7862 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7863 | return -ENOBUFS; |
| 7864 | nla_nest_end(msg, nl_pat); |
| 7865 | } |
| 7866 | nla_nest_end(msg, nl_pats); |
| 7867 | |
| 7868 | return 0; |
| 7869 | } |
| 7870 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7871 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7872 | struct cfg80211_wowlan_tcp *tcp) |
| 7873 | { |
| 7874 | struct nlattr *nl_tcp; |
| 7875 | |
| 7876 | if (!tcp) |
| 7877 | return 0; |
| 7878 | |
| 7879 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7880 | if (!nl_tcp) |
| 7881 | return -ENOBUFS; |
| 7882 | |
| 7883 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7884 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7885 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7886 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7887 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7888 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7889 | tcp->payload_len, tcp->payload) || |
| 7890 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7891 | tcp->data_interval) || |
| 7892 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7893 | tcp->wake_len, tcp->wake_data) || |
| 7894 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7895 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7896 | return -ENOBUFS; |
| 7897 | |
| 7898 | if (tcp->payload_seq.len && |
| 7899 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7900 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7901 | return -ENOBUFS; |
| 7902 | |
| 7903 | if (tcp->payload_tok.len && |
| 7904 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7905 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7906 | &tcp->payload_tok)) |
| 7907 | return -ENOBUFS; |
| 7908 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 7909 | nla_nest_end(msg, nl_tcp); |
| 7910 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7911 | return 0; |
| 7912 | } |
| 7913 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7914 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7915 | { |
| 7916 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7917 | struct sk_buff *msg; |
| 7918 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7919 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7920 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7921 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7922 | return -EOPNOTSUPP; |
| 7923 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7924 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7925 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7926 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 7927 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 7928 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 7929 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7930 | } |
| 7931 | |
| 7932 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7933 | if (!msg) |
| 7934 | return -ENOMEM; |
| 7935 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7936 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7937 | NL80211_CMD_GET_WOWLAN); |
| 7938 | if (!hdr) |
| 7939 | goto nla_put_failure; |
| 7940 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7941 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7942 | struct nlattr *nl_wowlan; |
| 7943 | |
| 7944 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7945 | if (!nl_wowlan) |
| 7946 | goto nla_put_failure; |
| 7947 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7948 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7949 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7950 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7951 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7952 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7953 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7954 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7955 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7956 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7957 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7958 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7959 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7960 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7961 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7962 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7963 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7964 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7965 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7966 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7967 | if (nl80211_send_wowlan_tcp(msg, |
| 7968 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7969 | goto nla_put_failure; |
| 7970 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7971 | nla_nest_end(msg, nl_wowlan); |
| 7972 | } |
| 7973 | |
| 7974 | genlmsg_end(msg, hdr); |
| 7975 | return genlmsg_reply(msg, info); |
| 7976 | |
| 7977 | nla_put_failure: |
| 7978 | nlmsg_free(msg); |
| 7979 | return -ENOBUFS; |
| 7980 | } |
| 7981 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7982 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7983 | struct nlattr *attr, |
| 7984 | struct cfg80211_wowlan *trig) |
| 7985 | { |
| 7986 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7987 | struct cfg80211_wowlan_tcp *cfg; |
| 7988 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7989 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7990 | u32 size; |
| 7991 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7992 | int err, port; |
| 7993 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7994 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7995 | return -EINVAL; |
| 7996 | |
| 7997 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7998 | nla_data(attr), nla_len(attr), |
| 7999 | nl80211_wowlan_tcp_policy); |
| 8000 | if (err) |
| 8001 | return err; |
| 8002 | |
| 8003 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8004 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8005 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8006 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8007 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8008 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8009 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8010 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8011 | return -EINVAL; |
| 8012 | |
| 8013 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8014 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8015 | return -EINVAL; |
| 8016 | |
| 8017 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8018 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8019 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8020 | return -EINVAL; |
| 8021 | |
| 8022 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8023 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8024 | return -EINVAL; |
| 8025 | |
| 8026 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8027 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8028 | return -EINVAL; |
| 8029 | |
| 8030 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8031 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8032 | |
| 8033 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8034 | tokens_size = tokln - sizeof(*tok); |
| 8035 | |
| 8036 | if (!tok->len || tokens_size % tok->len) |
| 8037 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8038 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8039 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8040 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8041 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8042 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8043 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8044 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8045 | return -EINVAL; |
| 8046 | if (tok->offset + tok->len > data_size) |
| 8047 | return -EINVAL; |
| 8048 | } |
| 8049 | |
| 8050 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8051 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8052 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8053 | return -EINVAL; |
| 8054 | if (seq->len == 0 || seq->len > 4) |
| 8055 | return -EINVAL; |
| 8056 | if (seq->len + seq->offset > data_size) |
| 8057 | return -EINVAL; |
| 8058 | } |
| 8059 | |
| 8060 | size = sizeof(*cfg); |
| 8061 | size += data_size; |
| 8062 | size += wake_size + wake_mask_size; |
| 8063 | size += tokens_size; |
| 8064 | |
| 8065 | cfg = kzalloc(size, GFP_KERNEL); |
| 8066 | if (!cfg) |
| 8067 | return -ENOMEM; |
| 8068 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8069 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8070 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8071 | ETH_ALEN); |
| 8072 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8073 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8074 | else |
| 8075 | port = 0; |
| 8076 | #ifdef CONFIG_INET |
| 8077 | /* allocate a socket and port for it and use it */ |
| 8078 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8079 | IPPROTO_TCP, &cfg->sock, 1); |
| 8080 | if (err) { |
| 8081 | kfree(cfg); |
| 8082 | return err; |
| 8083 | } |
| 8084 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8085 | sock_release(cfg->sock); |
| 8086 | kfree(cfg); |
| 8087 | return -EADDRINUSE; |
| 8088 | } |
| 8089 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8090 | #else |
| 8091 | if (!port) { |
| 8092 | kfree(cfg); |
| 8093 | return -EINVAL; |
| 8094 | } |
| 8095 | cfg->src_port = port; |
| 8096 | #endif |
| 8097 | |
| 8098 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8099 | cfg->payload_len = data_size; |
| 8100 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8101 | memcpy((void *)cfg->payload, |
| 8102 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8103 | data_size); |
| 8104 | if (seq) |
| 8105 | cfg->payload_seq = *seq; |
| 8106 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8107 | cfg->wake_len = wake_size; |
| 8108 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8109 | memcpy((void *)cfg->wake_data, |
| 8110 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8111 | wake_size); |
| 8112 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8113 | data_size + wake_size; |
| 8114 | memcpy((void *)cfg->wake_mask, |
| 8115 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8116 | wake_mask_size); |
| 8117 | if (tok) { |
| 8118 | cfg->tokens_size = tokens_size; |
| 8119 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8120 | } |
| 8121 | |
| 8122 | trig->tcp = cfg; |
| 8123 | |
| 8124 | return 0; |
| 8125 | } |
| 8126 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8127 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8128 | { |
| 8129 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8130 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8131 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8132 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8133 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8134 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8135 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8136 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8137 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8138 | return -EOPNOTSUPP; |
| 8139 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8140 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8141 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8142 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8143 | goto set_wakeup; |
| 8144 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8145 | |
| 8146 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8147 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8148 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8149 | nl80211_wowlan_policy); |
| 8150 | if (err) |
| 8151 | return err; |
| 8152 | |
| 8153 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8154 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8155 | return -EINVAL; |
| 8156 | new_triggers.any = true; |
| 8157 | } |
| 8158 | |
| 8159 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8160 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8161 | return -EINVAL; |
| 8162 | new_triggers.disconnect = true; |
| 8163 | } |
| 8164 | |
| 8165 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8166 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8167 | return -EINVAL; |
| 8168 | new_triggers.magic_pkt = true; |
| 8169 | } |
| 8170 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8171 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8172 | return -EINVAL; |
| 8173 | |
| 8174 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8175 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8176 | return -EINVAL; |
| 8177 | new_triggers.gtk_rekey_failure = true; |
| 8178 | } |
| 8179 | |
| 8180 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8181 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8182 | return -EINVAL; |
| 8183 | new_triggers.eap_identity_req = true; |
| 8184 | } |
| 8185 | |
| 8186 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8187 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8188 | return -EINVAL; |
| 8189 | new_triggers.four_way_handshake = true; |
| 8190 | } |
| 8191 | |
| 8192 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8193 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8194 | return -EINVAL; |
| 8195 | new_triggers.rfkill_release = true; |
| 8196 | } |
| 8197 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8198 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8199 | struct nlattr *pat; |
| 8200 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8201 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8202 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8203 | |
| 8204 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8205 | rem) |
| 8206 | n_patterns++; |
| 8207 | if (n_patterns > wowlan->n_patterns) |
| 8208 | return -EINVAL; |
| 8209 | |
| 8210 | new_triggers.patterns = kcalloc(n_patterns, |
| 8211 | sizeof(new_triggers.patterns[0]), |
| 8212 | GFP_KERNEL); |
| 8213 | if (!new_triggers.patterns) |
| 8214 | return -ENOMEM; |
| 8215 | |
| 8216 | new_triggers.n_patterns = n_patterns; |
| 8217 | i = 0; |
| 8218 | |
| 8219 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8220 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8221 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8222 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8223 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8224 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8225 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8226 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8227 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8228 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8229 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8230 | goto error; |
| 8231 | if (pat_len > wowlan->pattern_max_len || |
| 8232 | pat_len < wowlan->pattern_min_len) |
| 8233 | goto error; |
| 8234 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8235 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8236 | pkt_offset = 0; |
| 8237 | else |
| 8238 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8239 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8240 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8241 | goto error; |
| 8242 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8243 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8244 | new_triggers.patterns[i].mask = |
| 8245 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8246 | if (!new_triggers.patterns[i].mask) { |
| 8247 | err = -ENOMEM; |
| 8248 | goto error; |
| 8249 | } |
| 8250 | new_triggers.patterns[i].pattern = |
| 8251 | new_triggers.patterns[i].mask + mask_len; |
| 8252 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8253 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8254 | mask_len); |
| 8255 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8256 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8257 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8258 | pat_len); |
| 8259 | i++; |
| 8260 | } |
| 8261 | } |
| 8262 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8263 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8264 | err = nl80211_parse_wowlan_tcp( |
| 8265 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8266 | &new_triggers); |
| 8267 | if (err) |
| 8268 | goto error; |
| 8269 | } |
| 8270 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8271 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8272 | if (!ntrig) { |
| 8273 | err = -ENOMEM; |
| 8274 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8275 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8276 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8277 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8278 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8279 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8280 | if (rdev->ops->set_wakeup && |
| 8281 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8282 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8283 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8284 | return 0; |
| 8285 | error: |
| 8286 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8287 | kfree(new_triggers.patterns[i].mask); |
| 8288 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8289 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8290 | sock_release(new_triggers.tcp->sock); |
| 8291 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8292 | return err; |
| 8293 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8294 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8295 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8296 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8297 | struct cfg80211_registered_device *rdev) |
| 8298 | { |
| 8299 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8300 | int i, j, pat_len; |
| 8301 | struct cfg80211_coalesce_rules *rule; |
| 8302 | |
| 8303 | if (!rdev->coalesce->n_rules) |
| 8304 | return 0; |
| 8305 | |
| 8306 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8307 | if (!nl_rules) |
| 8308 | return -ENOBUFS; |
| 8309 | |
| 8310 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8311 | nl_rule = nla_nest_start(msg, i + 1); |
| 8312 | if (!nl_rule) |
| 8313 | return -ENOBUFS; |
| 8314 | |
| 8315 | rule = &rdev->coalesce->rules[i]; |
| 8316 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8317 | rule->delay)) |
| 8318 | return -ENOBUFS; |
| 8319 | |
| 8320 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8321 | rule->condition)) |
| 8322 | return -ENOBUFS; |
| 8323 | |
| 8324 | nl_pats = nla_nest_start(msg, |
| 8325 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8326 | if (!nl_pats) |
| 8327 | return -ENOBUFS; |
| 8328 | |
| 8329 | for (j = 0; j < rule->n_patterns; j++) { |
| 8330 | nl_pat = nla_nest_start(msg, j + 1); |
| 8331 | if (!nl_pat) |
| 8332 | return -ENOBUFS; |
| 8333 | pat_len = rule->patterns[j].pattern_len; |
| 8334 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8335 | DIV_ROUND_UP(pat_len, 8), |
| 8336 | rule->patterns[j].mask) || |
| 8337 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8338 | rule->patterns[j].pattern) || |
| 8339 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8340 | rule->patterns[j].pkt_offset)) |
| 8341 | return -ENOBUFS; |
| 8342 | nla_nest_end(msg, nl_pat); |
| 8343 | } |
| 8344 | nla_nest_end(msg, nl_pats); |
| 8345 | nla_nest_end(msg, nl_rule); |
| 8346 | } |
| 8347 | nla_nest_end(msg, nl_rules); |
| 8348 | |
| 8349 | return 0; |
| 8350 | } |
| 8351 | |
| 8352 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8353 | { |
| 8354 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8355 | struct sk_buff *msg; |
| 8356 | void *hdr; |
| 8357 | |
| 8358 | if (!rdev->wiphy.coalesce) |
| 8359 | return -EOPNOTSUPP; |
| 8360 | |
| 8361 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8362 | if (!msg) |
| 8363 | return -ENOMEM; |
| 8364 | |
| 8365 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8366 | NL80211_CMD_GET_COALESCE); |
| 8367 | if (!hdr) |
| 8368 | goto nla_put_failure; |
| 8369 | |
| 8370 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8371 | goto nla_put_failure; |
| 8372 | |
| 8373 | genlmsg_end(msg, hdr); |
| 8374 | return genlmsg_reply(msg, info); |
| 8375 | |
| 8376 | nla_put_failure: |
| 8377 | nlmsg_free(msg); |
| 8378 | return -ENOBUFS; |
| 8379 | } |
| 8380 | |
| 8381 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8382 | { |
| 8383 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8384 | int i, j; |
| 8385 | struct cfg80211_coalesce_rules *rule; |
| 8386 | |
| 8387 | if (!coalesce) |
| 8388 | return; |
| 8389 | |
| 8390 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8391 | rule = &coalesce->rules[i]; |
| 8392 | for (j = 0; j < rule->n_patterns; j++) |
| 8393 | kfree(rule->patterns[j].mask); |
| 8394 | kfree(rule->patterns); |
| 8395 | } |
| 8396 | kfree(coalesce->rules); |
| 8397 | kfree(coalesce); |
| 8398 | rdev->coalesce = NULL; |
| 8399 | } |
| 8400 | |
| 8401 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8402 | struct nlattr *rule, |
| 8403 | struct cfg80211_coalesce_rules *new_rule) |
| 8404 | { |
| 8405 | int err, i; |
| 8406 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8407 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8408 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8409 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8410 | |
| 8411 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8412 | nla_len(rule), nl80211_coalesce_policy); |
| 8413 | if (err) |
| 8414 | return err; |
| 8415 | |
| 8416 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8417 | new_rule->delay = |
| 8418 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8419 | if (new_rule->delay > coalesce->max_delay) |
| 8420 | return -EINVAL; |
| 8421 | |
| 8422 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8423 | new_rule->condition = |
| 8424 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8425 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8426 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8427 | return -EINVAL; |
| 8428 | |
| 8429 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8430 | return -EINVAL; |
| 8431 | |
| 8432 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8433 | rem) |
| 8434 | n_patterns++; |
| 8435 | if (n_patterns > coalesce->n_patterns) |
| 8436 | return -EINVAL; |
| 8437 | |
| 8438 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8439 | GFP_KERNEL); |
| 8440 | if (!new_rule->patterns) |
| 8441 | return -ENOMEM; |
| 8442 | |
| 8443 | new_rule->n_patterns = n_patterns; |
| 8444 | i = 0; |
| 8445 | |
| 8446 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8447 | rem) { |
| 8448 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8449 | nla_len(pat), NULL); |
| 8450 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8451 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8452 | return -EINVAL; |
| 8453 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8454 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8455 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8456 | return -EINVAL; |
| 8457 | if (pat_len > coalesce->pattern_max_len || |
| 8458 | pat_len < coalesce->pattern_min_len) |
| 8459 | return -EINVAL; |
| 8460 | |
| 8461 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8462 | pkt_offset = 0; |
| 8463 | else |
| 8464 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8465 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8466 | return -EINVAL; |
| 8467 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8468 | |
| 8469 | new_rule->patterns[i].mask = |
| 8470 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8471 | if (!new_rule->patterns[i].mask) |
| 8472 | return -ENOMEM; |
| 8473 | new_rule->patterns[i].pattern = |
| 8474 | new_rule->patterns[i].mask + mask_len; |
| 8475 | memcpy(new_rule->patterns[i].mask, |
| 8476 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8477 | new_rule->patterns[i].pattern_len = pat_len; |
| 8478 | memcpy(new_rule->patterns[i].pattern, |
| 8479 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8480 | i++; |
| 8481 | } |
| 8482 | |
| 8483 | return 0; |
| 8484 | } |
| 8485 | |
| 8486 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8487 | { |
| 8488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8489 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8490 | struct cfg80211_coalesce new_coalesce = {}; |
| 8491 | struct cfg80211_coalesce *n_coalesce; |
| 8492 | int err, rem_rule, n_rules = 0, i, j; |
| 8493 | struct nlattr *rule; |
| 8494 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8495 | |
| 8496 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8497 | return -EOPNOTSUPP; |
| 8498 | |
| 8499 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8500 | cfg80211_rdev_free_coalesce(rdev); |
| 8501 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8502 | return 0; |
| 8503 | } |
| 8504 | |
| 8505 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8506 | rem_rule) |
| 8507 | n_rules++; |
| 8508 | if (n_rules > coalesce->n_rules) |
| 8509 | return -EINVAL; |
| 8510 | |
| 8511 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8512 | GFP_KERNEL); |
| 8513 | if (!new_coalesce.rules) |
| 8514 | return -ENOMEM; |
| 8515 | |
| 8516 | new_coalesce.n_rules = n_rules; |
| 8517 | i = 0; |
| 8518 | |
| 8519 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8520 | rem_rule) { |
| 8521 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8522 | &new_coalesce.rules[i]); |
| 8523 | if (err) |
| 8524 | goto error; |
| 8525 | |
| 8526 | i++; |
| 8527 | } |
| 8528 | |
| 8529 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8530 | if (err) |
| 8531 | goto error; |
| 8532 | |
| 8533 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8534 | if (!n_coalesce) { |
| 8535 | err = -ENOMEM; |
| 8536 | goto error; |
| 8537 | } |
| 8538 | cfg80211_rdev_free_coalesce(rdev); |
| 8539 | rdev->coalesce = n_coalesce; |
| 8540 | |
| 8541 | return 0; |
| 8542 | error: |
| 8543 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8544 | tmp_rule = &new_coalesce.rules[i]; |
| 8545 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8546 | kfree(tmp_rule->patterns[j].mask); |
| 8547 | kfree(tmp_rule->patterns); |
| 8548 | } |
| 8549 | kfree(new_coalesce.rules); |
| 8550 | |
| 8551 | return err; |
| 8552 | } |
| 8553 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8554 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8555 | { |
| 8556 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8557 | struct net_device *dev = info->user_ptr[1]; |
| 8558 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8559 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8560 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8561 | int err; |
| 8562 | |
| 8563 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8564 | return -EINVAL; |
| 8565 | |
| 8566 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8567 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8568 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8569 | nl80211_rekey_policy); |
| 8570 | if (err) |
| 8571 | return err; |
| 8572 | |
| 8573 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8574 | return -ERANGE; |
| 8575 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8576 | return -ERANGE; |
| 8577 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8578 | return -ERANGE; |
| 8579 | |
| 8580 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8581 | NL80211_KEK_LEN); |
| 8582 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8583 | NL80211_KCK_LEN); |
| 8584 | memcpy(rekey_data.replay_ctr, |
| 8585 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8586 | NL80211_REPLAY_CTR_LEN); |
| 8587 | |
| 8588 | wdev_lock(wdev); |
| 8589 | if (!wdev->current_bss) { |
| 8590 | err = -ENOTCONN; |
| 8591 | goto out; |
| 8592 | } |
| 8593 | |
| 8594 | if (!rdev->ops->set_rekey_data) { |
| 8595 | err = -EOPNOTSUPP; |
| 8596 | goto out; |
| 8597 | } |
| 8598 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8599 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8600 | out: |
| 8601 | wdev_unlock(wdev); |
| 8602 | return err; |
| 8603 | } |
| 8604 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8605 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8606 | struct genl_info *info) |
| 8607 | { |
| 8608 | struct net_device *dev = info->user_ptr[1]; |
| 8609 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8610 | |
| 8611 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8612 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8613 | return -EINVAL; |
| 8614 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8615 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8616 | return -EBUSY; |
| 8617 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8618 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8619 | return 0; |
| 8620 | } |
| 8621 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8622 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8623 | struct genl_info *info) |
| 8624 | { |
| 8625 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8626 | struct net_device *dev = info->user_ptr[1]; |
| 8627 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8628 | struct sk_buff *msg; |
| 8629 | void *hdr; |
| 8630 | const u8 *addr; |
| 8631 | u64 cookie; |
| 8632 | int err; |
| 8633 | |
| 8634 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8635 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8636 | return -EOPNOTSUPP; |
| 8637 | |
| 8638 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8639 | return -EINVAL; |
| 8640 | |
| 8641 | if (!rdev->ops->probe_client) |
| 8642 | return -EOPNOTSUPP; |
| 8643 | |
| 8644 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8645 | if (!msg) |
| 8646 | return -ENOMEM; |
| 8647 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8648 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8649 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8650 | if (!hdr) { |
| 8651 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8652 | goto free_msg; |
| 8653 | } |
| 8654 | |
| 8655 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8656 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8657 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8658 | if (err) |
| 8659 | goto free_msg; |
| 8660 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8661 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8662 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8663 | |
| 8664 | genlmsg_end(msg, hdr); |
| 8665 | |
| 8666 | return genlmsg_reply(msg, info); |
| 8667 | |
| 8668 | nla_put_failure: |
| 8669 | err = -ENOBUFS; |
| 8670 | free_msg: |
| 8671 | nlmsg_free(msg); |
| 8672 | return err; |
| 8673 | } |
| 8674 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8675 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8676 | { |
| 8677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8678 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8679 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8680 | |
| 8681 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8682 | return -EOPNOTSUPP; |
| 8683 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8684 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8685 | if (!nreg) |
| 8686 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8687 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8688 | /* First, check if already registered. */ |
| 8689 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8690 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8691 | if (reg->nlportid == info->snd_portid) { |
| 8692 | rv = -EALREADY; |
| 8693 | goto out_err; |
| 8694 | } |
| 8695 | } |
| 8696 | /* Add it to the list */ |
| 8697 | nreg->nlportid = info->snd_portid; |
| 8698 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8699 | |
| 8700 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8701 | |
| 8702 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8703 | out_err: |
| 8704 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8705 | kfree(nreg); |
| 8706 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8707 | } |
| 8708 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8709 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8710 | { |
| 8711 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8712 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8713 | int err; |
| 8714 | |
| 8715 | if (!rdev->ops->start_p2p_device) |
| 8716 | return -EOPNOTSUPP; |
| 8717 | |
| 8718 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8719 | return -EOPNOTSUPP; |
| 8720 | |
| 8721 | if (wdev->p2p_started) |
| 8722 | return 0; |
| 8723 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8724 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8725 | if (err) |
| 8726 | return err; |
| 8727 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8728 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8729 | if (err) |
| 8730 | return err; |
| 8731 | |
| 8732 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8733 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8734 | |
| 8735 | return 0; |
| 8736 | } |
| 8737 | |
| 8738 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8739 | { |
| 8740 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8741 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8742 | |
| 8743 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8744 | return -EOPNOTSUPP; |
| 8745 | |
| 8746 | if (!rdev->ops->stop_p2p_device) |
| 8747 | return -EOPNOTSUPP; |
| 8748 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8749 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8750 | |
| 8751 | return 0; |
| 8752 | } |
| 8753 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8754 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8755 | struct genl_info *info) |
| 8756 | { |
| 8757 | void *hdr; |
| 8758 | struct sk_buff *msg; |
| 8759 | |
| 8760 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8761 | if (!msg) |
| 8762 | return -ENOMEM; |
| 8763 | |
| 8764 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8765 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8766 | if (!hdr) |
| 8767 | goto nla_put_failure; |
| 8768 | |
| 8769 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8770 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8771 | goto nla_put_failure; |
| 8772 | |
| 8773 | genlmsg_end(msg, hdr); |
| 8774 | return genlmsg_reply(msg, info); |
| 8775 | |
| 8776 | nla_put_failure: |
| 8777 | kfree_skb(msg); |
| 8778 | return -ENOBUFS; |
| 8779 | } |
| 8780 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8781 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8782 | { |
| 8783 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8784 | struct cfg80211_update_ft_ies_params ft_params; |
| 8785 | struct net_device *dev = info->user_ptr[1]; |
| 8786 | |
| 8787 | if (!rdev->ops->update_ft_ies) |
| 8788 | return -EOPNOTSUPP; |
| 8789 | |
| 8790 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8791 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8792 | return -EINVAL; |
| 8793 | |
| 8794 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8795 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8796 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8797 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8798 | |
| 8799 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8800 | } |
| 8801 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8802 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8803 | struct genl_info *info) |
| 8804 | { |
| 8805 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8806 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8807 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8808 | u16 duration; |
| 8809 | int ret; |
| 8810 | |
| 8811 | if (!rdev->ops->crit_proto_start) |
| 8812 | return -EOPNOTSUPP; |
| 8813 | |
| 8814 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8815 | return -EINVAL; |
| 8816 | |
| 8817 | if (rdev->crit_proto_nlportid) |
| 8818 | return -EBUSY; |
| 8819 | |
| 8820 | /* determine protocol if provided */ |
| 8821 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8822 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8823 | |
| 8824 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8825 | return -EINVAL; |
| 8826 | |
| 8827 | /* timeout must be provided */ |
| 8828 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8829 | return -EINVAL; |
| 8830 | |
| 8831 | duration = |
| 8832 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8833 | |
| 8834 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8835 | return -ERANGE; |
| 8836 | |
| 8837 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8838 | if (!ret) |
| 8839 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8840 | |
| 8841 | return ret; |
| 8842 | } |
| 8843 | |
| 8844 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8845 | struct genl_info *info) |
| 8846 | { |
| 8847 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8848 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8849 | |
| 8850 | if (!rdev->ops->crit_proto_stop) |
| 8851 | return -EOPNOTSUPP; |
| 8852 | |
| 8853 | if (rdev->crit_proto_nlportid) { |
| 8854 | rdev->crit_proto_nlportid = 0; |
| 8855 | rdev_crit_proto_stop(rdev, wdev); |
| 8856 | } |
| 8857 | return 0; |
| 8858 | } |
| 8859 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8860 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 8861 | { |
| 8862 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8863 | struct wireless_dev *wdev = |
| 8864 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 8865 | int i, err; |
| 8866 | u32 vid, subcmd; |
| 8867 | |
| 8868 | if (!rdev->wiphy.vendor_commands) |
| 8869 | return -EOPNOTSUPP; |
| 8870 | |
| 8871 | if (IS_ERR(wdev)) { |
| 8872 | err = PTR_ERR(wdev); |
| 8873 | if (err != -EINVAL) |
| 8874 | return err; |
| 8875 | wdev = NULL; |
| 8876 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 8877 | return -EINVAL; |
| 8878 | } |
| 8879 | |
| 8880 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 8881 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 8882 | return -EINVAL; |
| 8883 | |
| 8884 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 8885 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 8886 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 8887 | const struct wiphy_vendor_command *vcmd; |
| 8888 | void *data = NULL; |
| 8889 | int len = 0; |
| 8890 | |
| 8891 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 8892 | |
| 8893 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 8894 | continue; |
| 8895 | |
| 8896 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 8897 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 8898 | if (!wdev) |
| 8899 | return -EINVAL; |
| 8900 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 8901 | !wdev->netdev) |
| 8902 | return -EINVAL; |
| 8903 | |
| 8904 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 8905 | if (wdev->netdev && |
| 8906 | !netif_running(wdev->netdev)) |
| 8907 | return -ENETDOWN; |
| 8908 | if (!wdev->netdev && !wdev->p2p_started) |
| 8909 | return -ENETDOWN; |
| 8910 | } |
| 8911 | } else { |
| 8912 | wdev = NULL; |
| 8913 | } |
| 8914 | |
| 8915 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 8916 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 8917 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 8918 | } |
| 8919 | |
| 8920 | rdev->cur_cmd_info = info; |
| 8921 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 8922 | data, len); |
| 8923 | rdev->cur_cmd_info = NULL; |
| 8924 | return err; |
| 8925 | } |
| 8926 | |
| 8927 | return -EOPNOTSUPP; |
| 8928 | } |
| 8929 | |
| 8930 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 8931 | enum nl80211_commands cmd, |
| 8932 | enum nl80211_attrs attr, |
| 8933 | int approxlen) |
| 8934 | { |
| 8935 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 8936 | |
| 8937 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 8938 | return NULL; |
| 8939 | |
| 8940 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 8941 | rdev->cur_cmd_info->snd_portid, |
| 8942 | rdev->cur_cmd_info->snd_seq, |
| 8943 | cmd, attr, GFP_KERNEL); |
| 8944 | } |
| 8945 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 8946 | |
| 8947 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 8948 | { |
| 8949 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 8950 | void *hdr = ((void **)skb->cb)[1]; |
| 8951 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 8952 | |
| 8953 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 8954 | kfree_skb(skb); |
| 8955 | return -EINVAL; |
| 8956 | } |
| 8957 | |
| 8958 | nla_nest_end(skb, data); |
| 8959 | genlmsg_end(skb, hdr); |
| 8960 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 8961 | } |
| 8962 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 8963 | |
| 8964 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8965 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8966 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8967 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8968 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8969 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8970 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8971 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8972 | /* 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] | 8973 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8974 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8975 | |
| 8976 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8977 | struct genl_info *info) |
| 8978 | { |
| 8979 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8980 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8981 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8982 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8983 | |
| 8984 | if (rtnl) |
| 8985 | rtnl_lock(); |
| 8986 | |
| 8987 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8988 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8989 | if (IS_ERR(rdev)) { |
| 8990 | if (rtnl) |
| 8991 | rtnl_unlock(); |
| 8992 | return PTR_ERR(rdev); |
| 8993 | } |
| 8994 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8995 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8996 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8997 | ASSERT_RTNL(); |
| 8998 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8999 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9000 | info->attrs); |
| 9001 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9002 | if (rtnl) |
| 9003 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9004 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9005 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9006 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9007 | dev = wdev->netdev; |
| 9008 | rdev = wiphy_to_dev(wdev->wiphy); |
| 9009 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9010 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9011 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9012 | if (rtnl) |
| 9013 | rtnl_unlock(); |
| 9014 | return -EINVAL; |
| 9015 | } |
| 9016 | |
| 9017 | info->user_ptr[1] = dev; |
| 9018 | } else { |
| 9019 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9020 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9021 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9022 | if (dev) { |
| 9023 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9024 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9025 | if (rtnl) |
| 9026 | rtnl_unlock(); |
| 9027 | return -ENETDOWN; |
| 9028 | } |
| 9029 | |
| 9030 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9031 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9032 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9033 | if (rtnl) |
| 9034 | rtnl_unlock(); |
| 9035 | return -ENETDOWN; |
| 9036 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9037 | } |
| 9038 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9039 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9040 | } |
| 9041 | |
| 9042 | return 0; |
| 9043 | } |
| 9044 | |
| 9045 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 9046 | struct genl_info *info) |
| 9047 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9048 | if (info->user_ptr[1]) { |
| 9049 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9050 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9051 | |
| 9052 | if (wdev->netdev) |
| 9053 | dev_put(wdev->netdev); |
| 9054 | } else { |
| 9055 | dev_put(info->user_ptr[1]); |
| 9056 | } |
| 9057 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9058 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9059 | rtnl_unlock(); |
| 9060 | } |
| 9061 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9062 | static struct genl_ops nl80211_ops[] = { |
| 9063 | { |
| 9064 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9065 | .doit = nl80211_get_wiphy, |
| 9066 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9067 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9068 | .policy = nl80211_policy, |
| 9069 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9070 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9071 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9072 | }, |
| 9073 | { |
| 9074 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9075 | .doit = nl80211_set_wiphy, |
| 9076 | .policy = nl80211_policy, |
| 9077 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9078 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9079 | }, |
| 9080 | { |
| 9081 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9082 | .doit = nl80211_get_interface, |
| 9083 | .dumpit = nl80211_dump_interface, |
| 9084 | .policy = nl80211_policy, |
| 9085 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9086 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9087 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9088 | }, |
| 9089 | { |
| 9090 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9091 | .doit = nl80211_set_interface, |
| 9092 | .policy = nl80211_policy, |
| 9093 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9094 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9095 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9096 | }, |
| 9097 | { |
| 9098 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9099 | .doit = nl80211_new_interface, |
| 9100 | .policy = nl80211_policy, |
| 9101 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9102 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9103 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9104 | }, |
| 9105 | { |
| 9106 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9107 | .doit = nl80211_del_interface, |
| 9108 | .policy = nl80211_policy, |
| 9109 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9110 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9111 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9112 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9113 | { |
| 9114 | .cmd = NL80211_CMD_GET_KEY, |
| 9115 | .doit = nl80211_get_key, |
| 9116 | .policy = nl80211_policy, |
| 9117 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9118 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9119 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9120 | }, |
| 9121 | { |
| 9122 | .cmd = NL80211_CMD_SET_KEY, |
| 9123 | .doit = nl80211_set_key, |
| 9124 | .policy = nl80211_policy, |
| 9125 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9126 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9127 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9128 | }, |
| 9129 | { |
| 9130 | .cmd = NL80211_CMD_NEW_KEY, |
| 9131 | .doit = nl80211_new_key, |
| 9132 | .policy = nl80211_policy, |
| 9133 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9134 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9135 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9136 | }, |
| 9137 | { |
| 9138 | .cmd = NL80211_CMD_DEL_KEY, |
| 9139 | .doit = nl80211_del_key, |
| 9140 | .policy = nl80211_policy, |
| 9141 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +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, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9144 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9145 | { |
| 9146 | .cmd = NL80211_CMD_SET_BEACON, |
| 9147 | .policy = nl80211_policy, |
| 9148 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9149 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [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, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9152 | }, |
| 9153 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9154 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9155 | .policy = nl80211_policy, |
| 9156 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9157 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9158 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9159 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9160 | }, |
| 9161 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9162 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9163 | .policy = nl80211_policy, |
| 9164 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9165 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9166 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9167 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9168 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9169 | { |
| 9170 | .cmd = NL80211_CMD_GET_STATION, |
| 9171 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9172 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9173 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9174 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9175 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9176 | }, |
| 9177 | { |
| 9178 | .cmd = NL80211_CMD_SET_STATION, |
| 9179 | .doit = nl80211_set_station, |
| 9180 | .policy = nl80211_policy, |
| 9181 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9182 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9183 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9184 | }, |
| 9185 | { |
| 9186 | .cmd = NL80211_CMD_NEW_STATION, |
| 9187 | .doit = nl80211_new_station, |
| 9188 | .policy = nl80211_policy, |
| 9189 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9190 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9191 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9192 | }, |
| 9193 | { |
| 9194 | .cmd = NL80211_CMD_DEL_STATION, |
| 9195 | .doit = nl80211_del_station, |
| 9196 | .policy = nl80211_policy, |
| 9197 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9198 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9199 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9200 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9201 | { |
| 9202 | .cmd = NL80211_CMD_GET_MPATH, |
| 9203 | .doit = nl80211_get_mpath, |
| 9204 | .dumpit = nl80211_dump_mpath, |
| 9205 | .policy = nl80211_policy, |
| 9206 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9207 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9208 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9209 | }, |
| 9210 | { |
| 9211 | .cmd = NL80211_CMD_SET_MPATH, |
| 9212 | .doit = nl80211_set_mpath, |
| 9213 | .policy = nl80211_policy, |
| 9214 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9215 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9216 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9217 | }, |
| 9218 | { |
| 9219 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9220 | .doit = nl80211_new_mpath, |
| 9221 | .policy = nl80211_policy, |
| 9222 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9223 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9224 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9225 | }, |
| 9226 | { |
| 9227 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9228 | .doit = nl80211_del_mpath, |
| 9229 | .policy = nl80211_policy, |
| 9230 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9231 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9232 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9233 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9234 | { |
| 9235 | .cmd = NL80211_CMD_SET_BSS, |
| 9236 | .doit = nl80211_set_bss, |
| 9237 | .policy = nl80211_policy, |
| 9238 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9239 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9240 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9241 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9242 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9243 | .cmd = NL80211_CMD_GET_REG, |
| 9244 | .doit = nl80211_get_reg, |
| 9245 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9246 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9247 | /* can be retrieved by unprivileged users */ |
| 9248 | }, |
| 9249 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9250 | .cmd = NL80211_CMD_SET_REG, |
| 9251 | .doit = nl80211_set_reg, |
| 9252 | .policy = nl80211_policy, |
| 9253 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9254 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9255 | }, |
| 9256 | { |
| 9257 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9258 | .doit = nl80211_req_set_reg, |
| 9259 | .policy = nl80211_policy, |
| 9260 | .flags = GENL_ADMIN_PERM, |
| 9261 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9262 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9263 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9264 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9265 | .policy = nl80211_policy, |
| 9266 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9267 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9268 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9269 | }, |
| 9270 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9271 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9272 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9273 | .policy = nl80211_policy, |
| 9274 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [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, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9277 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9278 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9279 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9280 | .doit = nl80211_trigger_scan, |
| 9281 | .policy = nl80211_policy, |
| 9282 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9283 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9284 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9285 | }, |
| 9286 | { |
| 9287 | .cmd = NL80211_CMD_GET_SCAN, |
| 9288 | .policy = nl80211_policy, |
| 9289 | .dumpit = nl80211_dump_scan, |
| 9290 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9291 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9292 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9293 | .doit = nl80211_start_sched_scan, |
| 9294 | .policy = nl80211_policy, |
| 9295 | .flags = GENL_ADMIN_PERM, |
| 9296 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9297 | NL80211_FLAG_NEED_RTNL, |
| 9298 | }, |
| 9299 | { |
| 9300 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9301 | .doit = nl80211_stop_sched_scan, |
| 9302 | .policy = nl80211_policy, |
| 9303 | .flags = GENL_ADMIN_PERM, |
| 9304 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9305 | NL80211_FLAG_NEED_RTNL, |
| 9306 | }, |
| 9307 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9308 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9309 | .doit = nl80211_authenticate, |
| 9310 | .policy = nl80211_policy, |
| 9311 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9312 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9313 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9314 | }, |
| 9315 | { |
| 9316 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9317 | .doit = nl80211_associate, |
| 9318 | .policy = nl80211_policy, |
| 9319 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9320 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9321 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9322 | }, |
| 9323 | { |
| 9324 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9325 | .doit = nl80211_deauthenticate, |
| 9326 | .policy = nl80211_policy, |
| 9327 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9328 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9329 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9330 | }, |
| 9331 | { |
| 9332 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9333 | .doit = nl80211_disassociate, |
| 9334 | .policy = nl80211_policy, |
| 9335 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9336 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9337 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9338 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9339 | { |
| 9340 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9341 | .doit = nl80211_join_ibss, |
| 9342 | .policy = nl80211_policy, |
| 9343 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9344 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9345 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9346 | }, |
| 9347 | { |
| 9348 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9349 | .doit = nl80211_leave_ibss, |
| 9350 | .policy = nl80211_policy, |
| 9351 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9352 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9353 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9354 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9355 | #ifdef CONFIG_NL80211_TESTMODE |
| 9356 | { |
| 9357 | .cmd = NL80211_CMD_TESTMODE, |
| 9358 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9359 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9360 | .policy = nl80211_policy, |
| 9361 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9362 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9363 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9364 | }, |
| 9365 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9366 | { |
| 9367 | .cmd = NL80211_CMD_CONNECT, |
| 9368 | .doit = nl80211_connect, |
| 9369 | .policy = nl80211_policy, |
| 9370 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9371 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9372 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9373 | }, |
| 9374 | { |
| 9375 | .cmd = NL80211_CMD_DISCONNECT, |
| 9376 | .doit = nl80211_disconnect, |
| 9377 | .policy = nl80211_policy, |
| 9378 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9379 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9380 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9381 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9382 | { |
| 9383 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9384 | .doit = nl80211_wiphy_netns, |
| 9385 | .policy = nl80211_policy, |
| 9386 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9387 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9388 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9389 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9390 | { |
| 9391 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9392 | .policy = nl80211_policy, |
| 9393 | .dumpit = nl80211_dump_survey, |
| 9394 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9395 | { |
| 9396 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9397 | .doit = nl80211_setdel_pmksa, |
| 9398 | .policy = nl80211_policy, |
| 9399 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9400 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9401 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9402 | }, |
| 9403 | { |
| 9404 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9405 | .doit = nl80211_setdel_pmksa, |
| 9406 | .policy = nl80211_policy, |
| 9407 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9408 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9409 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9410 | }, |
| 9411 | { |
| 9412 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9413 | .doit = nl80211_flush_pmksa, |
| 9414 | .policy = nl80211_policy, |
| 9415 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9416 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9417 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9418 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9419 | { |
| 9420 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9421 | .doit = nl80211_remain_on_channel, |
| 9422 | .policy = nl80211_policy, |
| 9423 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9424 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9425 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9426 | }, |
| 9427 | { |
| 9428 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9429 | .doit = nl80211_cancel_remain_on_channel, |
| 9430 | .policy = nl80211_policy, |
| 9431 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9432 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9433 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9434 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9435 | { |
| 9436 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9437 | .doit = nl80211_set_tx_bitrate_mask, |
| 9438 | .policy = nl80211_policy, |
| 9439 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9440 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9441 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9442 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9443 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9444 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9445 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9446 | .policy = nl80211_policy, |
| 9447 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9448 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9449 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9450 | }, |
| 9451 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9452 | .cmd = NL80211_CMD_FRAME, |
| 9453 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9454 | .policy = nl80211_policy, |
| 9455 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9456 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9457 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9458 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9459 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9460 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9461 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9462 | .policy = nl80211_policy, |
| 9463 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9464 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9465 | NL80211_FLAG_NEED_RTNL, |
| 9466 | }, |
| 9467 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9468 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9469 | .doit = nl80211_set_power_save, |
| 9470 | .policy = nl80211_policy, |
| 9471 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9472 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9473 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9474 | }, |
| 9475 | { |
| 9476 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9477 | .doit = nl80211_get_power_save, |
| 9478 | .policy = nl80211_policy, |
| 9479 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9480 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9481 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9482 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9483 | { |
| 9484 | .cmd = NL80211_CMD_SET_CQM, |
| 9485 | .doit = nl80211_set_cqm, |
| 9486 | .policy = nl80211_policy, |
| 9487 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9488 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9489 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9490 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9491 | { |
| 9492 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9493 | .doit = nl80211_set_channel, |
| 9494 | .policy = nl80211_policy, |
| 9495 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9496 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9497 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9498 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9499 | { |
| 9500 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9501 | .doit = nl80211_set_wds_peer, |
| 9502 | .policy = nl80211_policy, |
| 9503 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9504 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9505 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9506 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9507 | { |
| 9508 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9509 | .doit = nl80211_join_mesh, |
| 9510 | .policy = nl80211_policy, |
| 9511 | .flags = GENL_ADMIN_PERM, |
| 9512 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9513 | NL80211_FLAG_NEED_RTNL, |
| 9514 | }, |
| 9515 | { |
| 9516 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9517 | .doit = nl80211_leave_mesh, |
| 9518 | .policy = nl80211_policy, |
| 9519 | .flags = GENL_ADMIN_PERM, |
| 9520 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9521 | NL80211_FLAG_NEED_RTNL, |
| 9522 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9523 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9524 | { |
| 9525 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9526 | .doit = nl80211_get_wowlan, |
| 9527 | .policy = nl80211_policy, |
| 9528 | /* can be retrieved by unprivileged users */ |
| 9529 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9530 | NL80211_FLAG_NEED_RTNL, |
| 9531 | }, |
| 9532 | { |
| 9533 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9534 | .doit = nl80211_set_wowlan, |
| 9535 | .policy = nl80211_policy, |
| 9536 | .flags = GENL_ADMIN_PERM, |
| 9537 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9538 | NL80211_FLAG_NEED_RTNL, |
| 9539 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9540 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9541 | { |
| 9542 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9543 | .doit = nl80211_set_rekey_data, |
| 9544 | .policy = nl80211_policy, |
| 9545 | .flags = GENL_ADMIN_PERM, |
| 9546 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9547 | NL80211_FLAG_NEED_RTNL, |
| 9548 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9549 | { |
| 9550 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9551 | .doit = nl80211_tdls_mgmt, |
| 9552 | .policy = nl80211_policy, |
| 9553 | .flags = GENL_ADMIN_PERM, |
| 9554 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9555 | NL80211_FLAG_NEED_RTNL, |
| 9556 | }, |
| 9557 | { |
| 9558 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9559 | .doit = nl80211_tdls_oper, |
| 9560 | .policy = nl80211_policy, |
| 9561 | .flags = GENL_ADMIN_PERM, |
| 9562 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9563 | NL80211_FLAG_NEED_RTNL, |
| 9564 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9565 | { |
| 9566 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9567 | .doit = nl80211_register_unexpected_frame, |
| 9568 | .policy = nl80211_policy, |
| 9569 | .flags = GENL_ADMIN_PERM, |
| 9570 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9571 | NL80211_FLAG_NEED_RTNL, |
| 9572 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9573 | { |
| 9574 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9575 | .doit = nl80211_probe_client, |
| 9576 | .policy = nl80211_policy, |
| 9577 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9578 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9579 | NL80211_FLAG_NEED_RTNL, |
| 9580 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9581 | { |
| 9582 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9583 | .doit = nl80211_register_beacons, |
| 9584 | .policy = nl80211_policy, |
| 9585 | .flags = GENL_ADMIN_PERM, |
| 9586 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9587 | NL80211_FLAG_NEED_RTNL, |
| 9588 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9589 | { |
| 9590 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9591 | .doit = nl80211_set_noack_map, |
| 9592 | .policy = nl80211_policy, |
| 9593 | .flags = GENL_ADMIN_PERM, |
| 9594 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9595 | NL80211_FLAG_NEED_RTNL, |
| 9596 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9597 | { |
| 9598 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9599 | .doit = nl80211_start_p2p_device, |
| 9600 | .policy = nl80211_policy, |
| 9601 | .flags = GENL_ADMIN_PERM, |
| 9602 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9603 | NL80211_FLAG_NEED_RTNL, |
| 9604 | }, |
| 9605 | { |
| 9606 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9607 | .doit = nl80211_stop_p2p_device, |
| 9608 | .policy = nl80211_policy, |
| 9609 | .flags = GENL_ADMIN_PERM, |
| 9610 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9611 | NL80211_FLAG_NEED_RTNL, |
| 9612 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9613 | { |
| 9614 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9615 | .doit = nl80211_set_mcast_rate, |
| 9616 | .policy = nl80211_policy, |
| 9617 | .flags = GENL_ADMIN_PERM, |
| 9618 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9619 | NL80211_FLAG_NEED_RTNL, |
| 9620 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9621 | { |
| 9622 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9623 | .doit = nl80211_set_mac_acl, |
| 9624 | .policy = nl80211_policy, |
| 9625 | .flags = GENL_ADMIN_PERM, |
| 9626 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9627 | NL80211_FLAG_NEED_RTNL, |
| 9628 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9629 | { |
| 9630 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9631 | .doit = nl80211_start_radar_detection, |
| 9632 | .policy = nl80211_policy, |
| 9633 | .flags = GENL_ADMIN_PERM, |
| 9634 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9635 | NL80211_FLAG_NEED_RTNL, |
| 9636 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9637 | { |
| 9638 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9639 | .doit = nl80211_get_protocol_features, |
| 9640 | .policy = nl80211_policy, |
| 9641 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9642 | { |
| 9643 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9644 | .doit = nl80211_update_ft_ies, |
| 9645 | .policy = nl80211_policy, |
| 9646 | .flags = GENL_ADMIN_PERM, |
| 9647 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9648 | NL80211_FLAG_NEED_RTNL, |
| 9649 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9650 | { |
| 9651 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9652 | .doit = nl80211_crit_protocol_start, |
| 9653 | .policy = nl80211_policy, |
| 9654 | .flags = GENL_ADMIN_PERM, |
| 9655 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9656 | NL80211_FLAG_NEED_RTNL, |
| 9657 | }, |
| 9658 | { |
| 9659 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9660 | .doit = nl80211_crit_protocol_stop, |
| 9661 | .policy = nl80211_policy, |
| 9662 | .flags = GENL_ADMIN_PERM, |
| 9663 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9664 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9665 | }, |
| 9666 | { |
| 9667 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9668 | .doit = nl80211_get_coalesce, |
| 9669 | .policy = nl80211_policy, |
| 9670 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9671 | NL80211_FLAG_NEED_RTNL, |
| 9672 | }, |
| 9673 | { |
| 9674 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9675 | .doit = nl80211_set_coalesce, |
| 9676 | .policy = nl80211_policy, |
| 9677 | .flags = GENL_ADMIN_PERM, |
| 9678 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9679 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9680 | }, |
| 9681 | { |
| 9682 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9683 | .doit = nl80211_channel_switch, |
| 9684 | .policy = nl80211_policy, |
| 9685 | .flags = GENL_ADMIN_PERM, |
| 9686 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9687 | NL80211_FLAG_NEED_RTNL, |
| 9688 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9689 | { |
| 9690 | .cmd = NL80211_CMD_VENDOR, |
| 9691 | .doit = nl80211_vendor_cmd, |
| 9692 | .policy = nl80211_policy, |
| 9693 | .flags = GENL_ADMIN_PERM, |
| 9694 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9695 | NL80211_FLAG_NEED_RTNL, |
| 9696 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9697 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9698 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9699 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 9700 | .name = "mlme", |
| 9701 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9702 | |
| 9703 | /* multicast groups */ |
| 9704 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 9705 | .name = "config", |
| 9706 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9707 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 9708 | .name = "scan", |
| 9709 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9710 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 9711 | .name = "regulatory", |
| 9712 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9713 | |
| 9714 | /* notification functions */ |
| 9715 | |
| 9716 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9717 | { |
| 9718 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9719 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9720 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9721 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9722 | if (!msg) |
| 9723 | return; |
| 9724 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9725 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9726 | nlmsg_free(msg); |
| 9727 | return; |
| 9728 | } |
| 9729 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9730 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9731 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9732 | } |
| 9733 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9734 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9735 | struct cfg80211_registered_device *rdev) |
| 9736 | { |
| 9737 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9738 | struct nlattr *nest; |
| 9739 | int i; |
| 9740 | |
| 9741 | if (WARN_ON(!req)) |
| 9742 | return 0; |
| 9743 | |
| 9744 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9745 | if (!nest) |
| 9746 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9747 | for (i = 0; i < req->n_ssids; i++) { |
| 9748 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9749 | goto nla_put_failure; |
| 9750 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9751 | nla_nest_end(msg, nest); |
| 9752 | |
| 9753 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9754 | if (!nest) |
| 9755 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9756 | for (i = 0; i < req->n_channels; i++) { |
| 9757 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9758 | goto nla_put_failure; |
| 9759 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9760 | nla_nest_end(msg, nest); |
| 9761 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9762 | if (req->ie && |
| 9763 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9764 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9765 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9766 | if (req->flags) |
| 9767 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 9768 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9769 | return 0; |
| 9770 | nla_put_failure: |
| 9771 | return -ENOBUFS; |
| 9772 | } |
| 9773 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9774 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9775 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9776 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9777 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9778 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9779 | { |
| 9780 | void *hdr; |
| 9781 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9782 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9783 | if (!hdr) |
| 9784 | return -1; |
| 9785 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9786 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9787 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9788 | wdev->netdev->ifindex)) || |
| 9789 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9790 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9791 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9792 | /* ignore errors and send incomplete event anyway */ |
| 9793 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9794 | |
| 9795 | return genlmsg_end(msg, hdr); |
| 9796 | |
| 9797 | nla_put_failure: |
| 9798 | genlmsg_cancel(msg, hdr); |
| 9799 | return -EMSGSIZE; |
| 9800 | } |
| 9801 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9802 | static int |
| 9803 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9804 | struct cfg80211_registered_device *rdev, |
| 9805 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9806 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9807 | { |
| 9808 | void *hdr; |
| 9809 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9810 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9811 | if (!hdr) |
| 9812 | return -1; |
| 9813 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9814 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9815 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9816 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9817 | |
| 9818 | return genlmsg_end(msg, hdr); |
| 9819 | |
| 9820 | nla_put_failure: |
| 9821 | genlmsg_cancel(msg, hdr); |
| 9822 | return -EMSGSIZE; |
| 9823 | } |
| 9824 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9825 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9826 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9827 | { |
| 9828 | struct sk_buff *msg; |
| 9829 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9830 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9831 | if (!msg) |
| 9832 | return; |
| 9833 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9834 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9835 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9836 | nlmsg_free(msg); |
| 9837 | return; |
| 9838 | } |
| 9839 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9840 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9841 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9842 | } |
| 9843 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9844 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9845 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9846 | { |
| 9847 | struct sk_buff *msg; |
| 9848 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9849 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9850 | if (!msg) |
| 9851 | return; |
| 9852 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9853 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9854 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9855 | nlmsg_free(msg); |
| 9856 | return; |
| 9857 | } |
| 9858 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9859 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9860 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9861 | } |
| 9862 | |
| 9863 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9864 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9865 | { |
| 9866 | struct sk_buff *msg; |
| 9867 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9868 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9869 | if (!msg) |
| 9870 | return; |
| 9871 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9872 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9873 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9874 | nlmsg_free(msg); |
| 9875 | return; |
| 9876 | } |
| 9877 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9878 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9879 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9880 | } |
| 9881 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9882 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9883 | struct net_device *netdev) |
| 9884 | { |
| 9885 | struct sk_buff *msg; |
| 9886 | |
| 9887 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9888 | if (!msg) |
| 9889 | return; |
| 9890 | |
| 9891 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9892 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9893 | nlmsg_free(msg); |
| 9894 | return; |
| 9895 | } |
| 9896 | |
| 9897 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9898 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9899 | } |
| 9900 | |
| 9901 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9902 | struct net_device *netdev, u32 cmd) |
| 9903 | { |
| 9904 | struct sk_buff *msg; |
| 9905 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9906 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9907 | if (!msg) |
| 9908 | return; |
| 9909 | |
| 9910 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9911 | nlmsg_free(msg); |
| 9912 | return; |
| 9913 | } |
| 9914 | |
| 9915 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9916 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9917 | } |
| 9918 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9919 | /* |
| 9920 | * This can happen on global regulatory changes or device specific settings |
| 9921 | * based on custom world regulatory domains. |
| 9922 | */ |
| 9923 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9924 | { |
| 9925 | struct sk_buff *msg; |
| 9926 | void *hdr; |
| 9927 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9928 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9929 | if (!msg) |
| 9930 | return; |
| 9931 | |
| 9932 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9933 | if (!hdr) { |
| 9934 | nlmsg_free(msg); |
| 9935 | return; |
| 9936 | } |
| 9937 | |
| 9938 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9939 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9940 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9941 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9942 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9943 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9944 | NL80211_REGDOM_TYPE_WORLD)) |
| 9945 | goto nla_put_failure; |
| 9946 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9947 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9948 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9949 | goto nla_put_failure; |
| 9950 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9951 | request->intersect) { |
| 9952 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9953 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9954 | goto nla_put_failure; |
| 9955 | } else { |
| 9956 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9957 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9958 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9959 | request->alpha2)) |
| 9960 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9961 | } |
| 9962 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9963 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9964 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9965 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9966 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9967 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9968 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9969 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9970 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9971 | GFP_ATOMIC); |
| 9972 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9973 | |
| 9974 | return; |
| 9975 | |
| 9976 | nla_put_failure: |
| 9977 | genlmsg_cancel(msg, hdr); |
| 9978 | nlmsg_free(msg); |
| 9979 | } |
| 9980 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9981 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9982 | struct net_device *netdev, |
| 9983 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9984 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9985 | { |
| 9986 | struct sk_buff *msg; |
| 9987 | void *hdr; |
| 9988 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9989 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9990 | if (!msg) |
| 9991 | return; |
| 9992 | |
| 9993 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9994 | if (!hdr) { |
| 9995 | nlmsg_free(msg); |
| 9996 | return; |
| 9997 | } |
| 9998 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9999 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10000 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10001 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10002 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10003 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10004 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10005 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10006 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10007 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10008 | return; |
| 10009 | |
| 10010 | nla_put_failure: |
| 10011 | genlmsg_cancel(msg, hdr); |
| 10012 | nlmsg_free(msg); |
| 10013 | } |
| 10014 | |
| 10015 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10016 | struct net_device *netdev, const u8 *buf, |
| 10017 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10018 | { |
| 10019 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10020 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10021 | } |
| 10022 | |
| 10023 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10024 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10025 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10026 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10027 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 10028 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10029 | } |
| 10030 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10031 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10032 | struct net_device *netdev, const u8 *buf, |
| 10033 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10034 | { |
| 10035 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10036 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10037 | } |
| 10038 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10039 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 10040 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10041 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10042 | { |
| 10043 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10044 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10045 | } |
| 10046 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10047 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10048 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10049 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10050 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10051 | struct wiphy *wiphy = wdev->wiphy; |
| 10052 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10053 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10054 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10055 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10056 | if (WARN_ON(len < 2)) |
| 10057 | return; |
| 10058 | |
| 10059 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10060 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10061 | else |
| 10062 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10063 | |
| 10064 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 10065 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10066 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10067 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10068 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10069 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10070 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10071 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10072 | { |
| 10073 | struct sk_buff *msg; |
| 10074 | void *hdr; |
| 10075 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10076 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10077 | if (!msg) |
| 10078 | return; |
| 10079 | |
| 10080 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10081 | if (!hdr) { |
| 10082 | nlmsg_free(msg); |
| 10083 | return; |
| 10084 | } |
| 10085 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10086 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10087 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10088 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 10089 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10090 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10091 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10092 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [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); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10096 | return; |
| 10097 | |
| 10098 | nla_put_failure: |
| 10099 | genlmsg_cancel(msg, hdr); |
| 10100 | nlmsg_free(msg); |
| 10101 | } |
| 10102 | |
| 10103 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10104 | struct net_device *netdev, const u8 *addr, |
| 10105 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10106 | { |
| 10107 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10108 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10109 | } |
| 10110 | |
| 10111 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10112 | struct net_device *netdev, const u8 *addr, |
| 10113 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10114 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10115 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10116 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10117 | } |
| 10118 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10119 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10120 | struct net_device *netdev, const u8 *bssid, |
| 10121 | const u8 *req_ie, size_t req_ie_len, |
| 10122 | const u8 *resp_ie, size_t resp_ie_len, |
| 10123 | u16 status, gfp_t gfp) |
| 10124 | { |
| 10125 | struct sk_buff *msg; |
| 10126 | void *hdr; |
| 10127 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10128 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10129 | if (!msg) |
| 10130 | return; |
| 10131 | |
| 10132 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10133 | if (!hdr) { |
| 10134 | nlmsg_free(msg); |
| 10135 | return; |
| 10136 | } |
| 10137 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10138 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10139 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10140 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10141 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10142 | (req_ie && |
| 10143 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10144 | (resp_ie && |
| 10145 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10146 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10147 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10148 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10149 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10150 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10151 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10152 | return; |
| 10153 | |
| 10154 | nla_put_failure: |
| 10155 | genlmsg_cancel(msg, hdr); |
| 10156 | nlmsg_free(msg); |
| 10157 | |
| 10158 | } |
| 10159 | |
| 10160 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10161 | struct net_device *netdev, const u8 *bssid, |
| 10162 | const u8 *req_ie, size_t req_ie_len, |
| 10163 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10164 | { |
| 10165 | struct sk_buff *msg; |
| 10166 | void *hdr; |
| 10167 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10168 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10169 | if (!msg) |
| 10170 | return; |
| 10171 | |
| 10172 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10173 | if (!hdr) { |
| 10174 | nlmsg_free(msg); |
| 10175 | return; |
| 10176 | } |
| 10177 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10178 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10179 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10180 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10181 | (req_ie && |
| 10182 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10183 | (resp_ie && |
| 10184 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10185 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10186 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10187 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10188 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10189 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10190 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10191 | return; |
| 10192 | |
| 10193 | nla_put_failure: |
| 10194 | genlmsg_cancel(msg, hdr); |
| 10195 | nlmsg_free(msg); |
| 10196 | |
| 10197 | } |
| 10198 | |
| 10199 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10200 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10201 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10202 | { |
| 10203 | struct sk_buff *msg; |
| 10204 | void *hdr; |
| 10205 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10206 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10207 | if (!msg) |
| 10208 | return; |
| 10209 | |
| 10210 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10211 | if (!hdr) { |
| 10212 | nlmsg_free(msg); |
| 10213 | return; |
| 10214 | } |
| 10215 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10216 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10217 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10218 | (from_ap && reason && |
| 10219 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10220 | (from_ap && |
| 10221 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10222 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10223 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10224 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10225 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10226 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10227 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10228 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10229 | return; |
| 10230 | |
| 10231 | nla_put_failure: |
| 10232 | genlmsg_cancel(msg, hdr); |
| 10233 | nlmsg_free(msg); |
| 10234 | |
| 10235 | } |
| 10236 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10237 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10238 | struct net_device *netdev, const u8 *bssid, |
| 10239 | gfp_t gfp) |
| 10240 | { |
| 10241 | struct sk_buff *msg; |
| 10242 | void *hdr; |
| 10243 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10244 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10245 | if (!msg) |
| 10246 | return; |
| 10247 | |
| 10248 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10249 | if (!hdr) { |
| 10250 | nlmsg_free(msg); |
| 10251 | return; |
| 10252 | } |
| 10253 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10254 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10255 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10256 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10257 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10258 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10259 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10260 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10261 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10262 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10263 | return; |
| 10264 | |
| 10265 | nla_put_failure: |
| 10266 | genlmsg_cancel(msg, hdr); |
| 10267 | nlmsg_free(msg); |
| 10268 | } |
| 10269 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10270 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10271 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10272 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10273 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10274 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10275 | struct sk_buff *msg; |
| 10276 | void *hdr; |
| 10277 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10278 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10279 | return; |
| 10280 | |
| 10281 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10282 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10283 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10284 | if (!msg) |
| 10285 | return; |
| 10286 | |
| 10287 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10288 | if (!hdr) { |
| 10289 | nlmsg_free(msg); |
| 10290 | return; |
| 10291 | } |
| 10292 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10293 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10294 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10295 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10296 | (ie_len && ie && |
| 10297 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10298 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10299 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10300 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10301 | |
| 10302 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10303 | nl80211_mlme_mcgrp.id, gfp); |
| 10304 | return; |
| 10305 | |
| 10306 | nla_put_failure: |
| 10307 | genlmsg_cancel(msg, hdr); |
| 10308 | nlmsg_free(msg); |
| 10309 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10310 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10311 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10312 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10313 | struct net_device *netdev, const u8 *addr, |
| 10314 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10315 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10316 | { |
| 10317 | struct sk_buff *msg; |
| 10318 | void *hdr; |
| 10319 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10320 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10321 | if (!msg) |
| 10322 | return; |
| 10323 | |
| 10324 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10325 | if (!hdr) { |
| 10326 | nlmsg_free(msg); |
| 10327 | return; |
| 10328 | } |
| 10329 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10330 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10331 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10332 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10333 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10334 | (key_id != -1 && |
| 10335 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10336 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10337 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10338 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10339 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10340 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10341 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10342 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10343 | return; |
| 10344 | |
| 10345 | nla_put_failure: |
| 10346 | genlmsg_cancel(msg, hdr); |
| 10347 | nlmsg_free(msg); |
| 10348 | } |
| 10349 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10350 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10351 | struct ieee80211_channel *channel_before, |
| 10352 | struct ieee80211_channel *channel_after) |
| 10353 | { |
| 10354 | struct sk_buff *msg; |
| 10355 | void *hdr; |
| 10356 | struct nlattr *nl_freq; |
| 10357 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10358 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10359 | if (!msg) |
| 10360 | return; |
| 10361 | |
| 10362 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10363 | if (!hdr) { |
| 10364 | nlmsg_free(msg); |
| 10365 | return; |
| 10366 | } |
| 10367 | |
| 10368 | /* |
| 10369 | * Since we are applying the beacon hint to a wiphy we know its |
| 10370 | * wiphy_idx is valid |
| 10371 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10372 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10373 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10374 | |
| 10375 | /* Before */ |
| 10376 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10377 | if (!nl_freq) |
| 10378 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10379 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10380 | goto nla_put_failure; |
| 10381 | nla_nest_end(msg, nl_freq); |
| 10382 | |
| 10383 | /* After */ |
| 10384 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10385 | if (!nl_freq) |
| 10386 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10387 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10388 | goto nla_put_failure; |
| 10389 | nla_nest_end(msg, nl_freq); |
| 10390 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10391 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10392 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10393 | rcu_read_lock(); |
| 10394 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 10395 | GFP_ATOMIC); |
| 10396 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10397 | |
| 10398 | return; |
| 10399 | |
| 10400 | nla_put_failure: |
| 10401 | genlmsg_cancel(msg, hdr); |
| 10402 | nlmsg_free(msg); |
| 10403 | } |
| 10404 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10405 | static void nl80211_send_remain_on_chan_event( |
| 10406 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10407 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10408 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10409 | unsigned int duration, gfp_t gfp) |
| 10410 | { |
| 10411 | struct sk_buff *msg; |
| 10412 | void *hdr; |
| 10413 | |
| 10414 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10415 | if (!msg) |
| 10416 | return; |
| 10417 | |
| 10418 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10419 | if (!hdr) { |
| 10420 | nlmsg_free(msg); |
| 10421 | return; |
| 10422 | } |
| 10423 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10424 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10425 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10426 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10427 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10428 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10429 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10430 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10431 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10432 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10433 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10434 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10435 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10436 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10437 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10438 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10439 | |
| 10440 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10441 | nl80211_mlme_mcgrp.id, gfp); |
| 10442 | return; |
| 10443 | |
| 10444 | nla_put_failure: |
| 10445 | genlmsg_cancel(msg, hdr); |
| 10446 | nlmsg_free(msg); |
| 10447 | } |
| 10448 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10449 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10450 | struct ieee80211_channel *chan, |
| 10451 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10452 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10453 | struct wiphy *wiphy = wdev->wiphy; |
| 10454 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10455 | |
| 10456 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10457 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10458 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10459 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10460 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10461 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10462 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10463 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10464 | struct ieee80211_channel *chan, |
| 10465 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10466 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10467 | struct wiphy *wiphy = wdev->wiphy; |
| 10468 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10469 | |
| 10470 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10471 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10472 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10473 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10474 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10475 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10476 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10477 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10478 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10479 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10480 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10481 | struct sk_buff *msg; |
| 10482 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10483 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10484 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10485 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10486 | if (!msg) |
| 10487 | return; |
| 10488 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10489 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10490 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10491 | nlmsg_free(msg); |
| 10492 | return; |
| 10493 | } |
| 10494 | |
| 10495 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10496 | nl80211_mlme_mcgrp.id, gfp); |
| 10497 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10498 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10499 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10500 | 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] | 10501 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10502 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10503 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10504 | struct sk_buff *msg; |
| 10505 | void *hdr; |
| 10506 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10507 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10508 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10509 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10510 | if (!msg) |
| 10511 | return; |
| 10512 | |
| 10513 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10514 | if (!hdr) { |
| 10515 | nlmsg_free(msg); |
| 10516 | return; |
| 10517 | } |
| 10518 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10519 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10520 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10521 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10522 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10523 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10524 | |
| 10525 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10526 | nl80211_mlme_mcgrp.id, gfp); |
| 10527 | return; |
| 10528 | |
| 10529 | nla_put_failure: |
| 10530 | genlmsg_cancel(msg, hdr); |
| 10531 | nlmsg_free(msg); |
| 10532 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10533 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10534 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10535 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10536 | enum nl80211_connect_failed_reason reason, |
| 10537 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10538 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10539 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10540 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10541 | struct sk_buff *msg; |
| 10542 | void *hdr; |
| 10543 | |
| 10544 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10545 | if (!msg) |
| 10546 | return; |
| 10547 | |
| 10548 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10549 | if (!hdr) { |
| 10550 | nlmsg_free(msg); |
| 10551 | return; |
| 10552 | } |
| 10553 | |
| 10554 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10555 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10556 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10557 | goto nla_put_failure; |
| 10558 | |
| 10559 | genlmsg_end(msg, hdr); |
| 10560 | |
| 10561 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10562 | nl80211_mlme_mcgrp.id, gfp); |
| 10563 | return; |
| 10564 | |
| 10565 | nla_put_failure: |
| 10566 | genlmsg_cancel(msg, hdr); |
| 10567 | nlmsg_free(msg); |
| 10568 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10569 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10570 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10571 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10572 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10573 | { |
| 10574 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10575 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10576 | struct sk_buff *msg; |
| 10577 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10578 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10579 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10580 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10581 | return false; |
| 10582 | |
| 10583 | msg = nlmsg_new(100, gfp); |
| 10584 | if (!msg) |
| 10585 | return true; |
| 10586 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10587 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10588 | if (!hdr) { |
| 10589 | nlmsg_free(msg); |
| 10590 | return true; |
| 10591 | } |
| 10592 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10593 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10594 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10595 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10596 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10597 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10598 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10599 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10600 | return true; |
| 10601 | |
| 10602 | nla_put_failure: |
| 10603 | genlmsg_cancel(msg, hdr); |
| 10604 | nlmsg_free(msg); |
| 10605 | return true; |
| 10606 | } |
| 10607 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10608 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10609 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10610 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10611 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10612 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10613 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10614 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10615 | |
| 10616 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10617 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10618 | trace_cfg80211_return_bool(false); |
| 10619 | return false; |
| 10620 | } |
| 10621 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10622 | addr, gfp); |
| 10623 | trace_cfg80211_return_bool(ret); |
| 10624 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10625 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10626 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10627 | |
| 10628 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10629 | const u8 *addr, gfp_t gfp) |
| 10630 | { |
| 10631 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10632 | bool ret; |
| 10633 | |
| 10634 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10635 | |
| 10636 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10637 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10638 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10639 | trace_cfg80211_return_bool(false); |
| 10640 | return false; |
| 10641 | } |
| 10642 | ret = __nl80211_unexpected_frame(dev, |
| 10643 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10644 | addr, gfp); |
| 10645 | trace_cfg80211_return_bool(ret); |
| 10646 | return ret; |
| 10647 | } |
| 10648 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10649 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10650 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10651 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10652 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10653 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10654 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10655 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10656 | struct sk_buff *msg; |
| 10657 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10658 | |
| 10659 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10660 | if (!msg) |
| 10661 | return -ENOMEM; |
| 10662 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10663 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10664 | if (!hdr) { |
| 10665 | nlmsg_free(msg); |
| 10666 | return -ENOMEM; |
| 10667 | } |
| 10668 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10669 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10670 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10671 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10672 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10673 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10674 | (sig_dbm && |
| 10675 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10676 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10677 | (flags && |
| 10678 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10679 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10680 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10681 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10682 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10683 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10684 | |
| 10685 | nla_put_failure: |
| 10686 | genlmsg_cancel(msg, hdr); |
| 10687 | nlmsg_free(msg); |
| 10688 | return -ENOBUFS; |
| 10689 | } |
| 10690 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10691 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10692 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10693 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10694 | struct wiphy *wiphy = wdev->wiphy; |
| 10695 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10696 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10697 | struct sk_buff *msg; |
| 10698 | void *hdr; |
| 10699 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10700 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10701 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10703 | if (!msg) |
| 10704 | return; |
| 10705 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10706 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10707 | if (!hdr) { |
| 10708 | nlmsg_free(msg); |
| 10709 | return; |
| 10710 | } |
| 10711 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10712 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10713 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10714 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10715 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10716 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10717 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10718 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10719 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10720 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10721 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10722 | |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 10723 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10724 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10725 | return; |
| 10726 | |
| 10727 | nla_put_failure: |
| 10728 | genlmsg_cancel(msg, hdr); |
| 10729 | nlmsg_free(msg); |
| 10730 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10731 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10732 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10733 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10734 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10735 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10736 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10737 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10738 | struct wiphy *wiphy = wdev->wiphy; |
| 10739 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10740 | struct sk_buff *msg; |
| 10741 | struct nlattr *pinfoattr; |
| 10742 | void *hdr; |
| 10743 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10744 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10745 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10746 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10747 | if (!msg) |
| 10748 | return; |
| 10749 | |
| 10750 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10751 | if (!hdr) { |
| 10752 | nlmsg_free(msg); |
| 10753 | return; |
| 10754 | } |
| 10755 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10756 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10757 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10758 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10759 | |
| 10760 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10761 | if (!pinfoattr) |
| 10762 | goto nla_put_failure; |
| 10763 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10764 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10765 | rssi_event)) |
| 10766 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10767 | |
| 10768 | nla_nest_end(msg, pinfoattr); |
| 10769 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10770 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10771 | |
| 10772 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10773 | nl80211_mlme_mcgrp.id, gfp); |
| 10774 | return; |
| 10775 | |
| 10776 | nla_put_failure: |
| 10777 | genlmsg_cancel(msg, hdr); |
| 10778 | nlmsg_free(msg); |
| 10779 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10780 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10781 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10782 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10783 | struct net_device *netdev, const u8 *bssid, |
| 10784 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10785 | { |
| 10786 | struct sk_buff *msg; |
| 10787 | struct nlattr *rekey_attr; |
| 10788 | void *hdr; |
| 10789 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10790 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10791 | if (!msg) |
| 10792 | return; |
| 10793 | |
| 10794 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10795 | if (!hdr) { |
| 10796 | nlmsg_free(msg); |
| 10797 | return; |
| 10798 | } |
| 10799 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10800 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10801 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10802 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10803 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10804 | |
| 10805 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10806 | if (!rekey_attr) |
| 10807 | goto nla_put_failure; |
| 10808 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10809 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10810 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10811 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10812 | |
| 10813 | nla_nest_end(msg, rekey_attr); |
| 10814 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10815 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10816 | |
| 10817 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10818 | nl80211_mlme_mcgrp.id, gfp); |
| 10819 | return; |
| 10820 | |
| 10821 | nla_put_failure: |
| 10822 | genlmsg_cancel(msg, hdr); |
| 10823 | nlmsg_free(msg); |
| 10824 | } |
| 10825 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10826 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10827 | const u8 *replay_ctr, gfp_t gfp) |
| 10828 | { |
| 10829 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10830 | struct wiphy *wiphy = wdev->wiphy; |
| 10831 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10832 | |
| 10833 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10834 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10835 | } |
| 10836 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10837 | |
| 10838 | static void |
| 10839 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10840 | struct net_device *netdev, int index, |
| 10841 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10842 | { |
| 10843 | struct sk_buff *msg; |
| 10844 | struct nlattr *attr; |
| 10845 | void *hdr; |
| 10846 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10847 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10848 | if (!msg) |
| 10849 | return; |
| 10850 | |
| 10851 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10852 | if (!hdr) { |
| 10853 | nlmsg_free(msg); |
| 10854 | return; |
| 10855 | } |
| 10856 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10857 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10858 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10859 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10860 | |
| 10861 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10862 | if (!attr) |
| 10863 | goto nla_put_failure; |
| 10864 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10865 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10866 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10867 | (preauth && |
| 10868 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10869 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10870 | |
| 10871 | nla_nest_end(msg, attr); |
| 10872 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10873 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10874 | |
| 10875 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10876 | nl80211_mlme_mcgrp.id, gfp); |
| 10877 | return; |
| 10878 | |
| 10879 | nla_put_failure: |
| 10880 | genlmsg_cancel(msg, hdr); |
| 10881 | nlmsg_free(msg); |
| 10882 | } |
| 10883 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10884 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10885 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10886 | { |
| 10887 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10888 | struct wiphy *wiphy = wdev->wiphy; |
| 10889 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10890 | |
| 10891 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10892 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10893 | } |
| 10894 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10895 | |
| 10896 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10897 | struct net_device *netdev, |
| 10898 | struct cfg80211_chan_def *chandef, |
| 10899 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10900 | { |
| 10901 | struct sk_buff *msg; |
| 10902 | void *hdr; |
| 10903 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10904 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10905 | if (!msg) |
| 10906 | return; |
| 10907 | |
| 10908 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10909 | if (!hdr) { |
| 10910 | nlmsg_free(msg); |
| 10911 | return; |
| 10912 | } |
| 10913 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10914 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10915 | goto nla_put_failure; |
| 10916 | |
| 10917 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10918 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10919 | |
| 10920 | genlmsg_end(msg, hdr); |
| 10921 | |
| 10922 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10923 | nl80211_mlme_mcgrp.id, gfp); |
| 10924 | return; |
| 10925 | |
| 10926 | nla_put_failure: |
| 10927 | genlmsg_cancel(msg, hdr); |
| 10928 | nlmsg_free(msg); |
| 10929 | } |
| 10930 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10931 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10932 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10933 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10934 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10935 | struct wiphy *wiphy = wdev->wiphy; |
| 10936 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10937 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 10938 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10939 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 10940 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10941 | |
| 10942 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 10943 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 10944 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 10945 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 10946 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10947 | |
| 10948 | wdev->channel = chandef->chan; |
| 10949 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10950 | } |
| 10951 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10952 | |
| 10953 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10954 | const u8 *peer, u32 num_packets, |
| 10955 | u32 rate, u32 intvl, gfp_t gfp) |
| 10956 | { |
| 10957 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10958 | struct wiphy *wiphy = wdev->wiphy; |
| 10959 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10960 | struct sk_buff *msg; |
| 10961 | struct nlattr *pinfoattr; |
| 10962 | void *hdr; |
| 10963 | |
| 10964 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10965 | if (!msg) |
| 10966 | return; |
| 10967 | |
| 10968 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10969 | if (!hdr) { |
| 10970 | nlmsg_free(msg); |
| 10971 | return; |
| 10972 | } |
| 10973 | |
| 10974 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10975 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10976 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10977 | goto nla_put_failure; |
| 10978 | |
| 10979 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10980 | if (!pinfoattr) |
| 10981 | goto nla_put_failure; |
| 10982 | |
| 10983 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10984 | goto nla_put_failure; |
| 10985 | |
| 10986 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10987 | goto nla_put_failure; |
| 10988 | |
| 10989 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10990 | goto nla_put_failure; |
| 10991 | |
| 10992 | nla_nest_end(msg, pinfoattr); |
| 10993 | |
| 10994 | genlmsg_end(msg, hdr); |
| 10995 | |
| 10996 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10997 | nl80211_mlme_mcgrp.id, gfp); |
| 10998 | return; |
| 10999 | |
| 11000 | nla_put_failure: |
| 11001 | genlmsg_cancel(msg, hdr); |
| 11002 | nlmsg_free(msg); |
| 11003 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11004 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11005 | |
| 11006 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11007 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11008 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11009 | enum nl80211_radar_event event, |
| 11010 | struct net_device *netdev, gfp_t gfp) |
| 11011 | { |
| 11012 | struct sk_buff *msg; |
| 11013 | void *hdr; |
| 11014 | |
| 11015 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11016 | if (!msg) |
| 11017 | return; |
| 11018 | |
| 11019 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11020 | if (!hdr) { |
| 11021 | nlmsg_free(msg); |
| 11022 | return; |
| 11023 | } |
| 11024 | |
| 11025 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11026 | goto nla_put_failure; |
| 11027 | |
| 11028 | /* NOP and radar events don't need a netdev parameter */ |
| 11029 | if (netdev) { |
| 11030 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11031 | |
| 11032 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11033 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11034 | goto nla_put_failure; |
| 11035 | } |
| 11036 | |
| 11037 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11038 | goto nla_put_failure; |
| 11039 | |
| 11040 | if (nl80211_send_chandef(msg, chandef)) |
| 11041 | goto nla_put_failure; |
| 11042 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11043 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11044 | |
| 11045 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11046 | nl80211_mlme_mcgrp.id, gfp); |
| 11047 | return; |
| 11048 | |
| 11049 | nla_put_failure: |
| 11050 | genlmsg_cancel(msg, hdr); |
| 11051 | nlmsg_free(msg); |
| 11052 | } |
| 11053 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11054 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11055 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11056 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11057 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11058 | struct wiphy *wiphy = wdev->wiphy; |
| 11059 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11060 | struct sk_buff *msg; |
| 11061 | struct nlattr *pinfoattr; |
| 11062 | void *hdr; |
| 11063 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11064 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 11065 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11066 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11067 | if (!msg) |
| 11068 | return; |
| 11069 | |
| 11070 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11071 | if (!hdr) { |
| 11072 | nlmsg_free(msg); |
| 11073 | return; |
| 11074 | } |
| 11075 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11076 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11077 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11078 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11079 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11080 | |
| 11081 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11082 | if (!pinfoattr) |
| 11083 | goto nla_put_failure; |
| 11084 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11085 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 11086 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11087 | |
| 11088 | nla_nest_end(msg, pinfoattr); |
| 11089 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11090 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11091 | |
| 11092 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11093 | nl80211_mlme_mcgrp.id, gfp); |
| 11094 | return; |
| 11095 | |
| 11096 | nla_put_failure: |
| 11097 | genlmsg_cancel(msg, hdr); |
| 11098 | nlmsg_free(msg); |
| 11099 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11100 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11101 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11102 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11103 | u64 cookie, bool acked, gfp_t gfp) |
| 11104 | { |
| 11105 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11106 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11107 | struct sk_buff *msg; |
| 11108 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11109 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11110 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11111 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11112 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11113 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11114 | if (!msg) |
| 11115 | return; |
| 11116 | |
| 11117 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11118 | if (!hdr) { |
| 11119 | nlmsg_free(msg); |
| 11120 | return; |
| 11121 | } |
| 11122 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11123 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11124 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11125 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11126 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11127 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11128 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11129 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11130 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11131 | |
| 11132 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11133 | nl80211_mlme_mcgrp.id, gfp); |
| 11134 | return; |
| 11135 | |
| 11136 | nla_put_failure: |
| 11137 | genlmsg_cancel(msg, hdr); |
| 11138 | nlmsg_free(msg); |
| 11139 | } |
| 11140 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11141 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11142 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11143 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11144 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11145 | { |
| 11146 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11147 | struct sk_buff *msg; |
| 11148 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11149 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11150 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11151 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11152 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11153 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11154 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11155 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11156 | if (!msg) { |
| 11157 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11158 | return; |
| 11159 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11160 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11161 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11162 | if (!hdr) |
| 11163 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11164 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11165 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11166 | (freq && |
| 11167 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11168 | (sig_dbm && |
| 11169 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11170 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11171 | goto nla_put_failure; |
| 11172 | |
| 11173 | genlmsg_end(msg, hdr); |
| 11174 | |
| 11175 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11176 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11177 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11178 | return; |
| 11179 | |
| 11180 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11181 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11182 | if (hdr) |
| 11183 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11184 | nlmsg_free(msg); |
| 11185 | } |
| 11186 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11187 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11188 | #ifdef CONFIG_PM |
| 11189 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11190 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11191 | gfp_t gfp) |
| 11192 | { |
| 11193 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11194 | struct sk_buff *msg; |
| 11195 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11196 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11197 | |
| 11198 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11199 | |
| 11200 | if (wakeup) |
| 11201 | size += wakeup->packet_present_len; |
| 11202 | |
| 11203 | msg = nlmsg_new(size, gfp); |
| 11204 | if (!msg) |
| 11205 | return; |
| 11206 | |
| 11207 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11208 | if (!hdr) |
| 11209 | goto free_msg; |
| 11210 | |
| 11211 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11212 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11213 | goto free_msg; |
| 11214 | |
| 11215 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11216 | wdev->netdev->ifindex)) |
| 11217 | goto free_msg; |
| 11218 | |
| 11219 | if (wakeup) { |
| 11220 | struct nlattr *reasons; |
| 11221 | |
| 11222 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 11223 | |
| 11224 | if (wakeup->disconnect && |
| 11225 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11226 | goto free_msg; |
| 11227 | if (wakeup->magic_pkt && |
| 11228 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11229 | goto free_msg; |
| 11230 | if (wakeup->gtk_rekey_failure && |
| 11231 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11232 | goto free_msg; |
| 11233 | if (wakeup->eap_identity_req && |
| 11234 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11235 | goto free_msg; |
| 11236 | if (wakeup->four_way_handshake && |
| 11237 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11238 | goto free_msg; |
| 11239 | if (wakeup->rfkill_release && |
| 11240 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11241 | goto free_msg; |
| 11242 | |
| 11243 | if (wakeup->pattern_idx >= 0 && |
| 11244 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11245 | wakeup->pattern_idx)) |
| 11246 | goto free_msg; |
| 11247 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11248 | if (wakeup->tcp_match) |
| 11249 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 11250 | |
| 11251 | if (wakeup->tcp_connlost) |
| 11252 | nla_put_flag(msg, |
| 11253 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 11254 | |
| 11255 | if (wakeup->tcp_nomoretokens) |
| 11256 | nla_put_flag(msg, |
| 11257 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 11258 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11259 | if (wakeup->packet) { |
| 11260 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11261 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11262 | |
| 11263 | if (!wakeup->packet_80211) { |
| 11264 | pkt_attr = |
| 11265 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11266 | len_attr = |
| 11267 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11268 | } |
| 11269 | |
| 11270 | if (wakeup->packet_len && |
| 11271 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11272 | goto free_msg; |
| 11273 | |
| 11274 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11275 | wakeup->packet)) |
| 11276 | goto free_msg; |
| 11277 | } |
| 11278 | |
| 11279 | nla_nest_end(msg, reasons); |
| 11280 | } |
| 11281 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11282 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11283 | |
| 11284 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11285 | nl80211_mlme_mcgrp.id, gfp); |
| 11286 | return; |
| 11287 | |
| 11288 | free_msg: |
| 11289 | nlmsg_free(msg); |
| 11290 | } |
| 11291 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11292 | #endif |
| 11293 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11294 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11295 | enum nl80211_tdls_operation oper, |
| 11296 | u16 reason_code, gfp_t gfp) |
| 11297 | { |
| 11298 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11299 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11300 | struct sk_buff *msg; |
| 11301 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11302 | |
| 11303 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11304 | reason_code); |
| 11305 | |
| 11306 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11307 | if (!msg) |
| 11308 | return; |
| 11309 | |
| 11310 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11311 | if (!hdr) { |
| 11312 | nlmsg_free(msg); |
| 11313 | return; |
| 11314 | } |
| 11315 | |
| 11316 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11317 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11318 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11319 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11320 | (reason_code > 0 && |
| 11321 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11322 | goto nla_put_failure; |
| 11323 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11324 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11325 | |
| 11326 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11327 | nl80211_mlme_mcgrp.id, gfp); |
| 11328 | return; |
| 11329 | |
| 11330 | nla_put_failure: |
| 11331 | genlmsg_cancel(msg, hdr); |
| 11332 | nlmsg_free(msg); |
| 11333 | } |
| 11334 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11335 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11336 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11337 | unsigned long state, |
| 11338 | void *_notify) |
| 11339 | { |
| 11340 | struct netlink_notify *notify = _notify; |
| 11341 | struct cfg80211_registered_device *rdev; |
| 11342 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11343 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11344 | |
| 11345 | if (state != NETLINK_URELEASE) |
| 11346 | return NOTIFY_DONE; |
| 11347 | |
| 11348 | rcu_read_lock(); |
| 11349 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11350 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11351 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11352 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11353 | |
| 11354 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11355 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11356 | list) { |
| 11357 | if (reg->nlportid == notify->portid) { |
| 11358 | list_del(®->list); |
| 11359 | kfree(reg); |
| 11360 | break; |
| 11361 | } |
| 11362 | } |
| 11363 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11364 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11365 | |
| 11366 | rcu_read_unlock(); |
| 11367 | |
| 11368 | return NOTIFY_DONE; |
| 11369 | } |
| 11370 | |
| 11371 | static struct notifier_block nl80211_netlink_notifier = { |
| 11372 | .notifier_call = nl80211_netlink_notify, |
| 11373 | }; |
| 11374 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11375 | void cfg80211_ft_event(struct net_device *netdev, |
| 11376 | struct cfg80211_ft_event_params *ft_event) |
| 11377 | { |
| 11378 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11379 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11380 | struct sk_buff *msg; |
| 11381 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11382 | |
| 11383 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11384 | |
| 11385 | if (!ft_event->target_ap) |
| 11386 | return; |
| 11387 | |
| 11388 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11389 | if (!msg) |
| 11390 | return; |
| 11391 | |
| 11392 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 11393 | if (!hdr) { |
| 11394 | nlmsg_free(msg); |
| 11395 | return; |
| 11396 | } |
| 11397 | |
| 11398 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 11399 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 11400 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 11401 | if (ft_event->ies) |
| 11402 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 11403 | if (ft_event->ric_ies) |
| 11404 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11405 | ft_event->ric_ies); |
| 11406 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11407 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11408 | |
| 11409 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11410 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 11411 | } |
| 11412 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11413 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11414 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11415 | { |
| 11416 | struct cfg80211_registered_device *rdev; |
| 11417 | struct sk_buff *msg; |
| 11418 | void *hdr; |
| 11419 | u32 nlportid; |
| 11420 | |
| 11421 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11422 | if (!rdev->crit_proto_nlportid) |
| 11423 | return; |
| 11424 | |
| 11425 | nlportid = rdev->crit_proto_nlportid; |
| 11426 | rdev->crit_proto_nlportid = 0; |
| 11427 | |
| 11428 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11429 | if (!msg) |
| 11430 | return; |
| 11431 | |
| 11432 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11433 | if (!hdr) |
| 11434 | goto nla_put_failure; |
| 11435 | |
| 11436 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11437 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11438 | goto nla_put_failure; |
| 11439 | |
| 11440 | genlmsg_end(msg, hdr); |
| 11441 | |
| 11442 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11443 | return; |
| 11444 | |
| 11445 | nla_put_failure: |
| 11446 | if (hdr) |
| 11447 | genlmsg_cancel(msg, hdr); |
| 11448 | nlmsg_free(msg); |
| 11449 | |
| 11450 | } |
| 11451 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11452 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11453 | /* initialisation/exit functions */ |
| 11454 | |
| 11455 | int nl80211_init(void) |
| 11456 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11457 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11458 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11459 | err = genl_register_family_with_ops(&nl80211_fam, |
| 11460 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11461 | if (err) |
| 11462 | return err; |
| 11463 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11464 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 11465 | if (err) |
| 11466 | goto err_out; |
| 11467 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11468 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 11469 | if (err) |
| 11470 | goto err_out; |
| 11471 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11472 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 11473 | if (err) |
| 11474 | goto err_out; |
| 11475 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11476 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 11477 | if (err) |
| 11478 | goto err_out; |
| 11479 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11480 | #ifdef CONFIG_NL80211_TESTMODE |
| 11481 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 11482 | if (err) |
| 11483 | goto err_out; |
| 11484 | #endif |
| 11485 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11486 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11487 | if (err) |
| 11488 | goto err_out; |
| 11489 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11490 | return 0; |
| 11491 | err_out: |
| 11492 | genl_unregister_family(&nl80211_fam); |
| 11493 | return err; |
| 11494 | } |
| 11495 | |
| 11496 | void nl80211_exit(void) |
| 11497 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11498 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11499 | genl_unregister_family(&nl80211_fam); |
| 11500 | } |