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 | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 361 | }; |
| 362 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 363 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 364 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 365 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 366 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 367 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 368 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 369 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 370 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 371 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 372 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 373 | }; |
| 374 | |
| 375 | /* policy for the key default flags */ |
| 376 | static const struct nla_policy |
| 377 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 378 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 379 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 380 | }; |
| 381 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 382 | /* policy for WoWLAN attributes */ |
| 383 | static const struct nla_policy |
| 384 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 385 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 386 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 387 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 388 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 389 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 390 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 391 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 392 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 393 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 394 | }; |
| 395 | |
| 396 | static const struct nla_policy |
| 397 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 398 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 399 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 400 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 401 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 402 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 403 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 404 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 405 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 406 | }, |
| 407 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 408 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 409 | }, |
| 410 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 411 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 412 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 413 | }; |
| 414 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 415 | /* policy for coalesce rule attributes */ |
| 416 | static const struct nla_policy |
| 417 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 418 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 419 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 420 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 421 | }; |
| 422 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 423 | /* policy for GTK rekey offload attributes */ |
| 424 | static const struct nla_policy |
| 425 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 426 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 427 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 428 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 429 | }; |
| 430 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 431 | static const struct nla_policy |
| 432 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 433 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 434 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 435 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 436 | }; |
| 437 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 438 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 439 | struct netlink_callback *cb, |
| 440 | struct cfg80211_registered_device **rdev, |
| 441 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 442 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 443 | int err; |
| 444 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 445 | rtnl_lock(); |
| 446 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 447 | if (!cb->args[0]) { |
| 448 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 449 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 450 | nl80211_policy); |
| 451 | if (err) |
| 452 | goto out_unlock; |
| 453 | |
| 454 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 455 | nl80211_fam.attrbuf); |
| 456 | if (IS_ERR(*wdev)) { |
| 457 | err = PTR_ERR(*wdev); |
| 458 | goto out_unlock; |
| 459 | } |
| 460 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 461 | /* 0 is the first index - add 1 to parse only once */ |
| 462 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 463 | cb->args[1] = (*wdev)->identifier; |
| 464 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 465 | /* subtract the 1 again here */ |
| 466 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 467 | struct wireless_dev *tmp; |
| 468 | |
| 469 | if (!wiphy) { |
| 470 | err = -ENODEV; |
| 471 | goto out_unlock; |
| 472 | } |
| 473 | *rdev = wiphy_to_dev(wiphy); |
| 474 | *wdev = NULL; |
| 475 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 476 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 477 | if (tmp->identifier == cb->args[1]) { |
| 478 | *wdev = tmp; |
| 479 | break; |
| 480 | } |
| 481 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 482 | |
| 483 | if (!*wdev) { |
| 484 | err = -ENODEV; |
| 485 | goto out_unlock; |
| 486 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 487 | } |
| 488 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 489 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 490 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 491 | rtnl_unlock(); |
| 492 | return err; |
| 493 | } |
| 494 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 495 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 496 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 497 | rtnl_unlock(); |
| 498 | } |
| 499 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 500 | /* IE validation */ |
| 501 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 502 | { |
| 503 | const u8 *pos; |
| 504 | int len; |
| 505 | |
| 506 | if (!attr) |
| 507 | return true; |
| 508 | |
| 509 | pos = nla_data(attr); |
| 510 | len = nla_len(attr); |
| 511 | |
| 512 | while (len) { |
| 513 | u8 elemlen; |
| 514 | |
| 515 | if (len < 2) |
| 516 | return false; |
| 517 | len -= 2; |
| 518 | |
| 519 | elemlen = pos[1]; |
| 520 | if (elemlen > len) |
| 521 | return false; |
| 522 | |
| 523 | len -= elemlen; |
| 524 | pos += 2 + elemlen; |
| 525 | } |
| 526 | |
| 527 | return true; |
| 528 | } |
| 529 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 530 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 531 | 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] | 532 | int flags, u8 cmd) |
| 533 | { |
| 534 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 535 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 536 | } |
| 537 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 538 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 539 | struct ieee80211_channel *chan, |
| 540 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 541 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 542 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 543 | chan->center_freq)) |
| 544 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 545 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 546 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 547 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 548 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 549 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 550 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 551 | goto nla_put_failure; |
| 552 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 553 | goto nla_put_failure; |
| 554 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 555 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 556 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 557 | goto nla_put_failure; |
| 558 | if (large) { |
| 559 | u32 time; |
| 560 | |
| 561 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 562 | |
| 563 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 564 | chan->dfs_state)) |
| 565 | goto nla_put_failure; |
| 566 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 567 | time)) |
| 568 | goto nla_put_failure; |
| 569 | } |
| 570 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 571 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 572 | if (large) { |
| 573 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 574 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 575 | goto nla_put_failure; |
| 576 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 577 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 578 | goto nla_put_failure; |
| 579 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 580 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 581 | goto nla_put_failure; |
| 582 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 583 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 584 | goto nla_put_failure; |
| 585 | } |
| 586 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 587 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 588 | DBM_TO_MBM(chan->max_power))) |
| 589 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 590 | |
| 591 | return 0; |
| 592 | |
| 593 | nla_put_failure: |
| 594 | return -ENOBUFS; |
| 595 | } |
| 596 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 597 | /* netlink command implementations */ |
| 598 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 599 | struct key_parse { |
| 600 | struct key_params p; |
| 601 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 602 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 603 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 604 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 605 | }; |
| 606 | |
| 607 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 608 | { |
| 609 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 610 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 611 | nl80211_key_policy); |
| 612 | if (err) |
| 613 | return err; |
| 614 | |
| 615 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 616 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 617 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 618 | if (k->def) { |
| 619 | k->def_uni = true; |
| 620 | k->def_multi = true; |
| 621 | } |
| 622 | if (k->defmgmt) |
| 623 | k->def_multi = true; |
| 624 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 625 | if (tb[NL80211_KEY_IDX]) |
| 626 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 627 | |
| 628 | if (tb[NL80211_KEY_DATA]) { |
| 629 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 630 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 631 | } |
| 632 | |
| 633 | if (tb[NL80211_KEY_SEQ]) { |
| 634 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 635 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 636 | } |
| 637 | |
| 638 | if (tb[NL80211_KEY_CIPHER]) |
| 639 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 640 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 641 | if (tb[NL80211_KEY_TYPE]) { |
| 642 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 643 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 644 | return -EINVAL; |
| 645 | } |
| 646 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 647 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 648 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 649 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 650 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 651 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 652 | if (err) |
| 653 | return err; |
| 654 | |
| 655 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 656 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 657 | } |
| 658 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 659 | return 0; |
| 660 | } |
| 661 | |
| 662 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 663 | { |
| 664 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 665 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 666 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 667 | } |
| 668 | |
| 669 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 670 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 671 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 672 | } |
| 673 | |
| 674 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 675 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 676 | |
| 677 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 678 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 679 | |
| 680 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 681 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 682 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 683 | if (k->def) { |
| 684 | k->def_uni = true; |
| 685 | k->def_multi = true; |
| 686 | } |
| 687 | if (k->defmgmt) |
| 688 | k->def_multi = true; |
| 689 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 690 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 691 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 692 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 693 | return -EINVAL; |
| 694 | } |
| 695 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 696 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 697 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 698 | int err = nla_parse_nested( |
| 699 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 700 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 701 | nl80211_key_default_policy); |
| 702 | if (err) |
| 703 | return err; |
| 704 | |
| 705 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 706 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 707 | } |
| 708 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 713 | { |
| 714 | int err; |
| 715 | |
| 716 | memset(k, 0, sizeof(*k)); |
| 717 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 718 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 719 | |
| 720 | if (info->attrs[NL80211_ATTR_KEY]) |
| 721 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 722 | else |
| 723 | err = nl80211_parse_key_old(info, k); |
| 724 | |
| 725 | if (err) |
| 726 | return err; |
| 727 | |
| 728 | if (k->def && k->defmgmt) |
| 729 | return -EINVAL; |
| 730 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 731 | if (k->defmgmt) { |
| 732 | if (k->def_uni || !k->def_multi) |
| 733 | return -EINVAL; |
| 734 | } |
| 735 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 736 | if (k->idx != -1) { |
| 737 | if (k->defmgmt) { |
| 738 | if (k->idx < 4 || k->idx > 5) |
| 739 | return -EINVAL; |
| 740 | } else if (k->def) { |
| 741 | if (k->idx < 0 || k->idx > 3) |
| 742 | return -EINVAL; |
| 743 | } else { |
| 744 | if (k->idx < 0 || k->idx > 5) |
| 745 | return -EINVAL; |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | return 0; |
| 750 | } |
| 751 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 752 | static struct cfg80211_cached_keys * |
| 753 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 754 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 755 | { |
| 756 | struct key_parse parse; |
| 757 | struct nlattr *key; |
| 758 | struct cfg80211_cached_keys *result; |
| 759 | int rem, err, def = 0; |
| 760 | |
| 761 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 762 | if (!result) |
| 763 | return ERR_PTR(-ENOMEM); |
| 764 | |
| 765 | result->def = -1; |
| 766 | result->defmgmt = -1; |
| 767 | |
| 768 | nla_for_each_nested(key, keys, rem) { |
| 769 | memset(&parse, 0, sizeof(parse)); |
| 770 | parse.idx = -1; |
| 771 | |
| 772 | err = nl80211_parse_key_new(key, &parse); |
| 773 | if (err) |
| 774 | goto error; |
| 775 | err = -EINVAL; |
| 776 | if (!parse.p.key) |
| 777 | goto error; |
| 778 | if (parse.idx < 0 || parse.idx > 4) |
| 779 | goto error; |
| 780 | if (parse.def) { |
| 781 | if (def) |
| 782 | goto error; |
| 783 | def = 1; |
| 784 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 785 | if (!parse.def_uni || !parse.def_multi) |
| 786 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 787 | } else if (parse.defmgmt) |
| 788 | goto error; |
| 789 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 790 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 791 | if (err) |
| 792 | goto error; |
| 793 | result->params[parse.idx].cipher = parse.p.cipher; |
| 794 | result->params[parse.idx].key_len = parse.p.key_len; |
| 795 | result->params[parse.idx].key = result->data[parse.idx]; |
| 796 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 797 | |
| 798 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 799 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 800 | if (no_ht) |
| 801 | *no_ht = true; |
| 802 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | return result; |
| 806 | error: |
| 807 | kfree(result); |
| 808 | return ERR_PTR(err); |
| 809 | } |
| 810 | |
| 811 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 812 | { |
| 813 | ASSERT_WDEV_LOCK(wdev); |
| 814 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 815 | switch (wdev->iftype) { |
| 816 | case NL80211_IFTYPE_AP: |
| 817 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 818 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 819 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 820 | break; |
| 821 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 822 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 823 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 824 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 825 | return -ENOLINK; |
| 826 | break; |
| 827 | default: |
| 828 | return -EINVAL; |
| 829 | } |
| 830 | |
| 831 | return 0; |
| 832 | } |
| 833 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 834 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 835 | { |
| 836 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 837 | int i; |
| 838 | |
| 839 | if (!nl_modes) |
| 840 | goto nla_put_failure; |
| 841 | |
| 842 | i = 0; |
| 843 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 844 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 845 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 846 | ifmodes >>= 1; |
| 847 | i++; |
| 848 | } |
| 849 | |
| 850 | nla_nest_end(msg, nl_modes); |
| 851 | return 0; |
| 852 | |
| 853 | nla_put_failure: |
| 854 | return -ENOBUFS; |
| 855 | } |
| 856 | |
| 857 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 858 | struct sk_buff *msg, |
| 859 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 860 | { |
| 861 | struct nlattr *nl_combis; |
| 862 | int i, j; |
| 863 | |
| 864 | nl_combis = nla_nest_start(msg, |
| 865 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 866 | if (!nl_combis) |
| 867 | goto nla_put_failure; |
| 868 | |
| 869 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 870 | const struct ieee80211_iface_combination *c; |
| 871 | struct nlattr *nl_combi, *nl_limits; |
| 872 | |
| 873 | c = &wiphy->iface_combinations[i]; |
| 874 | |
| 875 | nl_combi = nla_nest_start(msg, i + 1); |
| 876 | if (!nl_combi) |
| 877 | goto nla_put_failure; |
| 878 | |
| 879 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 880 | if (!nl_limits) |
| 881 | goto nla_put_failure; |
| 882 | |
| 883 | for (j = 0; j < c->n_limits; j++) { |
| 884 | struct nlattr *nl_limit; |
| 885 | |
| 886 | nl_limit = nla_nest_start(msg, j + 1); |
| 887 | if (!nl_limit) |
| 888 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 889 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 890 | c->limits[j].max)) |
| 891 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 892 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 893 | c->limits[j].types)) |
| 894 | goto nla_put_failure; |
| 895 | nla_nest_end(msg, nl_limit); |
| 896 | } |
| 897 | |
| 898 | nla_nest_end(msg, nl_limits); |
| 899 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 900 | if (c->beacon_int_infra_match && |
| 901 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 902 | goto nla_put_failure; |
| 903 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 904 | c->num_different_channels) || |
| 905 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 906 | c->max_interfaces)) |
| 907 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 908 | if (large && |
| 909 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 910 | c->radar_detect_widths)) |
| 911 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 912 | |
| 913 | nla_nest_end(msg, nl_combi); |
| 914 | } |
| 915 | |
| 916 | nla_nest_end(msg, nl_combis); |
| 917 | |
| 918 | return 0; |
| 919 | nla_put_failure: |
| 920 | return -ENOBUFS; |
| 921 | } |
| 922 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 923 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 924 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 925 | struct sk_buff *msg) |
| 926 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 927 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 928 | struct nlattr *nl_tcp; |
| 929 | |
| 930 | if (!tcp) |
| 931 | return 0; |
| 932 | |
| 933 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 934 | if (!nl_tcp) |
| 935 | return -ENOBUFS; |
| 936 | |
| 937 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 938 | tcp->data_payload_max)) |
| 939 | return -ENOBUFS; |
| 940 | |
| 941 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 942 | tcp->data_payload_max)) |
| 943 | return -ENOBUFS; |
| 944 | |
| 945 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 946 | return -ENOBUFS; |
| 947 | |
| 948 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 949 | sizeof(*tcp->tok), tcp->tok)) |
| 950 | return -ENOBUFS; |
| 951 | |
| 952 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 953 | tcp->data_interval_max)) |
| 954 | return -ENOBUFS; |
| 955 | |
| 956 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 957 | tcp->wake_payload_max)) |
| 958 | return -ENOBUFS; |
| 959 | |
| 960 | nla_nest_end(msg, nl_tcp); |
| 961 | return 0; |
| 962 | } |
| 963 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 964 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 965 | struct cfg80211_registered_device *dev, |
| 966 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 967 | { |
| 968 | struct nlattr *nl_wowlan; |
| 969 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 970 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 971 | return 0; |
| 972 | |
| 973 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 974 | if (!nl_wowlan) |
| 975 | return -ENOBUFS; |
| 976 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 977 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 978 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 979 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 980 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 981 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 982 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 983 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 984 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 985 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 986 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 987 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 988 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 989 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 990 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 991 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 992 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 993 | return -ENOBUFS; |
| 994 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 995 | if (dev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 996 | struct nl80211_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 997 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 998 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 999 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 1000 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1001 | }; |
| 1002 | |
| 1003 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1004 | sizeof(pat), &pat)) |
| 1005 | return -ENOBUFS; |
| 1006 | } |
| 1007 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1008 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1009 | return -ENOBUFS; |
| 1010 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1011 | nla_nest_end(msg, nl_wowlan); |
| 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | #endif |
| 1016 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1017 | static int nl80211_send_coalesce(struct sk_buff *msg, |
| 1018 | struct cfg80211_registered_device *dev) |
| 1019 | { |
| 1020 | struct nl80211_coalesce_rule_support rule; |
| 1021 | |
| 1022 | if (!dev->wiphy.coalesce) |
| 1023 | return 0; |
| 1024 | |
| 1025 | rule.max_rules = dev->wiphy.coalesce->n_rules; |
| 1026 | rule.max_delay = dev->wiphy.coalesce->max_delay; |
| 1027 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; |
| 1028 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; |
| 1029 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; |
| 1030 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; |
| 1031 | |
| 1032 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1033 | return -ENOBUFS; |
| 1034 | |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1038 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1039 | struct ieee80211_supported_band *sband) |
| 1040 | { |
| 1041 | struct nlattr *nl_rates, *nl_rate; |
| 1042 | struct ieee80211_rate *rate; |
| 1043 | int i; |
| 1044 | |
| 1045 | /* add HT info */ |
| 1046 | if (sband->ht_cap.ht_supported && |
| 1047 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1048 | sizeof(sband->ht_cap.mcs), |
| 1049 | &sband->ht_cap.mcs) || |
| 1050 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1051 | sband->ht_cap.cap) || |
| 1052 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1053 | sband->ht_cap.ampdu_factor) || |
| 1054 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1055 | sband->ht_cap.ampdu_density))) |
| 1056 | return -ENOBUFS; |
| 1057 | |
| 1058 | /* add VHT info */ |
| 1059 | if (sband->vht_cap.vht_supported && |
| 1060 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1061 | sizeof(sband->vht_cap.vht_mcs), |
| 1062 | &sband->vht_cap.vht_mcs) || |
| 1063 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1064 | sband->vht_cap.cap))) |
| 1065 | return -ENOBUFS; |
| 1066 | |
| 1067 | /* add bitrates */ |
| 1068 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1069 | if (!nl_rates) |
| 1070 | return -ENOBUFS; |
| 1071 | |
| 1072 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1073 | nl_rate = nla_nest_start(msg, i); |
| 1074 | if (!nl_rate) |
| 1075 | return -ENOBUFS; |
| 1076 | |
| 1077 | rate = &sband->bitrates[i]; |
| 1078 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1079 | rate->bitrate)) |
| 1080 | return -ENOBUFS; |
| 1081 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1082 | nla_put_flag(msg, |
| 1083 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1084 | return -ENOBUFS; |
| 1085 | |
| 1086 | nla_nest_end(msg, nl_rate); |
| 1087 | } |
| 1088 | |
| 1089 | nla_nest_end(msg, nl_rates); |
| 1090 | |
| 1091 | return 0; |
| 1092 | } |
| 1093 | |
| 1094 | static int |
| 1095 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1096 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1097 | { |
| 1098 | u16 stypes; |
| 1099 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1100 | enum nl80211_iftype ift; |
| 1101 | int i; |
| 1102 | |
| 1103 | if (!mgmt_stypes) |
| 1104 | return 0; |
| 1105 | |
| 1106 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1107 | if (!nl_ifs) |
| 1108 | return -ENOBUFS; |
| 1109 | |
| 1110 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1111 | nl_ftypes = nla_nest_start(msg, ift); |
| 1112 | if (!nl_ftypes) |
| 1113 | return -ENOBUFS; |
| 1114 | i = 0; |
| 1115 | stypes = mgmt_stypes[ift].tx; |
| 1116 | while (stypes) { |
| 1117 | if ((stypes & 1) && |
| 1118 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1119 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1120 | return -ENOBUFS; |
| 1121 | stypes >>= 1; |
| 1122 | i++; |
| 1123 | } |
| 1124 | nla_nest_end(msg, nl_ftypes); |
| 1125 | } |
| 1126 | |
| 1127 | nla_nest_end(msg, nl_ifs); |
| 1128 | |
| 1129 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1130 | if (!nl_ifs) |
| 1131 | return -ENOBUFS; |
| 1132 | |
| 1133 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1134 | nl_ftypes = nla_nest_start(msg, ift); |
| 1135 | if (!nl_ftypes) |
| 1136 | return -ENOBUFS; |
| 1137 | i = 0; |
| 1138 | stypes = mgmt_stypes[ift].rx; |
| 1139 | while (stypes) { |
| 1140 | if ((stypes & 1) && |
| 1141 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1142 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1143 | return -ENOBUFS; |
| 1144 | stypes >>= 1; |
| 1145 | i++; |
| 1146 | } |
| 1147 | nla_nest_end(msg, nl_ftypes); |
| 1148 | } |
| 1149 | nla_nest_end(msg, nl_ifs); |
| 1150 | |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1154 | struct nl80211_dump_wiphy_state { |
| 1155 | s64 filter_wiphy; |
| 1156 | long start; |
| 1157 | long split_start, band_start, chan_start; |
| 1158 | bool split; |
| 1159 | }; |
| 1160 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1161 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1162 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1163 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1164 | { |
| 1165 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1166 | struct nlattr *nl_bands, *nl_band; |
| 1167 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1168 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1169 | enum ieee80211_band band; |
| 1170 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1171 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1172 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1173 | dev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1174 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1175 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1176 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1177 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1178 | return -ENOBUFS; |
| 1179 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1180 | if (WARN_ON(!state)) |
| 1181 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1182 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1183 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1184 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1185 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1186 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1187 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1188 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1189 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1190 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1191 | case 0: |
| 1192 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1193 | dev->wiphy.retry_short) || |
| 1194 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1195 | dev->wiphy.retry_long) || |
| 1196 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1197 | dev->wiphy.frag_threshold) || |
| 1198 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1199 | dev->wiphy.rts_threshold) || |
| 1200 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1201 | dev->wiphy.coverage_class) || |
| 1202 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1203 | dev->wiphy.max_scan_ssids) || |
| 1204 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1205 | dev->wiphy.max_sched_scan_ssids) || |
| 1206 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1207 | dev->wiphy.max_scan_ie_len) || |
| 1208 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1209 | dev->wiphy.max_sched_scan_ie_len) || |
| 1210 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1211 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1212 | goto nla_put_failure; |
| 1213 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1214 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1215 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1216 | goto nla_put_failure; |
| 1217 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1218 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1219 | goto nla_put_failure; |
| 1220 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1221 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1222 | goto nla_put_failure; |
| 1223 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1224 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1225 | goto nla_put_failure; |
| 1226 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1227 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1228 | goto nla_put_failure; |
| 1229 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1230 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1231 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1232 | state->split_start++; |
| 1233 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1234 | break; |
| 1235 | case 1: |
| 1236 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1237 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1238 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1239 | goto nla_put_failure; |
| 1240 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1241 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1242 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1243 | goto nla_put_failure; |
| 1244 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1245 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1246 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1247 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1248 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1249 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1250 | dev->wiphy.available_antennas_tx) || |
| 1251 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1252 | dev->wiphy.available_antennas_rx)) |
| 1253 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1254 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1255 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1256 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1257 | dev->wiphy.probe_resp_offload)) |
| 1258 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1259 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1260 | if ((dev->wiphy.available_antennas_tx || |
| 1261 | dev->wiphy.available_antennas_rx) && |
| 1262 | dev->ops->get_antenna) { |
| 1263 | u32 tx_ant = 0, rx_ant = 0; |
| 1264 | int res; |
| 1265 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1266 | if (!res) { |
| 1267 | if (nla_put_u32(msg, |
| 1268 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1269 | tx_ant) || |
| 1270 | nla_put_u32(msg, |
| 1271 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1272 | rx_ant)) |
| 1273 | goto nla_put_failure; |
| 1274 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1275 | } |
| 1276 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1277 | state->split_start++; |
| 1278 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1279 | break; |
| 1280 | case 2: |
| 1281 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1282 | dev->wiphy.interface_modes)) |
| 1283 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1284 | state->split_start++; |
| 1285 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1286 | break; |
| 1287 | case 3: |
| 1288 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1289 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1290 | goto nla_put_failure; |
| 1291 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1292 | for (band = state->band_start; |
| 1293 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1294 | struct ieee80211_supported_band *sband; |
| 1295 | |
| 1296 | sband = dev->wiphy.bands[band]; |
| 1297 | |
| 1298 | if (!sband) |
| 1299 | continue; |
| 1300 | |
| 1301 | nl_band = nla_nest_start(msg, band); |
| 1302 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1303 | goto nla_put_failure; |
| 1304 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1305 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1306 | case 0: |
| 1307 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1308 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1309 | state->chan_start++; |
| 1310 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1311 | break; |
| 1312 | default: |
| 1313 | /* add frequencies */ |
| 1314 | nl_freqs = nla_nest_start( |
| 1315 | msg, NL80211_BAND_ATTR_FREQS); |
| 1316 | if (!nl_freqs) |
| 1317 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1318 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1319 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1320 | i < sband->n_channels; |
| 1321 | i++) { |
| 1322 | nl_freq = nla_nest_start(msg, i); |
| 1323 | if (!nl_freq) |
| 1324 | goto nla_put_failure; |
| 1325 | |
| 1326 | chan = &sband->channels[i]; |
| 1327 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1328 | if (nl80211_msg_put_channel( |
| 1329 | msg, chan, |
| 1330 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1331 | goto nla_put_failure; |
| 1332 | |
| 1333 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1334 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1335 | break; |
| 1336 | } |
| 1337 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1338 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1339 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1340 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1341 | nla_nest_end(msg, nl_freqs); |
| 1342 | } |
| 1343 | |
| 1344 | nla_nest_end(msg, nl_band); |
| 1345 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1346 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1347 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1348 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1349 | band--; |
| 1350 | break; |
| 1351 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1352 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1353 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1354 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1355 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1356 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1357 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1358 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1359 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1360 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1361 | if (state->band_start == 0 && state->chan_start == 0) |
| 1362 | state->split_start++; |
| 1363 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1364 | break; |
| 1365 | case 4: |
| 1366 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1367 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1368 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1369 | |
| 1370 | i = 0; |
| 1371 | #define CMD(op, n) \ |
| 1372 | do { \ |
| 1373 | if (dev->ops->op) { \ |
| 1374 | i++; \ |
| 1375 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1376 | goto nla_put_failure; \ |
| 1377 | } \ |
| 1378 | } while (0) |
| 1379 | |
| 1380 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1381 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1382 | CMD(add_key, NEW_KEY); |
| 1383 | CMD(start_ap, START_AP); |
| 1384 | CMD(add_station, NEW_STATION); |
| 1385 | CMD(add_mpath, NEW_MPATH); |
| 1386 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1387 | CMD(change_bss, SET_BSS); |
| 1388 | CMD(auth, AUTHENTICATE); |
| 1389 | CMD(assoc, ASSOCIATE); |
| 1390 | CMD(deauth, DEAUTHENTICATE); |
| 1391 | CMD(disassoc, DISASSOCIATE); |
| 1392 | CMD(join_ibss, JOIN_IBSS); |
| 1393 | CMD(join_mesh, JOIN_MESH); |
| 1394 | CMD(set_pmksa, SET_PMKSA); |
| 1395 | CMD(del_pmksa, DEL_PMKSA); |
| 1396 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1397 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1398 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1399 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1400 | CMD(mgmt_tx, FRAME); |
| 1401 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1402 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1403 | i++; |
| 1404 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1405 | goto nla_put_failure; |
| 1406 | } |
| 1407 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1408 | dev->ops->join_mesh) { |
| 1409 | i++; |
| 1410 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1411 | goto nla_put_failure; |
| 1412 | } |
| 1413 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1414 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1415 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1416 | CMD(tdls_oper, TDLS_OPER); |
| 1417 | } |
| 1418 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1419 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1420 | CMD(probe_client, PROBE_CLIENT); |
| 1421 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1422 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1423 | i++; |
| 1424 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1425 | goto nla_put_failure; |
| 1426 | } |
| 1427 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1428 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1429 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1430 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1431 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1432 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
| 1433 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1434 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1435 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1436 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1437 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1438 | #endif |
| 1439 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1440 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1441 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1442 | if (dev->ops->connect || dev->ops->auth) { |
| 1443 | i++; |
| 1444 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1445 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1446 | } |
| 1447 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1448 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1449 | i++; |
| 1450 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1451 | goto nla_put_failure; |
| 1452 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1453 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1454 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1455 | state->split_start++; |
| 1456 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1457 | break; |
| 1458 | case 5: |
| 1459 | if (dev->ops->remain_on_channel && |
| 1460 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1461 | nla_put_u32(msg, |
| 1462 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1463 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1464 | goto nla_put_failure; |
| 1465 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1466 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1467 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1468 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1469 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1470 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1471 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1472 | state->split_start++; |
| 1473 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1474 | break; |
| 1475 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1476 | #ifdef CONFIG_PM |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1477 | if (nl80211_send_wowlan(msg, dev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1478 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1479 | state->split_start++; |
| 1480 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1481 | break; |
| 1482 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1483 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1484 | #endif |
| 1485 | case 7: |
| 1486 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1487 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1488 | goto nla_put_failure; |
| 1489 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1490 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
| 1491 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1492 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1493 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1494 | state->split_start++; |
| 1495 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1496 | break; |
| 1497 | case 8: |
| 1498 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1499 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1500 | dev->wiphy.ap_sme_capa)) |
| 1501 | goto nla_put_failure; |
| 1502 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1503 | features = dev->wiphy.features; |
| 1504 | /* |
| 1505 | * We can only add the per-channel limit information if the |
| 1506 | * dump is split, otherwise it makes it too big. Therefore |
| 1507 | * only advertise it in that case. |
| 1508 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1509 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1510 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1511 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1512 | goto nla_put_failure; |
| 1513 | |
| 1514 | if (dev->wiphy.ht_capa_mod_mask && |
| 1515 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1516 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1517 | dev->wiphy.ht_capa_mod_mask)) |
| 1518 | goto nla_put_failure; |
| 1519 | |
| 1520 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1521 | dev->wiphy.max_acl_mac_addrs && |
| 1522 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1523 | dev->wiphy.max_acl_mac_addrs)) |
| 1524 | goto nla_put_failure; |
| 1525 | |
| 1526 | /* |
| 1527 | * Any information below this point is only available to |
| 1528 | * applications that can deal with it being split. This |
| 1529 | * helps ensure that newly added capabilities don't break |
| 1530 | * older tools by overrunning their buffers. |
| 1531 | * |
| 1532 | * We still increment split_start so that in the split |
| 1533 | * case we'll continue with more data in the next round, |
| 1534 | * but break unconditionally so unsplit data stops here. |
| 1535 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1536 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1537 | break; |
| 1538 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1539 | if (dev->wiphy.extended_capabilities && |
| 1540 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1541 | dev->wiphy.extended_capabilities_len, |
| 1542 | dev->wiphy.extended_capabilities) || |
| 1543 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1544 | dev->wiphy.extended_capabilities_len, |
| 1545 | dev->wiphy.extended_capabilities_mask))) |
| 1546 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1547 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1548 | if (dev->wiphy.vht_capa_mod_mask && |
| 1549 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1550 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1551 | dev->wiphy.vht_capa_mod_mask)) |
| 1552 | goto nla_put_failure; |
| 1553 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1554 | state->split_start++; |
| 1555 | break; |
| 1556 | case 10: |
| 1557 | if (nl80211_send_coalesce(msg, dev)) |
| 1558 | goto nla_put_failure; |
| 1559 | |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1560 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1561 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1562 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1563 | goto nla_put_failure; |
| 1564 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1565 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1566 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1567 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1568 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1569 | return genlmsg_end(msg, hdr); |
| 1570 | |
| 1571 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1572 | genlmsg_cancel(msg, hdr); |
| 1573 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1574 | } |
| 1575 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1576 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1577 | struct netlink_callback *cb, |
| 1578 | struct nl80211_dump_wiphy_state *state) |
| 1579 | { |
| 1580 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1581 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1582 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1583 | /* ignore parse errors for backward compatibility */ |
| 1584 | if (ret) |
| 1585 | return 0; |
| 1586 | |
| 1587 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1588 | if (tb[NL80211_ATTR_WIPHY]) |
| 1589 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1590 | if (tb[NL80211_ATTR_WDEV]) |
| 1591 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1592 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1593 | struct net_device *netdev; |
| 1594 | struct cfg80211_registered_device *rdev; |
| 1595 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1596 | |
| 1597 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1598 | if (!netdev) |
| 1599 | return -ENODEV; |
| 1600 | if (netdev->ieee80211_ptr) { |
| 1601 | rdev = wiphy_to_dev( |
| 1602 | netdev->ieee80211_ptr->wiphy); |
| 1603 | state->filter_wiphy = rdev->wiphy_idx; |
| 1604 | } |
| 1605 | dev_put(netdev); |
| 1606 | } |
| 1607 | |
| 1608 | return 0; |
| 1609 | } |
| 1610 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1611 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1612 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1613 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1614 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1615 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1616 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1617 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1618 | if (!state) { |
| 1619 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1620 | if (!state) { |
| 1621 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1622 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1623 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1624 | state->filter_wiphy = -1; |
| 1625 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1626 | if (ret) { |
| 1627 | kfree(state); |
| 1628 | rtnl_unlock(); |
| 1629 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1630 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1631 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1632 | } |
| 1633 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1634 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1635 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1636 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1637 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1638 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1639 | if (state->filter_wiphy != -1 && |
| 1640 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1641 | continue; |
| 1642 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1643 | do { |
| 1644 | ret = nl80211_send_wiphy(dev, skb, |
| 1645 | NETLINK_CB(cb->skb).portid, |
| 1646 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1647 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1648 | if (ret < 0) { |
| 1649 | /* |
| 1650 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1651 | * or EMSGSIZE returned), this SKB is still |
| 1652 | * empty (so it's not too big because another |
| 1653 | * wiphy dataset is already in the skb) and |
| 1654 | * we've not tried to adjust the dump allocation |
| 1655 | * yet ... then adjust the alloc size to be |
| 1656 | * bigger, and return 1 but with the empty skb. |
| 1657 | * This results in an empty message being RX'ed |
| 1658 | * in userspace, but that is ignored. |
| 1659 | * |
| 1660 | * We can then retry with the larger buffer. |
| 1661 | */ |
| 1662 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1663 | !skb->len && |
| 1664 | cb->min_dump_alloc < 4096) { |
| 1665 | cb->min_dump_alloc = 4096; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1666 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1667 | return 1; |
| 1668 | } |
| 1669 | idx--; |
| 1670 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1671 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1672 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1673 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1674 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1675 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1676 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1677 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1678 | |
| 1679 | return skb->len; |
| 1680 | } |
| 1681 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1682 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1683 | { |
| 1684 | kfree((void *)cb->args[0]); |
| 1685 | return 0; |
| 1686 | } |
| 1687 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1688 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1689 | { |
| 1690 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1691 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1692 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1693 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1694 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1695 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1696 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1697 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1698 | 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] | 1699 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1700 | nlmsg_free(msg); |
| 1701 | return -ENOBUFS; |
| 1702 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1703 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1704 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1705 | } |
| 1706 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1707 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1708 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1709 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1710 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1711 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1712 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1713 | }; |
| 1714 | |
| 1715 | static int parse_txq_params(struct nlattr *tb[], |
| 1716 | struct ieee80211_txq_params *txq_params) |
| 1717 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1718 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1719 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1720 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1721 | return -EINVAL; |
| 1722 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1723 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1724 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1725 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1726 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1727 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1728 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1729 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1730 | return -EINVAL; |
| 1731 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1732 | return 0; |
| 1733 | } |
| 1734 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1735 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1736 | { |
| 1737 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1738 | * You can only set the channel explicitly for WDS interfaces, |
| 1739 | * all others have their channel managed via their respective |
| 1740 | * "establish a connection" command (connect, join, ...) |
| 1741 | * |
| 1742 | * For AP/GO and mesh mode, the channel can be set with the |
| 1743 | * channel userspace API, but is only stored and passed to the |
| 1744 | * low-level driver when the AP starts or the mesh is joined. |
| 1745 | * This is for backward compatibility, userspace can also give |
| 1746 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1747 | * |
| 1748 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1749 | * whatever else is going on, so they have their own special |
| 1750 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1751 | */ |
| 1752 | return !wdev || |
| 1753 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1754 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1755 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1756 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1757 | } |
| 1758 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1759 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1760 | struct genl_info *info, |
| 1761 | struct cfg80211_chan_def *chandef) |
| 1762 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1763 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1764 | |
| 1765 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1766 | return -EINVAL; |
| 1767 | |
| 1768 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1769 | |
| 1770 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1771 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1772 | chandef->center_freq1 = control_freq; |
| 1773 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1774 | |
| 1775 | /* Primary channel not allowed */ |
| 1776 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1777 | return -EINVAL; |
| 1778 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1779 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1780 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1781 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1782 | chantype = nla_get_u32( |
| 1783 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1784 | |
| 1785 | switch (chantype) { |
| 1786 | case NL80211_CHAN_NO_HT: |
| 1787 | case NL80211_CHAN_HT20: |
| 1788 | case NL80211_CHAN_HT40PLUS: |
| 1789 | case NL80211_CHAN_HT40MINUS: |
| 1790 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1791 | chantype); |
| 1792 | break; |
| 1793 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1794 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1795 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1796 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1797 | chandef->width = |
| 1798 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1799 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1800 | chandef->center_freq1 = |
| 1801 | nla_get_u32( |
| 1802 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1803 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1804 | chandef->center_freq2 = |
| 1805 | nla_get_u32( |
| 1806 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1807 | } |
| 1808 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1809 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1810 | return -EINVAL; |
| 1811 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1812 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1813 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1814 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1815 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1816 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1817 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1818 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1819 | return -EINVAL; |
| 1820 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1821 | return 0; |
| 1822 | } |
| 1823 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1824 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1825 | struct wireless_dev *wdev, |
| 1826 | struct genl_info *info) |
| 1827 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1828 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1829 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1830 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1831 | |
| 1832 | if (wdev) |
| 1833 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1834 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1835 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1836 | return -EOPNOTSUPP; |
| 1837 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1838 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1839 | if (result) |
| 1840 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1841 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1842 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1843 | case NL80211_IFTYPE_AP: |
| 1844 | case NL80211_IFTYPE_P2P_GO: |
| 1845 | if (wdev->beacon_interval) { |
| 1846 | result = -EBUSY; |
| 1847 | break; |
| 1848 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1849 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1850 | result = -EINVAL; |
| 1851 | break; |
| 1852 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1853 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1854 | result = 0; |
| 1855 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1856 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1857 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1858 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1859 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1860 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1861 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1862 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1863 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1864 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1865 | |
| 1866 | return result; |
| 1867 | } |
| 1868 | |
| 1869 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1870 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1871 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1872 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1873 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1874 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1875 | } |
| 1876 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1877 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1878 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1879 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1880 | struct net_device *dev = info->user_ptr[1]; |
| 1881 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1882 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1883 | |
| 1884 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1885 | return -EINVAL; |
| 1886 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1887 | if (netif_running(dev)) |
| 1888 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1889 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1890 | if (!rdev->ops->set_wds_peer) |
| 1891 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1892 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1893 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1894 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1895 | |
| 1896 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1897 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1901 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1902 | { |
| 1903 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1904 | struct net_device *netdev = NULL; |
| 1905 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1906 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1907 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1908 | u32 changed; |
| 1909 | u8 retry_short = 0, retry_long = 0; |
| 1910 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1911 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1912 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1913 | ASSERT_RTNL(); |
| 1914 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1915 | /* |
| 1916 | * Try to find the wiphy and netdev. Normally this |
| 1917 | * function shouldn't need the netdev, but this is |
| 1918 | * done for backward compatibility -- previously |
| 1919 | * setting the channel was done per wiphy, but now |
| 1920 | * it is per netdev. Previous userland like hostapd |
| 1921 | * also passed a netdev to set_wiphy, so that it is |
| 1922 | * possible to let that go to the right netdev! |
| 1923 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1924 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1925 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1926 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1927 | |
| 1928 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1929 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1930 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1931 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1932 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1933 | } |
| 1934 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1935 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1936 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1937 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1938 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1939 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1940 | wdev = NULL; |
| 1941 | netdev = NULL; |
| 1942 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1943 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1944 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1945 | |
| 1946 | /* |
| 1947 | * end workaround code, by now the rdev is available |
| 1948 | * and locked, and wdev may or may not be NULL. |
| 1949 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1950 | |
| 1951 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1952 | result = cfg80211_dev_rename( |
| 1953 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1954 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1955 | if (result) |
| 1956 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1957 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1958 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1959 | struct ieee80211_txq_params txq_params; |
| 1960 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1961 | |
| 1962 | if (!rdev->ops->set_txq_params) { |
| 1963 | result = -EOPNOTSUPP; |
| 1964 | goto bad_res; |
| 1965 | } |
| 1966 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1967 | if (!netdev) { |
| 1968 | result = -EINVAL; |
| 1969 | goto bad_res; |
| 1970 | } |
| 1971 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1972 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1973 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1974 | result = -EINVAL; |
| 1975 | goto bad_res; |
| 1976 | } |
| 1977 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1978 | if (!netif_running(netdev)) { |
| 1979 | result = -ENETDOWN; |
| 1980 | goto bad_res; |
| 1981 | } |
| 1982 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1983 | nla_for_each_nested(nl_txq_params, |
| 1984 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1985 | rem_txq_params) { |
| 1986 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1987 | nla_data(nl_txq_params), |
| 1988 | nla_len(nl_txq_params), |
| 1989 | txq_params_policy); |
| 1990 | result = parse_txq_params(tb, &txq_params); |
| 1991 | if (result) |
| 1992 | goto bad_res; |
| 1993 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1994 | result = rdev_set_txq_params(rdev, netdev, |
| 1995 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1996 | if (result) |
| 1997 | goto bad_res; |
| 1998 | } |
| 1999 | } |
| 2000 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2001 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2002 | result = __nl80211_set_channel(rdev, |
| 2003 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 2004 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2005 | if (result) |
| 2006 | goto bad_res; |
| 2007 | } |
| 2008 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2009 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2010 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2011 | enum nl80211_tx_power_setting type; |
| 2012 | int idx, mbm = 0; |
| 2013 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2014 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2015 | txp_wdev = NULL; |
| 2016 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2017 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 2018 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2019 | goto bad_res; |
| 2020 | } |
| 2021 | |
| 2022 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2023 | type = nla_get_u32(info->attrs[idx]); |
| 2024 | |
| 2025 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 2026 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 2027 | result = -EINVAL; |
| 2028 | goto bad_res; |
| 2029 | } |
| 2030 | |
| 2031 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2032 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2033 | mbm = nla_get_u32(info->attrs[idx]); |
| 2034 | } |
| 2035 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2036 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2037 | if (result) |
| 2038 | goto bad_res; |
| 2039 | } |
| 2040 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2041 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2042 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2043 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2044 | if ((!rdev->wiphy.available_antennas_tx && |
| 2045 | !rdev->wiphy.available_antennas_rx) || |
| 2046 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2047 | result = -EOPNOTSUPP; |
| 2048 | goto bad_res; |
| 2049 | } |
| 2050 | |
| 2051 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2052 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2053 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2054 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2055 | * available antenna masks, except for the "all" mask */ |
| 2056 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2057 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2058 | result = -EINVAL; |
| 2059 | goto bad_res; |
| 2060 | } |
| 2061 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2062 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2063 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2064 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2065 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2066 | if (result) |
| 2067 | goto bad_res; |
| 2068 | } |
| 2069 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2070 | changed = 0; |
| 2071 | |
| 2072 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2073 | retry_short = nla_get_u8( |
| 2074 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2075 | if (retry_short == 0) { |
| 2076 | result = -EINVAL; |
| 2077 | goto bad_res; |
| 2078 | } |
| 2079 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2080 | } |
| 2081 | |
| 2082 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2083 | retry_long = nla_get_u8( |
| 2084 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2085 | if (retry_long == 0) { |
| 2086 | result = -EINVAL; |
| 2087 | goto bad_res; |
| 2088 | } |
| 2089 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2090 | } |
| 2091 | |
| 2092 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2093 | frag_threshold = nla_get_u32( |
| 2094 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2095 | if (frag_threshold < 256) { |
| 2096 | result = -EINVAL; |
| 2097 | goto bad_res; |
| 2098 | } |
| 2099 | if (frag_threshold != (u32) -1) { |
| 2100 | /* |
| 2101 | * Fragments (apart from the last one) are required to |
| 2102 | * have even length. Make the fragmentation code |
| 2103 | * simpler by stripping LSB should someone try to use |
| 2104 | * odd threshold value. |
| 2105 | */ |
| 2106 | frag_threshold &= ~0x1; |
| 2107 | } |
| 2108 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2109 | } |
| 2110 | |
| 2111 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2112 | rts_threshold = nla_get_u32( |
| 2113 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2114 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2115 | } |
| 2116 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2117 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2118 | coverage_class = nla_get_u8( |
| 2119 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2120 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2121 | } |
| 2122 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2123 | if (changed) { |
| 2124 | u8 old_retry_short, old_retry_long; |
| 2125 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2126 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2127 | |
| 2128 | if (!rdev->ops->set_wiphy_params) { |
| 2129 | result = -EOPNOTSUPP; |
| 2130 | goto bad_res; |
| 2131 | } |
| 2132 | |
| 2133 | old_retry_short = rdev->wiphy.retry_short; |
| 2134 | old_retry_long = rdev->wiphy.retry_long; |
| 2135 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2136 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2137 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2138 | |
| 2139 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2140 | rdev->wiphy.retry_short = retry_short; |
| 2141 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2142 | rdev->wiphy.retry_long = retry_long; |
| 2143 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2144 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2145 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2146 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2147 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2148 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2149 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2150 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2151 | if (result) { |
| 2152 | rdev->wiphy.retry_short = old_retry_short; |
| 2153 | rdev->wiphy.retry_long = old_retry_long; |
| 2154 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2155 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2156 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2157 | } |
| 2158 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2159 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2160 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2161 | if (netdev) |
| 2162 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2163 | return result; |
| 2164 | } |
| 2165 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2166 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2167 | { |
| 2168 | return (u64)wdev->identifier | |
| 2169 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2170 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2171 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2172 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2173 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2174 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2175 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2176 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2177 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2178 | chandef->chan->center_freq)) |
| 2179 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2180 | switch (chandef->width) { |
| 2181 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2182 | case NL80211_CHAN_WIDTH_20: |
| 2183 | case NL80211_CHAN_WIDTH_40: |
| 2184 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2185 | cfg80211_get_chandef_type(chandef))) |
| 2186 | return -ENOBUFS; |
| 2187 | break; |
| 2188 | default: |
| 2189 | break; |
| 2190 | } |
| 2191 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2192 | return -ENOBUFS; |
| 2193 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2194 | return -ENOBUFS; |
| 2195 | if (chandef->center_freq2 && |
| 2196 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2197 | return -ENOBUFS; |
| 2198 | return 0; |
| 2199 | } |
| 2200 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2201 | 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] | 2202 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2203 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2204 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2205 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2206 | void *hdr; |
| 2207 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2208 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2209 | if (!hdr) |
| 2210 | return -1; |
| 2211 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2212 | if (dev && |
| 2213 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2214 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2215 | goto nla_put_failure; |
| 2216 | |
| 2217 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2218 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2219 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2220 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2221 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2222 | rdev->devlist_generation ^ |
| 2223 | (cfg80211_rdev_list_generation << 2))) |
| 2224 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2225 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2226 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2227 | int ret; |
| 2228 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2229 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2230 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2231 | if (ret == 0) { |
| 2232 | if (nl80211_send_chandef(msg, &chandef)) |
| 2233 | goto nla_put_failure; |
| 2234 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2235 | } |
| 2236 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2237 | if (wdev->ssid_len) { |
| 2238 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2239 | goto nla_put_failure; |
| 2240 | } |
| 2241 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2242 | return genlmsg_end(msg, hdr); |
| 2243 | |
| 2244 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2245 | genlmsg_cancel(msg, hdr); |
| 2246 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2250 | { |
| 2251 | int wp_idx = 0; |
| 2252 | int if_idx = 0; |
| 2253 | int wp_start = cb->args[0]; |
| 2254 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2255 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2256 | struct wireless_dev *wdev; |
| 2257 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2258 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2259 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2260 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2261 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2262 | if (wp_idx < wp_start) { |
| 2263 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2264 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2265 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2266 | if_idx = 0; |
| 2267 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2268 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2269 | if (if_idx < if_start) { |
| 2270 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2271 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2272 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2273 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2274 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2275 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2276 | goto out; |
| 2277 | } |
| 2278 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2279 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2280 | |
| 2281 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2282 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2283 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2284 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2285 | |
| 2286 | cb->args[0] = wp_idx; |
| 2287 | cb->args[1] = if_idx; |
| 2288 | |
| 2289 | return skb->len; |
| 2290 | } |
| 2291 | |
| 2292 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2293 | { |
| 2294 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2295 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2296 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2297 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2298 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2299 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2300 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2301 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2302 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2303 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2304 | nlmsg_free(msg); |
| 2305 | return -ENOBUFS; |
| 2306 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2307 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2308 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2309 | } |
| 2310 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2311 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2312 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2313 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2314 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2315 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2316 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2317 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2318 | }; |
| 2319 | |
| 2320 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2321 | { |
| 2322 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2323 | int flag; |
| 2324 | |
| 2325 | *mntrflags = 0; |
| 2326 | |
| 2327 | if (!nla) |
| 2328 | return -EINVAL; |
| 2329 | |
| 2330 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2331 | nla, mntr_flags_policy)) |
| 2332 | return -EINVAL; |
| 2333 | |
| 2334 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2335 | if (flags[flag]) |
| 2336 | *mntrflags |= (1<<flag); |
| 2337 | |
| 2338 | return 0; |
| 2339 | } |
| 2340 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2341 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2342 | struct net_device *netdev, u8 use_4addr, |
| 2343 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2344 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2345 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2346 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2347 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2348 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2349 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2350 | |
| 2351 | switch (iftype) { |
| 2352 | case NL80211_IFTYPE_AP_VLAN: |
| 2353 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2354 | return 0; |
| 2355 | break; |
| 2356 | case NL80211_IFTYPE_STATION: |
| 2357 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2358 | return 0; |
| 2359 | break; |
| 2360 | default: |
| 2361 | break; |
| 2362 | } |
| 2363 | |
| 2364 | return -EOPNOTSUPP; |
| 2365 | } |
| 2366 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2367 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2368 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2369 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2370 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2371 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2372 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2373 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2374 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2375 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2376 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2377 | memset(¶ms, 0, sizeof(params)); |
| 2378 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2379 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2380 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2381 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2382 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2383 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2384 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2385 | if (ntype > NL80211_IFTYPE_MAX) |
| 2386 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2387 | } |
| 2388 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2389 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2390 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2391 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2392 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2393 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2394 | if (netif_running(dev)) |
| 2395 | return -EBUSY; |
| 2396 | |
| 2397 | wdev_lock(wdev); |
| 2398 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2399 | IEEE80211_MAX_MESH_ID_LEN); |
| 2400 | wdev->mesh_id_up_len = |
| 2401 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2402 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2403 | wdev->mesh_id_up_len); |
| 2404 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2405 | } |
| 2406 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2407 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2408 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2409 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2410 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2411 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2412 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2413 | } else { |
| 2414 | params.use_4addr = -1; |
| 2415 | } |
| 2416 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2417 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2418 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2419 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2420 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2421 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2422 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2423 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2424 | |
| 2425 | flags = &_flags; |
| 2426 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2427 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2428 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2429 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2430 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2431 | return -EOPNOTSUPP; |
| 2432 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2433 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2434 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2435 | else |
| 2436 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2437 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2438 | if (!err && params.use_4addr != -1) |
| 2439 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2440 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2441 | return err; |
| 2442 | } |
| 2443 | |
| 2444 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2445 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2446 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2447 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2448 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2449 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2450 | int err; |
| 2451 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2452 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2453 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2454 | memset(¶ms, 0, sizeof(params)); |
| 2455 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2456 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2457 | return -EINVAL; |
| 2458 | |
| 2459 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2460 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2461 | if (type > NL80211_IFTYPE_MAX) |
| 2462 | return -EINVAL; |
| 2463 | } |
| 2464 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2465 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2466 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2467 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2468 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2469 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2470 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2471 | ETH_ALEN); |
| 2472 | if (!is_valid_ether_addr(params.macaddr)) |
| 2473 | return -EADDRNOTAVAIL; |
| 2474 | } |
| 2475 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2476 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2477 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2478 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2479 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2480 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2481 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2482 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2483 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2484 | if (!msg) |
| 2485 | return -ENOMEM; |
| 2486 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2487 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2488 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2489 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2490 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2491 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2492 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2493 | return -EOPNOTSUPP; |
| 2494 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2495 | wdev = rdev_add_virtual_intf(rdev, |
| 2496 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2497 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2498 | if (IS_ERR(wdev)) { |
| 2499 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2500 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2501 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2502 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2503 | switch (type) { |
| 2504 | case NL80211_IFTYPE_MESH_POINT: |
| 2505 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2506 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2507 | wdev_lock(wdev); |
| 2508 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2509 | IEEE80211_MAX_MESH_ID_LEN); |
| 2510 | wdev->mesh_id_up_len = |
| 2511 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2512 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2513 | wdev->mesh_id_up_len); |
| 2514 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2515 | break; |
| 2516 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2517 | /* |
| 2518 | * P2P Device doesn't have a netdev, so doesn't go |
| 2519 | * through the netdev notifier and must be added here |
| 2520 | */ |
| 2521 | mutex_init(&wdev->mtx); |
| 2522 | INIT_LIST_HEAD(&wdev->event_list); |
| 2523 | spin_lock_init(&wdev->event_lock); |
| 2524 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2525 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2526 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2527 | wdev->identifier = ++rdev->wdev_id; |
| 2528 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2529 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2530 | break; |
| 2531 | default: |
| 2532 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2533 | } |
| 2534 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2535 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2536 | rdev, wdev) < 0) { |
| 2537 | nlmsg_free(msg); |
| 2538 | return -ENOBUFS; |
| 2539 | } |
| 2540 | |
| 2541 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2545 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2546 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2547 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2548 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2549 | if (!rdev->ops->del_virtual_intf) |
| 2550 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2551 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2552 | /* |
| 2553 | * If we remove a wireless device without a netdev then clear |
| 2554 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2555 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2556 | * since the wdev has been freed, unlike with a netdev where |
| 2557 | * we need the dev_put() for the netdev to really be freed. |
| 2558 | */ |
| 2559 | if (!wdev->netdev) |
| 2560 | info->user_ptr[1] = NULL; |
| 2561 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2562 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2563 | } |
| 2564 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2565 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2566 | { |
| 2567 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2568 | struct net_device *dev = info->user_ptr[1]; |
| 2569 | u16 noack_map; |
| 2570 | |
| 2571 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2572 | return -EINVAL; |
| 2573 | |
| 2574 | if (!rdev->ops->set_noack_map) |
| 2575 | return -EOPNOTSUPP; |
| 2576 | |
| 2577 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2578 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2579 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2580 | } |
| 2581 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2582 | struct get_key_cookie { |
| 2583 | struct sk_buff *msg; |
| 2584 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2585 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2586 | }; |
| 2587 | |
| 2588 | static void get_key_callback(void *c, struct key_params *params) |
| 2589 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2590 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2591 | struct get_key_cookie *cookie = c; |
| 2592 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2593 | if ((params->key && |
| 2594 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2595 | params->key_len, params->key)) || |
| 2596 | (params->seq && |
| 2597 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2598 | params->seq_len, params->seq)) || |
| 2599 | (params->cipher && |
| 2600 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2601 | params->cipher))) |
| 2602 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2603 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2604 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2605 | if (!key) |
| 2606 | goto nla_put_failure; |
| 2607 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2608 | if ((params->key && |
| 2609 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2610 | params->key_len, params->key)) || |
| 2611 | (params->seq && |
| 2612 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2613 | params->seq_len, params->seq)) || |
| 2614 | (params->cipher && |
| 2615 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2616 | params->cipher))) |
| 2617 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2618 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2619 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2620 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2621 | |
| 2622 | nla_nest_end(cookie->msg, key); |
| 2623 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2624 | return; |
| 2625 | nla_put_failure: |
| 2626 | cookie->error = 1; |
| 2627 | } |
| 2628 | |
| 2629 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2630 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2632 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2633 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2634 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2635 | const u8 *mac_addr = NULL; |
| 2636 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2637 | struct get_key_cookie cookie = { |
| 2638 | .error = 0, |
| 2639 | }; |
| 2640 | void *hdr; |
| 2641 | struct sk_buff *msg; |
| 2642 | |
| 2643 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2644 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2645 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2646 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2647 | return -EINVAL; |
| 2648 | |
| 2649 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2650 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2651 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2652 | pairwise = !!mac_addr; |
| 2653 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2654 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2655 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2656 | return -EINVAL; |
| 2657 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2658 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2659 | return -EINVAL; |
| 2660 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2661 | } |
| 2662 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2663 | if (!rdev->ops->get_key) |
| 2664 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2665 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2666 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2667 | if (!msg) |
| 2668 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2669 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2670 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2671 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2672 | if (!hdr) |
| 2673 | return -ENOBUFS; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2674 | |
| 2675 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2676 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2677 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2678 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2679 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2680 | goto nla_put_failure; |
| 2681 | if (mac_addr && |
| 2682 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2683 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2684 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2685 | if (pairwise && mac_addr && |
| 2686 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2687 | return -ENOENT; |
| 2688 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2689 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2690 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2691 | |
| 2692 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2693 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2694 | |
| 2695 | if (cookie.error) |
| 2696 | goto nla_put_failure; |
| 2697 | |
| 2698 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2699 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2700 | |
| 2701 | nla_put_failure: |
| 2702 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2703 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2704 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2705 | return err; |
| 2706 | } |
| 2707 | |
| 2708 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2709 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2710 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2711 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2712 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2713 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2714 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2715 | err = nl80211_parse_key(info, &key); |
| 2716 | if (err) |
| 2717 | return err; |
| 2718 | |
| 2719 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2720 | return -EINVAL; |
| 2721 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2722 | /* only support setting default key */ |
| 2723 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2724 | return -EINVAL; |
| 2725 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2726 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2727 | |
| 2728 | if (key.def) { |
| 2729 | if (!rdev->ops->set_default_key) { |
| 2730 | err = -EOPNOTSUPP; |
| 2731 | goto out; |
| 2732 | } |
| 2733 | |
| 2734 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2735 | if (err) |
| 2736 | goto out; |
| 2737 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2738 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2739 | key.def_uni, key.def_multi); |
| 2740 | |
| 2741 | if (err) |
| 2742 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2743 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2744 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2745 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2746 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2747 | } else { |
| 2748 | if (key.def_uni || !key.def_multi) { |
| 2749 | err = -EINVAL; |
| 2750 | goto out; |
| 2751 | } |
| 2752 | |
| 2753 | if (!rdev->ops->set_default_mgmt_key) { |
| 2754 | err = -EOPNOTSUPP; |
| 2755 | goto out; |
| 2756 | } |
| 2757 | |
| 2758 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2759 | if (err) |
| 2760 | goto out; |
| 2761 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2762 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2763 | if (err) |
| 2764 | goto out; |
| 2765 | |
| 2766 | #ifdef CONFIG_CFG80211_WEXT |
| 2767 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2768 | #endif |
| 2769 | } |
| 2770 | |
| 2771 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2772 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2773 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2774 | return err; |
| 2775 | } |
| 2776 | |
| 2777 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2778 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2779 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2780 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2781 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2782 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2783 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2784 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2785 | err = nl80211_parse_key(info, &key); |
| 2786 | if (err) |
| 2787 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2788 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2789 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2790 | return -EINVAL; |
| 2791 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2792 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2793 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2794 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2795 | if (key.type == -1) { |
| 2796 | if (mac_addr) |
| 2797 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2798 | else |
| 2799 | key.type = NL80211_KEYTYPE_GROUP; |
| 2800 | } |
| 2801 | |
| 2802 | /* for now */ |
| 2803 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2804 | key.type != NL80211_KEYTYPE_GROUP) |
| 2805 | return -EINVAL; |
| 2806 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2807 | if (!rdev->ops->add_key) |
| 2808 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2809 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2810 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2811 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2812 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2813 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2814 | |
| 2815 | wdev_lock(dev->ieee80211_ptr); |
| 2816 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2817 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2818 | err = rdev_add_key(rdev, dev, key.idx, |
| 2819 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2820 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2821 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2822 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2823 | return err; |
| 2824 | } |
| 2825 | |
| 2826 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2827 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2828 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2829 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2830 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2831 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2832 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2833 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2834 | err = nl80211_parse_key(info, &key); |
| 2835 | if (err) |
| 2836 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2837 | |
| 2838 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2839 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2840 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2841 | if (key.type == -1) { |
| 2842 | if (mac_addr) |
| 2843 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2844 | else |
| 2845 | key.type = NL80211_KEYTYPE_GROUP; |
| 2846 | } |
| 2847 | |
| 2848 | /* for now */ |
| 2849 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2850 | key.type != NL80211_KEYTYPE_GROUP) |
| 2851 | return -EINVAL; |
| 2852 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2853 | if (!rdev->ops->del_key) |
| 2854 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2855 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2856 | wdev_lock(dev->ieee80211_ptr); |
| 2857 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2858 | |
| 2859 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2860 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2861 | err = -ENOENT; |
| 2862 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2863 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2864 | err = rdev_del_key(rdev, dev, key.idx, |
| 2865 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2866 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2867 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2868 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2869 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2870 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2871 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2872 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2873 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2874 | } |
| 2875 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2876 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2877 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2878 | return err; |
| 2879 | } |
| 2880 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2881 | /* This function returns an error or the number of nested attributes */ |
| 2882 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2883 | { |
| 2884 | struct nlattr *attr; |
| 2885 | int n_entries = 0, tmp; |
| 2886 | |
| 2887 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2888 | if (nla_len(attr) != ETH_ALEN) |
| 2889 | return -EINVAL; |
| 2890 | |
| 2891 | n_entries++; |
| 2892 | } |
| 2893 | |
| 2894 | return n_entries; |
| 2895 | } |
| 2896 | |
| 2897 | /* |
| 2898 | * This function parses ACL information and allocates memory for ACL data. |
| 2899 | * On successful return, the calling function is responsible to free the |
| 2900 | * ACL buffer returned by this function. |
| 2901 | */ |
| 2902 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2903 | struct genl_info *info) |
| 2904 | { |
| 2905 | enum nl80211_acl_policy acl_policy; |
| 2906 | struct nlattr *attr; |
| 2907 | struct cfg80211_acl_data *acl; |
| 2908 | int i = 0, n_entries, tmp; |
| 2909 | |
| 2910 | if (!wiphy->max_acl_mac_addrs) |
| 2911 | return ERR_PTR(-EOPNOTSUPP); |
| 2912 | |
| 2913 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2914 | return ERR_PTR(-EINVAL); |
| 2915 | |
| 2916 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2917 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2918 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2919 | return ERR_PTR(-EINVAL); |
| 2920 | |
| 2921 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2922 | return ERR_PTR(-EINVAL); |
| 2923 | |
| 2924 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2925 | if (n_entries < 0) |
| 2926 | return ERR_PTR(n_entries); |
| 2927 | |
| 2928 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2929 | return ERR_PTR(-ENOTSUPP); |
| 2930 | |
| 2931 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2932 | GFP_KERNEL); |
| 2933 | if (!acl) |
| 2934 | return ERR_PTR(-ENOMEM); |
| 2935 | |
| 2936 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2937 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2938 | i++; |
| 2939 | } |
| 2940 | |
| 2941 | acl->n_acl_entries = n_entries; |
| 2942 | acl->acl_policy = acl_policy; |
| 2943 | |
| 2944 | return acl; |
| 2945 | } |
| 2946 | |
| 2947 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2948 | { |
| 2949 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2950 | struct net_device *dev = info->user_ptr[1]; |
| 2951 | struct cfg80211_acl_data *acl; |
| 2952 | int err; |
| 2953 | |
| 2954 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2955 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2956 | return -EOPNOTSUPP; |
| 2957 | |
| 2958 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2959 | return -EINVAL; |
| 2960 | |
| 2961 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2962 | if (IS_ERR(acl)) |
| 2963 | return PTR_ERR(acl); |
| 2964 | |
| 2965 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2966 | |
| 2967 | kfree(acl); |
| 2968 | |
| 2969 | return err; |
| 2970 | } |
| 2971 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2972 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2973 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2974 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2975 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2976 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2977 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2978 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 2979 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2980 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2981 | return -EINVAL; |
| 2982 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2983 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2984 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2985 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2986 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2987 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2988 | if (!bcn->head_len) |
| 2989 | return -EINVAL; |
| 2990 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2991 | } |
| 2992 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2993 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2994 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2995 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2996 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2997 | } |
| 2998 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2999 | if (!haveinfo) |
| 3000 | return -EINVAL; |
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_IE]) { |
| 3003 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3004 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3005 | } |
| 3006 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3007 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3008 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3009 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3010 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3011 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3012 | } |
| 3013 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3014 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3015 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3016 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3017 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3018 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3019 | } |
| 3020 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3021 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3022 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3023 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3024 | } |
| 3025 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3026 | return 0; |
| 3027 | } |
| 3028 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3029 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3030 | struct cfg80211_ap_settings *params) |
| 3031 | { |
| 3032 | struct wireless_dev *wdev; |
| 3033 | bool ret = false; |
| 3034 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3035 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3036 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3037 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3038 | continue; |
| 3039 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3040 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3041 | continue; |
| 3042 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3043 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3044 | ret = true; |
| 3045 | break; |
| 3046 | } |
| 3047 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3048 | return ret; |
| 3049 | } |
| 3050 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3051 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3052 | enum nl80211_auth_type auth_type, |
| 3053 | enum nl80211_commands cmd) |
| 3054 | { |
| 3055 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3056 | return false; |
| 3057 | |
| 3058 | switch (cmd) { |
| 3059 | case NL80211_CMD_AUTHENTICATE: |
| 3060 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3061 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3062 | return false; |
| 3063 | return true; |
| 3064 | case NL80211_CMD_CONNECT: |
| 3065 | case NL80211_CMD_START_AP: |
| 3066 | /* SAE not supported yet */ |
| 3067 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3068 | return false; |
| 3069 | return true; |
| 3070 | default: |
| 3071 | return false; |
| 3072 | } |
| 3073 | } |
| 3074 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3075 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3076 | { |
| 3077 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3078 | struct net_device *dev = info->user_ptr[1]; |
| 3079 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3080 | struct cfg80211_ap_settings params; |
| 3081 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3082 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3083 | |
| 3084 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3085 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3086 | return -EOPNOTSUPP; |
| 3087 | |
| 3088 | if (!rdev->ops->start_ap) |
| 3089 | return -EOPNOTSUPP; |
| 3090 | |
| 3091 | if (wdev->beacon_interval) |
| 3092 | return -EALREADY; |
| 3093 | |
| 3094 | memset(¶ms, 0, sizeof(params)); |
| 3095 | |
| 3096 | /* these are required for START_AP */ |
| 3097 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3098 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3099 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3100 | return -EINVAL; |
| 3101 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3102 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3103 | if (err) |
| 3104 | return err; |
| 3105 | |
| 3106 | params.beacon_interval = |
| 3107 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3108 | params.dtim_period = |
| 3109 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3110 | |
| 3111 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3112 | if (err) |
| 3113 | return err; |
| 3114 | |
| 3115 | /* |
| 3116 | * In theory, some of these attributes should be required here |
| 3117 | * but since they were not used when the command was originally |
| 3118 | * added, keep them optional for old user space programs to let |
| 3119 | * them continue to work with drivers that do not need the |
| 3120 | * additional information -- drivers must check! |
| 3121 | */ |
| 3122 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3123 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3124 | params.ssid_len = |
| 3125 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3126 | if (params.ssid_len == 0 || |
| 3127 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3128 | return -EINVAL; |
| 3129 | } |
| 3130 | |
| 3131 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3132 | params.hidden_ssid = nla_get_u32( |
| 3133 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3134 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3135 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3136 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3137 | return -EINVAL; |
| 3138 | } |
| 3139 | |
| 3140 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3141 | |
| 3142 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3143 | params.auth_type = nla_get_u32( |
| 3144 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3145 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3146 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3147 | return -EINVAL; |
| 3148 | } else |
| 3149 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3150 | |
| 3151 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3152 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3153 | if (err) |
| 3154 | return err; |
| 3155 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3156 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3157 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3158 | return -EOPNOTSUPP; |
| 3159 | params.inactivity_timeout = nla_get_u16( |
| 3160 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3161 | } |
| 3162 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3163 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3164 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3165 | return -EINVAL; |
| 3166 | params.p2p_ctwindow = |
| 3167 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3168 | if (params.p2p_ctwindow > 127) |
| 3169 | return -EINVAL; |
| 3170 | if (params.p2p_ctwindow != 0 && |
| 3171 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3172 | return -EINVAL; |
| 3173 | } |
| 3174 | |
| 3175 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3176 | u8 tmp; |
| 3177 | |
| 3178 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3179 | return -EINVAL; |
| 3180 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3181 | if (tmp > 1) |
| 3182 | return -EINVAL; |
| 3183 | params.p2p_opp_ps = tmp; |
| 3184 | if (params.p2p_opp_ps != 0 && |
| 3185 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3186 | return -EINVAL; |
| 3187 | } |
| 3188 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3189 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3190 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3191 | if (err) |
| 3192 | return err; |
| 3193 | } else if (wdev->preset_chandef.chan) { |
| 3194 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3195 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3196 | return -EINVAL; |
| 3197 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3198 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3199 | return -EINVAL; |
| 3200 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3201 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3202 | if (err < 0) |
| 3203 | return err; |
| 3204 | if (err) { |
| 3205 | radar_detect_width = BIT(params.chandef.width); |
| 3206 | params.radar_required = true; |
| 3207 | } |
| 3208 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3209 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3210 | params.chandef.chan, |
| 3211 | CHAN_MODE_SHARED, |
| 3212 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3213 | if (err) |
| 3214 | return err; |
| 3215 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3216 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3217 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3218 | if (IS_ERR(params.acl)) |
| 3219 | return PTR_ERR(params.acl); |
| 3220 | } |
| 3221 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3222 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3223 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3224 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3225 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3226 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3227 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3228 | wdev->ssid_len = params.ssid_len; |
| 3229 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3230 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3231 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3232 | |
| 3233 | kfree(params.acl); |
| 3234 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3235 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3236 | } |
| 3237 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3238 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3239 | { |
| 3240 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3241 | struct net_device *dev = info->user_ptr[1]; |
| 3242 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3243 | struct cfg80211_beacon_data params; |
| 3244 | int err; |
| 3245 | |
| 3246 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3247 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3248 | return -EOPNOTSUPP; |
| 3249 | |
| 3250 | if (!rdev->ops->change_beacon) |
| 3251 | return -EOPNOTSUPP; |
| 3252 | |
| 3253 | if (!wdev->beacon_interval) |
| 3254 | return -EINVAL; |
| 3255 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3256 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3257 | if (err) |
| 3258 | return err; |
| 3259 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3260 | wdev_lock(wdev); |
| 3261 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3262 | wdev_unlock(wdev); |
| 3263 | |
| 3264 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | 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] | 3268 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3269 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3270 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3271 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3272 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3273 | } |
| 3274 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3275 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3276 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3277 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3278 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3279 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3280 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3281 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3282 | }; |
| 3283 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3284 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3285 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3286 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3287 | { |
| 3288 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3289 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3290 | int flag; |
| 3291 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3292 | /* |
| 3293 | * Try parsing the new attribute first so userspace |
| 3294 | * can specify both for older kernels. |
| 3295 | */ |
| 3296 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3297 | if (nla) { |
| 3298 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3299 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3300 | sta_flags = nla_data(nla); |
| 3301 | params->sta_flags_mask = sta_flags->mask; |
| 3302 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3303 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3304 | if ((params->sta_flags_mask | |
| 3305 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3306 | return -EINVAL; |
| 3307 | return 0; |
| 3308 | } |
| 3309 | |
| 3310 | /* if present, parse the old attribute */ |
| 3311 | |
| 3312 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3313 | if (!nla) |
| 3314 | return 0; |
| 3315 | |
| 3316 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3317 | nla, sta_flags_policy)) |
| 3318 | return -EINVAL; |
| 3319 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3320 | /* |
| 3321 | * Only allow certain flags for interface types so that |
| 3322 | * other attributes are silently ignored. Remember that |
| 3323 | * this is backward compatibility code with old userspace |
| 3324 | * and shouldn't be hit in other cases anyway. |
| 3325 | */ |
| 3326 | switch (iftype) { |
| 3327 | case NL80211_IFTYPE_AP: |
| 3328 | case NL80211_IFTYPE_AP_VLAN: |
| 3329 | case NL80211_IFTYPE_P2P_GO: |
| 3330 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3331 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3332 | BIT(NL80211_STA_FLAG_WME) | |
| 3333 | BIT(NL80211_STA_FLAG_MFP); |
| 3334 | break; |
| 3335 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3336 | case NL80211_IFTYPE_STATION: |
| 3337 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3338 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3339 | break; |
| 3340 | case NL80211_IFTYPE_MESH_POINT: |
| 3341 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3342 | BIT(NL80211_STA_FLAG_MFP) | |
| 3343 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3344 | default: |
| 3345 | return -EINVAL; |
| 3346 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3347 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3348 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3349 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3350 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3351 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3352 | /* no longer support new API additions in old API */ |
| 3353 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3354 | return -EINVAL; |
| 3355 | } |
| 3356 | } |
| 3357 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3358 | return 0; |
| 3359 | } |
| 3360 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3361 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3362 | int attr) |
| 3363 | { |
| 3364 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3365 | u32 bitrate; |
| 3366 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3367 | |
| 3368 | rate = nla_nest_start(msg, attr); |
| 3369 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3370 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3371 | |
| 3372 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3373 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3374 | /* report 16-bit bitrate only if we can */ |
| 3375 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3376 | if (bitrate > 0 && |
| 3377 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3378 | return false; |
| 3379 | if (bitrate_compat > 0 && |
| 3380 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3381 | return false; |
| 3382 | |
| 3383 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3384 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3385 | return false; |
| 3386 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3387 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3388 | return false; |
| 3389 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3390 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3391 | return false; |
| 3392 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3393 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3394 | return false; |
| 3395 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3396 | return false; |
| 3397 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3398 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3399 | return false; |
| 3400 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3401 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3402 | return false; |
| 3403 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3404 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3405 | return false; |
| 3406 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3407 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3408 | return false; |
| 3409 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3410 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3411 | return false; |
| 3412 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3413 | |
| 3414 | nla_nest_end(msg, rate); |
| 3415 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3416 | } |
| 3417 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3418 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3419 | int id) |
| 3420 | { |
| 3421 | void *attr; |
| 3422 | int i = 0; |
| 3423 | |
| 3424 | if (!mask) |
| 3425 | return true; |
| 3426 | |
| 3427 | attr = nla_nest_start(msg, id); |
| 3428 | if (!attr) |
| 3429 | return false; |
| 3430 | |
| 3431 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3432 | if (!(mask & BIT(i))) |
| 3433 | continue; |
| 3434 | |
| 3435 | if (nla_put_u8(msg, i, signal[i])) |
| 3436 | return false; |
| 3437 | } |
| 3438 | |
| 3439 | nla_nest_end(msg, attr); |
| 3440 | |
| 3441 | return true; |
| 3442 | } |
| 3443 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3444 | 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] | 3445 | int flags, |
| 3446 | struct cfg80211_registered_device *rdev, |
| 3447 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3448 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3449 | { |
| 3450 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3451 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3452 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3453 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3454 | if (!hdr) |
| 3455 | return -1; |
| 3456 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3457 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3458 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3459 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3460 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3461 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3462 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3463 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3464 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3465 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3466 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3467 | sinfo->connected_time)) |
| 3468 | goto nla_put_failure; |
| 3469 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3470 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3471 | sinfo->inactive_time)) |
| 3472 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3473 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3474 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3475 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3476 | (u32)sinfo->rx_bytes)) |
| 3477 | goto nla_put_failure; |
| 3478 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3479 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3480 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3481 | (u32)sinfo->tx_bytes)) |
| 3482 | goto nla_put_failure; |
| 3483 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3484 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3485 | sinfo->rx_bytes)) |
| 3486 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3487 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3488 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3489 | sinfo->tx_bytes)) |
| 3490 | goto nla_put_failure; |
| 3491 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3492 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3493 | goto nla_put_failure; |
| 3494 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3495 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3496 | goto nla_put_failure; |
| 3497 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3498 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3499 | sinfo->plink_state)) |
| 3500 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3501 | switch (rdev->wiphy.signal_type) { |
| 3502 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3503 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3504 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3505 | sinfo->signal)) |
| 3506 | goto nla_put_failure; |
| 3507 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3508 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3509 | sinfo->signal_avg)) |
| 3510 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3511 | break; |
| 3512 | default: |
| 3513 | break; |
| 3514 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3515 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3516 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3517 | sinfo->chain_signal, |
| 3518 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3519 | goto nla_put_failure; |
| 3520 | } |
| 3521 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3522 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3523 | sinfo->chain_signal_avg, |
| 3524 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3525 | goto nla_put_failure; |
| 3526 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3527 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3528 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3529 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3530 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3531 | } |
| 3532 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3533 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3534 | NL80211_STA_INFO_RX_BITRATE)) |
| 3535 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3536 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3537 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3538 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3539 | sinfo->rx_packets)) |
| 3540 | goto nla_put_failure; |
| 3541 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3542 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3543 | sinfo->tx_packets)) |
| 3544 | goto nla_put_failure; |
| 3545 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3546 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3547 | sinfo->tx_retries)) |
| 3548 | goto nla_put_failure; |
| 3549 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3550 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3551 | sinfo->tx_failed)) |
| 3552 | goto nla_put_failure; |
| 3553 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3554 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3555 | sinfo->beacon_loss_count)) |
| 3556 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3557 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3558 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3559 | sinfo->local_pm)) |
| 3560 | goto nla_put_failure; |
| 3561 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3562 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3563 | sinfo->peer_pm)) |
| 3564 | goto nla_put_failure; |
| 3565 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3566 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3567 | sinfo->nonpeer_pm)) |
| 3568 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3569 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3570 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3571 | if (!bss_param) |
| 3572 | goto nla_put_failure; |
| 3573 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3574 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3575 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3576 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3577 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3578 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3579 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3580 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3581 | sinfo->bss_param.dtim_period) || |
| 3582 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3583 | sinfo->bss_param.beacon_interval)) |
| 3584 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3585 | |
| 3586 | nla_nest_end(msg, bss_param); |
| 3587 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3588 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3589 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3590 | sizeof(struct nl80211_sta_flag_update), |
| 3591 | &sinfo->sta_flags)) |
| 3592 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3593 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3594 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3595 | sinfo->t_offset)) |
| 3596 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3597 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3598 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3599 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3600 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3601 | sinfo->assoc_req_ies)) |
| 3602 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3603 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3604 | return genlmsg_end(msg, hdr); |
| 3605 | |
| 3606 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3607 | genlmsg_cancel(msg, hdr); |
| 3608 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3609 | } |
| 3610 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3611 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3612 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3613 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3614 | struct station_info sinfo; |
| 3615 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3616 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3617 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3618 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3619 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3620 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3621 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3622 | if (err) |
| 3623 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3624 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3625 | if (!wdev->netdev) { |
| 3626 | err = -EINVAL; |
| 3627 | goto out_err; |
| 3628 | } |
| 3629 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3630 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3631 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3632 | goto out_err; |
| 3633 | } |
| 3634 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3635 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3636 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3637 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3638 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3639 | if (err == -ENOENT) |
| 3640 | break; |
| 3641 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3642 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3643 | |
| 3644 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3645 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3646 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3647 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3648 | &sinfo) < 0) |
| 3649 | goto out; |
| 3650 | |
| 3651 | sta_idx++; |
| 3652 | } |
| 3653 | |
| 3654 | |
| 3655 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3656 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3657 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3658 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3659 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3660 | |
| 3661 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3662 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3663 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3664 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3665 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3666 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3667 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3668 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3669 | struct sk_buff *msg; |
| 3670 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3671 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3672 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3673 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3674 | |
| 3675 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3676 | return -EINVAL; |
| 3677 | |
| 3678 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3679 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3680 | if (!rdev->ops->get_station) |
| 3681 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3682 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3683 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3684 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3685 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3686 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3687 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3688 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3689 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3690 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3691 | 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] | 3692 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3693 | nlmsg_free(msg); |
| 3694 | return -ENOBUFS; |
| 3695 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3696 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3697 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3698 | } |
| 3699 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3700 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3701 | struct station_parameters *params, |
| 3702 | enum cfg80211_station_type statype) |
| 3703 | { |
| 3704 | if (params->listen_interval != -1) |
| 3705 | return -EINVAL; |
| 3706 | if (params->aid) |
| 3707 | return -EINVAL; |
| 3708 | |
| 3709 | /* When you run into this, adjust the code below for the new flag */ |
| 3710 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3711 | |
| 3712 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3713 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3714 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3715 | /* |
| 3716 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3717 | * code doesn't have the bug of including TDLS in the |
| 3718 | * mask everywhere. |
| 3719 | */ |
| 3720 | if (params->sta_flags_mask & |
| 3721 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3722 | BIT(NL80211_STA_FLAG_MFP) | |
| 3723 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3724 | return -EINVAL; |
| 3725 | break; |
| 3726 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3727 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3728 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3729 | return -EINVAL; |
| 3730 | /* ignore since it can't change */ |
| 3731 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3732 | break; |
| 3733 | default: |
| 3734 | /* disallow mesh-specific things */ |
| 3735 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3736 | return -EINVAL; |
| 3737 | if (params->local_pm) |
| 3738 | return -EINVAL; |
| 3739 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3740 | return -EINVAL; |
| 3741 | } |
| 3742 | |
| 3743 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3744 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3745 | /* TDLS can't be set, ... */ |
| 3746 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3747 | return -EINVAL; |
| 3748 | /* |
| 3749 | * ... but don't bother the driver with it. This works around |
| 3750 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3751 | * TLDS_PEER flag in the mask even for AP mode. |
| 3752 | */ |
| 3753 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3754 | } |
| 3755 | |
| 3756 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3757 | /* reject other things that can't change */ |
| 3758 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3759 | return -EINVAL; |
| 3760 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3761 | return -EINVAL; |
| 3762 | if (params->supported_rates) |
| 3763 | return -EINVAL; |
| 3764 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3765 | return -EINVAL; |
| 3766 | } |
| 3767 | |
| 3768 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3769 | if (params->vlan) |
| 3770 | return -EINVAL; |
| 3771 | } |
| 3772 | |
| 3773 | switch (statype) { |
| 3774 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3775 | /* Use this only for authorizing/unauthorizing a station */ |
| 3776 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3777 | return -EOPNOTSUPP; |
| 3778 | break; |
| 3779 | case CFG80211_STA_AP_CLIENT: |
| 3780 | /* accept only the listed bits */ |
| 3781 | if (params->sta_flags_mask & |
| 3782 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3783 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3784 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3785 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3786 | BIT(NL80211_STA_FLAG_WME) | |
| 3787 | BIT(NL80211_STA_FLAG_MFP))) |
| 3788 | return -EINVAL; |
| 3789 | |
| 3790 | /* but authenticated/associated only if driver handles it */ |
| 3791 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3792 | params->sta_flags_mask & |
| 3793 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3794 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3795 | return -EINVAL; |
| 3796 | break; |
| 3797 | case CFG80211_STA_IBSS: |
| 3798 | case CFG80211_STA_AP_STA: |
| 3799 | /* reject any changes other than AUTHORIZED */ |
| 3800 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3801 | return -EINVAL; |
| 3802 | break; |
| 3803 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3804 | /* reject any changes other than AUTHORIZED or WME */ |
| 3805 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3806 | BIT(NL80211_STA_FLAG_WME))) |
| 3807 | return -EINVAL; |
| 3808 | /* force (at least) rates when authorizing */ |
| 3809 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3810 | !params->supported_rates) |
| 3811 | return -EINVAL; |
| 3812 | break; |
| 3813 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3814 | /* reject any changes */ |
| 3815 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3816 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3817 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3818 | return -EINVAL; |
| 3819 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3820 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3821 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3822 | return -EINVAL; |
| 3823 | break; |
| 3824 | } |
| 3825 | |
| 3826 | return 0; |
| 3827 | } |
| 3828 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3829 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3830 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3831 | * 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] | 3832 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3833 | static struct net_device *get_vlan(struct genl_info *info, |
| 3834 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3835 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3836 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3837 | struct net_device *v; |
| 3838 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3839 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3840 | if (!vlanattr) |
| 3841 | return NULL; |
| 3842 | |
| 3843 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3844 | if (!v) |
| 3845 | return ERR_PTR(-ENODEV); |
| 3846 | |
| 3847 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3848 | ret = -EINVAL; |
| 3849 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3850 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3851 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3852 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3853 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3854 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3855 | ret = -EINVAL; |
| 3856 | goto error; |
| 3857 | } |
| 3858 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3859 | if (!netif_running(v)) { |
| 3860 | ret = -ENETDOWN; |
| 3861 | goto error; |
| 3862 | } |
| 3863 | |
| 3864 | return v; |
| 3865 | error: |
| 3866 | dev_put(v); |
| 3867 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3868 | } |
| 3869 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3870 | static struct nla_policy |
| 3871 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3872 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3873 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3874 | }; |
| 3875 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3876 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3877 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3878 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3879 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3880 | struct nlattr *nla; |
| 3881 | int err; |
| 3882 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3883 | /* parse WME attributes if present */ |
| 3884 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3885 | return 0; |
| 3886 | |
| 3887 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3888 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3889 | nl80211_sta_wme_policy); |
| 3890 | if (err) |
| 3891 | return err; |
| 3892 | |
| 3893 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3894 | params->uapsd_queues = nla_get_u8( |
| 3895 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3896 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3897 | return -EINVAL; |
| 3898 | |
| 3899 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3900 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3901 | |
| 3902 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3903 | return -EINVAL; |
| 3904 | |
| 3905 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3906 | |
| 3907 | return 0; |
| 3908 | } |
| 3909 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3910 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 3911 | struct station_parameters *params) |
| 3912 | { |
| 3913 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 3914 | params->supported_channels = |
| 3915 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3916 | params->supported_channels_len = |
| 3917 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3918 | /* |
| 3919 | * Need to include at least one (first channel, number of |
| 3920 | * channels) tuple for each subband, and must have proper |
| 3921 | * tuples for the rest of the data as well. |
| 3922 | */ |
| 3923 | if (params->supported_channels_len < 2) |
| 3924 | return -EINVAL; |
| 3925 | if (params->supported_channels_len % 2) |
| 3926 | return -EINVAL; |
| 3927 | } |
| 3928 | |
| 3929 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 3930 | params->supported_oper_classes = |
| 3931 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3932 | params->supported_oper_classes_len = |
| 3933 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3934 | /* |
| 3935 | * The value of the Length field of the Supported Operating |
| 3936 | * Classes element is between 2 and 253. |
| 3937 | */ |
| 3938 | if (params->supported_oper_classes_len < 2 || |
| 3939 | params->supported_oper_classes_len > 253) |
| 3940 | return -EINVAL; |
| 3941 | } |
| 3942 | return 0; |
| 3943 | } |
| 3944 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3945 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3946 | struct station_parameters *params) |
| 3947 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3948 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3949 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3950 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3951 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3952 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3953 | params->ht_capa = |
| 3954 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3955 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3956 | params->vht_capa = |
| 3957 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3958 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3959 | err = nl80211_parse_sta_channel_info(info, params); |
| 3960 | if (err) |
| 3961 | return err; |
| 3962 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3963 | return nl80211_parse_sta_wme(info, params); |
| 3964 | } |
| 3965 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3966 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3967 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3968 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3969 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3970 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3971 | u8 *mac_addr; |
| 3972 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3973 | |
| 3974 | memset(¶ms, 0, sizeof(params)); |
| 3975 | |
| 3976 | params.listen_interval = -1; |
| 3977 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3978 | if (!rdev->ops->change_station) |
| 3979 | return -EOPNOTSUPP; |
| 3980 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3981 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3982 | return -EINVAL; |
| 3983 | |
| 3984 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3985 | return -EINVAL; |
| 3986 | |
| 3987 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3988 | |
| 3989 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3990 | params.supported_rates = |
| 3991 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3992 | params.supported_rates_len = |
| 3993 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3994 | } |
| 3995 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3996 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3997 | params.capability = |
| 3998 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3999 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4000 | } |
| 4001 | |
| 4002 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4003 | params.ext_capab = |
| 4004 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4005 | params.ext_capab_len = |
| 4006 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4007 | } |
| 4008 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4009 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4010 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4011 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4012 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4013 | return -EINVAL; |
| 4014 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4015 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4016 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4017 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4018 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4019 | return -EINVAL; |
| 4020 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4021 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4022 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4023 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4024 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4025 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4026 | return -EINVAL; |
| 4027 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4028 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4029 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4030 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4031 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4032 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4033 | |
| 4034 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4035 | pm > NL80211_MESH_POWER_MAX) |
| 4036 | return -EINVAL; |
| 4037 | |
| 4038 | params.local_pm = pm; |
| 4039 | } |
| 4040 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4041 | /* Include parameters for TDLS peer (will check later) */ |
| 4042 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4043 | if (err) |
| 4044 | return err; |
| 4045 | |
| 4046 | params.vlan = get_vlan(info, rdev); |
| 4047 | if (IS_ERR(params.vlan)) |
| 4048 | return PTR_ERR(params.vlan); |
| 4049 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4050 | switch (dev->ieee80211_ptr->iftype) { |
| 4051 | case NL80211_IFTYPE_AP: |
| 4052 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4053 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4054 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4055 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4056 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4057 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4058 | break; |
| 4059 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4060 | err = -EOPNOTSUPP; |
| 4061 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4062 | } |
| 4063 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4064 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4065 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4066 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4067 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4068 | if (params.vlan) |
| 4069 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4070 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4071 | return err; |
| 4072 | } |
| 4073 | |
| 4074 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4075 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4076 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4077 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4078 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4079 | struct station_parameters params; |
| 4080 | u8 *mac_addr = NULL; |
| 4081 | |
| 4082 | memset(¶ms, 0, sizeof(params)); |
| 4083 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4084 | if (!rdev->ops->add_station) |
| 4085 | return -EOPNOTSUPP; |
| 4086 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4087 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4088 | return -EINVAL; |
| 4089 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4090 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4091 | return -EINVAL; |
| 4092 | |
| 4093 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4094 | return -EINVAL; |
| 4095 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4096 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4097 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4098 | return -EINVAL; |
| 4099 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4100 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4101 | params.supported_rates = |
| 4102 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4103 | params.supported_rates_len = |
| 4104 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4105 | params.listen_interval = |
| 4106 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4107 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4108 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4109 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4110 | else |
| 4111 | 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] | 4112 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4113 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4114 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4115 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4116 | params.capability = |
| 4117 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4118 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4119 | } |
| 4120 | |
| 4121 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4122 | params.ext_capab = |
| 4123 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4124 | params.ext_capab_len = |
| 4125 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4126 | } |
| 4127 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4128 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4129 | params.ht_capa = |
| 4130 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4131 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4132 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4133 | params.vht_capa = |
| 4134 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4135 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4136 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4137 | params.opmode_notif_used = true; |
| 4138 | params.opmode_notif = |
| 4139 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4140 | } |
| 4141 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4142 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4143 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4144 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4145 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4146 | return -EINVAL; |
| 4147 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4148 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4149 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4150 | if (err) |
| 4151 | return err; |
| 4152 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4153 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4154 | if (err) |
| 4155 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4156 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4157 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4158 | return -EINVAL; |
| 4159 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4160 | /* When you run into this, adjust the code below for the new flag */ |
| 4161 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4162 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4163 | switch (dev->ieee80211_ptr->iftype) { |
| 4164 | case NL80211_IFTYPE_AP: |
| 4165 | case NL80211_IFTYPE_AP_VLAN: |
| 4166 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4167 | /* ignore WME attributes if iface/sta is not capable */ |
| 4168 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4169 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4170 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4171 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4172 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4173 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4174 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4175 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4176 | /* but don't bother the driver with it */ |
| 4177 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4178 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4179 | /* allow authenticated/associated only if driver handles it */ |
| 4180 | if (!(rdev->wiphy.features & |
| 4181 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4182 | params.sta_flags_mask & |
| 4183 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4184 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4185 | return -EINVAL; |
| 4186 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4187 | /* must be last in here for error handling */ |
| 4188 | params.vlan = get_vlan(info, rdev); |
| 4189 | if (IS_ERR(params.vlan)) |
| 4190 | return PTR_ERR(params.vlan); |
| 4191 | break; |
| 4192 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4193 | /* ignore uAPSD data */ |
| 4194 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4195 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4196 | /* associated is disallowed */ |
| 4197 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4198 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4199 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4200 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4201 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4202 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4203 | break; |
| 4204 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4205 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4206 | /* ignore uAPSD data */ |
| 4207 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4208 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4209 | /* these are disallowed */ |
| 4210 | if (params.sta_flags_mask & |
| 4211 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4212 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4213 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4214 | /* Only TDLS peers can be added */ |
| 4215 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4216 | return -EINVAL; |
| 4217 | /* Can only add if TDLS ... */ |
| 4218 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4219 | return -EOPNOTSUPP; |
| 4220 | /* ... with external setup is supported */ |
| 4221 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4222 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4223 | /* |
| 4224 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4225 | * as authorized, but it shouldn't yet be. |
| 4226 | */ |
| 4227 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4228 | break; |
| 4229 | default: |
| 4230 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4231 | } |
| 4232 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4233 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4234 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4235 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4236 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4237 | if (params.vlan) |
| 4238 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4239 | return err; |
| 4240 | } |
| 4241 | |
| 4242 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4243 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4244 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4245 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4246 | u8 *mac_addr = NULL; |
| 4247 | |
| 4248 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4249 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4250 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4251 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4252 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4253 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4254 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4255 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4256 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4257 | if (!rdev->ops->del_station) |
| 4258 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4259 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4260 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4261 | } |
| 4262 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4263 | 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] | 4264 | int flags, struct net_device *dev, |
| 4265 | u8 *dst, u8 *next_hop, |
| 4266 | struct mpath_info *pinfo) |
| 4267 | { |
| 4268 | void *hdr; |
| 4269 | struct nlattr *pinfoattr; |
| 4270 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4271 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4272 | if (!hdr) |
| 4273 | return -1; |
| 4274 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4275 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4276 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4277 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4278 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4279 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4280 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4281 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4282 | if (!pinfoattr) |
| 4283 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4284 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4285 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4286 | pinfo->frame_qlen)) |
| 4287 | goto nla_put_failure; |
| 4288 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4289 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4290 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4291 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4292 | pinfo->metric)) || |
| 4293 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4294 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4295 | pinfo->exptime)) || |
| 4296 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4297 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4298 | pinfo->flags)) || |
| 4299 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4300 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4301 | pinfo->discovery_timeout)) || |
| 4302 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4303 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4304 | pinfo->discovery_retries))) |
| 4305 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4306 | |
| 4307 | nla_nest_end(msg, pinfoattr); |
| 4308 | |
| 4309 | return genlmsg_end(msg, hdr); |
| 4310 | |
| 4311 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4312 | genlmsg_cancel(msg, hdr); |
| 4313 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4314 | } |
| 4315 | |
| 4316 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4317 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4318 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4319 | struct mpath_info pinfo; |
| 4320 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4321 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4322 | u8 dst[ETH_ALEN]; |
| 4323 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4324 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4325 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4326 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4327 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4328 | if (err) |
| 4329 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4330 | |
| 4331 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4332 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4333 | goto out_err; |
| 4334 | } |
| 4335 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4336 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4337 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4338 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4339 | } |
| 4340 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4341 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4342 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4343 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4344 | if (err == -ENOENT) |
| 4345 | break; |
| 4346 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4347 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4348 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4349 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4350 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4351 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4352 | &pinfo) < 0) |
| 4353 | goto out; |
| 4354 | |
| 4355 | path_idx++; |
| 4356 | } |
| 4357 | |
| 4358 | |
| 4359 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4360 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4361 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4362 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4363 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4364 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4365 | } |
| 4366 | |
| 4367 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4368 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4369 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4370 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4371 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4372 | struct mpath_info pinfo; |
| 4373 | struct sk_buff *msg; |
| 4374 | u8 *dst = NULL; |
| 4375 | u8 next_hop[ETH_ALEN]; |
| 4376 | |
| 4377 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4378 | |
| 4379 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4380 | return -EINVAL; |
| 4381 | |
| 4382 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4383 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4384 | if (!rdev->ops->get_mpath) |
| 4385 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4386 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4387 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4388 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4389 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4390 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4391 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4392 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4393 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4394 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4395 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4396 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4397 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4398 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4399 | dev, dst, next_hop, &pinfo) < 0) { |
| 4400 | nlmsg_free(msg); |
| 4401 | return -ENOBUFS; |
| 4402 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4403 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4404 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4408 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4409 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4410 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4411 | u8 *dst = NULL; |
| 4412 | u8 *next_hop = NULL; |
| 4413 | |
| 4414 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4415 | return -EINVAL; |
| 4416 | |
| 4417 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4418 | return -EINVAL; |
| 4419 | |
| 4420 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4421 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4422 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4423 | if (!rdev->ops->change_mpath) |
| 4424 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4425 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4426 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4427 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4428 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4429 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4430 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4431 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4432 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4433 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4434 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4435 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4436 | u8 *dst = NULL; |
| 4437 | u8 *next_hop = NULL; |
| 4438 | |
| 4439 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4440 | return -EINVAL; |
| 4441 | |
| 4442 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4443 | return -EINVAL; |
| 4444 | |
| 4445 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4446 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4447 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4448 | if (!rdev->ops->add_mpath) |
| 4449 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4450 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4451 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4452 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4453 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4454 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4455 | } |
| 4456 | |
| 4457 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4458 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4459 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4460 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4461 | u8 *dst = NULL; |
| 4462 | |
| 4463 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4464 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4465 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4466 | if (!rdev->ops->del_mpath) |
| 4467 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4468 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4469 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4470 | } |
| 4471 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4472 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4473 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4474 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4475 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4476 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4477 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4478 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4479 | |
| 4480 | memset(¶ms, 0, sizeof(params)); |
| 4481 | /* default to not changing parameters */ |
| 4482 | params.use_cts_prot = -1; |
| 4483 | params.use_short_preamble = -1; |
| 4484 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4485 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4486 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4487 | params.p2p_ctwindow = -1; |
| 4488 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4489 | |
| 4490 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4491 | params.use_cts_prot = |
| 4492 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4493 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4494 | params.use_short_preamble = |
| 4495 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4496 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4497 | params.use_short_slot_time = |
| 4498 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4499 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4500 | params.basic_rates = |
| 4501 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4502 | params.basic_rates_len = |
| 4503 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4504 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4505 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4506 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4507 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4508 | params.ht_opmode = |
| 4509 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4510 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4511 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4512 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4513 | return -EINVAL; |
| 4514 | params.p2p_ctwindow = |
| 4515 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4516 | if (params.p2p_ctwindow < 0) |
| 4517 | return -EINVAL; |
| 4518 | if (params.p2p_ctwindow != 0 && |
| 4519 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4520 | return -EINVAL; |
| 4521 | } |
| 4522 | |
| 4523 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4524 | u8 tmp; |
| 4525 | |
| 4526 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4527 | return -EINVAL; |
| 4528 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4529 | if (tmp > 1) |
| 4530 | return -EINVAL; |
| 4531 | params.p2p_opp_ps = tmp; |
| 4532 | if (params.p2p_opp_ps && |
| 4533 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4534 | return -EINVAL; |
| 4535 | } |
| 4536 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4537 | if (!rdev->ops->change_bss) |
| 4538 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4539 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4540 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4541 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4542 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4543 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4544 | wdev_lock(wdev); |
| 4545 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4546 | wdev_unlock(wdev); |
| 4547 | |
| 4548 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4549 | } |
| 4550 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4551 | 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] | 4552 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4553 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4554 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4555 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4556 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4557 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4558 | }; |
| 4559 | |
| 4560 | static int parse_reg_rule(struct nlattr *tb[], |
| 4561 | struct ieee80211_reg_rule *reg_rule) |
| 4562 | { |
| 4563 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4564 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4565 | |
| 4566 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4567 | return -EINVAL; |
| 4568 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4569 | return -EINVAL; |
| 4570 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4571 | return -EINVAL; |
| 4572 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4573 | return -EINVAL; |
| 4574 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4575 | return -EINVAL; |
| 4576 | |
| 4577 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4578 | |
| 4579 | freq_range->start_freq_khz = |
| 4580 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4581 | freq_range->end_freq_khz = |
| 4582 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4583 | freq_range->max_bandwidth_khz = |
| 4584 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4585 | |
| 4586 | power_rule->max_eirp = |
| 4587 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4588 | |
| 4589 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4590 | power_rule->max_antenna_gain = |
| 4591 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4592 | |
| 4593 | return 0; |
| 4594 | } |
| 4595 | |
| 4596 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4597 | { |
| 4598 | int r; |
| 4599 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4600 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4601 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4602 | /* |
| 4603 | * You should only get this when cfg80211 hasn't yet initialized |
| 4604 | * completely when built-in to the kernel right between the time |
| 4605 | * window between nl80211_init() and regulatory_init(), if that is |
| 4606 | * even possible. |
| 4607 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4608 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4609 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4610 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4611 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4612 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4613 | |
| 4614 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4615 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4616 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4617 | user_reg_hint_type = |
| 4618 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4619 | else |
| 4620 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4621 | |
| 4622 | switch (user_reg_hint_type) { |
| 4623 | case NL80211_USER_REG_HINT_USER: |
| 4624 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4625 | break; |
| 4626 | default: |
| 4627 | return -EINVAL; |
| 4628 | } |
| 4629 | |
| 4630 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4631 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4632 | return r; |
| 4633 | } |
| 4634 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4635 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4636 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4637 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4639 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4640 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4641 | struct mesh_config cur_params; |
| 4642 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4643 | void *hdr; |
| 4644 | struct nlattr *pinfoattr; |
| 4645 | struct sk_buff *msg; |
| 4646 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4647 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4648 | return -EOPNOTSUPP; |
| 4649 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4650 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4651 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4652 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4653 | wdev_lock(wdev); |
| 4654 | /* If not connected, get default parameters */ |
| 4655 | if (!wdev->mesh_id_len) |
| 4656 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4657 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4658 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4659 | wdev_unlock(wdev); |
| 4660 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4661 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4662 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4663 | |
| 4664 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4665 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4666 | if (!msg) |
| 4667 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4668 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4669 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4670 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4671 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4672 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4673 | if (!pinfoattr) |
| 4674 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4675 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4676 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4677 | cur_params.dot11MeshRetryTimeout) || |
| 4678 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4679 | cur_params.dot11MeshConfirmTimeout) || |
| 4680 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4681 | cur_params.dot11MeshHoldingTimeout) || |
| 4682 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4683 | cur_params.dot11MeshMaxPeerLinks) || |
| 4684 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4685 | cur_params.dot11MeshMaxRetries) || |
| 4686 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4687 | cur_params.dot11MeshTTL) || |
| 4688 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4689 | cur_params.element_ttl) || |
| 4690 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4691 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4692 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4693 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4694 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4695 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4696 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4697 | cur_params.path_refresh_time) || |
| 4698 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4699 | cur_params.min_discovery_timeout) || |
| 4700 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4701 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4702 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4703 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4704 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4705 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4706 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4707 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4708 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4709 | cur_params.dot11MeshHWMPRootMode) || |
| 4710 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4711 | cur_params.dot11MeshHWMPRannInterval) || |
| 4712 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4713 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4714 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4715 | cur_params.dot11MeshForwarding) || |
| 4716 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4717 | cur_params.rssi_threshold) || |
| 4718 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4719 | cur_params.ht_opmode) || |
| 4720 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4721 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4722 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4723 | cur_params.dot11MeshHWMProotInterval) || |
| 4724 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4725 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4726 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4727 | cur_params.power_mode) || |
| 4728 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4729 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4730 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4731 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4732 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4733 | nla_nest_end(msg, pinfoattr); |
| 4734 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4735 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4736 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4737 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4738 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4739 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4740 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4741 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4742 | } |
| 4743 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4744 | 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] | 4745 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4746 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4747 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4748 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4749 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4750 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4751 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4752 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4753 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4754 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4755 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4756 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4757 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4758 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4759 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4760 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4761 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4762 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4763 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4764 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4765 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4766 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4767 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4768 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4769 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4770 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4771 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4772 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4773 | }; |
| 4774 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4775 | static const struct nla_policy |
| 4776 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4777 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4778 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4779 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4780 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4781 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4782 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4783 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4784 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4785 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4786 | }; |
| 4787 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4788 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4789 | struct mesh_config *cfg, |
| 4790 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4791 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4792 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4793 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4794 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4795 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4796 | do { \ |
| 4797 | if (tb[attr]) { \ |
| 4798 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4799 | return -EINVAL; \ |
| 4800 | cfg->param = fn(tb[attr]); \ |
| 4801 | mask |= (1 << (attr - 1)); \ |
| 4802 | } \ |
| 4803 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4804 | |
| 4805 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4806 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4807 | return -EINVAL; |
| 4808 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4809 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4810 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4811 | return -EINVAL; |
| 4812 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4813 | /* This makes sure that there aren't more than 32 mesh config |
| 4814 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4815 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4816 | |
| 4817 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4818 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4819 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4820 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4821 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4822 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4823 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4824 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4825 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4826 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4827 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4828 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4829 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4830 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4831 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4832 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4833 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4834 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4835 | 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] | 4836 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4837 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4838 | 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] | 4839 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4840 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4841 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4842 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4843 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4844 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4845 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4846 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4847 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4848 | 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] | 4849 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4850 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4851 | 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] | 4852 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4853 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4854 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4855 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4856 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4857 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4858 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4859 | 1, 65535, mask, |
| 4860 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4861 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4862 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4863 | 1, 65535, mask, |
| 4864 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4865 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4866 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4867 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4868 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4869 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 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, dot11MeshHWMPRootMode, 0, 4, |
| 4872 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4873 | nla_get_u8); |
| 4874 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4875 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4876 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4877 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4878 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4879 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4880 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4881 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4882 | mask, NL80211_MESHCONF_FORWARDING, |
| 4883 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4884 | 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] | 4885 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4886 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4887 | 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] | 4888 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4889 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4890 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4891 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4892 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4893 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4894 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4895 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4896 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4897 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4898 | dot11MeshHWMPconfirmationInterval, |
| 4899 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4900 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4901 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4902 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4903 | NL80211_MESH_POWER_ACTIVE, |
| 4904 | NL80211_MESH_POWER_MAX, |
| 4905 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4906 | nla_get_u32); |
| 4907 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4908 | 0, 65535, mask, |
| 4909 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4910 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4911 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4912 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4913 | if (mask_out) |
| 4914 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4915 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4916 | return 0; |
| 4917 | |
| 4918 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4919 | } |
| 4920 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4921 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4922 | struct mesh_setup *setup) |
| 4923 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4924 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4925 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4926 | |
| 4927 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4928 | return -EINVAL; |
| 4929 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4930 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4931 | nl80211_mesh_setup_params_policy)) |
| 4932 | return -EINVAL; |
| 4933 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4934 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4935 | setup->sync_method = |
| 4936 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4937 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4938 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4939 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4940 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4941 | setup->path_sel_proto = |
| 4942 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4943 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4944 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4945 | |
| 4946 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4947 | setup->path_metric = |
| 4948 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4949 | IEEE80211_PATH_METRIC_VENDOR : |
| 4950 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4951 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4952 | |
| 4953 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4954 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4955 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4956 | if (!is_valid_ie_attr(ieattr)) |
| 4957 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4958 | setup->ie = nla_data(ieattr); |
| 4959 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4960 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4961 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4962 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4963 | return -EINVAL; |
| 4964 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4965 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4966 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4967 | if (setup->is_secure) |
| 4968 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4969 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4970 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 4971 | if (!setup->user_mpm) |
| 4972 | return -EINVAL; |
| 4973 | setup->auth_id = |
| 4974 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 4975 | } |
| 4976 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4977 | return 0; |
| 4978 | } |
| 4979 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4980 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4981 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4982 | { |
| 4983 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4984 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4985 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4986 | struct mesh_config cfg; |
| 4987 | u32 mask; |
| 4988 | int err; |
| 4989 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4990 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4991 | return -EOPNOTSUPP; |
| 4992 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4993 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4994 | return -EOPNOTSUPP; |
| 4995 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4996 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4997 | if (err) |
| 4998 | return err; |
| 4999 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5000 | wdev_lock(wdev); |
| 5001 | if (!wdev->mesh_id_len) |
| 5002 | err = -ENOLINK; |
| 5003 | |
| 5004 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5005 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5006 | |
| 5007 | wdev_unlock(wdev); |
| 5008 | |
| 5009 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5010 | } |
| 5011 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5012 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5013 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5014 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5015 | struct sk_buff *msg; |
| 5016 | void *hdr = NULL; |
| 5017 | struct nlattr *nl_reg_rules; |
| 5018 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5019 | |
| 5020 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5021 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5022 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5023 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5024 | if (!msg) |
| 5025 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5026 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5027 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5028 | NL80211_CMD_GET_REG); |
| 5029 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5030 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5031 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5032 | if (reg_last_request_cell_base() && |
| 5033 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5034 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5035 | goto nla_put_failure; |
| 5036 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5037 | rcu_read_lock(); |
| 5038 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5039 | |
| 5040 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5041 | (regdom->dfs_region && |
| 5042 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5043 | goto nla_put_failure_rcu; |
| 5044 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5045 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5046 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5047 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5048 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5049 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5050 | struct nlattr *nl_reg_rule; |
| 5051 | const struct ieee80211_reg_rule *reg_rule; |
| 5052 | const struct ieee80211_freq_range *freq_range; |
| 5053 | const struct ieee80211_power_rule *power_rule; |
| 5054 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5055 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5056 | freq_range = ®_rule->freq_range; |
| 5057 | power_rule = ®_rule->power_rule; |
| 5058 | |
| 5059 | nl_reg_rule = nla_nest_start(msg, i); |
| 5060 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5061 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5062 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5063 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5064 | reg_rule->flags) || |
| 5065 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5066 | freq_range->start_freq_khz) || |
| 5067 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5068 | freq_range->end_freq_khz) || |
| 5069 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 5070 | freq_range->max_bandwidth_khz) || |
| 5071 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5072 | power_rule->max_antenna_gain) || |
| 5073 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 5074 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5075 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5076 | |
| 5077 | nla_nest_end(msg, nl_reg_rule); |
| 5078 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5079 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5080 | |
| 5081 | nla_nest_end(msg, nl_reg_rules); |
| 5082 | |
| 5083 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5084 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5085 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5086 | nla_put_failure_rcu: |
| 5087 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5088 | nla_put_failure: |
| 5089 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5090 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5091 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5092 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5093 | } |
| 5094 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5095 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5096 | { |
| 5097 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5098 | struct nlattr *nl_reg_rule; |
| 5099 | char *alpha2 = NULL; |
| 5100 | int rem_reg_rules = 0, r = 0; |
| 5101 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5102 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5103 | struct ieee80211_regdomain *rd = NULL; |
| 5104 | |
| 5105 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5106 | return -EINVAL; |
| 5107 | |
| 5108 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5109 | return -EINVAL; |
| 5110 | |
| 5111 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5112 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5113 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5114 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5115 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5116 | 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] | 5117 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5118 | num_rules++; |
| 5119 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5120 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5121 | } |
| 5122 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5123 | if (!reg_is_valid_request(alpha2)) |
| 5124 | return -EINVAL; |
| 5125 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5126 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5127 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5128 | |
| 5129 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5130 | if (!rd) |
| 5131 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5132 | |
| 5133 | rd->n_reg_rules = num_rules; |
| 5134 | rd->alpha2[0] = alpha2[0]; |
| 5135 | rd->alpha2[1] = alpha2[1]; |
| 5136 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5137 | /* |
| 5138 | * Disable DFS master mode if the DFS region was |
| 5139 | * not supported or known on this kernel. |
| 5140 | */ |
| 5141 | if (reg_supported_dfs_region(dfs_region)) |
| 5142 | rd->dfs_region = dfs_region; |
| 5143 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5144 | 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] | 5145 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5146 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5147 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5148 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5149 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5150 | if (r) |
| 5151 | goto bad_reg; |
| 5152 | |
| 5153 | rule_idx++; |
| 5154 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5155 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5156 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5157 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5158 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5161 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5162 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5163 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5164 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5165 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5166 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5167 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5168 | } |
| 5169 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5170 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5171 | { |
| 5172 | struct nlattr *attr1, *attr2; |
| 5173 | int n_channels = 0, tmp1, tmp2; |
| 5174 | |
| 5175 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5176 | n_channels++; |
| 5177 | /* |
| 5178 | * Some hardware has a limited channel list for |
| 5179 | * scanning, and it is pretty much nonsensical |
| 5180 | * to scan for a channel twice, so disallow that |
| 5181 | * and don't require drivers to check that the |
| 5182 | * channel list they get isn't longer than what |
| 5183 | * they can scan, as long as they can scan all |
| 5184 | * the channels they registered at once. |
| 5185 | */ |
| 5186 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5187 | if (attr1 != attr2 && |
| 5188 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5189 | return 0; |
| 5190 | } |
| 5191 | |
| 5192 | return n_channels; |
| 5193 | } |
| 5194 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5195 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5196 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5197 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5198 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5199 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5200 | struct nlattr *attr; |
| 5201 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5202 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5203 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5204 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5205 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5206 | return -EINVAL; |
| 5207 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5208 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5209 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5210 | if (!rdev->ops->scan) |
| 5211 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5212 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5213 | if (rdev->scan_req) { |
| 5214 | err = -EBUSY; |
| 5215 | goto unlock; |
| 5216 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5217 | |
| 5218 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5219 | n_channels = validate_scan_freqs( |
| 5220 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5221 | if (!n_channels) { |
| 5222 | err = -EINVAL; |
| 5223 | goto unlock; |
| 5224 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5225 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5226 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5227 | n_channels = 0; |
| 5228 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5229 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5230 | if (wiphy->bands[band]) |
| 5231 | n_channels += wiphy->bands[band]->n_channels; |
| 5232 | } |
| 5233 | |
| 5234 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5235 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5236 | n_ssids++; |
| 5237 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5238 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5239 | err = -EINVAL; |
| 5240 | goto unlock; |
| 5241 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5242 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5243 | if (info->attrs[NL80211_ATTR_IE]) |
| 5244 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5245 | else |
| 5246 | ie_len = 0; |
| 5247 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5248 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5249 | err = -EINVAL; |
| 5250 | goto unlock; |
| 5251 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5252 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5253 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5254 | + sizeof(*request->ssids) * n_ssids |
| 5255 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5256 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5257 | if (!request) { |
| 5258 | err = -ENOMEM; |
| 5259 | goto unlock; |
| 5260 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5261 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5262 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5263 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5264 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5265 | if (ie_len) { |
| 5266 | if (request->ssids) |
| 5267 | request->ie = (void *)(request->ssids + n_ssids); |
| 5268 | else |
| 5269 | request->ie = (void *)(request->channels + n_channels); |
| 5270 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5271 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5272 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5273 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5274 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5275 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5276 | struct ieee80211_channel *chan; |
| 5277 | |
| 5278 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5279 | |
| 5280 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5281 | err = -EINVAL; |
| 5282 | goto out_free; |
| 5283 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5284 | |
| 5285 | /* ignore disabled channels */ |
| 5286 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5287 | continue; |
| 5288 | |
| 5289 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5290 | i++; |
| 5291 | } |
| 5292 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5293 | enum ieee80211_band band; |
| 5294 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5295 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5296 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5297 | int j; |
| 5298 | if (!wiphy->bands[band]) |
| 5299 | continue; |
| 5300 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5301 | struct ieee80211_channel *chan; |
| 5302 | |
| 5303 | chan = &wiphy->bands[band]->channels[j]; |
| 5304 | |
| 5305 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5306 | continue; |
| 5307 | |
| 5308 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5309 | i++; |
| 5310 | } |
| 5311 | } |
| 5312 | } |
| 5313 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5314 | if (!i) { |
| 5315 | err = -EINVAL; |
| 5316 | goto out_free; |
| 5317 | } |
| 5318 | |
| 5319 | request->n_channels = i; |
| 5320 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5321 | i = 0; |
| 5322 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5323 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5324 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5325 | err = -EINVAL; |
| 5326 | goto out_free; |
| 5327 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5328 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5329 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5330 | i++; |
| 5331 | } |
| 5332 | } |
| 5333 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5334 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5335 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5336 | memcpy((void *)request->ie, |
| 5337 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5338 | request->ie_len); |
| 5339 | } |
| 5340 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5341 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5342 | if (wiphy->bands[i]) |
| 5343 | request->rates[i] = |
| 5344 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5345 | |
| 5346 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5347 | nla_for_each_nested(attr, |
| 5348 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5349 | tmp) { |
| 5350 | enum ieee80211_band band = nla_type(attr); |
| 5351 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5352 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5353 | err = -EINVAL; |
| 5354 | goto out_free; |
| 5355 | } |
| 5356 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5357 | nla_data(attr), |
| 5358 | nla_len(attr), |
| 5359 | &request->rates[band]); |
| 5360 | if (err) |
| 5361 | goto out_free; |
| 5362 | } |
| 5363 | } |
| 5364 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5365 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5366 | request->flags = nla_get_u32( |
| 5367 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5368 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5369 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5370 | err = -EOPNOTSUPP; |
| 5371 | goto out_free; |
| 5372 | } |
| 5373 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5374 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5375 | request->no_cck = |
| 5376 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5377 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5378 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5379 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5380 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5381 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5382 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5383 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5384 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5385 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5386 | nl80211_send_scan_start(rdev, wdev); |
| 5387 | if (wdev->netdev) |
| 5388 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5389 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5390 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5391 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5392 | kfree(request); |
| 5393 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5394 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5395 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5396 | return err; |
| 5397 | } |
| 5398 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5399 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5400 | struct genl_info *info) |
| 5401 | { |
| 5402 | struct cfg80211_sched_scan_request *request; |
| 5403 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5404 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5405 | struct nlattr *attr; |
| 5406 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5407 | 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] | 5408 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5409 | enum ieee80211_band band; |
| 5410 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5411 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5412 | |
| 5413 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5414 | !rdev->ops->sched_scan_start) |
| 5415 | return -EOPNOTSUPP; |
| 5416 | |
| 5417 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5418 | return -EINVAL; |
| 5419 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5420 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5421 | return -EINVAL; |
| 5422 | |
| 5423 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5424 | if (interval == 0) |
| 5425 | return -EINVAL; |
| 5426 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5427 | wiphy = &rdev->wiphy; |
| 5428 | |
| 5429 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5430 | n_channels = validate_scan_freqs( |
| 5431 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5432 | if (!n_channels) |
| 5433 | return -EINVAL; |
| 5434 | } else { |
| 5435 | n_channels = 0; |
| 5436 | |
| 5437 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5438 | if (wiphy->bands[band]) |
| 5439 | n_channels += wiphy->bands[band]->n_channels; |
| 5440 | } |
| 5441 | |
| 5442 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5443 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5444 | tmp) |
| 5445 | n_ssids++; |
| 5446 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5447 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5448 | return -EINVAL; |
| 5449 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5450 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5451 | nla_for_each_nested(attr, |
| 5452 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5453 | tmp) |
| 5454 | n_match_sets++; |
| 5455 | |
| 5456 | if (n_match_sets > wiphy->max_match_sets) |
| 5457 | return -EINVAL; |
| 5458 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5459 | if (info->attrs[NL80211_ATTR_IE]) |
| 5460 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5461 | else |
| 5462 | ie_len = 0; |
| 5463 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5464 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5465 | return -EINVAL; |
| 5466 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5467 | if (rdev->sched_scan_req) { |
| 5468 | err = -EINPROGRESS; |
| 5469 | goto out; |
| 5470 | } |
| 5471 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5472 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5473 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5474 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5475 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5476 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5477 | if (!request) { |
| 5478 | err = -ENOMEM; |
| 5479 | goto out; |
| 5480 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5481 | |
| 5482 | if (n_ssids) |
| 5483 | request->ssids = (void *)&request->channels[n_channels]; |
| 5484 | request->n_ssids = n_ssids; |
| 5485 | if (ie_len) { |
| 5486 | if (request->ssids) |
| 5487 | request->ie = (void *)(request->ssids + n_ssids); |
| 5488 | else |
| 5489 | request->ie = (void *)(request->channels + n_channels); |
| 5490 | } |
| 5491 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5492 | if (n_match_sets) { |
| 5493 | if (request->ie) |
| 5494 | request->match_sets = (void *)(request->ie + ie_len); |
| 5495 | else if (request->ssids) |
| 5496 | request->match_sets = |
| 5497 | (void *)(request->ssids + n_ssids); |
| 5498 | else |
| 5499 | request->match_sets = |
| 5500 | (void *)(request->channels + n_channels); |
| 5501 | } |
| 5502 | request->n_match_sets = n_match_sets; |
| 5503 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5504 | i = 0; |
| 5505 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5506 | /* user specified, bail out if channel not found */ |
| 5507 | nla_for_each_nested(attr, |
| 5508 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5509 | tmp) { |
| 5510 | struct ieee80211_channel *chan; |
| 5511 | |
| 5512 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5513 | |
| 5514 | if (!chan) { |
| 5515 | err = -EINVAL; |
| 5516 | goto out_free; |
| 5517 | } |
| 5518 | |
| 5519 | /* ignore disabled channels */ |
| 5520 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5521 | continue; |
| 5522 | |
| 5523 | request->channels[i] = chan; |
| 5524 | i++; |
| 5525 | } |
| 5526 | } else { |
| 5527 | /* all channels */ |
| 5528 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5529 | int j; |
| 5530 | if (!wiphy->bands[band]) |
| 5531 | continue; |
| 5532 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5533 | struct ieee80211_channel *chan; |
| 5534 | |
| 5535 | chan = &wiphy->bands[band]->channels[j]; |
| 5536 | |
| 5537 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5538 | continue; |
| 5539 | |
| 5540 | request->channels[i] = chan; |
| 5541 | i++; |
| 5542 | } |
| 5543 | } |
| 5544 | } |
| 5545 | |
| 5546 | if (!i) { |
| 5547 | err = -EINVAL; |
| 5548 | goto out_free; |
| 5549 | } |
| 5550 | |
| 5551 | request->n_channels = i; |
| 5552 | |
| 5553 | i = 0; |
| 5554 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5555 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5556 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5557 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5558 | err = -EINVAL; |
| 5559 | goto out_free; |
| 5560 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5561 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5562 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5563 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5564 | i++; |
| 5565 | } |
| 5566 | } |
| 5567 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5568 | i = 0; |
| 5569 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5570 | nla_for_each_nested(attr, |
| 5571 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5572 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5573 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5574 | |
| 5575 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5576 | nla_data(attr), nla_len(attr), |
| 5577 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5578 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5579 | if (ssid) { |
| 5580 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5581 | err = -EINVAL; |
| 5582 | goto out_free; |
| 5583 | } |
| 5584 | memcpy(request->match_sets[i].ssid.ssid, |
| 5585 | nla_data(ssid), nla_len(ssid)); |
| 5586 | request->match_sets[i].ssid.ssid_len = |
| 5587 | nla_len(ssid); |
| 5588 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5589 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5590 | if (rssi) |
| 5591 | request->rssi_thold = nla_get_u32(rssi); |
| 5592 | else |
| 5593 | request->rssi_thold = |
| 5594 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5595 | i++; |
| 5596 | } |
| 5597 | } |
| 5598 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5599 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5600 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5601 | memcpy((void *)request->ie, |
| 5602 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5603 | request->ie_len); |
| 5604 | } |
| 5605 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5606 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5607 | request->flags = nla_get_u32( |
| 5608 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5609 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5610 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5611 | err = -EOPNOTSUPP; |
| 5612 | goto out_free; |
| 5613 | } |
| 5614 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5615 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5616 | request->dev = dev; |
| 5617 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5618 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5619 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5620 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5621 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5622 | if (!err) { |
| 5623 | rdev->sched_scan_req = request; |
| 5624 | nl80211_send_sched_scan(rdev, dev, |
| 5625 | NL80211_CMD_START_SCHED_SCAN); |
| 5626 | goto out; |
| 5627 | } |
| 5628 | |
| 5629 | out_free: |
| 5630 | kfree(request); |
| 5631 | out: |
| 5632 | return err; |
| 5633 | } |
| 5634 | |
| 5635 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5636 | struct genl_info *info) |
| 5637 | { |
| 5638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5639 | |
| 5640 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5641 | !rdev->ops->sched_scan_stop) |
| 5642 | return -EOPNOTSUPP; |
| 5643 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5644 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5645 | } |
| 5646 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5647 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5648 | struct genl_info *info) |
| 5649 | { |
| 5650 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5651 | struct net_device *dev = info->user_ptr[1]; |
| 5652 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5653 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5654 | enum nl80211_dfs_regions dfs_region; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5655 | int err; |
| 5656 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5657 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5658 | if (dfs_region == NL80211_DFS_UNSET) |
| 5659 | return -EINVAL; |
| 5660 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5661 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5662 | if (err) |
| 5663 | return err; |
| 5664 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5665 | if (netif_carrier_ok(dev)) |
| 5666 | return -EBUSY; |
| 5667 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5668 | if (wdev->cac_started) |
| 5669 | return -EBUSY; |
| 5670 | |
| 5671 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5672 | if (err < 0) |
| 5673 | return err; |
| 5674 | |
| 5675 | if (err == 0) |
| 5676 | return -EINVAL; |
| 5677 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5678 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5679 | return -EINVAL; |
| 5680 | |
| 5681 | if (!rdev->ops->start_radar_detection) |
| 5682 | return -EOPNOTSUPP; |
| 5683 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5684 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5685 | chandef.chan, CHAN_MODE_SHARED, |
| 5686 | BIT(chandef.width)); |
| 5687 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5688 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5689 | |
| 5690 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5691 | if (!err) { |
| 5692 | wdev->channel = chandef.chan; |
| 5693 | wdev->cac_started = true; |
| 5694 | wdev->cac_start_time = jiffies; |
| 5695 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5696 | return err; |
| 5697 | } |
| 5698 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5699 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5700 | { |
| 5701 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5702 | struct net_device *dev = info->user_ptr[1]; |
| 5703 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5704 | struct cfg80211_csa_settings params; |
| 5705 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5706 | * function is called under RTNL lock, so this should not be a problem. |
| 5707 | */ |
| 5708 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5709 | u8 radar_detect_width = 0; |
| 5710 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5711 | bool need_new_beacon = false; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5712 | |
| 5713 | if (!rdev->ops->channel_switch || |
| 5714 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5715 | return -EOPNOTSUPP; |
| 5716 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5717 | switch (dev->ieee80211_ptr->iftype) { |
| 5718 | case NL80211_IFTYPE_AP: |
| 5719 | case NL80211_IFTYPE_P2P_GO: |
| 5720 | need_new_beacon = true; |
| 5721 | |
| 5722 | /* useless if AP is not running */ |
| 5723 | if (!wdev->beacon_interval) |
| 5724 | return -EINVAL; |
| 5725 | break; |
| 5726 | case NL80211_IFTYPE_ADHOC: |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5727 | case NL80211_IFTYPE_MESH_POINT: |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5728 | break; |
| 5729 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5730 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5731 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5732 | |
| 5733 | memset(¶ms, 0, sizeof(params)); |
| 5734 | |
| 5735 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5736 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5737 | return -EINVAL; |
| 5738 | |
| 5739 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5740 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5741 | return -EINVAL; |
| 5742 | |
| 5743 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5744 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5745 | if (!need_new_beacon) |
| 5746 | goto skip_beacons; |
| 5747 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5748 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5749 | if (err) |
| 5750 | return err; |
| 5751 | |
| 5752 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5753 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5754 | nl80211_policy); |
| 5755 | if (err) |
| 5756 | return err; |
| 5757 | |
| 5758 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5759 | if (err) |
| 5760 | return err; |
| 5761 | |
| 5762 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5763 | return -EINVAL; |
| 5764 | |
| 5765 | params.counter_offset_beacon = |
| 5766 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5767 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5768 | return -EINVAL; |
| 5769 | |
| 5770 | /* sanity check - counters should be the same */ |
| 5771 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5772 | params.count) |
| 5773 | return -EINVAL; |
| 5774 | |
| 5775 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5776 | params.counter_offset_presp = |
| 5777 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5778 | if (params.counter_offset_presp >= |
| 5779 | params.beacon_csa.probe_resp_len) |
| 5780 | return -EINVAL; |
| 5781 | |
| 5782 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5783 | params.count) |
| 5784 | return -EINVAL; |
| 5785 | } |
| 5786 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5787 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5788 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5789 | if (err) |
| 5790 | return err; |
| 5791 | |
| 5792 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5793 | return -EINVAL; |
| 5794 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5795 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 5796 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO || |
| 5797 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) { |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5798 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 5799 | ¶ms.chandef); |
| 5800 | if (err < 0) { |
| 5801 | return err; |
| 5802 | } else if (err) { |
| 5803 | radar_detect_width = BIT(params.chandef.width); |
| 5804 | params.radar_required = true; |
| 5805 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5806 | } |
| 5807 | |
| 5808 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5809 | params.chandef.chan, |
| 5810 | CHAN_MODE_SHARED, |
| 5811 | radar_detect_width); |
| 5812 | if (err) |
| 5813 | return err; |
| 5814 | |
| 5815 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5816 | params.block_tx = true; |
| 5817 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5818 | wdev_lock(wdev); |
| 5819 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 5820 | wdev_unlock(wdev); |
| 5821 | |
| 5822 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5823 | } |
| 5824 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5825 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5826 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5827 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5828 | struct wireless_dev *wdev, |
| 5829 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5830 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5831 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5832 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5833 | void *hdr; |
| 5834 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5835 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5836 | |
| 5837 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5838 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5839 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5840 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5841 | if (!hdr) |
| 5842 | return -1; |
| 5843 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5844 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5845 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5846 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5847 | goto nla_put_failure; |
| 5848 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5849 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5850 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5851 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5852 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5853 | |
| 5854 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5855 | if (!bss) |
| 5856 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5857 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5858 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5859 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5860 | |
| 5861 | rcu_read_lock(); |
| 5862 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5863 | if (ies) { |
| 5864 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5865 | goto fail_unlock_rcu; |
| 5866 | tsf = true; |
| 5867 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5868 | ies->len, ies->data)) |
| 5869 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5870 | } |
| 5871 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5872 | if (ies) { |
| 5873 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5874 | goto fail_unlock_rcu; |
| 5875 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5876 | ies->len, ies->data)) |
| 5877 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5878 | } |
| 5879 | rcu_read_unlock(); |
| 5880 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5881 | if (res->beacon_interval && |
| 5882 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5883 | goto nla_put_failure; |
| 5884 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5885 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 5886 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5887 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5888 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5889 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5890 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5891 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5892 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5893 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5894 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5895 | break; |
| 5896 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5897 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5898 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5899 | break; |
| 5900 | default: |
| 5901 | break; |
| 5902 | } |
| 5903 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5904 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5905 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5906 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5907 | if (intbss == wdev->current_bss && |
| 5908 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5909 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5910 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5911 | break; |
| 5912 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5913 | if (intbss == wdev->current_bss && |
| 5914 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5915 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5916 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5917 | break; |
| 5918 | default: |
| 5919 | break; |
| 5920 | } |
| 5921 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5922 | nla_nest_end(msg, bss); |
| 5923 | |
| 5924 | return genlmsg_end(msg, hdr); |
| 5925 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5926 | fail_unlock_rcu: |
| 5927 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5928 | nla_put_failure: |
| 5929 | genlmsg_cancel(msg, hdr); |
| 5930 | return -EMSGSIZE; |
| 5931 | } |
| 5932 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5933 | 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] | 5934 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5935 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5936 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5937 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5938 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5939 | int err; |
| 5940 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5941 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5942 | if (err) |
| 5943 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5944 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5945 | wdev_lock(wdev); |
| 5946 | spin_lock_bh(&rdev->bss_lock); |
| 5947 | cfg80211_bss_expire(rdev); |
| 5948 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5949 | cb->seq = rdev->bss_generation; |
| 5950 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5951 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5952 | if (++idx <= start) |
| 5953 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5954 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5955 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5956 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5957 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5958 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5959 | } |
| 5960 | } |
| 5961 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5962 | spin_unlock_bh(&rdev->bss_lock); |
| 5963 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5964 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5965 | cb->args[2] = idx; |
| 5966 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5967 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5968 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5969 | } |
| 5970 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5971 | 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] | 5972 | int flags, struct net_device *dev, |
| 5973 | struct survey_info *survey) |
| 5974 | { |
| 5975 | void *hdr; |
| 5976 | struct nlattr *infoattr; |
| 5977 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5978 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5979 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5980 | if (!hdr) |
| 5981 | return -ENOMEM; |
| 5982 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5983 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5984 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5985 | |
| 5986 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5987 | if (!infoattr) |
| 5988 | goto nla_put_failure; |
| 5989 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5990 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5991 | survey->channel->center_freq)) |
| 5992 | goto nla_put_failure; |
| 5993 | |
| 5994 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5995 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5996 | goto nla_put_failure; |
| 5997 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5998 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5999 | goto nla_put_failure; |
| 6000 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6001 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6002 | survey->channel_time)) |
| 6003 | goto nla_put_failure; |
| 6004 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6005 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6006 | survey->channel_time_busy)) |
| 6007 | goto nla_put_failure; |
| 6008 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6009 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6010 | survey->channel_time_ext_busy)) |
| 6011 | goto nla_put_failure; |
| 6012 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6013 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6014 | survey->channel_time_rx)) |
| 6015 | goto nla_put_failure; |
| 6016 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6017 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6018 | survey->channel_time_tx)) |
| 6019 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6020 | |
| 6021 | nla_nest_end(msg, infoattr); |
| 6022 | |
| 6023 | return genlmsg_end(msg, hdr); |
| 6024 | |
| 6025 | nla_put_failure: |
| 6026 | genlmsg_cancel(msg, hdr); |
| 6027 | return -EMSGSIZE; |
| 6028 | } |
| 6029 | |
| 6030 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6031 | struct netlink_callback *cb) |
| 6032 | { |
| 6033 | struct survey_info survey; |
| 6034 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6035 | struct wireless_dev *wdev; |
| 6036 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6037 | int res; |
| 6038 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6039 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6040 | if (res) |
| 6041 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6042 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6043 | if (!wdev->netdev) { |
| 6044 | res = -EINVAL; |
| 6045 | goto out_err; |
| 6046 | } |
| 6047 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6048 | if (!dev->ops->dump_survey) { |
| 6049 | res = -EOPNOTSUPP; |
| 6050 | goto out_err; |
| 6051 | } |
| 6052 | |
| 6053 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6054 | struct ieee80211_channel *chan; |
| 6055 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6056 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6057 | if (res == -ENOENT) |
| 6058 | break; |
| 6059 | if (res) |
| 6060 | goto out_err; |
| 6061 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6062 | /* Survey without a channel doesn't make sense */ |
| 6063 | if (!survey.channel) { |
| 6064 | res = -EINVAL; |
| 6065 | goto out; |
| 6066 | } |
| 6067 | |
| 6068 | chan = ieee80211_get_channel(&dev->wiphy, |
| 6069 | survey.channel->center_freq); |
| 6070 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6071 | survey_idx++; |
| 6072 | continue; |
| 6073 | } |
| 6074 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6075 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6076 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6077 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6078 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6079 | goto out; |
| 6080 | survey_idx++; |
| 6081 | } |
| 6082 | |
| 6083 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6084 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6085 | res = skb->len; |
| 6086 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6087 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6088 | return res; |
| 6089 | } |
| 6090 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6091 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6092 | { |
| 6093 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6094 | NL80211_WPA_VERSION_2)); |
| 6095 | } |
| 6096 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6097 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6098 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6099 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6100 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6101 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6102 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6103 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6104 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6105 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6106 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6107 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6108 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6109 | return -EINVAL; |
| 6110 | |
| 6111 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6112 | return -EINVAL; |
| 6113 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6114 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6115 | return -EINVAL; |
| 6116 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6117 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6118 | return -EINVAL; |
| 6119 | |
| 6120 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6121 | return -EINVAL; |
| 6122 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6123 | err = nl80211_parse_key(info, &key); |
| 6124 | if (err) |
| 6125 | return err; |
| 6126 | |
| 6127 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6128 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6129 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6130 | if (!key.p.key || !key.p.key_len) |
| 6131 | return -EINVAL; |
| 6132 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6133 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6134 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6135 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6136 | return -EINVAL; |
| 6137 | if (key.idx > 4) |
| 6138 | return -EINVAL; |
| 6139 | } else { |
| 6140 | key.p.key_len = 0; |
| 6141 | key.p.key = NULL; |
| 6142 | } |
| 6143 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6144 | if (key.idx >= 0) { |
| 6145 | int i; |
| 6146 | bool ok = false; |
| 6147 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6148 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6149 | ok = true; |
| 6150 | break; |
| 6151 | } |
| 6152 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6153 | if (!ok) |
| 6154 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6155 | } |
| 6156 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6157 | if (!rdev->ops->auth) |
| 6158 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6159 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6160 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6161 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6162 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6163 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6164 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6165 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6166 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6167 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6168 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6169 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6170 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6171 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6172 | |
| 6173 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6174 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6175 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6176 | } |
| 6177 | |
| 6178 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6179 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6180 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6181 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6182 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6183 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6184 | return -EINVAL; |
| 6185 | |
| 6186 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6187 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6188 | return -EINVAL; |
| 6189 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6190 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6191 | /* need to include at least Auth Transaction and Status Code */ |
| 6192 | if (sae_data_len < 4) |
| 6193 | return -EINVAL; |
| 6194 | } |
| 6195 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6196 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6197 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6198 | /* |
| 6199 | * Since we no longer track auth state, ignore |
| 6200 | * requests to only change local state. |
| 6201 | */ |
| 6202 | if (local_state_change) |
| 6203 | return 0; |
| 6204 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6205 | wdev_lock(dev->ieee80211_ptr); |
| 6206 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6207 | ssid, ssid_len, ie, ie_len, |
| 6208 | key.p.key, key.p.key_len, key.idx, |
| 6209 | sae_data, sae_data_len); |
| 6210 | wdev_unlock(dev->ieee80211_ptr); |
| 6211 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6212 | } |
| 6213 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6214 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6215 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6216 | struct cfg80211_crypto_settings *settings, |
| 6217 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6218 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6219 | memset(settings, 0, sizeof(*settings)); |
| 6220 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6221 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6222 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6223 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6224 | u16 proto; |
| 6225 | proto = nla_get_u16( |
| 6226 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6227 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6228 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6229 | proto != ETH_P_PAE) |
| 6230 | return -EINVAL; |
| 6231 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6232 | settings->control_port_no_encrypt = true; |
| 6233 | } else |
| 6234 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6235 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6236 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6237 | void *data; |
| 6238 | int len, i; |
| 6239 | |
| 6240 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6241 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6242 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6243 | |
| 6244 | if (len % sizeof(u32)) |
| 6245 | return -EINVAL; |
| 6246 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6247 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6248 | return -EINVAL; |
| 6249 | |
| 6250 | memcpy(settings->ciphers_pairwise, data, len); |
| 6251 | |
| 6252 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6253 | if (!cfg80211_supported_cipher_suite( |
| 6254 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6255 | settings->ciphers_pairwise[i])) |
| 6256 | return -EINVAL; |
| 6257 | } |
| 6258 | |
| 6259 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6260 | settings->cipher_group = |
| 6261 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6262 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6263 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6264 | return -EINVAL; |
| 6265 | } |
| 6266 | |
| 6267 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6268 | settings->wpa_versions = |
| 6269 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6270 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6271 | return -EINVAL; |
| 6272 | } |
| 6273 | |
| 6274 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6275 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6276 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6277 | |
| 6278 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6279 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6280 | settings->n_akm_suites = len / sizeof(u32); |
| 6281 | |
| 6282 | if (len % sizeof(u32)) |
| 6283 | return -EINVAL; |
| 6284 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6285 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6286 | return -EINVAL; |
| 6287 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6288 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6289 | } |
| 6290 | |
| 6291 | return 0; |
| 6292 | } |
| 6293 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6294 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6295 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6296 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6297 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6298 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6299 | struct cfg80211_assoc_request req = {}; |
| 6300 | const u8 *bssid, *ssid; |
| 6301 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6302 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6303 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6304 | return -EINVAL; |
| 6305 | |
| 6306 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6307 | !info->attrs[NL80211_ATTR_SSID] || |
| 6308 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6309 | return -EINVAL; |
| 6310 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6311 | if (!rdev->ops->assoc) |
| 6312 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6313 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6314 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6315 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6316 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6317 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6318 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6319 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6320 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6321 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6322 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6323 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6324 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6325 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6326 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6327 | |
| 6328 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6329 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6330 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6331 | } |
| 6332 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6333 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6334 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6335 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6336 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6337 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6338 | else if (mfp != NL80211_MFP_NO) |
| 6339 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6340 | } |
| 6341 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6342 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6343 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6344 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6345 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6346 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6347 | |
| 6348 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6349 | memcpy(&req.ht_capa_mask, |
| 6350 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6351 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6352 | |
| 6353 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6354 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6355 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6356 | memcpy(&req.ht_capa, |
| 6357 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6358 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6359 | } |
| 6360 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6361 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6362 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6363 | |
| 6364 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6365 | memcpy(&req.vht_capa_mask, |
| 6366 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6367 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6368 | |
| 6369 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6370 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6371 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6372 | memcpy(&req.vht_capa, |
| 6373 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6374 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6375 | } |
| 6376 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6377 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6378 | if (!err) { |
| 6379 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6380 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6381 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6382 | wdev_unlock(dev->ieee80211_ptr); |
| 6383 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6384 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6385 | return err; |
| 6386 | } |
| 6387 | |
| 6388 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6389 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6390 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6391 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6392 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6393 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6394 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6395 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6396 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6397 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6398 | return -EINVAL; |
| 6399 | |
| 6400 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6401 | return -EINVAL; |
| 6402 | |
| 6403 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6404 | return -EINVAL; |
| 6405 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6406 | if (!rdev->ops->deauth) |
| 6407 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6408 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6409 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6410 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6411 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6412 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6413 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6414 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6415 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6416 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6417 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6418 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6419 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6420 | |
| 6421 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6422 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6423 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6424 | } |
| 6425 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6426 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6427 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6428 | wdev_lock(dev->ieee80211_ptr); |
| 6429 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6430 | local_state_change); |
| 6431 | wdev_unlock(dev->ieee80211_ptr); |
| 6432 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6433 | } |
| 6434 | |
| 6435 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6436 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6437 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6438 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6439 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6440 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6441 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6442 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6443 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6444 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6445 | return -EINVAL; |
| 6446 | |
| 6447 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6448 | return -EINVAL; |
| 6449 | |
| 6450 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6451 | return -EINVAL; |
| 6452 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6453 | if (!rdev->ops->disassoc) |
| 6454 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6455 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6456 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6457 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6458 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6459 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6460 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6461 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6462 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6463 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6464 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6465 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6466 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6467 | |
| 6468 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6469 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6470 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6471 | } |
| 6472 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6473 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6474 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6475 | wdev_lock(dev->ieee80211_ptr); |
| 6476 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6477 | local_state_change); |
| 6478 | wdev_unlock(dev->ieee80211_ptr); |
| 6479 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6480 | } |
| 6481 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6482 | static bool |
| 6483 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6484 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6485 | int rateval) |
| 6486 | { |
| 6487 | struct wiphy *wiphy = &rdev->wiphy; |
| 6488 | bool found = false; |
| 6489 | int band, i; |
| 6490 | |
| 6491 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6492 | struct ieee80211_supported_band *sband; |
| 6493 | |
| 6494 | sband = wiphy->bands[band]; |
| 6495 | if (!sband) |
| 6496 | continue; |
| 6497 | |
| 6498 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6499 | if (sband->bitrates[i].bitrate == rateval) { |
| 6500 | mcast_rate[band] = i + 1; |
| 6501 | found = true; |
| 6502 | break; |
| 6503 | } |
| 6504 | } |
| 6505 | } |
| 6506 | |
| 6507 | return found; |
| 6508 | } |
| 6509 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6510 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6511 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6512 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6513 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6514 | struct cfg80211_ibss_params ibss; |
| 6515 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6516 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6517 | int err; |
| 6518 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6519 | memset(&ibss, 0, sizeof(ibss)); |
| 6520 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6521 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6522 | return -EINVAL; |
| 6523 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6524 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6525 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6526 | return -EINVAL; |
| 6527 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6528 | ibss.beacon_interval = 100; |
| 6529 | |
| 6530 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6531 | ibss.beacon_interval = |
| 6532 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6533 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6534 | return -EINVAL; |
| 6535 | } |
| 6536 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6537 | if (!rdev->ops->join_ibss) |
| 6538 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6539 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6540 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6541 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6542 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6543 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6544 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6545 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6546 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6547 | |
| 6548 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6549 | return -EINVAL; |
| 6550 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6551 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6552 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6553 | |
| 6554 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6555 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6556 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6557 | } |
| 6558 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6559 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6560 | if (err) |
| 6561 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6562 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6563 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6564 | return -EINVAL; |
| 6565 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6566 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6567 | case NL80211_CHAN_WIDTH_5: |
| 6568 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6569 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6570 | break; |
| 6571 | case NL80211_CHAN_WIDTH_20: |
| 6572 | case NL80211_CHAN_WIDTH_40: |
| 6573 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6574 | break; |
| 6575 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6576 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6577 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6578 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6579 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6580 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6581 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6582 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6583 | u8 *rates = |
| 6584 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6585 | int n_rates = |
| 6586 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6587 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6588 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6589 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6590 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6591 | &ibss.basic_rates); |
| 6592 | if (err) |
| 6593 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6594 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6595 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6596 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6597 | memcpy(&ibss.ht_capa_mask, |
| 6598 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6599 | sizeof(ibss.ht_capa_mask)); |
| 6600 | |
| 6601 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6602 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6603 | return -EINVAL; |
| 6604 | memcpy(&ibss.ht_capa, |
| 6605 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6606 | sizeof(ibss.ht_capa)); |
| 6607 | } |
| 6608 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6609 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6610 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6611 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6612 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6613 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6614 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6615 | bool no_ht = false; |
| 6616 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6617 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6618 | info->attrs[NL80211_ATTR_KEYS], |
| 6619 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6620 | if (IS_ERR(connkeys)) |
| 6621 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6622 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6623 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6624 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6625 | kfree(connkeys); |
| 6626 | return -EINVAL; |
| 6627 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6628 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6629 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6630 | ibss.control_port = |
| 6631 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6632 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6633 | ibss.userspace_handles_dfs = |
| 6634 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6635 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6636 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6637 | if (err) |
| 6638 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6639 | return err; |
| 6640 | } |
| 6641 | |
| 6642 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6643 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6644 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6645 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6646 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6647 | if (!rdev->ops->leave_ibss) |
| 6648 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6649 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6650 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6651 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6652 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6653 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6654 | } |
| 6655 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6656 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6657 | { |
| 6658 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6659 | struct net_device *dev = info->user_ptr[1]; |
| 6660 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6661 | u32 nla_rate; |
| 6662 | int err; |
| 6663 | |
| 6664 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6665 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6666 | return -EOPNOTSUPP; |
| 6667 | |
| 6668 | if (!rdev->ops->set_mcast_rate) |
| 6669 | return -EOPNOTSUPP; |
| 6670 | |
| 6671 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6672 | |
| 6673 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6674 | return -EINVAL; |
| 6675 | |
| 6676 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6677 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6678 | return -EINVAL; |
| 6679 | |
| 6680 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6681 | |
| 6682 | return err; |
| 6683 | } |
| 6684 | |
| 6685 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6686 | #ifdef CONFIG_NL80211_TESTMODE |
| 6687 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6688 | .name = "testmode", |
| 6689 | }; |
| 6690 | |
| 6691 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6692 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6693 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6694 | struct wireless_dev *wdev = |
| 6695 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6696 | int err; |
| 6697 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6698 | if (!rdev->ops->testmode_cmd) |
| 6699 | return -EOPNOTSUPP; |
| 6700 | |
| 6701 | if (IS_ERR(wdev)) { |
| 6702 | err = PTR_ERR(wdev); |
| 6703 | if (err != -EINVAL) |
| 6704 | return err; |
| 6705 | wdev = NULL; |
| 6706 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6707 | return -EINVAL; |
| 6708 | } |
| 6709 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6710 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6711 | return -EINVAL; |
| 6712 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6713 | rdev->testmode_info = info; |
| 6714 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6715 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6716 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6717 | rdev->testmode_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6718 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6719 | return err; |
| 6720 | } |
| 6721 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6722 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6723 | struct netlink_callback *cb) |
| 6724 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6725 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6726 | int err; |
| 6727 | long phy_idx; |
| 6728 | void *data = NULL; |
| 6729 | int data_len = 0; |
| 6730 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6731 | rtnl_lock(); |
| 6732 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6733 | if (cb->args[0]) { |
| 6734 | /* |
| 6735 | * 0 is a valid index, but not valid for args[0], |
| 6736 | * so we need to offset by 1. |
| 6737 | */ |
| 6738 | phy_idx = cb->args[0] - 1; |
| 6739 | } else { |
| 6740 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6741 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6742 | nl80211_policy); |
| 6743 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6744 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6745 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6746 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6747 | nl80211_fam.attrbuf); |
| 6748 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6749 | err = PTR_ERR(rdev); |
| 6750 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6751 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6752 | phy_idx = rdev->wiphy_idx; |
| 6753 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6754 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6755 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6756 | cb->args[1] = |
| 6757 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6758 | } |
| 6759 | |
| 6760 | if (cb->args[1]) { |
| 6761 | data = nla_data((void *)cb->args[1]); |
| 6762 | data_len = nla_len((void *)cb->args[1]); |
| 6763 | } |
| 6764 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6765 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6766 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6767 | err = -ENOENT; |
| 6768 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6769 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6770 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6771 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6772 | err = -EOPNOTSUPP; |
| 6773 | goto out_err; |
| 6774 | } |
| 6775 | |
| 6776 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6777 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6778 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6779 | NL80211_CMD_TESTMODE); |
| 6780 | struct nlattr *tmdata; |
| 6781 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 6782 | if (!hdr) |
| 6783 | break; |
| 6784 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6785 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6786 | genlmsg_cancel(skb, hdr); |
| 6787 | break; |
| 6788 | } |
| 6789 | |
| 6790 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6791 | if (!tmdata) { |
| 6792 | genlmsg_cancel(skb, hdr); |
| 6793 | break; |
| 6794 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6795 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6796 | nla_nest_end(skb, tmdata); |
| 6797 | |
| 6798 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6799 | genlmsg_cancel(skb, hdr); |
| 6800 | break; |
| 6801 | } else if (err) { |
| 6802 | genlmsg_cancel(skb, hdr); |
| 6803 | goto out_err; |
| 6804 | } |
| 6805 | |
| 6806 | genlmsg_end(skb, hdr); |
| 6807 | } |
| 6808 | |
| 6809 | err = skb->len; |
| 6810 | /* see above */ |
| 6811 | cb->args[0] = phy_idx + 1; |
| 6812 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6813 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6814 | return err; |
| 6815 | } |
| 6816 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6817 | static struct sk_buff * |
| 6818 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6819 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6820 | { |
| 6821 | struct sk_buff *skb; |
| 6822 | void *hdr; |
| 6823 | struct nlattr *data; |
| 6824 | |
| 6825 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6826 | if (!skb) |
| 6827 | return NULL; |
| 6828 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6829 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6830 | if (!hdr) { |
| 6831 | kfree_skb(skb); |
| 6832 | return NULL; |
| 6833 | } |
| 6834 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6835 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6836 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6837 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6838 | |
| 6839 | ((void **)skb->cb)[0] = rdev; |
| 6840 | ((void **)skb->cb)[1] = hdr; |
| 6841 | ((void **)skb->cb)[2] = data; |
| 6842 | |
| 6843 | return skb; |
| 6844 | |
| 6845 | nla_put_failure: |
| 6846 | kfree_skb(skb); |
| 6847 | return NULL; |
| 6848 | } |
| 6849 | |
| 6850 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6851 | int approxlen) |
| 6852 | { |
| 6853 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6854 | |
| 6855 | if (WARN_ON(!rdev->testmode_info)) |
| 6856 | return NULL; |
| 6857 | |
| 6858 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6859 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6860 | rdev->testmode_info->snd_seq, |
| 6861 | GFP_KERNEL); |
| 6862 | } |
| 6863 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6864 | |
| 6865 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6866 | { |
| 6867 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6868 | void *hdr = ((void **)skb->cb)[1]; |
| 6869 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6870 | |
| 6871 | if (WARN_ON(!rdev->testmode_info)) { |
| 6872 | kfree_skb(skb); |
| 6873 | return -EINVAL; |
| 6874 | } |
| 6875 | |
| 6876 | nla_nest_end(skb, data); |
| 6877 | genlmsg_end(skb, hdr); |
| 6878 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6879 | } |
| 6880 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6881 | |
| 6882 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6883 | int approxlen, gfp_t gfp) |
| 6884 | { |
| 6885 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6886 | |
| 6887 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6888 | } |
| 6889 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6890 | |
| 6891 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6892 | { |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6893 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6894 | void *hdr = ((void **)skb->cb)[1]; |
| 6895 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6896 | |
| 6897 | nla_nest_end(skb, data); |
| 6898 | genlmsg_end(skb, hdr); |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6899 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0, |
| 6900 | nl80211_testmode_mcgrp.id, gfp); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6901 | } |
| 6902 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6903 | #endif |
| 6904 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6905 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6906 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6908 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6909 | struct cfg80211_connect_params connect; |
| 6910 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6911 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6912 | int err; |
| 6913 | |
| 6914 | memset(&connect, 0, sizeof(connect)); |
| 6915 | |
| 6916 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6917 | return -EINVAL; |
| 6918 | |
| 6919 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6920 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6921 | return -EINVAL; |
| 6922 | |
| 6923 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6924 | connect.auth_type = |
| 6925 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6926 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6927 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6928 | return -EINVAL; |
| 6929 | } else |
| 6930 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6931 | |
| 6932 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6933 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6934 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6935 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6936 | if (err) |
| 6937 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6938 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6939 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6940 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6941 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6942 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6943 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6944 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6945 | connect.bg_scan_period = -1; |
| 6946 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6947 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6948 | connect.bg_scan_period = |
| 6949 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6950 | } |
| 6951 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6952 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6953 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6954 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6955 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6956 | |
| 6957 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6958 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6959 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6960 | } |
| 6961 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6962 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6963 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6964 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6965 | connect.mfp != NL80211_MFP_NO) |
| 6966 | return -EINVAL; |
| 6967 | } else { |
| 6968 | connect.mfp = NL80211_MFP_NO; |
| 6969 | } |
| 6970 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6971 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6972 | connect.channel = |
| 6973 | ieee80211_get_channel(wiphy, |
| 6974 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6975 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6976 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6977 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6978 | } |
| 6979 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6980 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6981 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6982 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6983 | if (IS_ERR(connkeys)) |
| 6984 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6985 | } |
| 6986 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6987 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6988 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6989 | |
| 6990 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6991 | memcpy(&connect.ht_capa_mask, |
| 6992 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6993 | sizeof(connect.ht_capa_mask)); |
| 6994 | |
| 6995 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6996 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6997 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6998 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6999 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7000 | memcpy(&connect.ht_capa, |
| 7001 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7002 | sizeof(connect.ht_capa)); |
| 7003 | } |
| 7004 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7005 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7006 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7007 | |
| 7008 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7009 | memcpy(&connect.vht_capa_mask, |
| 7010 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7011 | sizeof(connect.vht_capa_mask)); |
| 7012 | |
| 7013 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7014 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 7015 | kfree(connkeys); |
| 7016 | return -EINVAL; |
| 7017 | } |
| 7018 | memcpy(&connect.vht_capa, |
| 7019 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7020 | sizeof(connect.vht_capa)); |
| 7021 | } |
| 7022 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7023 | wdev_lock(dev->ieee80211_ptr); |
| 7024 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7025 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7026 | if (err) |
| 7027 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7028 | return err; |
| 7029 | } |
| 7030 | |
| 7031 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7032 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7034 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7035 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7036 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7037 | |
| 7038 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7039 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7040 | else |
| 7041 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7042 | |
| 7043 | if (reason == 0) |
| 7044 | return -EINVAL; |
| 7045 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7046 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7047 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7048 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7049 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7050 | wdev_lock(dev->ieee80211_ptr); |
| 7051 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7052 | wdev_unlock(dev->ieee80211_ptr); |
| 7053 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7054 | } |
| 7055 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7056 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7057 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7058 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7059 | struct net *net; |
| 7060 | int err; |
| 7061 | u32 pid; |
| 7062 | |
| 7063 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7064 | return -EINVAL; |
| 7065 | |
| 7066 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7067 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7068 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7069 | if (IS_ERR(net)) |
| 7070 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7071 | |
| 7072 | err = 0; |
| 7073 | |
| 7074 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7075 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7076 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7077 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7078 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7079 | return err; |
| 7080 | } |
| 7081 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7082 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7083 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7084 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7085 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7086 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7087 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7088 | struct cfg80211_pmksa pmksa; |
| 7089 | |
| 7090 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7091 | |
| 7092 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7093 | return -EINVAL; |
| 7094 | |
| 7095 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7096 | return -EINVAL; |
| 7097 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7098 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7099 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7100 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7101 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7102 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7103 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7104 | |
| 7105 | switch (info->genlhdr->cmd) { |
| 7106 | case NL80211_CMD_SET_PMKSA: |
| 7107 | rdev_ops = rdev->ops->set_pmksa; |
| 7108 | break; |
| 7109 | case NL80211_CMD_DEL_PMKSA: |
| 7110 | rdev_ops = rdev->ops->del_pmksa; |
| 7111 | break; |
| 7112 | default: |
| 7113 | WARN_ON(1); |
| 7114 | break; |
| 7115 | } |
| 7116 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7117 | if (!rdev_ops) |
| 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 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7121 | } |
| 7122 | |
| 7123 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7124 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7125 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7126 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7127 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7128 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7129 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7130 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7131 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7132 | if (!rdev->ops->flush_pmksa) |
| 7133 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7134 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7135 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7136 | } |
| 7137 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7138 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7139 | { |
| 7140 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7141 | struct net_device *dev = info->user_ptr[1]; |
| 7142 | u8 action_code, dialog_token; |
| 7143 | u16 status_code; |
| 7144 | u8 *peer; |
| 7145 | |
| 7146 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7147 | !rdev->ops->tdls_mgmt) |
| 7148 | return -EOPNOTSUPP; |
| 7149 | |
| 7150 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7151 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7152 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7153 | !info->attrs[NL80211_ATTR_IE] || |
| 7154 | !info->attrs[NL80211_ATTR_MAC]) |
| 7155 | return -EINVAL; |
| 7156 | |
| 7157 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7158 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7159 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7160 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 7161 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7162 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 7163 | dialog_token, status_code, |
| 7164 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7165 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7166 | } |
| 7167 | |
| 7168 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7169 | { |
| 7170 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7171 | struct net_device *dev = info->user_ptr[1]; |
| 7172 | enum nl80211_tdls_operation operation; |
| 7173 | u8 *peer; |
| 7174 | |
| 7175 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7176 | !rdev->ops->tdls_oper) |
| 7177 | return -EOPNOTSUPP; |
| 7178 | |
| 7179 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7180 | !info->attrs[NL80211_ATTR_MAC]) |
| 7181 | return -EINVAL; |
| 7182 | |
| 7183 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7184 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7185 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7186 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7187 | } |
| 7188 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7189 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7190 | struct genl_info *info) |
| 7191 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7192 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7193 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7194 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7195 | struct sk_buff *msg; |
| 7196 | void *hdr; |
| 7197 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7198 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7199 | int err; |
| 7200 | |
| 7201 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7202 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7203 | return -EINVAL; |
| 7204 | |
| 7205 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7206 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7207 | if (!rdev->ops->remain_on_channel || |
| 7208 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7209 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7210 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7211 | /* |
| 7212 | * We should be on that channel for at least a minimum amount of |
| 7213 | * time (10ms) but no longer than the driver supports. |
| 7214 | */ |
| 7215 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7216 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7217 | return -EINVAL; |
| 7218 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7219 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7220 | if (err) |
| 7221 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7222 | |
| 7223 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7224 | if (!msg) |
| 7225 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7226 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7227 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7228 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7229 | if (!hdr) { |
| 7230 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7231 | goto free_msg; |
| 7232 | } |
| 7233 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7234 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7235 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7236 | |
| 7237 | if (err) |
| 7238 | goto free_msg; |
| 7239 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7240 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7241 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7242 | |
| 7243 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7244 | |
| 7245 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7246 | |
| 7247 | nla_put_failure: |
| 7248 | err = -ENOBUFS; |
| 7249 | free_msg: |
| 7250 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7251 | return err; |
| 7252 | } |
| 7253 | |
| 7254 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7255 | struct genl_info *info) |
| 7256 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7257 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7258 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7259 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7260 | |
| 7261 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7262 | return -EINVAL; |
| 7263 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7264 | if (!rdev->ops->cancel_remain_on_channel) |
| 7265 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7266 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7267 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7268 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7269 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7270 | } |
| 7271 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7272 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7273 | u8 *rates, u8 rates_len) |
| 7274 | { |
| 7275 | u8 i; |
| 7276 | u32 mask = 0; |
| 7277 | |
| 7278 | for (i = 0; i < rates_len; i++) { |
| 7279 | int rate = (rates[i] & 0x7f) * 5; |
| 7280 | int ridx; |
| 7281 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7282 | struct ieee80211_rate *srate = |
| 7283 | &sband->bitrates[ridx]; |
| 7284 | if (rate == srate->bitrate) { |
| 7285 | mask |= 1 << ridx; |
| 7286 | break; |
| 7287 | } |
| 7288 | } |
| 7289 | if (ridx == sband->n_bitrates) |
| 7290 | return 0; /* rate not found */ |
| 7291 | } |
| 7292 | |
| 7293 | return mask; |
| 7294 | } |
| 7295 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7296 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7297 | u8 *rates, u8 rates_len, |
| 7298 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7299 | { |
| 7300 | u8 i; |
| 7301 | |
| 7302 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7303 | |
| 7304 | for (i = 0; i < rates_len; i++) { |
| 7305 | int ridx, rbit; |
| 7306 | |
| 7307 | ridx = rates[i] / 8; |
| 7308 | rbit = BIT(rates[i] % 8); |
| 7309 | |
| 7310 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7311 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7312 | return false; |
| 7313 | |
| 7314 | /* check availability */ |
| 7315 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7316 | mcs[ridx] |= rbit; |
| 7317 | else |
| 7318 | return false; |
| 7319 | } |
| 7320 | |
| 7321 | return true; |
| 7322 | } |
| 7323 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7324 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7325 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7326 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7327 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 7328 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7329 | }; |
| 7330 | |
| 7331 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7332 | struct genl_info *info) |
| 7333 | { |
| 7334 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7335 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7336 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7337 | int rem, i; |
| 7338 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7339 | struct nlattr *tx_rates; |
| 7340 | struct ieee80211_supported_band *sband; |
| 7341 | |
| 7342 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7343 | return -EINVAL; |
| 7344 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7345 | if (!rdev->ops->set_bitrate_mask) |
| 7346 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7347 | |
| 7348 | memset(&mask, 0, sizeof(mask)); |
| 7349 | /* Default to all rates enabled */ |
| 7350 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7351 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame^] | 7352 | |
| 7353 | if (!sband) |
| 7354 | continue; |
| 7355 | |
| 7356 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 7357 | memcpy(mask.control[i].mcs, |
| 7358 | sband->ht_cap.mcs.rx_mask, |
| 7359 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7360 | } |
| 7361 | |
| 7362 | /* |
| 7363 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7364 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7365 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7366 | 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] | 7367 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7368 | { |
| 7369 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7370 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7371 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7372 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7373 | if (sband == NULL) |
| 7374 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7375 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7376 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7377 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7378 | mask.control[band].legacy = rateset_to_mask( |
| 7379 | sband, |
| 7380 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7381 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7382 | if ((mask.control[band].legacy == 0) && |
| 7383 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7384 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7385 | } |
| 7386 | if (tb[NL80211_TXRATE_MCS]) { |
| 7387 | if (!ht_rateset_to_mask( |
| 7388 | sband, |
| 7389 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7390 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7391 | mask.control[band].mcs)) |
| 7392 | return -EINVAL; |
| 7393 | } |
| 7394 | |
| 7395 | if (mask.control[band].legacy == 0) { |
| 7396 | /* don't allow empty legacy rates if HT |
| 7397 | * is not even supported. */ |
| 7398 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7399 | return -EINVAL; |
| 7400 | |
| 7401 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7402 | if (mask.control[band].mcs[i]) |
| 7403 | break; |
| 7404 | |
| 7405 | /* legacy and mcs rates may not be both empty */ |
| 7406 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7407 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7408 | } |
| 7409 | } |
| 7410 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7411 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7412 | } |
| 7413 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7414 | 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] | 7415 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7416 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7417 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7418 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7419 | |
| 7420 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7421 | return -EINVAL; |
| 7422 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7423 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7424 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7425 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7426 | switch (wdev->iftype) { |
| 7427 | case NL80211_IFTYPE_STATION: |
| 7428 | case NL80211_IFTYPE_ADHOC: |
| 7429 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7430 | case NL80211_IFTYPE_AP: |
| 7431 | case NL80211_IFTYPE_AP_VLAN: |
| 7432 | case NL80211_IFTYPE_MESH_POINT: |
| 7433 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7434 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7435 | break; |
| 7436 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7437 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7438 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7439 | |
| 7440 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7441 | if (!rdev->ops->mgmt_tx) |
| 7442 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7443 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7444 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7445 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7446 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7447 | } |
| 7448 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7449 | 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] | 7450 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7451 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7452 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7453 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7454 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7455 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7456 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7457 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7458 | struct cfg80211_mgmt_tx_params params = { |
| 7459 | .dont_wait_for_ack = |
| 7460 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7461 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7462 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7463 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7464 | return -EINVAL; |
| 7465 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7466 | if (!rdev->ops->mgmt_tx) |
| 7467 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7468 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7469 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7470 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7471 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7472 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7473 | case NL80211_IFTYPE_STATION: |
| 7474 | case NL80211_IFTYPE_ADHOC: |
| 7475 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7476 | case NL80211_IFTYPE_AP: |
| 7477 | case NL80211_IFTYPE_AP_VLAN: |
| 7478 | case NL80211_IFTYPE_MESH_POINT: |
| 7479 | case NL80211_IFTYPE_P2P_GO: |
| 7480 | break; |
| 7481 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7482 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7483 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7484 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7485 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7486 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7487 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7488 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7489 | |
| 7490 | /* |
| 7491 | * We should wait on the channel for at least a minimum amount |
| 7492 | * of time (10ms) but no longer than the driver supports. |
| 7493 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7494 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7495 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7496 | return -EINVAL; |
| 7497 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7498 | } |
| 7499 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7500 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7501 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7502 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7503 | return -EINVAL; |
| 7504 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7505 | 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] | 7506 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7507 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7508 | * the driver. The latter will use the current one |
| 7509 | */ |
| 7510 | chandef.chan = NULL; |
| 7511 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7512 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7513 | if (err) |
| 7514 | return err; |
| 7515 | } |
| 7516 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7517 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7518 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7519 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7520 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7521 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7522 | if (!msg) |
| 7523 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7524 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7525 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7526 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7527 | if (!hdr) { |
| 7528 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7529 | goto free_msg; |
| 7530 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7531 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7532 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7533 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 7534 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 7535 | params.chan = chandef.chan; |
| 7536 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7537 | if (err) |
| 7538 | goto free_msg; |
| 7539 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7540 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7541 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7542 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7543 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7544 | genlmsg_end(msg, hdr); |
| 7545 | return genlmsg_reply(msg, info); |
| 7546 | } |
| 7547 | |
| 7548 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7549 | |
| 7550 | nla_put_failure: |
| 7551 | err = -ENOBUFS; |
| 7552 | free_msg: |
| 7553 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7554 | return err; |
| 7555 | } |
| 7556 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7557 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7558 | { |
| 7559 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7560 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7561 | u64 cookie; |
| 7562 | |
| 7563 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7564 | return -EINVAL; |
| 7565 | |
| 7566 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7567 | return -EOPNOTSUPP; |
| 7568 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7569 | switch (wdev->iftype) { |
| 7570 | case NL80211_IFTYPE_STATION: |
| 7571 | case NL80211_IFTYPE_ADHOC: |
| 7572 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7573 | case NL80211_IFTYPE_AP: |
| 7574 | case NL80211_IFTYPE_AP_VLAN: |
| 7575 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7576 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7577 | break; |
| 7578 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7579 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7580 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7581 | |
| 7582 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7583 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7584 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7585 | } |
| 7586 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7587 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7588 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7589 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7590 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7591 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7592 | u8 ps_state; |
| 7593 | bool state; |
| 7594 | int err; |
| 7595 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7596 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7597 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7598 | |
| 7599 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7600 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7601 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7602 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7603 | |
| 7604 | wdev = dev->ieee80211_ptr; |
| 7605 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7606 | if (!rdev->ops->set_power_mgmt) |
| 7607 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7608 | |
| 7609 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7610 | |
| 7611 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7612 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7613 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7614 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7615 | if (!err) |
| 7616 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7617 | return err; |
| 7618 | } |
| 7619 | |
| 7620 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7621 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7622 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7623 | enum nl80211_ps_state ps_state; |
| 7624 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7625 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7626 | struct sk_buff *msg; |
| 7627 | void *hdr; |
| 7628 | int err; |
| 7629 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7630 | wdev = dev->ieee80211_ptr; |
| 7631 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7632 | if (!rdev->ops->set_power_mgmt) |
| 7633 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7634 | |
| 7635 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7636 | if (!msg) |
| 7637 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7638 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7639 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7640 | NL80211_CMD_GET_POWER_SAVE); |
| 7641 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7642 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7643 | goto free_msg; |
| 7644 | } |
| 7645 | |
| 7646 | if (wdev->ps) |
| 7647 | ps_state = NL80211_PS_ENABLED; |
| 7648 | else |
| 7649 | ps_state = NL80211_PS_DISABLED; |
| 7650 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7651 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7652 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7653 | |
| 7654 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7655 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7656 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7657 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7658 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7659 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7660 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7661 | return err; |
| 7662 | } |
| 7663 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7664 | static struct nla_policy |
| 7665 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7666 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7667 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7668 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7669 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7670 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7671 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7672 | }; |
| 7673 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7674 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7675 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7676 | { |
| 7677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7678 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7679 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7680 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7681 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7682 | return -EINVAL; |
| 7683 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7684 | if (!rdev->ops->set_cqm_txe_config) |
| 7685 | return -EOPNOTSUPP; |
| 7686 | |
| 7687 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7688 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7689 | return -EOPNOTSUPP; |
| 7690 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7691 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7692 | } |
| 7693 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7694 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7695 | s32 threshold, u32 hysteresis) |
| 7696 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7697 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7698 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7699 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7700 | |
| 7701 | if (threshold > 0) |
| 7702 | return -EINVAL; |
| 7703 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7704 | /* disabling - hysteresis should also be zero then */ |
| 7705 | if (threshold == 0) |
| 7706 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7707 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7708 | if (!rdev->ops->set_cqm_rssi_config) |
| 7709 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7710 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7711 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7712 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7713 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7714 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7715 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7716 | } |
| 7717 | |
| 7718 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7719 | { |
| 7720 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7721 | struct nlattr *cqm; |
| 7722 | int err; |
| 7723 | |
| 7724 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7725 | if (!cqm) |
| 7726 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7727 | |
| 7728 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7729 | nl80211_attr_cqm_policy); |
| 7730 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7731 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7732 | |
| 7733 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7734 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7735 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7736 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7737 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7738 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7739 | } |
| 7740 | |
| 7741 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7742 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7743 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7744 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7745 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7746 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7747 | |
| 7748 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 7749 | } |
| 7750 | |
| 7751 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7752 | } |
| 7753 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7754 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7755 | { |
| 7756 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7757 | struct net_device *dev = info->user_ptr[1]; |
| 7758 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7759 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7760 | int err; |
| 7761 | |
| 7762 | /* start with default */ |
| 7763 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7764 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7765 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7766 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7767 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7768 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7769 | if (err) |
| 7770 | return err; |
| 7771 | } |
| 7772 | |
| 7773 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7774 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7775 | return -EINVAL; |
| 7776 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7777 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7778 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7779 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7780 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7781 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7782 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7783 | return -EINVAL; |
| 7784 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7785 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7786 | setup.beacon_interval = |
| 7787 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7788 | if (setup.beacon_interval < 10 || |
| 7789 | setup.beacon_interval > 10000) |
| 7790 | return -EINVAL; |
| 7791 | } |
| 7792 | |
| 7793 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7794 | setup.dtim_period = |
| 7795 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7796 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7797 | return -EINVAL; |
| 7798 | } |
| 7799 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7800 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7801 | /* parse additional setup parameters if given */ |
| 7802 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7803 | if (err) |
| 7804 | return err; |
| 7805 | } |
| 7806 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7807 | if (setup.user_mpm) |
| 7808 | cfg.auto_open_plinks = false; |
| 7809 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7810 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7811 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7812 | if (err) |
| 7813 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7814 | } else { |
| 7815 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7816 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7817 | } |
| 7818 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7819 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7820 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7821 | int n_rates = |
| 7822 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7823 | struct ieee80211_supported_band *sband; |
| 7824 | |
| 7825 | if (!setup.chandef.chan) |
| 7826 | return -EINVAL; |
| 7827 | |
| 7828 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7829 | |
| 7830 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7831 | &setup.basic_rates); |
| 7832 | if (err) |
| 7833 | return err; |
| 7834 | } |
| 7835 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7836 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7837 | } |
| 7838 | |
| 7839 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7840 | { |
| 7841 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7842 | struct net_device *dev = info->user_ptr[1]; |
| 7843 | |
| 7844 | return cfg80211_leave_mesh(rdev, dev); |
| 7845 | } |
| 7846 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7847 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7848 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7849 | struct cfg80211_registered_device *rdev) |
| 7850 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7851 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7852 | struct nlattr *nl_pats, *nl_pat; |
| 7853 | int i, pat_len; |
| 7854 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7855 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7856 | return 0; |
| 7857 | |
| 7858 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7859 | if (!nl_pats) |
| 7860 | return -ENOBUFS; |
| 7861 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7862 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7863 | nl_pat = nla_nest_start(msg, i + 1); |
| 7864 | if (!nl_pat) |
| 7865 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7866 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7867 | 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] | 7868 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7869 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 7870 | wowlan->patterns[i].pattern) || |
| 7871 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7872 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7873 | return -ENOBUFS; |
| 7874 | nla_nest_end(msg, nl_pat); |
| 7875 | } |
| 7876 | nla_nest_end(msg, nl_pats); |
| 7877 | |
| 7878 | return 0; |
| 7879 | } |
| 7880 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7881 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7882 | struct cfg80211_wowlan_tcp *tcp) |
| 7883 | { |
| 7884 | struct nlattr *nl_tcp; |
| 7885 | |
| 7886 | if (!tcp) |
| 7887 | return 0; |
| 7888 | |
| 7889 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7890 | if (!nl_tcp) |
| 7891 | return -ENOBUFS; |
| 7892 | |
| 7893 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7894 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7895 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7896 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7897 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7898 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7899 | tcp->payload_len, tcp->payload) || |
| 7900 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7901 | tcp->data_interval) || |
| 7902 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7903 | tcp->wake_len, tcp->wake_data) || |
| 7904 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7905 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7906 | return -ENOBUFS; |
| 7907 | |
| 7908 | if (tcp->payload_seq.len && |
| 7909 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7910 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7911 | return -ENOBUFS; |
| 7912 | |
| 7913 | if (tcp->payload_tok.len && |
| 7914 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7915 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7916 | &tcp->payload_tok)) |
| 7917 | return -ENOBUFS; |
| 7918 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 7919 | nla_nest_end(msg, nl_tcp); |
| 7920 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7921 | return 0; |
| 7922 | } |
| 7923 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7924 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7925 | { |
| 7926 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7927 | struct sk_buff *msg; |
| 7928 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7929 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7930 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7931 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7932 | return -EOPNOTSUPP; |
| 7933 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7934 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7935 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7936 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 7937 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 7938 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 7939 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7940 | } |
| 7941 | |
| 7942 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7943 | if (!msg) |
| 7944 | return -ENOMEM; |
| 7945 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7946 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7947 | NL80211_CMD_GET_WOWLAN); |
| 7948 | if (!hdr) |
| 7949 | goto nla_put_failure; |
| 7950 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7951 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7952 | struct nlattr *nl_wowlan; |
| 7953 | |
| 7954 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7955 | if (!nl_wowlan) |
| 7956 | goto nla_put_failure; |
| 7957 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7958 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7959 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7960 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7961 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7962 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7963 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7964 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7965 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7966 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7967 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7968 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7969 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7970 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7971 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7972 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7973 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7974 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7975 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7976 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7977 | if (nl80211_send_wowlan_tcp(msg, |
| 7978 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7979 | goto nla_put_failure; |
| 7980 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7981 | nla_nest_end(msg, nl_wowlan); |
| 7982 | } |
| 7983 | |
| 7984 | genlmsg_end(msg, hdr); |
| 7985 | return genlmsg_reply(msg, info); |
| 7986 | |
| 7987 | nla_put_failure: |
| 7988 | nlmsg_free(msg); |
| 7989 | return -ENOBUFS; |
| 7990 | } |
| 7991 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7992 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7993 | struct nlattr *attr, |
| 7994 | struct cfg80211_wowlan *trig) |
| 7995 | { |
| 7996 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7997 | struct cfg80211_wowlan_tcp *cfg; |
| 7998 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7999 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8000 | u32 size; |
| 8001 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8002 | int err, port; |
| 8003 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8004 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8005 | return -EINVAL; |
| 8006 | |
| 8007 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8008 | nla_data(attr), nla_len(attr), |
| 8009 | nl80211_wowlan_tcp_policy); |
| 8010 | if (err) |
| 8011 | return err; |
| 8012 | |
| 8013 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8014 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8015 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8016 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8017 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8018 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8019 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8020 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8021 | return -EINVAL; |
| 8022 | |
| 8023 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8024 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8025 | return -EINVAL; |
| 8026 | |
| 8027 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8028 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8029 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8030 | return -EINVAL; |
| 8031 | |
| 8032 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8033 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8034 | return -EINVAL; |
| 8035 | |
| 8036 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8037 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8038 | return -EINVAL; |
| 8039 | |
| 8040 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8041 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8042 | |
| 8043 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8044 | tokens_size = tokln - sizeof(*tok); |
| 8045 | |
| 8046 | if (!tok->len || tokens_size % tok->len) |
| 8047 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8048 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8049 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8050 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8051 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8052 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8053 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8054 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8055 | return -EINVAL; |
| 8056 | if (tok->offset + tok->len > data_size) |
| 8057 | return -EINVAL; |
| 8058 | } |
| 8059 | |
| 8060 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8061 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8062 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8063 | return -EINVAL; |
| 8064 | if (seq->len == 0 || seq->len > 4) |
| 8065 | return -EINVAL; |
| 8066 | if (seq->len + seq->offset > data_size) |
| 8067 | return -EINVAL; |
| 8068 | } |
| 8069 | |
| 8070 | size = sizeof(*cfg); |
| 8071 | size += data_size; |
| 8072 | size += wake_size + wake_mask_size; |
| 8073 | size += tokens_size; |
| 8074 | |
| 8075 | cfg = kzalloc(size, GFP_KERNEL); |
| 8076 | if (!cfg) |
| 8077 | return -ENOMEM; |
| 8078 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8079 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8080 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8081 | ETH_ALEN); |
| 8082 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8083 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8084 | else |
| 8085 | port = 0; |
| 8086 | #ifdef CONFIG_INET |
| 8087 | /* allocate a socket and port for it and use it */ |
| 8088 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8089 | IPPROTO_TCP, &cfg->sock, 1); |
| 8090 | if (err) { |
| 8091 | kfree(cfg); |
| 8092 | return err; |
| 8093 | } |
| 8094 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8095 | sock_release(cfg->sock); |
| 8096 | kfree(cfg); |
| 8097 | return -EADDRINUSE; |
| 8098 | } |
| 8099 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8100 | #else |
| 8101 | if (!port) { |
| 8102 | kfree(cfg); |
| 8103 | return -EINVAL; |
| 8104 | } |
| 8105 | cfg->src_port = port; |
| 8106 | #endif |
| 8107 | |
| 8108 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8109 | cfg->payload_len = data_size; |
| 8110 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8111 | memcpy((void *)cfg->payload, |
| 8112 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8113 | data_size); |
| 8114 | if (seq) |
| 8115 | cfg->payload_seq = *seq; |
| 8116 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8117 | cfg->wake_len = wake_size; |
| 8118 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8119 | memcpy((void *)cfg->wake_data, |
| 8120 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8121 | wake_size); |
| 8122 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8123 | data_size + wake_size; |
| 8124 | memcpy((void *)cfg->wake_mask, |
| 8125 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8126 | wake_mask_size); |
| 8127 | if (tok) { |
| 8128 | cfg->tokens_size = tokens_size; |
| 8129 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8130 | } |
| 8131 | |
| 8132 | trig->tcp = cfg; |
| 8133 | |
| 8134 | return 0; |
| 8135 | } |
| 8136 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8137 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8138 | { |
| 8139 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8140 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8141 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8142 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8143 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8144 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8145 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8146 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8147 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8148 | return -EOPNOTSUPP; |
| 8149 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8150 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8151 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8152 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8153 | goto set_wakeup; |
| 8154 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8155 | |
| 8156 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8157 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8158 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8159 | nl80211_wowlan_policy); |
| 8160 | if (err) |
| 8161 | return err; |
| 8162 | |
| 8163 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8164 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8165 | return -EINVAL; |
| 8166 | new_triggers.any = true; |
| 8167 | } |
| 8168 | |
| 8169 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8170 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8171 | return -EINVAL; |
| 8172 | new_triggers.disconnect = true; |
| 8173 | } |
| 8174 | |
| 8175 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8176 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8177 | return -EINVAL; |
| 8178 | new_triggers.magic_pkt = true; |
| 8179 | } |
| 8180 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8181 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8182 | return -EINVAL; |
| 8183 | |
| 8184 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8185 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8186 | return -EINVAL; |
| 8187 | new_triggers.gtk_rekey_failure = true; |
| 8188 | } |
| 8189 | |
| 8190 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8191 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8192 | return -EINVAL; |
| 8193 | new_triggers.eap_identity_req = true; |
| 8194 | } |
| 8195 | |
| 8196 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8197 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8198 | return -EINVAL; |
| 8199 | new_triggers.four_way_handshake = true; |
| 8200 | } |
| 8201 | |
| 8202 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8203 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8204 | return -EINVAL; |
| 8205 | new_triggers.rfkill_release = true; |
| 8206 | } |
| 8207 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8208 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8209 | struct nlattr *pat; |
| 8210 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8211 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8212 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8213 | |
| 8214 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8215 | rem) |
| 8216 | n_patterns++; |
| 8217 | if (n_patterns > wowlan->n_patterns) |
| 8218 | return -EINVAL; |
| 8219 | |
| 8220 | new_triggers.patterns = kcalloc(n_patterns, |
| 8221 | sizeof(new_triggers.patterns[0]), |
| 8222 | GFP_KERNEL); |
| 8223 | if (!new_triggers.patterns) |
| 8224 | return -ENOMEM; |
| 8225 | |
| 8226 | new_triggers.n_patterns = n_patterns; |
| 8227 | i = 0; |
| 8228 | |
| 8229 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8230 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8231 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8232 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8233 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8234 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8235 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8236 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8237 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8238 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8239 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8240 | goto error; |
| 8241 | if (pat_len > wowlan->pattern_max_len || |
| 8242 | pat_len < wowlan->pattern_min_len) |
| 8243 | goto error; |
| 8244 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8245 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8246 | pkt_offset = 0; |
| 8247 | else |
| 8248 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8249 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8250 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8251 | goto error; |
| 8252 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8253 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8254 | new_triggers.patterns[i].mask = |
| 8255 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8256 | if (!new_triggers.patterns[i].mask) { |
| 8257 | err = -ENOMEM; |
| 8258 | goto error; |
| 8259 | } |
| 8260 | new_triggers.patterns[i].pattern = |
| 8261 | new_triggers.patterns[i].mask + mask_len; |
| 8262 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8263 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8264 | mask_len); |
| 8265 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8266 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8267 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8268 | pat_len); |
| 8269 | i++; |
| 8270 | } |
| 8271 | } |
| 8272 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8273 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8274 | err = nl80211_parse_wowlan_tcp( |
| 8275 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8276 | &new_triggers); |
| 8277 | if (err) |
| 8278 | goto error; |
| 8279 | } |
| 8280 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8281 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8282 | if (!ntrig) { |
| 8283 | err = -ENOMEM; |
| 8284 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8285 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8286 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8287 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8288 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8289 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8290 | if (rdev->ops->set_wakeup && |
| 8291 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8292 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8293 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8294 | return 0; |
| 8295 | error: |
| 8296 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8297 | kfree(new_triggers.patterns[i].mask); |
| 8298 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8299 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8300 | sock_release(new_triggers.tcp->sock); |
| 8301 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8302 | return err; |
| 8303 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8304 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8305 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8306 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8307 | struct cfg80211_registered_device *rdev) |
| 8308 | { |
| 8309 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8310 | int i, j, pat_len; |
| 8311 | struct cfg80211_coalesce_rules *rule; |
| 8312 | |
| 8313 | if (!rdev->coalesce->n_rules) |
| 8314 | return 0; |
| 8315 | |
| 8316 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8317 | if (!nl_rules) |
| 8318 | return -ENOBUFS; |
| 8319 | |
| 8320 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8321 | nl_rule = nla_nest_start(msg, i + 1); |
| 8322 | if (!nl_rule) |
| 8323 | return -ENOBUFS; |
| 8324 | |
| 8325 | rule = &rdev->coalesce->rules[i]; |
| 8326 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8327 | rule->delay)) |
| 8328 | return -ENOBUFS; |
| 8329 | |
| 8330 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8331 | rule->condition)) |
| 8332 | return -ENOBUFS; |
| 8333 | |
| 8334 | nl_pats = nla_nest_start(msg, |
| 8335 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8336 | if (!nl_pats) |
| 8337 | return -ENOBUFS; |
| 8338 | |
| 8339 | for (j = 0; j < rule->n_patterns; j++) { |
| 8340 | nl_pat = nla_nest_start(msg, j + 1); |
| 8341 | if (!nl_pat) |
| 8342 | return -ENOBUFS; |
| 8343 | pat_len = rule->patterns[j].pattern_len; |
| 8344 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8345 | DIV_ROUND_UP(pat_len, 8), |
| 8346 | rule->patterns[j].mask) || |
| 8347 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8348 | rule->patterns[j].pattern) || |
| 8349 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8350 | rule->patterns[j].pkt_offset)) |
| 8351 | return -ENOBUFS; |
| 8352 | nla_nest_end(msg, nl_pat); |
| 8353 | } |
| 8354 | nla_nest_end(msg, nl_pats); |
| 8355 | nla_nest_end(msg, nl_rule); |
| 8356 | } |
| 8357 | nla_nest_end(msg, nl_rules); |
| 8358 | |
| 8359 | return 0; |
| 8360 | } |
| 8361 | |
| 8362 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8363 | { |
| 8364 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8365 | struct sk_buff *msg; |
| 8366 | void *hdr; |
| 8367 | |
| 8368 | if (!rdev->wiphy.coalesce) |
| 8369 | return -EOPNOTSUPP; |
| 8370 | |
| 8371 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8372 | if (!msg) |
| 8373 | return -ENOMEM; |
| 8374 | |
| 8375 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8376 | NL80211_CMD_GET_COALESCE); |
| 8377 | if (!hdr) |
| 8378 | goto nla_put_failure; |
| 8379 | |
| 8380 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8381 | goto nla_put_failure; |
| 8382 | |
| 8383 | genlmsg_end(msg, hdr); |
| 8384 | return genlmsg_reply(msg, info); |
| 8385 | |
| 8386 | nla_put_failure: |
| 8387 | nlmsg_free(msg); |
| 8388 | return -ENOBUFS; |
| 8389 | } |
| 8390 | |
| 8391 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8392 | { |
| 8393 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8394 | int i, j; |
| 8395 | struct cfg80211_coalesce_rules *rule; |
| 8396 | |
| 8397 | if (!coalesce) |
| 8398 | return; |
| 8399 | |
| 8400 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8401 | rule = &coalesce->rules[i]; |
| 8402 | for (j = 0; j < rule->n_patterns; j++) |
| 8403 | kfree(rule->patterns[j].mask); |
| 8404 | kfree(rule->patterns); |
| 8405 | } |
| 8406 | kfree(coalesce->rules); |
| 8407 | kfree(coalesce); |
| 8408 | rdev->coalesce = NULL; |
| 8409 | } |
| 8410 | |
| 8411 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8412 | struct nlattr *rule, |
| 8413 | struct cfg80211_coalesce_rules *new_rule) |
| 8414 | { |
| 8415 | int err, i; |
| 8416 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8417 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8418 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8419 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8420 | |
| 8421 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8422 | nla_len(rule), nl80211_coalesce_policy); |
| 8423 | if (err) |
| 8424 | return err; |
| 8425 | |
| 8426 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8427 | new_rule->delay = |
| 8428 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8429 | if (new_rule->delay > coalesce->max_delay) |
| 8430 | return -EINVAL; |
| 8431 | |
| 8432 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8433 | new_rule->condition = |
| 8434 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8435 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8436 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8437 | return -EINVAL; |
| 8438 | |
| 8439 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8440 | return -EINVAL; |
| 8441 | |
| 8442 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8443 | rem) |
| 8444 | n_patterns++; |
| 8445 | if (n_patterns > coalesce->n_patterns) |
| 8446 | return -EINVAL; |
| 8447 | |
| 8448 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8449 | GFP_KERNEL); |
| 8450 | if (!new_rule->patterns) |
| 8451 | return -ENOMEM; |
| 8452 | |
| 8453 | new_rule->n_patterns = n_patterns; |
| 8454 | i = 0; |
| 8455 | |
| 8456 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8457 | rem) { |
| 8458 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8459 | nla_len(pat), NULL); |
| 8460 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8461 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8462 | return -EINVAL; |
| 8463 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8464 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8465 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8466 | return -EINVAL; |
| 8467 | if (pat_len > coalesce->pattern_max_len || |
| 8468 | pat_len < coalesce->pattern_min_len) |
| 8469 | return -EINVAL; |
| 8470 | |
| 8471 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8472 | pkt_offset = 0; |
| 8473 | else |
| 8474 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8475 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8476 | return -EINVAL; |
| 8477 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8478 | |
| 8479 | new_rule->patterns[i].mask = |
| 8480 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8481 | if (!new_rule->patterns[i].mask) |
| 8482 | return -ENOMEM; |
| 8483 | new_rule->patterns[i].pattern = |
| 8484 | new_rule->patterns[i].mask + mask_len; |
| 8485 | memcpy(new_rule->patterns[i].mask, |
| 8486 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8487 | new_rule->patterns[i].pattern_len = pat_len; |
| 8488 | memcpy(new_rule->patterns[i].pattern, |
| 8489 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8490 | i++; |
| 8491 | } |
| 8492 | |
| 8493 | return 0; |
| 8494 | } |
| 8495 | |
| 8496 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8497 | { |
| 8498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8499 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8500 | struct cfg80211_coalesce new_coalesce = {}; |
| 8501 | struct cfg80211_coalesce *n_coalesce; |
| 8502 | int err, rem_rule, n_rules = 0, i, j; |
| 8503 | struct nlattr *rule; |
| 8504 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8505 | |
| 8506 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8507 | return -EOPNOTSUPP; |
| 8508 | |
| 8509 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8510 | cfg80211_rdev_free_coalesce(rdev); |
| 8511 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8512 | return 0; |
| 8513 | } |
| 8514 | |
| 8515 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8516 | rem_rule) |
| 8517 | n_rules++; |
| 8518 | if (n_rules > coalesce->n_rules) |
| 8519 | return -EINVAL; |
| 8520 | |
| 8521 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8522 | GFP_KERNEL); |
| 8523 | if (!new_coalesce.rules) |
| 8524 | return -ENOMEM; |
| 8525 | |
| 8526 | new_coalesce.n_rules = n_rules; |
| 8527 | i = 0; |
| 8528 | |
| 8529 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8530 | rem_rule) { |
| 8531 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8532 | &new_coalesce.rules[i]); |
| 8533 | if (err) |
| 8534 | goto error; |
| 8535 | |
| 8536 | i++; |
| 8537 | } |
| 8538 | |
| 8539 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8540 | if (err) |
| 8541 | goto error; |
| 8542 | |
| 8543 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8544 | if (!n_coalesce) { |
| 8545 | err = -ENOMEM; |
| 8546 | goto error; |
| 8547 | } |
| 8548 | cfg80211_rdev_free_coalesce(rdev); |
| 8549 | rdev->coalesce = n_coalesce; |
| 8550 | |
| 8551 | return 0; |
| 8552 | error: |
| 8553 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8554 | tmp_rule = &new_coalesce.rules[i]; |
| 8555 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8556 | kfree(tmp_rule->patterns[j].mask); |
| 8557 | kfree(tmp_rule->patterns); |
| 8558 | } |
| 8559 | kfree(new_coalesce.rules); |
| 8560 | |
| 8561 | return err; |
| 8562 | } |
| 8563 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8564 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8565 | { |
| 8566 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8567 | struct net_device *dev = info->user_ptr[1]; |
| 8568 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8569 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8570 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8571 | int err; |
| 8572 | |
| 8573 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8574 | return -EINVAL; |
| 8575 | |
| 8576 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8577 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8578 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8579 | nl80211_rekey_policy); |
| 8580 | if (err) |
| 8581 | return err; |
| 8582 | |
| 8583 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8584 | return -ERANGE; |
| 8585 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8586 | return -ERANGE; |
| 8587 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8588 | return -ERANGE; |
| 8589 | |
| 8590 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8591 | NL80211_KEK_LEN); |
| 8592 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8593 | NL80211_KCK_LEN); |
| 8594 | memcpy(rekey_data.replay_ctr, |
| 8595 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8596 | NL80211_REPLAY_CTR_LEN); |
| 8597 | |
| 8598 | wdev_lock(wdev); |
| 8599 | if (!wdev->current_bss) { |
| 8600 | err = -ENOTCONN; |
| 8601 | goto out; |
| 8602 | } |
| 8603 | |
| 8604 | if (!rdev->ops->set_rekey_data) { |
| 8605 | err = -EOPNOTSUPP; |
| 8606 | goto out; |
| 8607 | } |
| 8608 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8609 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8610 | out: |
| 8611 | wdev_unlock(wdev); |
| 8612 | return err; |
| 8613 | } |
| 8614 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8615 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8616 | struct genl_info *info) |
| 8617 | { |
| 8618 | struct net_device *dev = info->user_ptr[1]; |
| 8619 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8620 | |
| 8621 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8622 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8623 | return -EINVAL; |
| 8624 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8625 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8626 | return -EBUSY; |
| 8627 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8628 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8629 | return 0; |
| 8630 | } |
| 8631 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8632 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8633 | struct genl_info *info) |
| 8634 | { |
| 8635 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8636 | struct net_device *dev = info->user_ptr[1]; |
| 8637 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8638 | struct sk_buff *msg; |
| 8639 | void *hdr; |
| 8640 | const u8 *addr; |
| 8641 | u64 cookie; |
| 8642 | int err; |
| 8643 | |
| 8644 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8645 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8646 | return -EOPNOTSUPP; |
| 8647 | |
| 8648 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8649 | return -EINVAL; |
| 8650 | |
| 8651 | if (!rdev->ops->probe_client) |
| 8652 | return -EOPNOTSUPP; |
| 8653 | |
| 8654 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8655 | if (!msg) |
| 8656 | return -ENOMEM; |
| 8657 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8658 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8659 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8660 | if (!hdr) { |
| 8661 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8662 | goto free_msg; |
| 8663 | } |
| 8664 | |
| 8665 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8666 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8667 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8668 | if (err) |
| 8669 | goto free_msg; |
| 8670 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8671 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8672 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8673 | |
| 8674 | genlmsg_end(msg, hdr); |
| 8675 | |
| 8676 | return genlmsg_reply(msg, info); |
| 8677 | |
| 8678 | nla_put_failure: |
| 8679 | err = -ENOBUFS; |
| 8680 | free_msg: |
| 8681 | nlmsg_free(msg); |
| 8682 | return err; |
| 8683 | } |
| 8684 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8685 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8686 | { |
| 8687 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8688 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8689 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8690 | |
| 8691 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8692 | return -EOPNOTSUPP; |
| 8693 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8694 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8695 | if (!nreg) |
| 8696 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8697 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8698 | /* First, check if already registered. */ |
| 8699 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8700 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8701 | if (reg->nlportid == info->snd_portid) { |
| 8702 | rv = -EALREADY; |
| 8703 | goto out_err; |
| 8704 | } |
| 8705 | } |
| 8706 | /* Add it to the list */ |
| 8707 | nreg->nlportid = info->snd_portid; |
| 8708 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8709 | |
| 8710 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8711 | |
| 8712 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8713 | out_err: |
| 8714 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8715 | kfree(nreg); |
| 8716 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8717 | } |
| 8718 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8719 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8720 | { |
| 8721 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8722 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8723 | int err; |
| 8724 | |
| 8725 | if (!rdev->ops->start_p2p_device) |
| 8726 | return -EOPNOTSUPP; |
| 8727 | |
| 8728 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8729 | return -EOPNOTSUPP; |
| 8730 | |
| 8731 | if (wdev->p2p_started) |
| 8732 | return 0; |
| 8733 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8734 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8735 | if (err) |
| 8736 | return err; |
| 8737 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8738 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8739 | if (err) |
| 8740 | return err; |
| 8741 | |
| 8742 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8743 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8744 | |
| 8745 | return 0; |
| 8746 | } |
| 8747 | |
| 8748 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8749 | { |
| 8750 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8751 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8752 | |
| 8753 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8754 | return -EOPNOTSUPP; |
| 8755 | |
| 8756 | if (!rdev->ops->stop_p2p_device) |
| 8757 | return -EOPNOTSUPP; |
| 8758 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8759 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8760 | |
| 8761 | return 0; |
| 8762 | } |
| 8763 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8764 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8765 | struct genl_info *info) |
| 8766 | { |
| 8767 | void *hdr; |
| 8768 | struct sk_buff *msg; |
| 8769 | |
| 8770 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8771 | if (!msg) |
| 8772 | return -ENOMEM; |
| 8773 | |
| 8774 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8775 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8776 | if (!hdr) |
| 8777 | goto nla_put_failure; |
| 8778 | |
| 8779 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8780 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8781 | goto nla_put_failure; |
| 8782 | |
| 8783 | genlmsg_end(msg, hdr); |
| 8784 | return genlmsg_reply(msg, info); |
| 8785 | |
| 8786 | nla_put_failure: |
| 8787 | kfree_skb(msg); |
| 8788 | return -ENOBUFS; |
| 8789 | } |
| 8790 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8791 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8792 | { |
| 8793 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8794 | struct cfg80211_update_ft_ies_params ft_params; |
| 8795 | struct net_device *dev = info->user_ptr[1]; |
| 8796 | |
| 8797 | if (!rdev->ops->update_ft_ies) |
| 8798 | return -EOPNOTSUPP; |
| 8799 | |
| 8800 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8801 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8802 | return -EINVAL; |
| 8803 | |
| 8804 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8805 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8806 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8807 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8808 | |
| 8809 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8810 | } |
| 8811 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8812 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8813 | struct genl_info *info) |
| 8814 | { |
| 8815 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8816 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8817 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8818 | u16 duration; |
| 8819 | int ret; |
| 8820 | |
| 8821 | if (!rdev->ops->crit_proto_start) |
| 8822 | return -EOPNOTSUPP; |
| 8823 | |
| 8824 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8825 | return -EINVAL; |
| 8826 | |
| 8827 | if (rdev->crit_proto_nlportid) |
| 8828 | return -EBUSY; |
| 8829 | |
| 8830 | /* determine protocol if provided */ |
| 8831 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8832 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8833 | |
| 8834 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8835 | return -EINVAL; |
| 8836 | |
| 8837 | /* timeout must be provided */ |
| 8838 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8839 | return -EINVAL; |
| 8840 | |
| 8841 | duration = |
| 8842 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8843 | |
| 8844 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8845 | return -ERANGE; |
| 8846 | |
| 8847 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8848 | if (!ret) |
| 8849 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8850 | |
| 8851 | return ret; |
| 8852 | } |
| 8853 | |
| 8854 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8855 | struct genl_info *info) |
| 8856 | { |
| 8857 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8858 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8859 | |
| 8860 | if (!rdev->ops->crit_proto_stop) |
| 8861 | return -EOPNOTSUPP; |
| 8862 | |
| 8863 | if (rdev->crit_proto_nlportid) { |
| 8864 | rdev->crit_proto_nlportid = 0; |
| 8865 | rdev_crit_proto_stop(rdev, wdev); |
| 8866 | } |
| 8867 | return 0; |
| 8868 | } |
| 8869 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8870 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8871 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8872 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8873 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8874 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8875 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8876 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8877 | /* 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] | 8878 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8879 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8880 | |
| 8881 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8882 | struct genl_info *info) |
| 8883 | { |
| 8884 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8885 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8886 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8887 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8888 | |
| 8889 | if (rtnl) |
| 8890 | rtnl_lock(); |
| 8891 | |
| 8892 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8893 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8894 | if (IS_ERR(rdev)) { |
| 8895 | if (rtnl) |
| 8896 | rtnl_unlock(); |
| 8897 | return PTR_ERR(rdev); |
| 8898 | } |
| 8899 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8900 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8901 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8902 | ASSERT_RTNL(); |
| 8903 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8904 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8905 | info->attrs); |
| 8906 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8907 | if (rtnl) |
| 8908 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8909 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8910 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8911 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8912 | dev = wdev->netdev; |
| 8913 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8914 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8915 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8916 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8917 | if (rtnl) |
| 8918 | rtnl_unlock(); |
| 8919 | return -EINVAL; |
| 8920 | } |
| 8921 | |
| 8922 | info->user_ptr[1] = dev; |
| 8923 | } else { |
| 8924 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8925 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8926 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8927 | if (dev) { |
| 8928 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8929 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8930 | if (rtnl) |
| 8931 | rtnl_unlock(); |
| 8932 | return -ENETDOWN; |
| 8933 | } |
| 8934 | |
| 8935 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8936 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8937 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8938 | if (rtnl) |
| 8939 | rtnl_unlock(); |
| 8940 | return -ENETDOWN; |
| 8941 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8942 | } |
| 8943 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8944 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8945 | } |
| 8946 | |
| 8947 | return 0; |
| 8948 | } |
| 8949 | |
| 8950 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8951 | struct genl_info *info) |
| 8952 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8953 | if (info->user_ptr[1]) { |
| 8954 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8955 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8956 | |
| 8957 | if (wdev->netdev) |
| 8958 | dev_put(wdev->netdev); |
| 8959 | } else { |
| 8960 | dev_put(info->user_ptr[1]); |
| 8961 | } |
| 8962 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8963 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8964 | rtnl_unlock(); |
| 8965 | } |
| 8966 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8967 | static struct genl_ops nl80211_ops[] = { |
| 8968 | { |
| 8969 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8970 | .doit = nl80211_get_wiphy, |
| 8971 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 8972 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8973 | .policy = nl80211_policy, |
| 8974 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8975 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8976 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8977 | }, |
| 8978 | { |
| 8979 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8980 | .doit = nl80211_set_wiphy, |
| 8981 | .policy = nl80211_policy, |
| 8982 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8983 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8984 | }, |
| 8985 | { |
| 8986 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8987 | .doit = nl80211_get_interface, |
| 8988 | .dumpit = nl80211_dump_interface, |
| 8989 | .policy = nl80211_policy, |
| 8990 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8991 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8992 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8993 | }, |
| 8994 | { |
| 8995 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8996 | .doit = nl80211_set_interface, |
| 8997 | .policy = nl80211_policy, |
| 8998 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8999 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9000 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9001 | }, |
| 9002 | { |
| 9003 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9004 | .doit = nl80211_new_interface, |
| 9005 | .policy = nl80211_policy, |
| 9006 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9007 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9008 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9009 | }, |
| 9010 | { |
| 9011 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9012 | .doit = nl80211_del_interface, |
| 9013 | .policy = nl80211_policy, |
| 9014 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9015 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9016 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9017 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9018 | { |
| 9019 | .cmd = NL80211_CMD_GET_KEY, |
| 9020 | .doit = nl80211_get_key, |
| 9021 | .policy = nl80211_policy, |
| 9022 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9023 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9024 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9025 | }, |
| 9026 | { |
| 9027 | .cmd = NL80211_CMD_SET_KEY, |
| 9028 | .doit = nl80211_set_key, |
| 9029 | .policy = nl80211_policy, |
| 9030 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9031 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9032 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9033 | }, |
| 9034 | { |
| 9035 | .cmd = NL80211_CMD_NEW_KEY, |
| 9036 | .doit = nl80211_new_key, |
| 9037 | .policy = nl80211_policy, |
| 9038 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9039 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9040 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9041 | }, |
| 9042 | { |
| 9043 | .cmd = NL80211_CMD_DEL_KEY, |
| 9044 | .doit = nl80211_del_key, |
| 9045 | .policy = nl80211_policy, |
| 9046 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9047 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9048 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9049 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9050 | { |
| 9051 | .cmd = NL80211_CMD_SET_BEACON, |
| 9052 | .policy = nl80211_policy, |
| 9053 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9054 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9055 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9056 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9057 | }, |
| 9058 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9059 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9060 | .policy = nl80211_policy, |
| 9061 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9062 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9063 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9064 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9065 | }, |
| 9066 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9067 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9068 | .policy = nl80211_policy, |
| 9069 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9070 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9071 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9072 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9073 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9074 | { |
| 9075 | .cmd = NL80211_CMD_GET_STATION, |
| 9076 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9077 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9078 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9079 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9080 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9081 | }, |
| 9082 | { |
| 9083 | .cmd = NL80211_CMD_SET_STATION, |
| 9084 | .doit = nl80211_set_station, |
| 9085 | .policy = nl80211_policy, |
| 9086 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9087 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9088 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9089 | }, |
| 9090 | { |
| 9091 | .cmd = NL80211_CMD_NEW_STATION, |
| 9092 | .doit = nl80211_new_station, |
| 9093 | .policy = nl80211_policy, |
| 9094 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9095 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9096 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9097 | }, |
| 9098 | { |
| 9099 | .cmd = NL80211_CMD_DEL_STATION, |
| 9100 | .doit = nl80211_del_station, |
| 9101 | .policy = nl80211_policy, |
| 9102 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9103 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9104 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9105 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9106 | { |
| 9107 | .cmd = NL80211_CMD_GET_MPATH, |
| 9108 | .doit = nl80211_get_mpath, |
| 9109 | .dumpit = nl80211_dump_mpath, |
| 9110 | .policy = nl80211_policy, |
| 9111 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9112 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9113 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9114 | }, |
| 9115 | { |
| 9116 | .cmd = NL80211_CMD_SET_MPATH, |
| 9117 | .doit = nl80211_set_mpath, |
| 9118 | .policy = nl80211_policy, |
| 9119 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9120 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9121 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9122 | }, |
| 9123 | { |
| 9124 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9125 | .doit = nl80211_new_mpath, |
| 9126 | .policy = nl80211_policy, |
| 9127 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9128 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9129 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9130 | }, |
| 9131 | { |
| 9132 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9133 | .doit = nl80211_del_mpath, |
| 9134 | .policy = nl80211_policy, |
| 9135 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9136 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9137 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9138 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9139 | { |
| 9140 | .cmd = NL80211_CMD_SET_BSS, |
| 9141 | .doit = nl80211_set_bss, |
| 9142 | .policy = nl80211_policy, |
| 9143 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9144 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9145 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9146 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9147 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9148 | .cmd = NL80211_CMD_GET_REG, |
| 9149 | .doit = nl80211_get_reg, |
| 9150 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9151 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9152 | /* can be retrieved by unprivileged users */ |
| 9153 | }, |
| 9154 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9155 | .cmd = NL80211_CMD_SET_REG, |
| 9156 | .doit = nl80211_set_reg, |
| 9157 | .policy = nl80211_policy, |
| 9158 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9159 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9160 | }, |
| 9161 | { |
| 9162 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9163 | .doit = nl80211_req_set_reg, |
| 9164 | .policy = nl80211_policy, |
| 9165 | .flags = GENL_ADMIN_PERM, |
| 9166 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9167 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9168 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9169 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9170 | .policy = nl80211_policy, |
| 9171 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9172 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9173 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9174 | }, |
| 9175 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9176 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9177 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9178 | .policy = nl80211_policy, |
| 9179 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9180 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9181 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9182 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9183 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9184 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9185 | .doit = nl80211_trigger_scan, |
| 9186 | .policy = nl80211_policy, |
| 9187 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9188 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9189 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9190 | }, |
| 9191 | { |
| 9192 | .cmd = NL80211_CMD_GET_SCAN, |
| 9193 | .policy = nl80211_policy, |
| 9194 | .dumpit = nl80211_dump_scan, |
| 9195 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9196 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9197 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9198 | .doit = nl80211_start_sched_scan, |
| 9199 | .policy = nl80211_policy, |
| 9200 | .flags = GENL_ADMIN_PERM, |
| 9201 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9202 | NL80211_FLAG_NEED_RTNL, |
| 9203 | }, |
| 9204 | { |
| 9205 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9206 | .doit = nl80211_stop_sched_scan, |
| 9207 | .policy = nl80211_policy, |
| 9208 | .flags = GENL_ADMIN_PERM, |
| 9209 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9210 | NL80211_FLAG_NEED_RTNL, |
| 9211 | }, |
| 9212 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9213 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9214 | .doit = nl80211_authenticate, |
| 9215 | .policy = nl80211_policy, |
| 9216 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9217 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9218 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9219 | }, |
| 9220 | { |
| 9221 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9222 | .doit = nl80211_associate, |
| 9223 | .policy = nl80211_policy, |
| 9224 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9225 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9226 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9227 | }, |
| 9228 | { |
| 9229 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9230 | .doit = nl80211_deauthenticate, |
| 9231 | .policy = nl80211_policy, |
| 9232 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9233 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9234 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9235 | }, |
| 9236 | { |
| 9237 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9238 | .doit = nl80211_disassociate, |
| 9239 | .policy = nl80211_policy, |
| 9240 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9241 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9242 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9243 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9244 | { |
| 9245 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9246 | .doit = nl80211_join_ibss, |
| 9247 | .policy = nl80211_policy, |
| 9248 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9249 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9250 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9251 | }, |
| 9252 | { |
| 9253 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9254 | .doit = nl80211_leave_ibss, |
| 9255 | .policy = nl80211_policy, |
| 9256 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9257 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9258 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9259 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9260 | #ifdef CONFIG_NL80211_TESTMODE |
| 9261 | { |
| 9262 | .cmd = NL80211_CMD_TESTMODE, |
| 9263 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9264 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9265 | .policy = nl80211_policy, |
| 9266 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9267 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9268 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9269 | }, |
| 9270 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9271 | { |
| 9272 | .cmd = NL80211_CMD_CONNECT, |
| 9273 | .doit = nl80211_connect, |
| 9274 | .policy = nl80211_policy, |
| 9275 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9276 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9277 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9278 | }, |
| 9279 | { |
| 9280 | .cmd = NL80211_CMD_DISCONNECT, |
| 9281 | .doit = nl80211_disconnect, |
| 9282 | .policy = nl80211_policy, |
| 9283 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9284 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9285 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9286 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9287 | { |
| 9288 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9289 | .doit = nl80211_wiphy_netns, |
| 9290 | .policy = nl80211_policy, |
| 9291 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9292 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9293 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9294 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9295 | { |
| 9296 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9297 | .policy = nl80211_policy, |
| 9298 | .dumpit = nl80211_dump_survey, |
| 9299 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9300 | { |
| 9301 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9302 | .doit = nl80211_setdel_pmksa, |
| 9303 | .policy = nl80211_policy, |
| 9304 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9305 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9306 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9307 | }, |
| 9308 | { |
| 9309 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9310 | .doit = nl80211_setdel_pmksa, |
| 9311 | .policy = nl80211_policy, |
| 9312 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9313 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9314 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9315 | }, |
| 9316 | { |
| 9317 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9318 | .doit = nl80211_flush_pmksa, |
| 9319 | .policy = nl80211_policy, |
| 9320 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9321 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9322 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9323 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9324 | { |
| 9325 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9326 | .doit = nl80211_remain_on_channel, |
| 9327 | .policy = nl80211_policy, |
| 9328 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9329 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9330 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9331 | }, |
| 9332 | { |
| 9333 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9334 | .doit = nl80211_cancel_remain_on_channel, |
| 9335 | .policy = nl80211_policy, |
| 9336 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9337 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9338 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9339 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9340 | { |
| 9341 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9342 | .doit = nl80211_set_tx_bitrate_mask, |
| 9343 | .policy = nl80211_policy, |
| 9344 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9345 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9346 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9347 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9348 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9349 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9350 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9351 | .policy = nl80211_policy, |
| 9352 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9353 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9354 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9355 | }, |
| 9356 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9357 | .cmd = NL80211_CMD_FRAME, |
| 9358 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9359 | .policy = nl80211_policy, |
| 9360 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9361 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9362 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9363 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9364 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9365 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9366 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9367 | .policy = nl80211_policy, |
| 9368 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9369 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9370 | NL80211_FLAG_NEED_RTNL, |
| 9371 | }, |
| 9372 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9373 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9374 | .doit = nl80211_set_power_save, |
| 9375 | .policy = nl80211_policy, |
| 9376 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9377 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9378 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9379 | }, |
| 9380 | { |
| 9381 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9382 | .doit = nl80211_get_power_save, |
| 9383 | .policy = nl80211_policy, |
| 9384 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9385 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9386 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9387 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9388 | { |
| 9389 | .cmd = NL80211_CMD_SET_CQM, |
| 9390 | .doit = nl80211_set_cqm, |
| 9391 | .policy = nl80211_policy, |
| 9392 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9393 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9394 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9395 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9396 | { |
| 9397 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9398 | .doit = nl80211_set_channel, |
| 9399 | .policy = nl80211_policy, |
| 9400 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9401 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9402 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9403 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9404 | { |
| 9405 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9406 | .doit = nl80211_set_wds_peer, |
| 9407 | .policy = nl80211_policy, |
| 9408 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9409 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9410 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9411 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9412 | { |
| 9413 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9414 | .doit = nl80211_join_mesh, |
| 9415 | .policy = nl80211_policy, |
| 9416 | .flags = GENL_ADMIN_PERM, |
| 9417 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9418 | NL80211_FLAG_NEED_RTNL, |
| 9419 | }, |
| 9420 | { |
| 9421 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9422 | .doit = nl80211_leave_mesh, |
| 9423 | .policy = nl80211_policy, |
| 9424 | .flags = GENL_ADMIN_PERM, |
| 9425 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9426 | NL80211_FLAG_NEED_RTNL, |
| 9427 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9428 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9429 | { |
| 9430 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9431 | .doit = nl80211_get_wowlan, |
| 9432 | .policy = nl80211_policy, |
| 9433 | /* can be retrieved by unprivileged users */ |
| 9434 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9435 | NL80211_FLAG_NEED_RTNL, |
| 9436 | }, |
| 9437 | { |
| 9438 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9439 | .doit = nl80211_set_wowlan, |
| 9440 | .policy = nl80211_policy, |
| 9441 | .flags = GENL_ADMIN_PERM, |
| 9442 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9443 | NL80211_FLAG_NEED_RTNL, |
| 9444 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9445 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9446 | { |
| 9447 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9448 | .doit = nl80211_set_rekey_data, |
| 9449 | .policy = nl80211_policy, |
| 9450 | .flags = GENL_ADMIN_PERM, |
| 9451 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9452 | NL80211_FLAG_NEED_RTNL, |
| 9453 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9454 | { |
| 9455 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9456 | .doit = nl80211_tdls_mgmt, |
| 9457 | .policy = nl80211_policy, |
| 9458 | .flags = GENL_ADMIN_PERM, |
| 9459 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9460 | NL80211_FLAG_NEED_RTNL, |
| 9461 | }, |
| 9462 | { |
| 9463 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9464 | .doit = nl80211_tdls_oper, |
| 9465 | .policy = nl80211_policy, |
| 9466 | .flags = GENL_ADMIN_PERM, |
| 9467 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9468 | NL80211_FLAG_NEED_RTNL, |
| 9469 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9470 | { |
| 9471 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9472 | .doit = nl80211_register_unexpected_frame, |
| 9473 | .policy = nl80211_policy, |
| 9474 | .flags = GENL_ADMIN_PERM, |
| 9475 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9476 | NL80211_FLAG_NEED_RTNL, |
| 9477 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9478 | { |
| 9479 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9480 | .doit = nl80211_probe_client, |
| 9481 | .policy = nl80211_policy, |
| 9482 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9483 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9484 | NL80211_FLAG_NEED_RTNL, |
| 9485 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9486 | { |
| 9487 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9488 | .doit = nl80211_register_beacons, |
| 9489 | .policy = nl80211_policy, |
| 9490 | .flags = GENL_ADMIN_PERM, |
| 9491 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9492 | NL80211_FLAG_NEED_RTNL, |
| 9493 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9494 | { |
| 9495 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9496 | .doit = nl80211_set_noack_map, |
| 9497 | .policy = nl80211_policy, |
| 9498 | .flags = GENL_ADMIN_PERM, |
| 9499 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9500 | NL80211_FLAG_NEED_RTNL, |
| 9501 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9502 | { |
| 9503 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9504 | .doit = nl80211_start_p2p_device, |
| 9505 | .policy = nl80211_policy, |
| 9506 | .flags = GENL_ADMIN_PERM, |
| 9507 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9508 | NL80211_FLAG_NEED_RTNL, |
| 9509 | }, |
| 9510 | { |
| 9511 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9512 | .doit = nl80211_stop_p2p_device, |
| 9513 | .policy = nl80211_policy, |
| 9514 | .flags = GENL_ADMIN_PERM, |
| 9515 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9516 | NL80211_FLAG_NEED_RTNL, |
| 9517 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9518 | { |
| 9519 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9520 | .doit = nl80211_set_mcast_rate, |
| 9521 | .policy = nl80211_policy, |
| 9522 | .flags = GENL_ADMIN_PERM, |
| 9523 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9524 | NL80211_FLAG_NEED_RTNL, |
| 9525 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9526 | { |
| 9527 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9528 | .doit = nl80211_set_mac_acl, |
| 9529 | .policy = nl80211_policy, |
| 9530 | .flags = GENL_ADMIN_PERM, |
| 9531 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9532 | NL80211_FLAG_NEED_RTNL, |
| 9533 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9534 | { |
| 9535 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9536 | .doit = nl80211_start_radar_detection, |
| 9537 | .policy = nl80211_policy, |
| 9538 | .flags = GENL_ADMIN_PERM, |
| 9539 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9540 | NL80211_FLAG_NEED_RTNL, |
| 9541 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9542 | { |
| 9543 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9544 | .doit = nl80211_get_protocol_features, |
| 9545 | .policy = nl80211_policy, |
| 9546 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9547 | { |
| 9548 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9549 | .doit = nl80211_update_ft_ies, |
| 9550 | .policy = nl80211_policy, |
| 9551 | .flags = GENL_ADMIN_PERM, |
| 9552 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9553 | NL80211_FLAG_NEED_RTNL, |
| 9554 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9555 | { |
| 9556 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9557 | .doit = nl80211_crit_protocol_start, |
| 9558 | .policy = nl80211_policy, |
| 9559 | .flags = GENL_ADMIN_PERM, |
| 9560 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9561 | NL80211_FLAG_NEED_RTNL, |
| 9562 | }, |
| 9563 | { |
| 9564 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9565 | .doit = nl80211_crit_protocol_stop, |
| 9566 | .policy = nl80211_policy, |
| 9567 | .flags = GENL_ADMIN_PERM, |
| 9568 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9569 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9570 | }, |
| 9571 | { |
| 9572 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9573 | .doit = nl80211_get_coalesce, |
| 9574 | .policy = nl80211_policy, |
| 9575 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9576 | NL80211_FLAG_NEED_RTNL, |
| 9577 | }, |
| 9578 | { |
| 9579 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9580 | .doit = nl80211_set_coalesce, |
| 9581 | .policy = nl80211_policy, |
| 9582 | .flags = GENL_ADMIN_PERM, |
| 9583 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9584 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9585 | }, |
| 9586 | { |
| 9587 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9588 | .doit = nl80211_channel_switch, |
| 9589 | .policy = nl80211_policy, |
| 9590 | .flags = GENL_ADMIN_PERM, |
| 9591 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9592 | NL80211_FLAG_NEED_RTNL, |
| 9593 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9594 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9595 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9596 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 9597 | .name = "mlme", |
| 9598 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9599 | |
| 9600 | /* multicast groups */ |
| 9601 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 9602 | .name = "config", |
| 9603 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9604 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 9605 | .name = "scan", |
| 9606 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9607 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 9608 | .name = "regulatory", |
| 9609 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9610 | |
| 9611 | /* notification functions */ |
| 9612 | |
| 9613 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9614 | { |
| 9615 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9616 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9617 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9618 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9619 | if (!msg) |
| 9620 | return; |
| 9621 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9622 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9623 | nlmsg_free(msg); |
| 9624 | return; |
| 9625 | } |
| 9626 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9627 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9628 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9629 | } |
| 9630 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9631 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9632 | struct cfg80211_registered_device *rdev) |
| 9633 | { |
| 9634 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9635 | struct nlattr *nest; |
| 9636 | int i; |
| 9637 | |
| 9638 | if (WARN_ON(!req)) |
| 9639 | return 0; |
| 9640 | |
| 9641 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9642 | if (!nest) |
| 9643 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9644 | for (i = 0; i < req->n_ssids; i++) { |
| 9645 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9646 | goto nla_put_failure; |
| 9647 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9648 | nla_nest_end(msg, nest); |
| 9649 | |
| 9650 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9651 | if (!nest) |
| 9652 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9653 | for (i = 0; i < req->n_channels; i++) { |
| 9654 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9655 | goto nla_put_failure; |
| 9656 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9657 | nla_nest_end(msg, nest); |
| 9658 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9659 | if (req->ie && |
| 9660 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9661 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9662 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9663 | if (req->flags) |
| 9664 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 9665 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9666 | return 0; |
| 9667 | nla_put_failure: |
| 9668 | return -ENOBUFS; |
| 9669 | } |
| 9670 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9671 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9672 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9673 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9674 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9675 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9676 | { |
| 9677 | void *hdr; |
| 9678 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9679 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9680 | if (!hdr) |
| 9681 | return -1; |
| 9682 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9683 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9684 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9685 | wdev->netdev->ifindex)) || |
| 9686 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9687 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9688 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9689 | /* ignore errors and send incomplete event anyway */ |
| 9690 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9691 | |
| 9692 | return genlmsg_end(msg, hdr); |
| 9693 | |
| 9694 | nla_put_failure: |
| 9695 | genlmsg_cancel(msg, hdr); |
| 9696 | return -EMSGSIZE; |
| 9697 | } |
| 9698 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9699 | static int |
| 9700 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9701 | struct cfg80211_registered_device *rdev, |
| 9702 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9703 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9704 | { |
| 9705 | void *hdr; |
| 9706 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9707 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9708 | if (!hdr) |
| 9709 | return -1; |
| 9710 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9711 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9712 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9713 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9714 | |
| 9715 | return genlmsg_end(msg, hdr); |
| 9716 | |
| 9717 | nla_put_failure: |
| 9718 | genlmsg_cancel(msg, hdr); |
| 9719 | return -EMSGSIZE; |
| 9720 | } |
| 9721 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9722 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9723 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9724 | { |
| 9725 | struct sk_buff *msg; |
| 9726 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9727 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9728 | if (!msg) |
| 9729 | return; |
| 9730 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9731 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9732 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9733 | nlmsg_free(msg); |
| 9734 | return; |
| 9735 | } |
| 9736 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9737 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9738 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9739 | } |
| 9740 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9741 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9742 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9743 | { |
| 9744 | struct sk_buff *msg; |
| 9745 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9746 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9747 | if (!msg) |
| 9748 | return; |
| 9749 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9750 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9751 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9752 | nlmsg_free(msg); |
| 9753 | return; |
| 9754 | } |
| 9755 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9756 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9757 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9758 | } |
| 9759 | |
| 9760 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9761 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9762 | { |
| 9763 | struct sk_buff *msg; |
| 9764 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9765 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9766 | if (!msg) |
| 9767 | return; |
| 9768 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9769 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9770 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9771 | nlmsg_free(msg); |
| 9772 | return; |
| 9773 | } |
| 9774 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9775 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9776 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9777 | } |
| 9778 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9779 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9780 | struct net_device *netdev) |
| 9781 | { |
| 9782 | struct sk_buff *msg; |
| 9783 | |
| 9784 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9785 | if (!msg) |
| 9786 | return; |
| 9787 | |
| 9788 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9789 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9790 | nlmsg_free(msg); |
| 9791 | return; |
| 9792 | } |
| 9793 | |
| 9794 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9795 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9796 | } |
| 9797 | |
| 9798 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9799 | struct net_device *netdev, u32 cmd) |
| 9800 | { |
| 9801 | struct sk_buff *msg; |
| 9802 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9803 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9804 | if (!msg) |
| 9805 | return; |
| 9806 | |
| 9807 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9808 | nlmsg_free(msg); |
| 9809 | return; |
| 9810 | } |
| 9811 | |
| 9812 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9813 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9814 | } |
| 9815 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9816 | /* |
| 9817 | * This can happen on global regulatory changes or device specific settings |
| 9818 | * based on custom world regulatory domains. |
| 9819 | */ |
| 9820 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9821 | { |
| 9822 | struct sk_buff *msg; |
| 9823 | void *hdr; |
| 9824 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9825 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9826 | if (!msg) |
| 9827 | return; |
| 9828 | |
| 9829 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9830 | if (!hdr) { |
| 9831 | nlmsg_free(msg); |
| 9832 | return; |
| 9833 | } |
| 9834 | |
| 9835 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9836 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9837 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9838 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9839 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9840 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9841 | NL80211_REGDOM_TYPE_WORLD)) |
| 9842 | goto nla_put_failure; |
| 9843 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9844 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9845 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9846 | goto nla_put_failure; |
| 9847 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9848 | request->intersect) { |
| 9849 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9850 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9851 | goto nla_put_failure; |
| 9852 | } else { |
| 9853 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9854 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9855 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9856 | request->alpha2)) |
| 9857 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9858 | } |
| 9859 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9860 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9861 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9862 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9863 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9864 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9865 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9866 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9867 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9868 | GFP_ATOMIC); |
| 9869 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9870 | |
| 9871 | return; |
| 9872 | |
| 9873 | nla_put_failure: |
| 9874 | genlmsg_cancel(msg, hdr); |
| 9875 | nlmsg_free(msg); |
| 9876 | } |
| 9877 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9878 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9879 | struct net_device *netdev, |
| 9880 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9881 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9882 | { |
| 9883 | struct sk_buff *msg; |
| 9884 | void *hdr; |
| 9885 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9886 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9887 | if (!msg) |
| 9888 | return; |
| 9889 | |
| 9890 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9891 | if (!hdr) { |
| 9892 | nlmsg_free(msg); |
| 9893 | return; |
| 9894 | } |
| 9895 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9896 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9897 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9898 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9899 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9900 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9901 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9902 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9903 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9904 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9905 | return; |
| 9906 | |
| 9907 | nla_put_failure: |
| 9908 | genlmsg_cancel(msg, hdr); |
| 9909 | nlmsg_free(msg); |
| 9910 | } |
| 9911 | |
| 9912 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9913 | struct net_device *netdev, const u8 *buf, |
| 9914 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9915 | { |
| 9916 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9917 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9918 | } |
| 9919 | |
| 9920 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9921 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9922 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9923 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9924 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9925 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9926 | } |
| 9927 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9928 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9929 | struct net_device *netdev, const u8 *buf, |
| 9930 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9931 | { |
| 9932 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9933 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9934 | } |
| 9935 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9936 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9937 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9938 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9939 | { |
| 9940 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9941 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9942 | } |
| 9943 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9944 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 9945 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9946 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9947 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9948 | struct wiphy *wiphy = wdev->wiphy; |
| 9949 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9950 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 9951 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9952 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9953 | if (WARN_ON(len < 2)) |
| 9954 | return; |
| 9955 | |
| 9956 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 9957 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 9958 | else |
| 9959 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 9960 | |
| 9961 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 9962 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9963 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9964 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9965 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9966 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9967 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9968 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9969 | { |
| 9970 | struct sk_buff *msg; |
| 9971 | void *hdr; |
| 9972 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9973 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9974 | if (!msg) |
| 9975 | return; |
| 9976 | |
| 9977 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9978 | if (!hdr) { |
| 9979 | nlmsg_free(msg); |
| 9980 | return; |
| 9981 | } |
| 9982 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9983 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9984 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9985 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9986 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9987 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9988 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9989 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9990 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9991 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9992 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9993 | return; |
| 9994 | |
| 9995 | nla_put_failure: |
| 9996 | genlmsg_cancel(msg, hdr); |
| 9997 | nlmsg_free(msg); |
| 9998 | } |
| 9999 | |
| 10000 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10001 | struct net_device *netdev, const u8 *addr, |
| 10002 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10003 | { |
| 10004 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10005 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10006 | } |
| 10007 | |
| 10008 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10009 | struct net_device *netdev, const u8 *addr, |
| 10010 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10011 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10012 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10013 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10014 | } |
| 10015 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10016 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10017 | struct net_device *netdev, const u8 *bssid, |
| 10018 | const u8 *req_ie, size_t req_ie_len, |
| 10019 | const u8 *resp_ie, size_t resp_ie_len, |
| 10020 | u16 status, gfp_t gfp) |
| 10021 | { |
| 10022 | struct sk_buff *msg; |
| 10023 | void *hdr; |
| 10024 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10025 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10026 | if (!msg) |
| 10027 | return; |
| 10028 | |
| 10029 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10030 | if (!hdr) { |
| 10031 | nlmsg_free(msg); |
| 10032 | return; |
| 10033 | } |
| 10034 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10035 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10036 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10037 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10038 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10039 | (req_ie && |
| 10040 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10041 | (resp_ie && |
| 10042 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10043 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10044 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10045 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10046 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10047 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10048 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10049 | return; |
| 10050 | |
| 10051 | nla_put_failure: |
| 10052 | genlmsg_cancel(msg, hdr); |
| 10053 | nlmsg_free(msg); |
| 10054 | |
| 10055 | } |
| 10056 | |
| 10057 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10058 | struct net_device *netdev, const u8 *bssid, |
| 10059 | const u8 *req_ie, size_t req_ie_len, |
| 10060 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10061 | { |
| 10062 | struct sk_buff *msg; |
| 10063 | void *hdr; |
| 10064 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10065 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10066 | if (!msg) |
| 10067 | return; |
| 10068 | |
| 10069 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10070 | if (!hdr) { |
| 10071 | nlmsg_free(msg); |
| 10072 | return; |
| 10073 | } |
| 10074 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10075 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10076 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10077 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10078 | (req_ie && |
| 10079 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10080 | (resp_ie && |
| 10081 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10082 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10083 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10084 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10085 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10086 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10087 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10088 | return; |
| 10089 | |
| 10090 | nla_put_failure: |
| 10091 | genlmsg_cancel(msg, hdr); |
| 10092 | nlmsg_free(msg); |
| 10093 | |
| 10094 | } |
| 10095 | |
| 10096 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10097 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10098 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10099 | { |
| 10100 | struct sk_buff *msg; |
| 10101 | void *hdr; |
| 10102 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10103 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10104 | if (!msg) |
| 10105 | return; |
| 10106 | |
| 10107 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10108 | if (!hdr) { |
| 10109 | nlmsg_free(msg); |
| 10110 | return; |
| 10111 | } |
| 10112 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10113 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10114 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10115 | (from_ap && reason && |
| 10116 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10117 | (from_ap && |
| 10118 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10119 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10120 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10121 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10122 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10123 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10124 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10125 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10126 | return; |
| 10127 | |
| 10128 | nla_put_failure: |
| 10129 | genlmsg_cancel(msg, hdr); |
| 10130 | nlmsg_free(msg); |
| 10131 | |
| 10132 | } |
| 10133 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10134 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10135 | struct net_device *netdev, const u8 *bssid, |
| 10136 | gfp_t gfp) |
| 10137 | { |
| 10138 | struct sk_buff *msg; |
| 10139 | void *hdr; |
| 10140 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10141 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10142 | if (!msg) |
| 10143 | return; |
| 10144 | |
| 10145 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10146 | if (!hdr) { |
| 10147 | nlmsg_free(msg); |
| 10148 | return; |
| 10149 | } |
| 10150 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10151 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10152 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10153 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10154 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10155 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10156 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10157 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10158 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10159 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10160 | return; |
| 10161 | |
| 10162 | nla_put_failure: |
| 10163 | genlmsg_cancel(msg, hdr); |
| 10164 | nlmsg_free(msg); |
| 10165 | } |
| 10166 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10167 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10168 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10169 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10170 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10171 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10172 | struct sk_buff *msg; |
| 10173 | void *hdr; |
| 10174 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10175 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10176 | return; |
| 10177 | |
| 10178 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10179 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10180 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10181 | if (!msg) |
| 10182 | return; |
| 10183 | |
| 10184 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10185 | if (!hdr) { |
| 10186 | nlmsg_free(msg); |
| 10187 | return; |
| 10188 | } |
| 10189 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10190 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10191 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10192 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10193 | (ie_len && ie && |
| 10194 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10195 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10196 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10197 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10198 | |
| 10199 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10200 | nl80211_mlme_mcgrp.id, gfp); |
| 10201 | return; |
| 10202 | |
| 10203 | nla_put_failure: |
| 10204 | genlmsg_cancel(msg, hdr); |
| 10205 | nlmsg_free(msg); |
| 10206 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10207 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10208 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10209 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10210 | struct net_device *netdev, const u8 *addr, |
| 10211 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10212 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10213 | { |
| 10214 | struct sk_buff *msg; |
| 10215 | void *hdr; |
| 10216 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10217 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10218 | if (!msg) |
| 10219 | return; |
| 10220 | |
| 10221 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10222 | if (!hdr) { |
| 10223 | nlmsg_free(msg); |
| 10224 | return; |
| 10225 | } |
| 10226 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10227 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10228 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10229 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10230 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10231 | (key_id != -1 && |
| 10232 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10233 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10234 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10235 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10236 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10237 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10238 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10239 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10240 | return; |
| 10241 | |
| 10242 | nla_put_failure: |
| 10243 | genlmsg_cancel(msg, hdr); |
| 10244 | nlmsg_free(msg); |
| 10245 | } |
| 10246 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10247 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10248 | struct ieee80211_channel *channel_before, |
| 10249 | struct ieee80211_channel *channel_after) |
| 10250 | { |
| 10251 | struct sk_buff *msg; |
| 10252 | void *hdr; |
| 10253 | struct nlattr *nl_freq; |
| 10254 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10255 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10256 | if (!msg) |
| 10257 | return; |
| 10258 | |
| 10259 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10260 | if (!hdr) { |
| 10261 | nlmsg_free(msg); |
| 10262 | return; |
| 10263 | } |
| 10264 | |
| 10265 | /* |
| 10266 | * Since we are applying the beacon hint to a wiphy we know its |
| 10267 | * wiphy_idx is valid |
| 10268 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10269 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10270 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10271 | |
| 10272 | /* Before */ |
| 10273 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10274 | if (!nl_freq) |
| 10275 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10276 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10277 | goto nla_put_failure; |
| 10278 | nla_nest_end(msg, nl_freq); |
| 10279 | |
| 10280 | /* After */ |
| 10281 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10282 | if (!nl_freq) |
| 10283 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10284 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10285 | goto nla_put_failure; |
| 10286 | nla_nest_end(msg, nl_freq); |
| 10287 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10288 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10289 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10290 | rcu_read_lock(); |
| 10291 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 10292 | GFP_ATOMIC); |
| 10293 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10294 | |
| 10295 | return; |
| 10296 | |
| 10297 | nla_put_failure: |
| 10298 | genlmsg_cancel(msg, hdr); |
| 10299 | nlmsg_free(msg); |
| 10300 | } |
| 10301 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10302 | static void nl80211_send_remain_on_chan_event( |
| 10303 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10304 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10305 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10306 | unsigned int duration, gfp_t gfp) |
| 10307 | { |
| 10308 | struct sk_buff *msg; |
| 10309 | void *hdr; |
| 10310 | |
| 10311 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10312 | if (!msg) |
| 10313 | return; |
| 10314 | |
| 10315 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10316 | if (!hdr) { |
| 10317 | nlmsg_free(msg); |
| 10318 | return; |
| 10319 | } |
| 10320 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10321 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10322 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10323 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10324 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10325 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10326 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10327 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10328 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10329 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10330 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10331 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10332 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10333 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10334 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10335 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10336 | |
| 10337 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10338 | nl80211_mlme_mcgrp.id, gfp); |
| 10339 | return; |
| 10340 | |
| 10341 | nla_put_failure: |
| 10342 | genlmsg_cancel(msg, hdr); |
| 10343 | nlmsg_free(msg); |
| 10344 | } |
| 10345 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10346 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10347 | struct ieee80211_channel *chan, |
| 10348 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10349 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10350 | struct wiphy *wiphy = wdev->wiphy; |
| 10351 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10352 | |
| 10353 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10354 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10355 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10356 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10357 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10358 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10359 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10360 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10361 | struct ieee80211_channel *chan, |
| 10362 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10363 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10364 | struct wiphy *wiphy = wdev->wiphy; |
| 10365 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10366 | |
| 10367 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10368 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10369 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10370 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10371 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10372 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10373 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10374 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10375 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10376 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10377 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10378 | struct sk_buff *msg; |
| 10379 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10380 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10381 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10382 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10383 | if (!msg) |
| 10384 | return; |
| 10385 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10386 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10387 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10388 | nlmsg_free(msg); |
| 10389 | return; |
| 10390 | } |
| 10391 | |
| 10392 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10393 | nl80211_mlme_mcgrp.id, gfp); |
| 10394 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10395 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10396 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10397 | 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] | 10398 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10399 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10400 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10401 | struct sk_buff *msg; |
| 10402 | void *hdr; |
| 10403 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10404 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10405 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10406 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10407 | if (!msg) |
| 10408 | return; |
| 10409 | |
| 10410 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10411 | if (!hdr) { |
| 10412 | nlmsg_free(msg); |
| 10413 | return; |
| 10414 | } |
| 10415 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10416 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10417 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10418 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10419 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10420 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10421 | |
| 10422 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10423 | nl80211_mlme_mcgrp.id, gfp); |
| 10424 | return; |
| 10425 | |
| 10426 | nla_put_failure: |
| 10427 | genlmsg_cancel(msg, hdr); |
| 10428 | nlmsg_free(msg); |
| 10429 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10430 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10431 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10432 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10433 | enum nl80211_connect_failed_reason reason, |
| 10434 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10435 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10436 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10437 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10438 | struct sk_buff *msg; |
| 10439 | void *hdr; |
| 10440 | |
| 10441 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10442 | if (!msg) |
| 10443 | return; |
| 10444 | |
| 10445 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10446 | if (!hdr) { |
| 10447 | nlmsg_free(msg); |
| 10448 | return; |
| 10449 | } |
| 10450 | |
| 10451 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10452 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10453 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10454 | goto nla_put_failure; |
| 10455 | |
| 10456 | genlmsg_end(msg, hdr); |
| 10457 | |
| 10458 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10459 | nl80211_mlme_mcgrp.id, gfp); |
| 10460 | return; |
| 10461 | |
| 10462 | nla_put_failure: |
| 10463 | genlmsg_cancel(msg, hdr); |
| 10464 | nlmsg_free(msg); |
| 10465 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10466 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10467 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10468 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10469 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10470 | { |
| 10471 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10472 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10473 | struct sk_buff *msg; |
| 10474 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10475 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10476 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10477 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10478 | return false; |
| 10479 | |
| 10480 | msg = nlmsg_new(100, gfp); |
| 10481 | if (!msg) |
| 10482 | return true; |
| 10483 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10484 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10485 | if (!hdr) { |
| 10486 | nlmsg_free(msg); |
| 10487 | return true; |
| 10488 | } |
| 10489 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10490 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10491 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10492 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10493 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10494 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10495 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10496 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10497 | return true; |
| 10498 | |
| 10499 | nla_put_failure: |
| 10500 | genlmsg_cancel(msg, hdr); |
| 10501 | nlmsg_free(msg); |
| 10502 | return true; |
| 10503 | } |
| 10504 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10505 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10506 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10507 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10508 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10509 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10510 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10511 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10512 | |
| 10513 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10514 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10515 | trace_cfg80211_return_bool(false); |
| 10516 | return false; |
| 10517 | } |
| 10518 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10519 | addr, gfp); |
| 10520 | trace_cfg80211_return_bool(ret); |
| 10521 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10522 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10523 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10524 | |
| 10525 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10526 | const u8 *addr, gfp_t gfp) |
| 10527 | { |
| 10528 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10529 | bool ret; |
| 10530 | |
| 10531 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10532 | |
| 10533 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10534 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10535 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10536 | trace_cfg80211_return_bool(false); |
| 10537 | return false; |
| 10538 | } |
| 10539 | ret = __nl80211_unexpected_frame(dev, |
| 10540 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10541 | addr, gfp); |
| 10542 | trace_cfg80211_return_bool(ret); |
| 10543 | return ret; |
| 10544 | } |
| 10545 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10546 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10547 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10548 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10549 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10550 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10551 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10552 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10553 | struct sk_buff *msg; |
| 10554 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10555 | |
| 10556 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10557 | if (!msg) |
| 10558 | return -ENOMEM; |
| 10559 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10560 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10561 | if (!hdr) { |
| 10562 | nlmsg_free(msg); |
| 10563 | return -ENOMEM; |
| 10564 | } |
| 10565 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10566 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10567 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10568 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10569 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10570 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10571 | (sig_dbm && |
| 10572 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10573 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10574 | (flags && |
| 10575 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10576 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10577 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10578 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10579 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10580 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10581 | |
| 10582 | nla_put_failure: |
| 10583 | genlmsg_cancel(msg, hdr); |
| 10584 | nlmsg_free(msg); |
| 10585 | return -ENOBUFS; |
| 10586 | } |
| 10587 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10588 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10589 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10590 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10591 | struct wiphy *wiphy = wdev->wiphy; |
| 10592 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10593 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10594 | struct sk_buff *msg; |
| 10595 | void *hdr; |
| 10596 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10597 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10598 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10599 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10600 | if (!msg) |
| 10601 | return; |
| 10602 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10603 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10604 | if (!hdr) { |
| 10605 | nlmsg_free(msg); |
| 10606 | return; |
| 10607 | } |
| 10608 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10609 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10610 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10611 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10612 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10613 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10614 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10615 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10616 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10617 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10618 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10619 | |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 10620 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10621 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10622 | return; |
| 10623 | |
| 10624 | nla_put_failure: |
| 10625 | genlmsg_cancel(msg, hdr); |
| 10626 | nlmsg_free(msg); |
| 10627 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10628 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10629 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10630 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10631 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10632 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10633 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10634 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10635 | struct wiphy *wiphy = wdev->wiphy; |
| 10636 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10637 | struct sk_buff *msg; |
| 10638 | struct nlattr *pinfoattr; |
| 10639 | void *hdr; |
| 10640 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10641 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10642 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10643 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10644 | if (!msg) |
| 10645 | return; |
| 10646 | |
| 10647 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10648 | if (!hdr) { |
| 10649 | nlmsg_free(msg); |
| 10650 | return; |
| 10651 | } |
| 10652 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10653 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10654 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10655 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10656 | |
| 10657 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10658 | if (!pinfoattr) |
| 10659 | goto nla_put_failure; |
| 10660 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10661 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10662 | rssi_event)) |
| 10663 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10664 | |
| 10665 | nla_nest_end(msg, pinfoattr); |
| 10666 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10667 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10668 | |
| 10669 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10670 | nl80211_mlme_mcgrp.id, gfp); |
| 10671 | return; |
| 10672 | |
| 10673 | nla_put_failure: |
| 10674 | genlmsg_cancel(msg, hdr); |
| 10675 | nlmsg_free(msg); |
| 10676 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10677 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10678 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10679 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10680 | struct net_device *netdev, const u8 *bssid, |
| 10681 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10682 | { |
| 10683 | struct sk_buff *msg; |
| 10684 | struct nlattr *rekey_attr; |
| 10685 | void *hdr; |
| 10686 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10687 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10688 | if (!msg) |
| 10689 | return; |
| 10690 | |
| 10691 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10692 | if (!hdr) { |
| 10693 | nlmsg_free(msg); |
| 10694 | return; |
| 10695 | } |
| 10696 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10697 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10698 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10699 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10700 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10701 | |
| 10702 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10703 | if (!rekey_attr) |
| 10704 | goto nla_put_failure; |
| 10705 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10706 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10707 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10708 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10709 | |
| 10710 | nla_nest_end(msg, rekey_attr); |
| 10711 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10712 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10713 | |
| 10714 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10715 | nl80211_mlme_mcgrp.id, gfp); |
| 10716 | return; |
| 10717 | |
| 10718 | nla_put_failure: |
| 10719 | genlmsg_cancel(msg, hdr); |
| 10720 | nlmsg_free(msg); |
| 10721 | } |
| 10722 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10723 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10724 | const u8 *replay_ctr, gfp_t gfp) |
| 10725 | { |
| 10726 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10727 | struct wiphy *wiphy = wdev->wiphy; |
| 10728 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10729 | |
| 10730 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10731 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10732 | } |
| 10733 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10734 | |
| 10735 | static void |
| 10736 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10737 | struct net_device *netdev, int index, |
| 10738 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10739 | { |
| 10740 | struct sk_buff *msg; |
| 10741 | struct nlattr *attr; |
| 10742 | void *hdr; |
| 10743 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10744 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10745 | if (!msg) |
| 10746 | return; |
| 10747 | |
| 10748 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10749 | if (!hdr) { |
| 10750 | nlmsg_free(msg); |
| 10751 | return; |
| 10752 | } |
| 10753 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10754 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10755 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10756 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10757 | |
| 10758 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10759 | if (!attr) |
| 10760 | goto nla_put_failure; |
| 10761 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10762 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10763 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10764 | (preauth && |
| 10765 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10766 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10767 | |
| 10768 | nla_nest_end(msg, attr); |
| 10769 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10770 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [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 | } |
| 10780 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10781 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10782 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10783 | { |
| 10784 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10785 | struct wiphy *wiphy = wdev->wiphy; |
| 10786 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10787 | |
| 10788 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10789 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10790 | } |
| 10791 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10792 | |
| 10793 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10794 | struct net_device *netdev, |
| 10795 | struct cfg80211_chan_def *chandef, |
| 10796 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10797 | { |
| 10798 | struct sk_buff *msg; |
| 10799 | void *hdr; |
| 10800 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10801 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10802 | if (!msg) |
| 10803 | return; |
| 10804 | |
| 10805 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10806 | if (!hdr) { |
| 10807 | nlmsg_free(msg); |
| 10808 | return; |
| 10809 | } |
| 10810 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10811 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10812 | goto nla_put_failure; |
| 10813 | |
| 10814 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10815 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10816 | |
| 10817 | genlmsg_end(msg, hdr); |
| 10818 | |
| 10819 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10820 | nl80211_mlme_mcgrp.id, gfp); |
| 10821 | return; |
| 10822 | |
| 10823 | nla_put_failure: |
| 10824 | genlmsg_cancel(msg, hdr); |
| 10825 | nlmsg_free(msg); |
| 10826 | } |
| 10827 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10828 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10829 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10830 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10831 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10832 | struct wiphy *wiphy = wdev->wiphy; |
| 10833 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10834 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 10835 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10836 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 10837 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10838 | |
| 10839 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 10840 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 10841 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 10842 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 10843 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10844 | |
| 10845 | wdev->channel = chandef->chan; |
| 10846 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10847 | } |
| 10848 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10849 | |
| 10850 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10851 | const u8 *peer, u32 num_packets, |
| 10852 | u32 rate, u32 intvl, gfp_t gfp) |
| 10853 | { |
| 10854 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10855 | struct wiphy *wiphy = wdev->wiphy; |
| 10856 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10857 | struct sk_buff *msg; |
| 10858 | struct nlattr *pinfoattr; |
| 10859 | void *hdr; |
| 10860 | |
| 10861 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10862 | if (!msg) |
| 10863 | return; |
| 10864 | |
| 10865 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10866 | if (!hdr) { |
| 10867 | nlmsg_free(msg); |
| 10868 | return; |
| 10869 | } |
| 10870 | |
| 10871 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10872 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10873 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10874 | goto nla_put_failure; |
| 10875 | |
| 10876 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10877 | if (!pinfoattr) |
| 10878 | goto nla_put_failure; |
| 10879 | |
| 10880 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10881 | goto nla_put_failure; |
| 10882 | |
| 10883 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10884 | goto nla_put_failure; |
| 10885 | |
| 10886 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10887 | goto nla_put_failure; |
| 10888 | |
| 10889 | nla_nest_end(msg, pinfoattr); |
| 10890 | |
| 10891 | genlmsg_end(msg, hdr); |
| 10892 | |
| 10893 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10894 | nl80211_mlme_mcgrp.id, gfp); |
| 10895 | return; |
| 10896 | |
| 10897 | nla_put_failure: |
| 10898 | genlmsg_cancel(msg, hdr); |
| 10899 | nlmsg_free(msg); |
| 10900 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10901 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10902 | |
| 10903 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10904 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 10905 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10906 | enum nl80211_radar_event event, |
| 10907 | struct net_device *netdev, gfp_t gfp) |
| 10908 | { |
| 10909 | struct sk_buff *msg; |
| 10910 | void *hdr; |
| 10911 | |
| 10912 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10913 | if (!msg) |
| 10914 | return; |
| 10915 | |
| 10916 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10917 | if (!hdr) { |
| 10918 | nlmsg_free(msg); |
| 10919 | return; |
| 10920 | } |
| 10921 | |
| 10922 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10923 | goto nla_put_failure; |
| 10924 | |
| 10925 | /* NOP and radar events don't need a netdev parameter */ |
| 10926 | if (netdev) { |
| 10927 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10928 | |
| 10929 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10930 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10931 | goto nla_put_failure; |
| 10932 | } |
| 10933 | |
| 10934 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10935 | goto nla_put_failure; |
| 10936 | |
| 10937 | if (nl80211_send_chandef(msg, chandef)) |
| 10938 | goto nla_put_failure; |
| 10939 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10940 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10941 | |
| 10942 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10943 | nl80211_mlme_mcgrp.id, gfp); |
| 10944 | return; |
| 10945 | |
| 10946 | nla_put_failure: |
| 10947 | genlmsg_cancel(msg, hdr); |
| 10948 | nlmsg_free(msg); |
| 10949 | } |
| 10950 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10951 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10952 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10953 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10954 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10955 | struct wiphy *wiphy = wdev->wiphy; |
| 10956 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10957 | struct sk_buff *msg; |
| 10958 | struct nlattr *pinfoattr; |
| 10959 | void *hdr; |
| 10960 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10961 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10962 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10963 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10964 | if (!msg) |
| 10965 | return; |
| 10966 | |
| 10967 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10968 | if (!hdr) { |
| 10969 | nlmsg_free(msg); |
| 10970 | return; |
| 10971 | } |
| 10972 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10973 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10974 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10975 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10976 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10977 | |
| 10978 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10979 | if (!pinfoattr) |
| 10980 | goto nla_put_failure; |
| 10981 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10982 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10983 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10984 | |
| 10985 | nla_nest_end(msg, pinfoattr); |
| 10986 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10987 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10988 | |
| 10989 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10990 | nl80211_mlme_mcgrp.id, gfp); |
| 10991 | return; |
| 10992 | |
| 10993 | nla_put_failure: |
| 10994 | genlmsg_cancel(msg, hdr); |
| 10995 | nlmsg_free(msg); |
| 10996 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10997 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10998 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10999 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11000 | u64 cookie, bool acked, gfp_t gfp) |
| 11001 | { |
| 11002 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11003 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11004 | struct sk_buff *msg; |
| 11005 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11006 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11007 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11008 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11009 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11010 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11011 | if (!msg) |
| 11012 | return; |
| 11013 | |
| 11014 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11015 | if (!hdr) { |
| 11016 | nlmsg_free(msg); |
| 11017 | return; |
| 11018 | } |
| 11019 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11020 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11021 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11022 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11023 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11024 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11025 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11026 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11027 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11028 | |
| 11029 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11030 | nl80211_mlme_mcgrp.id, gfp); |
| 11031 | return; |
| 11032 | |
| 11033 | nla_put_failure: |
| 11034 | genlmsg_cancel(msg, hdr); |
| 11035 | nlmsg_free(msg); |
| 11036 | } |
| 11037 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11038 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11039 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11040 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11041 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11042 | { |
| 11043 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11044 | struct sk_buff *msg; |
| 11045 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11046 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11047 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11048 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11049 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11050 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11051 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11052 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11053 | if (!msg) { |
| 11054 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11055 | return; |
| 11056 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11057 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11058 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11059 | if (!hdr) |
| 11060 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11061 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11062 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11063 | (freq && |
| 11064 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11065 | (sig_dbm && |
| 11066 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11067 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11068 | goto nla_put_failure; |
| 11069 | |
| 11070 | genlmsg_end(msg, hdr); |
| 11071 | |
| 11072 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11073 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11074 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11075 | return; |
| 11076 | |
| 11077 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11078 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11079 | if (hdr) |
| 11080 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11081 | nlmsg_free(msg); |
| 11082 | } |
| 11083 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11084 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11085 | #ifdef CONFIG_PM |
| 11086 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11087 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11088 | gfp_t gfp) |
| 11089 | { |
| 11090 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11091 | struct sk_buff *msg; |
| 11092 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11093 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11094 | |
| 11095 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11096 | |
| 11097 | if (wakeup) |
| 11098 | size += wakeup->packet_present_len; |
| 11099 | |
| 11100 | msg = nlmsg_new(size, gfp); |
| 11101 | if (!msg) |
| 11102 | return; |
| 11103 | |
| 11104 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11105 | if (!hdr) |
| 11106 | goto free_msg; |
| 11107 | |
| 11108 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11109 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11110 | goto free_msg; |
| 11111 | |
| 11112 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11113 | wdev->netdev->ifindex)) |
| 11114 | goto free_msg; |
| 11115 | |
| 11116 | if (wakeup) { |
| 11117 | struct nlattr *reasons; |
| 11118 | |
| 11119 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 11120 | |
| 11121 | if (wakeup->disconnect && |
| 11122 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11123 | goto free_msg; |
| 11124 | if (wakeup->magic_pkt && |
| 11125 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11126 | goto free_msg; |
| 11127 | if (wakeup->gtk_rekey_failure && |
| 11128 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11129 | goto free_msg; |
| 11130 | if (wakeup->eap_identity_req && |
| 11131 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11132 | goto free_msg; |
| 11133 | if (wakeup->four_way_handshake && |
| 11134 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11135 | goto free_msg; |
| 11136 | if (wakeup->rfkill_release && |
| 11137 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11138 | goto free_msg; |
| 11139 | |
| 11140 | if (wakeup->pattern_idx >= 0 && |
| 11141 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11142 | wakeup->pattern_idx)) |
| 11143 | goto free_msg; |
| 11144 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11145 | if (wakeup->tcp_match) |
| 11146 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 11147 | |
| 11148 | if (wakeup->tcp_connlost) |
| 11149 | nla_put_flag(msg, |
| 11150 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 11151 | |
| 11152 | if (wakeup->tcp_nomoretokens) |
| 11153 | nla_put_flag(msg, |
| 11154 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 11155 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11156 | if (wakeup->packet) { |
| 11157 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11158 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11159 | |
| 11160 | if (!wakeup->packet_80211) { |
| 11161 | pkt_attr = |
| 11162 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11163 | len_attr = |
| 11164 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11165 | } |
| 11166 | |
| 11167 | if (wakeup->packet_len && |
| 11168 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11169 | goto free_msg; |
| 11170 | |
| 11171 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11172 | wakeup->packet)) |
| 11173 | goto free_msg; |
| 11174 | } |
| 11175 | |
| 11176 | nla_nest_end(msg, reasons); |
| 11177 | } |
| 11178 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11179 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11180 | |
| 11181 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11182 | nl80211_mlme_mcgrp.id, gfp); |
| 11183 | return; |
| 11184 | |
| 11185 | free_msg: |
| 11186 | nlmsg_free(msg); |
| 11187 | } |
| 11188 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11189 | #endif |
| 11190 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11191 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11192 | enum nl80211_tdls_operation oper, |
| 11193 | u16 reason_code, gfp_t gfp) |
| 11194 | { |
| 11195 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11196 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11197 | struct sk_buff *msg; |
| 11198 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11199 | |
| 11200 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11201 | reason_code); |
| 11202 | |
| 11203 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11204 | if (!msg) |
| 11205 | return; |
| 11206 | |
| 11207 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11208 | if (!hdr) { |
| 11209 | nlmsg_free(msg); |
| 11210 | return; |
| 11211 | } |
| 11212 | |
| 11213 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11214 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11215 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11216 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11217 | (reason_code > 0 && |
| 11218 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11219 | goto nla_put_failure; |
| 11220 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11221 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11222 | |
| 11223 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11224 | nl80211_mlme_mcgrp.id, gfp); |
| 11225 | return; |
| 11226 | |
| 11227 | nla_put_failure: |
| 11228 | genlmsg_cancel(msg, hdr); |
| 11229 | nlmsg_free(msg); |
| 11230 | } |
| 11231 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11232 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11233 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11234 | unsigned long state, |
| 11235 | void *_notify) |
| 11236 | { |
| 11237 | struct netlink_notify *notify = _notify; |
| 11238 | struct cfg80211_registered_device *rdev; |
| 11239 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11240 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11241 | |
| 11242 | if (state != NETLINK_URELEASE) |
| 11243 | return NOTIFY_DONE; |
| 11244 | |
| 11245 | rcu_read_lock(); |
| 11246 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11247 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11248 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11249 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11250 | |
| 11251 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11252 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11253 | list) { |
| 11254 | if (reg->nlportid == notify->portid) { |
| 11255 | list_del(®->list); |
| 11256 | kfree(reg); |
| 11257 | break; |
| 11258 | } |
| 11259 | } |
| 11260 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11261 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11262 | |
| 11263 | rcu_read_unlock(); |
| 11264 | |
| 11265 | return NOTIFY_DONE; |
| 11266 | } |
| 11267 | |
| 11268 | static struct notifier_block nl80211_netlink_notifier = { |
| 11269 | .notifier_call = nl80211_netlink_notify, |
| 11270 | }; |
| 11271 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11272 | void cfg80211_ft_event(struct net_device *netdev, |
| 11273 | struct cfg80211_ft_event_params *ft_event) |
| 11274 | { |
| 11275 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11276 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11277 | struct sk_buff *msg; |
| 11278 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11279 | |
| 11280 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11281 | |
| 11282 | if (!ft_event->target_ap) |
| 11283 | return; |
| 11284 | |
| 11285 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11286 | if (!msg) |
| 11287 | return; |
| 11288 | |
| 11289 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 11290 | if (!hdr) { |
| 11291 | nlmsg_free(msg); |
| 11292 | return; |
| 11293 | } |
| 11294 | |
| 11295 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 11296 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 11297 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 11298 | if (ft_event->ies) |
| 11299 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 11300 | if (ft_event->ric_ies) |
| 11301 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11302 | ft_event->ric_ies); |
| 11303 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11304 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11305 | |
| 11306 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11307 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 11308 | } |
| 11309 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11310 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11311 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11312 | { |
| 11313 | struct cfg80211_registered_device *rdev; |
| 11314 | struct sk_buff *msg; |
| 11315 | void *hdr; |
| 11316 | u32 nlportid; |
| 11317 | |
| 11318 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11319 | if (!rdev->crit_proto_nlportid) |
| 11320 | return; |
| 11321 | |
| 11322 | nlportid = rdev->crit_proto_nlportid; |
| 11323 | rdev->crit_proto_nlportid = 0; |
| 11324 | |
| 11325 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11326 | if (!msg) |
| 11327 | return; |
| 11328 | |
| 11329 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11330 | if (!hdr) |
| 11331 | goto nla_put_failure; |
| 11332 | |
| 11333 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11334 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11335 | goto nla_put_failure; |
| 11336 | |
| 11337 | genlmsg_end(msg, hdr); |
| 11338 | |
| 11339 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11340 | return; |
| 11341 | |
| 11342 | nla_put_failure: |
| 11343 | if (hdr) |
| 11344 | genlmsg_cancel(msg, hdr); |
| 11345 | nlmsg_free(msg); |
| 11346 | |
| 11347 | } |
| 11348 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11349 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11350 | /* initialisation/exit functions */ |
| 11351 | |
| 11352 | int nl80211_init(void) |
| 11353 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11354 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11355 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11356 | err = genl_register_family_with_ops(&nl80211_fam, |
| 11357 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11358 | if (err) |
| 11359 | return err; |
| 11360 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11361 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 11362 | if (err) |
| 11363 | goto err_out; |
| 11364 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11365 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 11366 | if (err) |
| 11367 | goto err_out; |
| 11368 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11369 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 11370 | if (err) |
| 11371 | goto err_out; |
| 11372 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11373 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 11374 | if (err) |
| 11375 | goto err_out; |
| 11376 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11377 | #ifdef CONFIG_NL80211_TESTMODE |
| 11378 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 11379 | if (err) |
| 11380 | goto err_out; |
| 11381 | #endif |
| 11382 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11383 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11384 | if (err) |
| 11385 | goto err_out; |
| 11386 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11387 | return 0; |
| 11388 | err_out: |
| 11389 | genl_unregister_family(&nl80211_fam); |
| 11390 | return err; |
| 11391 | } |
| 11392 | |
| 11393 | void nl80211_exit(void) |
| 11394 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11395 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11396 | genl_unregister_family(&nl80211_fam); |
| 11397 | } |