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 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 357 | }; |
| 358 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 359 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 360 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 361 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 362 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 363 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 364 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 365 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 366 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 367 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 368 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 369 | }; |
| 370 | |
| 371 | /* policy for the key default flags */ |
| 372 | static const struct nla_policy |
| 373 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 374 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 375 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 376 | }; |
| 377 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 378 | /* policy for WoWLAN attributes */ |
| 379 | static const struct nla_policy |
| 380 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 381 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 382 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 383 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 384 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 385 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 386 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 387 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 388 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 389 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 390 | }; |
| 391 | |
| 392 | static const struct nla_policy |
| 393 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 394 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 395 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 396 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 397 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 398 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 399 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 400 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 401 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 402 | }, |
| 403 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 404 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 405 | }, |
| 406 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 407 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 408 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 409 | }; |
| 410 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 411 | /* policy for coalesce rule attributes */ |
| 412 | static const struct nla_policy |
| 413 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 414 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 415 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 416 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 417 | }; |
| 418 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 419 | /* policy for GTK rekey offload attributes */ |
| 420 | static const struct nla_policy |
| 421 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 422 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 423 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 424 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 425 | }; |
| 426 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 427 | static const struct nla_policy |
| 428 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 429 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 430 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 431 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 432 | }; |
| 433 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 434 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 435 | struct netlink_callback *cb, |
| 436 | struct cfg80211_registered_device **rdev, |
| 437 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 438 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 439 | int err; |
| 440 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 441 | rtnl_lock(); |
| 442 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 443 | if (!cb->args[0]) { |
| 444 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 445 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 446 | nl80211_policy); |
| 447 | if (err) |
| 448 | goto out_unlock; |
| 449 | |
| 450 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 451 | nl80211_fam.attrbuf); |
| 452 | if (IS_ERR(*wdev)) { |
| 453 | err = PTR_ERR(*wdev); |
| 454 | goto out_unlock; |
| 455 | } |
| 456 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 457 | /* 0 is the first index - add 1 to parse only once */ |
| 458 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 459 | cb->args[1] = (*wdev)->identifier; |
| 460 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 461 | /* subtract the 1 again here */ |
| 462 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 463 | struct wireless_dev *tmp; |
| 464 | |
| 465 | if (!wiphy) { |
| 466 | err = -ENODEV; |
| 467 | goto out_unlock; |
| 468 | } |
| 469 | *rdev = wiphy_to_dev(wiphy); |
| 470 | *wdev = NULL; |
| 471 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 472 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 473 | if (tmp->identifier == cb->args[1]) { |
| 474 | *wdev = tmp; |
| 475 | break; |
| 476 | } |
| 477 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 478 | |
| 479 | if (!*wdev) { |
| 480 | err = -ENODEV; |
| 481 | goto out_unlock; |
| 482 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 483 | } |
| 484 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 485 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 486 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 487 | rtnl_unlock(); |
| 488 | return err; |
| 489 | } |
| 490 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 491 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 492 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 493 | rtnl_unlock(); |
| 494 | } |
| 495 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 496 | /* IE validation */ |
| 497 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 498 | { |
| 499 | const u8 *pos; |
| 500 | int len; |
| 501 | |
| 502 | if (!attr) |
| 503 | return true; |
| 504 | |
| 505 | pos = nla_data(attr); |
| 506 | len = nla_len(attr); |
| 507 | |
| 508 | while (len) { |
| 509 | u8 elemlen; |
| 510 | |
| 511 | if (len < 2) |
| 512 | return false; |
| 513 | len -= 2; |
| 514 | |
| 515 | elemlen = pos[1]; |
| 516 | if (elemlen > len) |
| 517 | return false; |
| 518 | |
| 519 | len -= elemlen; |
| 520 | pos += 2 + elemlen; |
| 521 | } |
| 522 | |
| 523 | return true; |
| 524 | } |
| 525 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 526 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 527 | 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] | 528 | int flags, u8 cmd) |
| 529 | { |
| 530 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 531 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 532 | } |
| 533 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 534 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 535 | struct ieee80211_channel *chan, |
| 536 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 537 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 538 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 539 | chan->center_freq)) |
| 540 | goto nla_put_failure; |
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 ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 543 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 544 | goto nla_put_failure; |
| 545 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 546 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 547 | goto nla_put_failure; |
| 548 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 549 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 550 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 551 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 552 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 553 | goto nla_put_failure; |
| 554 | if (large) { |
| 555 | u32 time; |
| 556 | |
| 557 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 558 | |
| 559 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 560 | chan->dfs_state)) |
| 561 | goto nla_put_failure; |
| 562 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 563 | time)) |
| 564 | goto nla_put_failure; |
| 565 | } |
| 566 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 567 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 568 | if (large) { |
| 569 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 570 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 571 | goto nla_put_failure; |
| 572 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 573 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 574 | goto nla_put_failure; |
| 575 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 576 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 577 | goto nla_put_failure; |
| 578 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 579 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 580 | goto nla_put_failure; |
| 581 | } |
| 582 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 583 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 584 | DBM_TO_MBM(chan->max_power))) |
| 585 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 586 | |
| 587 | return 0; |
| 588 | |
| 589 | nla_put_failure: |
| 590 | return -ENOBUFS; |
| 591 | } |
| 592 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 593 | /* netlink command implementations */ |
| 594 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 595 | struct key_parse { |
| 596 | struct key_params p; |
| 597 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 598 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 599 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 600 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 601 | }; |
| 602 | |
| 603 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 604 | { |
| 605 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 606 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 607 | nl80211_key_policy); |
| 608 | if (err) |
| 609 | return err; |
| 610 | |
| 611 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 612 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 613 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 614 | if (k->def) { |
| 615 | k->def_uni = true; |
| 616 | k->def_multi = true; |
| 617 | } |
| 618 | if (k->defmgmt) |
| 619 | k->def_multi = true; |
| 620 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 621 | if (tb[NL80211_KEY_IDX]) |
| 622 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 623 | |
| 624 | if (tb[NL80211_KEY_DATA]) { |
| 625 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 626 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 627 | } |
| 628 | |
| 629 | if (tb[NL80211_KEY_SEQ]) { |
| 630 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 631 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 632 | } |
| 633 | |
| 634 | if (tb[NL80211_KEY_CIPHER]) |
| 635 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 636 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 637 | if (tb[NL80211_KEY_TYPE]) { |
| 638 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 639 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 640 | return -EINVAL; |
| 641 | } |
| 642 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 643 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 644 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 645 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 646 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 647 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 648 | if (err) |
| 649 | return err; |
| 650 | |
| 651 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 652 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 653 | } |
| 654 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 655 | return 0; |
| 656 | } |
| 657 | |
| 658 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 659 | { |
| 660 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 661 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 662 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 663 | } |
| 664 | |
| 665 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 666 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 667 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 668 | } |
| 669 | |
| 670 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 671 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 672 | |
| 673 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 674 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 675 | |
| 676 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 677 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 678 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 679 | if (k->def) { |
| 680 | k->def_uni = true; |
| 681 | k->def_multi = true; |
| 682 | } |
| 683 | if (k->defmgmt) |
| 684 | k->def_multi = true; |
| 685 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 686 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 687 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 688 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 689 | return -EINVAL; |
| 690 | } |
| 691 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 692 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 693 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 694 | int err = nla_parse_nested( |
| 695 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 696 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 697 | nl80211_key_default_policy); |
| 698 | if (err) |
| 699 | return err; |
| 700 | |
| 701 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 702 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 703 | } |
| 704 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 709 | { |
| 710 | int err; |
| 711 | |
| 712 | memset(k, 0, sizeof(*k)); |
| 713 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 714 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 715 | |
| 716 | if (info->attrs[NL80211_ATTR_KEY]) |
| 717 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 718 | else |
| 719 | err = nl80211_parse_key_old(info, k); |
| 720 | |
| 721 | if (err) |
| 722 | return err; |
| 723 | |
| 724 | if (k->def && k->defmgmt) |
| 725 | return -EINVAL; |
| 726 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 727 | if (k->defmgmt) { |
| 728 | if (k->def_uni || !k->def_multi) |
| 729 | return -EINVAL; |
| 730 | } |
| 731 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 732 | if (k->idx != -1) { |
| 733 | if (k->defmgmt) { |
| 734 | if (k->idx < 4 || k->idx > 5) |
| 735 | return -EINVAL; |
| 736 | } else if (k->def) { |
| 737 | if (k->idx < 0 || k->idx > 3) |
| 738 | return -EINVAL; |
| 739 | } else { |
| 740 | if (k->idx < 0 || k->idx > 5) |
| 741 | return -EINVAL; |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | return 0; |
| 746 | } |
| 747 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 748 | static struct cfg80211_cached_keys * |
| 749 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 750 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 751 | { |
| 752 | struct key_parse parse; |
| 753 | struct nlattr *key; |
| 754 | struct cfg80211_cached_keys *result; |
| 755 | int rem, err, def = 0; |
| 756 | |
| 757 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 758 | if (!result) |
| 759 | return ERR_PTR(-ENOMEM); |
| 760 | |
| 761 | result->def = -1; |
| 762 | result->defmgmt = -1; |
| 763 | |
| 764 | nla_for_each_nested(key, keys, rem) { |
| 765 | memset(&parse, 0, sizeof(parse)); |
| 766 | parse.idx = -1; |
| 767 | |
| 768 | err = nl80211_parse_key_new(key, &parse); |
| 769 | if (err) |
| 770 | goto error; |
| 771 | err = -EINVAL; |
| 772 | if (!parse.p.key) |
| 773 | goto error; |
| 774 | if (parse.idx < 0 || parse.idx > 4) |
| 775 | goto error; |
| 776 | if (parse.def) { |
| 777 | if (def) |
| 778 | goto error; |
| 779 | def = 1; |
| 780 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 781 | if (!parse.def_uni || !parse.def_multi) |
| 782 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 783 | } else if (parse.defmgmt) |
| 784 | goto error; |
| 785 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 786 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 787 | if (err) |
| 788 | goto error; |
| 789 | result->params[parse.idx].cipher = parse.p.cipher; |
| 790 | result->params[parse.idx].key_len = parse.p.key_len; |
| 791 | result->params[parse.idx].key = result->data[parse.idx]; |
| 792 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 793 | |
| 794 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 795 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 796 | if (no_ht) |
| 797 | *no_ht = true; |
| 798 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | return result; |
| 802 | error: |
| 803 | kfree(result); |
| 804 | return ERR_PTR(err); |
| 805 | } |
| 806 | |
| 807 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 808 | { |
| 809 | ASSERT_WDEV_LOCK(wdev); |
| 810 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 811 | switch (wdev->iftype) { |
| 812 | case NL80211_IFTYPE_AP: |
| 813 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 814 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 815 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 816 | break; |
| 817 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 818 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 819 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 820 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 821 | return -ENOLINK; |
| 822 | break; |
| 823 | default: |
| 824 | return -EINVAL; |
| 825 | } |
| 826 | |
| 827 | return 0; |
| 828 | } |
| 829 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 830 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 831 | { |
| 832 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 833 | int i; |
| 834 | |
| 835 | if (!nl_modes) |
| 836 | goto nla_put_failure; |
| 837 | |
| 838 | i = 0; |
| 839 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 840 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 841 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 842 | ifmodes >>= 1; |
| 843 | i++; |
| 844 | } |
| 845 | |
| 846 | nla_nest_end(msg, nl_modes); |
| 847 | return 0; |
| 848 | |
| 849 | nla_put_failure: |
| 850 | return -ENOBUFS; |
| 851 | } |
| 852 | |
| 853 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 854 | struct sk_buff *msg, |
| 855 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 856 | { |
| 857 | struct nlattr *nl_combis; |
| 858 | int i, j; |
| 859 | |
| 860 | nl_combis = nla_nest_start(msg, |
| 861 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 862 | if (!nl_combis) |
| 863 | goto nla_put_failure; |
| 864 | |
| 865 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 866 | const struct ieee80211_iface_combination *c; |
| 867 | struct nlattr *nl_combi, *nl_limits; |
| 868 | |
| 869 | c = &wiphy->iface_combinations[i]; |
| 870 | |
| 871 | nl_combi = nla_nest_start(msg, i + 1); |
| 872 | if (!nl_combi) |
| 873 | goto nla_put_failure; |
| 874 | |
| 875 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 876 | if (!nl_limits) |
| 877 | goto nla_put_failure; |
| 878 | |
| 879 | for (j = 0; j < c->n_limits; j++) { |
| 880 | struct nlattr *nl_limit; |
| 881 | |
| 882 | nl_limit = nla_nest_start(msg, j + 1); |
| 883 | if (!nl_limit) |
| 884 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 885 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 886 | c->limits[j].max)) |
| 887 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 888 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 889 | c->limits[j].types)) |
| 890 | goto nla_put_failure; |
| 891 | nla_nest_end(msg, nl_limit); |
| 892 | } |
| 893 | |
| 894 | nla_nest_end(msg, nl_limits); |
| 895 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 896 | if (c->beacon_int_infra_match && |
| 897 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 898 | goto nla_put_failure; |
| 899 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 900 | c->num_different_channels) || |
| 901 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 902 | c->max_interfaces)) |
| 903 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 904 | if (large && |
| 905 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 906 | c->radar_detect_widths)) |
| 907 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 908 | |
| 909 | nla_nest_end(msg, nl_combi); |
| 910 | } |
| 911 | |
| 912 | nla_nest_end(msg, nl_combis); |
| 913 | |
| 914 | return 0; |
| 915 | nla_put_failure: |
| 916 | return -ENOBUFS; |
| 917 | } |
| 918 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 919 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 920 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 921 | struct sk_buff *msg) |
| 922 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 923 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 924 | struct nlattr *nl_tcp; |
| 925 | |
| 926 | if (!tcp) |
| 927 | return 0; |
| 928 | |
| 929 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 930 | if (!nl_tcp) |
| 931 | return -ENOBUFS; |
| 932 | |
| 933 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 934 | tcp->data_payload_max)) |
| 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 (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 942 | return -ENOBUFS; |
| 943 | |
| 944 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 945 | sizeof(*tcp->tok), tcp->tok)) |
| 946 | return -ENOBUFS; |
| 947 | |
| 948 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 949 | tcp->data_interval_max)) |
| 950 | return -ENOBUFS; |
| 951 | |
| 952 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 953 | tcp->wake_payload_max)) |
| 954 | return -ENOBUFS; |
| 955 | |
| 956 | nla_nest_end(msg, nl_tcp); |
| 957 | return 0; |
| 958 | } |
| 959 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 960 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 961 | struct cfg80211_registered_device *dev, |
| 962 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 963 | { |
| 964 | struct nlattr *nl_wowlan; |
| 965 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 966 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 967 | return 0; |
| 968 | |
| 969 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 970 | if (!nl_wowlan) |
| 971 | return -ENOBUFS; |
| 972 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 973 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 974 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 975 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 976 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 977 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 978 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 979 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 980 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 981 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 982 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 983 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 984 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 985 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 986 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 987 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 988 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 989 | return -ENOBUFS; |
| 990 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 991 | if (dev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 992 | struct nl80211_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 993 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 994 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 995 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 996 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 997 | }; |
| 998 | |
| 999 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1000 | sizeof(pat), &pat)) |
| 1001 | return -ENOBUFS; |
| 1002 | } |
| 1003 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1004 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1005 | return -ENOBUFS; |
| 1006 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1007 | nla_nest_end(msg, nl_wowlan); |
| 1008 | |
| 1009 | return 0; |
| 1010 | } |
| 1011 | #endif |
| 1012 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1013 | static int nl80211_send_coalesce(struct sk_buff *msg, |
| 1014 | struct cfg80211_registered_device *dev) |
| 1015 | { |
| 1016 | struct nl80211_coalesce_rule_support rule; |
| 1017 | |
| 1018 | if (!dev->wiphy.coalesce) |
| 1019 | return 0; |
| 1020 | |
| 1021 | rule.max_rules = dev->wiphy.coalesce->n_rules; |
| 1022 | rule.max_delay = dev->wiphy.coalesce->max_delay; |
| 1023 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; |
| 1024 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; |
| 1025 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; |
| 1026 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; |
| 1027 | |
| 1028 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1029 | return -ENOBUFS; |
| 1030 | |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1034 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1035 | struct ieee80211_supported_band *sband) |
| 1036 | { |
| 1037 | struct nlattr *nl_rates, *nl_rate; |
| 1038 | struct ieee80211_rate *rate; |
| 1039 | int i; |
| 1040 | |
| 1041 | /* add HT info */ |
| 1042 | if (sband->ht_cap.ht_supported && |
| 1043 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1044 | sizeof(sband->ht_cap.mcs), |
| 1045 | &sband->ht_cap.mcs) || |
| 1046 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1047 | sband->ht_cap.cap) || |
| 1048 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1049 | sband->ht_cap.ampdu_factor) || |
| 1050 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1051 | sband->ht_cap.ampdu_density))) |
| 1052 | return -ENOBUFS; |
| 1053 | |
| 1054 | /* add VHT info */ |
| 1055 | if (sband->vht_cap.vht_supported && |
| 1056 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1057 | sizeof(sband->vht_cap.vht_mcs), |
| 1058 | &sband->vht_cap.vht_mcs) || |
| 1059 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1060 | sband->vht_cap.cap))) |
| 1061 | return -ENOBUFS; |
| 1062 | |
| 1063 | /* add bitrates */ |
| 1064 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1065 | if (!nl_rates) |
| 1066 | return -ENOBUFS; |
| 1067 | |
| 1068 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1069 | nl_rate = nla_nest_start(msg, i); |
| 1070 | if (!nl_rate) |
| 1071 | return -ENOBUFS; |
| 1072 | |
| 1073 | rate = &sband->bitrates[i]; |
| 1074 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1075 | rate->bitrate)) |
| 1076 | return -ENOBUFS; |
| 1077 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1078 | nla_put_flag(msg, |
| 1079 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1080 | return -ENOBUFS; |
| 1081 | |
| 1082 | nla_nest_end(msg, nl_rate); |
| 1083 | } |
| 1084 | |
| 1085 | nla_nest_end(msg, nl_rates); |
| 1086 | |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | static int |
| 1091 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1092 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1093 | { |
| 1094 | u16 stypes; |
| 1095 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1096 | enum nl80211_iftype ift; |
| 1097 | int i; |
| 1098 | |
| 1099 | if (!mgmt_stypes) |
| 1100 | return 0; |
| 1101 | |
| 1102 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1103 | if (!nl_ifs) |
| 1104 | return -ENOBUFS; |
| 1105 | |
| 1106 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1107 | nl_ftypes = nla_nest_start(msg, ift); |
| 1108 | if (!nl_ftypes) |
| 1109 | return -ENOBUFS; |
| 1110 | i = 0; |
| 1111 | stypes = mgmt_stypes[ift].tx; |
| 1112 | while (stypes) { |
| 1113 | if ((stypes & 1) && |
| 1114 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1115 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1116 | return -ENOBUFS; |
| 1117 | stypes >>= 1; |
| 1118 | i++; |
| 1119 | } |
| 1120 | nla_nest_end(msg, nl_ftypes); |
| 1121 | } |
| 1122 | |
| 1123 | nla_nest_end(msg, nl_ifs); |
| 1124 | |
| 1125 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1126 | if (!nl_ifs) |
| 1127 | return -ENOBUFS; |
| 1128 | |
| 1129 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1130 | nl_ftypes = nla_nest_start(msg, ift); |
| 1131 | if (!nl_ftypes) |
| 1132 | return -ENOBUFS; |
| 1133 | i = 0; |
| 1134 | stypes = mgmt_stypes[ift].rx; |
| 1135 | while (stypes) { |
| 1136 | if ((stypes & 1) && |
| 1137 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1138 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1139 | return -ENOBUFS; |
| 1140 | stypes >>= 1; |
| 1141 | i++; |
| 1142 | } |
| 1143 | nla_nest_end(msg, nl_ftypes); |
| 1144 | } |
| 1145 | nla_nest_end(msg, nl_ifs); |
| 1146 | |
| 1147 | return 0; |
| 1148 | } |
| 1149 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1150 | struct nl80211_dump_wiphy_state { |
| 1151 | s64 filter_wiphy; |
| 1152 | long start; |
| 1153 | long split_start, band_start, chan_start; |
| 1154 | bool split; |
| 1155 | }; |
| 1156 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1157 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1158 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1159 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1160 | { |
| 1161 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1162 | struct nlattr *nl_bands, *nl_band; |
| 1163 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1164 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1165 | enum ieee80211_band band; |
| 1166 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1167 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1168 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1169 | dev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1170 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1171 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1172 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1173 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1174 | return -ENOBUFS; |
| 1175 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1176 | if (WARN_ON(!state)) |
| 1177 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1178 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1179 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1180 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1181 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1182 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1183 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1184 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1185 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1186 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1187 | case 0: |
| 1188 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1189 | dev->wiphy.retry_short) || |
| 1190 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1191 | dev->wiphy.retry_long) || |
| 1192 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1193 | dev->wiphy.frag_threshold) || |
| 1194 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1195 | dev->wiphy.rts_threshold) || |
| 1196 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1197 | dev->wiphy.coverage_class) || |
| 1198 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1199 | dev->wiphy.max_scan_ssids) || |
| 1200 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1201 | dev->wiphy.max_sched_scan_ssids) || |
| 1202 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1203 | dev->wiphy.max_scan_ie_len) || |
| 1204 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1205 | dev->wiphy.max_sched_scan_ie_len) || |
| 1206 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1207 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1208 | goto nla_put_failure; |
| 1209 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1210 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1211 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1212 | goto nla_put_failure; |
| 1213 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1214 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1215 | goto nla_put_failure; |
| 1216 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1217 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1218 | goto nla_put_failure; |
| 1219 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1220 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1221 | goto nla_put_failure; |
| 1222 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1223 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1224 | goto nla_put_failure; |
| 1225 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1226 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1227 | goto nla_put_failure; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1228 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1229 | nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1230 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1231 | |
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 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1560 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1561 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1562 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1563 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1564 | return genlmsg_end(msg, hdr); |
| 1565 | |
| 1566 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1567 | genlmsg_cancel(msg, hdr); |
| 1568 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1569 | } |
| 1570 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1571 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1572 | struct netlink_callback *cb, |
| 1573 | struct nl80211_dump_wiphy_state *state) |
| 1574 | { |
| 1575 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1576 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1577 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1578 | /* ignore parse errors for backward compatibility */ |
| 1579 | if (ret) |
| 1580 | return 0; |
| 1581 | |
| 1582 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1583 | if (tb[NL80211_ATTR_WIPHY]) |
| 1584 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1585 | if (tb[NL80211_ATTR_WDEV]) |
| 1586 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1587 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1588 | struct net_device *netdev; |
| 1589 | struct cfg80211_registered_device *rdev; |
| 1590 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1591 | |
| 1592 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1593 | if (!netdev) |
| 1594 | return -ENODEV; |
| 1595 | if (netdev->ieee80211_ptr) { |
| 1596 | rdev = wiphy_to_dev( |
| 1597 | netdev->ieee80211_ptr->wiphy); |
| 1598 | state->filter_wiphy = rdev->wiphy_idx; |
| 1599 | } |
| 1600 | dev_put(netdev); |
| 1601 | } |
| 1602 | |
| 1603 | return 0; |
| 1604 | } |
| 1605 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1606 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1607 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1608 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1609 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1610 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1611 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1612 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1613 | if (!state) { |
| 1614 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1615 | if (!state) { |
| 1616 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1617 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1618 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1619 | state->filter_wiphy = -1; |
| 1620 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1621 | if (ret) { |
| 1622 | kfree(state); |
| 1623 | rtnl_unlock(); |
| 1624 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1625 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1626 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1627 | } |
| 1628 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1629 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1630 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1631 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1632 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1633 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1634 | if (state->filter_wiphy != -1 && |
| 1635 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1636 | continue; |
| 1637 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1638 | do { |
| 1639 | ret = nl80211_send_wiphy(dev, skb, |
| 1640 | NETLINK_CB(cb->skb).portid, |
| 1641 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1642 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1643 | if (ret < 0) { |
| 1644 | /* |
| 1645 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1646 | * or EMSGSIZE returned), this SKB is still |
| 1647 | * empty (so it's not too big because another |
| 1648 | * wiphy dataset is already in the skb) and |
| 1649 | * we've not tried to adjust the dump allocation |
| 1650 | * yet ... then adjust the alloc size to be |
| 1651 | * bigger, and return 1 but with the empty skb. |
| 1652 | * This results in an empty message being RX'ed |
| 1653 | * in userspace, but that is ignored. |
| 1654 | * |
| 1655 | * We can then retry with the larger buffer. |
| 1656 | */ |
| 1657 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1658 | !skb->len && |
| 1659 | cb->min_dump_alloc < 4096) { |
| 1660 | cb->min_dump_alloc = 4096; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1661 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1662 | return 1; |
| 1663 | } |
| 1664 | idx--; |
| 1665 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1666 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1667 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1668 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1669 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1670 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1671 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1672 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1673 | |
| 1674 | return skb->len; |
| 1675 | } |
| 1676 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1677 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1678 | { |
| 1679 | kfree((void *)cb->args[0]); |
| 1680 | return 0; |
| 1681 | } |
| 1682 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1683 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1684 | { |
| 1685 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1686 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1687 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1688 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1689 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1690 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1691 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1692 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1693 | 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] | 1694 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1695 | nlmsg_free(msg); |
| 1696 | return -ENOBUFS; |
| 1697 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1698 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1699 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1700 | } |
| 1701 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1702 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1703 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1704 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1705 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1706 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1707 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1708 | }; |
| 1709 | |
| 1710 | static int parse_txq_params(struct nlattr *tb[], |
| 1711 | struct ieee80211_txq_params *txq_params) |
| 1712 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1713 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1714 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1715 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1716 | return -EINVAL; |
| 1717 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1718 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1719 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1720 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1721 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1722 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1723 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1724 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1725 | return -EINVAL; |
| 1726 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1727 | return 0; |
| 1728 | } |
| 1729 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1730 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1731 | { |
| 1732 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1733 | * You can only set the channel explicitly for WDS interfaces, |
| 1734 | * all others have their channel managed via their respective |
| 1735 | * "establish a connection" command (connect, join, ...) |
| 1736 | * |
| 1737 | * For AP/GO and mesh mode, the channel can be set with the |
| 1738 | * channel userspace API, but is only stored and passed to the |
| 1739 | * low-level driver when the AP starts or the mesh is joined. |
| 1740 | * This is for backward compatibility, userspace can also give |
| 1741 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1742 | * |
| 1743 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1744 | * whatever else is going on, so they have their own special |
| 1745 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1746 | */ |
| 1747 | return !wdev || |
| 1748 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1749 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1750 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1751 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1752 | } |
| 1753 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1754 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1755 | struct genl_info *info, |
| 1756 | struct cfg80211_chan_def *chandef) |
| 1757 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1758 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1759 | |
| 1760 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1761 | return -EINVAL; |
| 1762 | |
| 1763 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1764 | |
| 1765 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1766 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1767 | chandef->center_freq1 = control_freq; |
| 1768 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1769 | |
| 1770 | /* Primary channel not allowed */ |
| 1771 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1772 | return -EINVAL; |
| 1773 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1774 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1775 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1776 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1777 | chantype = nla_get_u32( |
| 1778 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1779 | |
| 1780 | switch (chantype) { |
| 1781 | case NL80211_CHAN_NO_HT: |
| 1782 | case NL80211_CHAN_HT20: |
| 1783 | case NL80211_CHAN_HT40PLUS: |
| 1784 | case NL80211_CHAN_HT40MINUS: |
| 1785 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1786 | chantype); |
| 1787 | break; |
| 1788 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1789 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1790 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1791 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1792 | chandef->width = |
| 1793 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1794 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1795 | chandef->center_freq1 = |
| 1796 | nla_get_u32( |
| 1797 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1798 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1799 | chandef->center_freq2 = |
| 1800 | nla_get_u32( |
| 1801 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1802 | } |
| 1803 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1804 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1805 | return -EINVAL; |
| 1806 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1807 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1808 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1809 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1810 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1811 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1812 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1813 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1814 | return -EINVAL; |
| 1815 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1816 | return 0; |
| 1817 | } |
| 1818 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1819 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1820 | struct wireless_dev *wdev, |
| 1821 | struct genl_info *info) |
| 1822 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1823 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1824 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1825 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1826 | |
| 1827 | if (wdev) |
| 1828 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1829 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1830 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1831 | return -EOPNOTSUPP; |
| 1832 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1833 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1834 | if (result) |
| 1835 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1836 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1837 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1838 | case NL80211_IFTYPE_AP: |
| 1839 | case NL80211_IFTYPE_P2P_GO: |
| 1840 | if (wdev->beacon_interval) { |
| 1841 | result = -EBUSY; |
| 1842 | break; |
| 1843 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1844 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1845 | result = -EINVAL; |
| 1846 | break; |
| 1847 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1848 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1849 | result = 0; |
| 1850 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1851 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1852 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1853 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1854 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1855 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1856 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1857 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1858 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1859 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1860 | |
| 1861 | return result; |
| 1862 | } |
| 1863 | |
| 1864 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1865 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1867 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1868 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1869 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1870 | } |
| 1871 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1872 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1873 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1874 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1875 | struct net_device *dev = info->user_ptr[1]; |
| 1876 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1877 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1878 | |
| 1879 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1880 | return -EINVAL; |
| 1881 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1882 | if (netif_running(dev)) |
| 1883 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1884 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1885 | if (!rdev->ops->set_wds_peer) |
| 1886 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1887 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1888 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1889 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1890 | |
| 1891 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1892 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1896 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1897 | { |
| 1898 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1899 | struct net_device *netdev = NULL; |
| 1900 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1901 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1902 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1903 | u32 changed; |
| 1904 | u8 retry_short = 0, retry_long = 0; |
| 1905 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1906 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1907 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1908 | ASSERT_RTNL(); |
| 1909 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1910 | /* |
| 1911 | * Try to find the wiphy and netdev. Normally this |
| 1912 | * function shouldn't need the netdev, but this is |
| 1913 | * done for backward compatibility -- previously |
| 1914 | * setting the channel was done per wiphy, but now |
| 1915 | * it is per netdev. Previous userland like hostapd |
| 1916 | * also passed a netdev to set_wiphy, so that it is |
| 1917 | * possible to let that go to the right netdev! |
| 1918 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1919 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1920 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1921 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1922 | |
| 1923 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1924 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1925 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1926 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1927 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1928 | } |
| 1929 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1930 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1931 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1932 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1933 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1934 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1935 | wdev = NULL; |
| 1936 | netdev = NULL; |
| 1937 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1938 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1939 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1940 | |
| 1941 | /* |
| 1942 | * end workaround code, by now the rdev is available |
| 1943 | * and locked, and wdev may or may not be NULL. |
| 1944 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1945 | |
| 1946 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1947 | result = cfg80211_dev_rename( |
| 1948 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1949 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1950 | if (result) |
| 1951 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1952 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1953 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1954 | struct ieee80211_txq_params txq_params; |
| 1955 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1956 | |
| 1957 | if (!rdev->ops->set_txq_params) { |
| 1958 | result = -EOPNOTSUPP; |
| 1959 | goto bad_res; |
| 1960 | } |
| 1961 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1962 | if (!netdev) { |
| 1963 | result = -EINVAL; |
| 1964 | goto bad_res; |
| 1965 | } |
| 1966 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1967 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1968 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1969 | result = -EINVAL; |
| 1970 | goto bad_res; |
| 1971 | } |
| 1972 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1973 | if (!netif_running(netdev)) { |
| 1974 | result = -ENETDOWN; |
| 1975 | goto bad_res; |
| 1976 | } |
| 1977 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1978 | nla_for_each_nested(nl_txq_params, |
| 1979 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1980 | rem_txq_params) { |
| 1981 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1982 | nla_data(nl_txq_params), |
| 1983 | nla_len(nl_txq_params), |
| 1984 | txq_params_policy); |
| 1985 | result = parse_txq_params(tb, &txq_params); |
| 1986 | if (result) |
| 1987 | goto bad_res; |
| 1988 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1989 | result = rdev_set_txq_params(rdev, netdev, |
| 1990 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1991 | if (result) |
| 1992 | goto bad_res; |
| 1993 | } |
| 1994 | } |
| 1995 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1996 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1997 | result = __nl80211_set_channel(rdev, |
| 1998 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1999 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2000 | if (result) |
| 2001 | goto bad_res; |
| 2002 | } |
| 2003 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2004 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2005 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2006 | enum nl80211_tx_power_setting type; |
| 2007 | int idx, mbm = 0; |
| 2008 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2009 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2010 | txp_wdev = NULL; |
| 2011 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2012 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 2013 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2014 | goto bad_res; |
| 2015 | } |
| 2016 | |
| 2017 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2018 | type = nla_get_u32(info->attrs[idx]); |
| 2019 | |
| 2020 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 2021 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 2022 | result = -EINVAL; |
| 2023 | goto bad_res; |
| 2024 | } |
| 2025 | |
| 2026 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2027 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2028 | mbm = nla_get_u32(info->attrs[idx]); |
| 2029 | } |
| 2030 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2031 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2032 | if (result) |
| 2033 | goto bad_res; |
| 2034 | } |
| 2035 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2036 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2037 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2038 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2039 | if ((!rdev->wiphy.available_antennas_tx && |
| 2040 | !rdev->wiphy.available_antennas_rx) || |
| 2041 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2042 | result = -EOPNOTSUPP; |
| 2043 | goto bad_res; |
| 2044 | } |
| 2045 | |
| 2046 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2047 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2048 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2049 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2050 | * available antenna masks, except for the "all" mask */ |
| 2051 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2052 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2053 | result = -EINVAL; |
| 2054 | goto bad_res; |
| 2055 | } |
| 2056 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2057 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2058 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2059 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2060 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2061 | if (result) |
| 2062 | goto bad_res; |
| 2063 | } |
| 2064 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2065 | changed = 0; |
| 2066 | |
| 2067 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2068 | retry_short = nla_get_u8( |
| 2069 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2070 | if (retry_short == 0) { |
| 2071 | result = -EINVAL; |
| 2072 | goto bad_res; |
| 2073 | } |
| 2074 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2075 | } |
| 2076 | |
| 2077 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2078 | retry_long = nla_get_u8( |
| 2079 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2080 | if (retry_long == 0) { |
| 2081 | result = -EINVAL; |
| 2082 | goto bad_res; |
| 2083 | } |
| 2084 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2085 | } |
| 2086 | |
| 2087 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2088 | frag_threshold = nla_get_u32( |
| 2089 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2090 | if (frag_threshold < 256) { |
| 2091 | result = -EINVAL; |
| 2092 | goto bad_res; |
| 2093 | } |
| 2094 | if (frag_threshold != (u32) -1) { |
| 2095 | /* |
| 2096 | * Fragments (apart from the last one) are required to |
| 2097 | * have even length. Make the fragmentation code |
| 2098 | * simpler by stripping LSB should someone try to use |
| 2099 | * odd threshold value. |
| 2100 | */ |
| 2101 | frag_threshold &= ~0x1; |
| 2102 | } |
| 2103 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2104 | } |
| 2105 | |
| 2106 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2107 | rts_threshold = nla_get_u32( |
| 2108 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2109 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2110 | } |
| 2111 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2112 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2113 | coverage_class = nla_get_u8( |
| 2114 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2115 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2116 | } |
| 2117 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2118 | if (changed) { |
| 2119 | u8 old_retry_short, old_retry_long; |
| 2120 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2121 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2122 | |
| 2123 | if (!rdev->ops->set_wiphy_params) { |
| 2124 | result = -EOPNOTSUPP; |
| 2125 | goto bad_res; |
| 2126 | } |
| 2127 | |
| 2128 | old_retry_short = rdev->wiphy.retry_short; |
| 2129 | old_retry_long = rdev->wiphy.retry_long; |
| 2130 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2131 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2132 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2133 | |
| 2134 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2135 | rdev->wiphy.retry_short = retry_short; |
| 2136 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2137 | rdev->wiphy.retry_long = retry_long; |
| 2138 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2139 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2140 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2141 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2142 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2143 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2144 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2145 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2146 | if (result) { |
| 2147 | rdev->wiphy.retry_short = old_retry_short; |
| 2148 | rdev->wiphy.retry_long = old_retry_long; |
| 2149 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2150 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2151 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2152 | } |
| 2153 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2154 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2155 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2156 | if (netdev) |
| 2157 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2158 | return result; |
| 2159 | } |
| 2160 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2161 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2162 | { |
| 2163 | return (u64)wdev->identifier | |
| 2164 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2165 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2166 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2167 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 2168 | struct cfg80211_chan_def *chandef) |
| 2169 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2170 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2171 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2172 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2173 | chandef->chan->center_freq)) |
| 2174 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2175 | switch (chandef->width) { |
| 2176 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2177 | case NL80211_CHAN_WIDTH_20: |
| 2178 | case NL80211_CHAN_WIDTH_40: |
| 2179 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2180 | cfg80211_get_chandef_type(chandef))) |
| 2181 | return -ENOBUFS; |
| 2182 | break; |
| 2183 | default: |
| 2184 | break; |
| 2185 | } |
| 2186 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2187 | return -ENOBUFS; |
| 2188 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2189 | return -ENOBUFS; |
| 2190 | if (chandef->center_freq2 && |
| 2191 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2192 | return -ENOBUFS; |
| 2193 | return 0; |
| 2194 | } |
| 2195 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2196 | 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] | 2197 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2198 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2199 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2200 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2201 | void *hdr; |
| 2202 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2203 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2204 | if (!hdr) |
| 2205 | return -1; |
| 2206 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2207 | if (dev && |
| 2208 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2209 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2210 | goto nla_put_failure; |
| 2211 | |
| 2212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2213 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2214 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2215 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2216 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2217 | rdev->devlist_generation ^ |
| 2218 | (cfg80211_rdev_list_generation << 2))) |
| 2219 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2220 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2221 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2222 | int ret; |
| 2223 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2224 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2225 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2226 | if (ret == 0) { |
| 2227 | if (nl80211_send_chandef(msg, &chandef)) |
| 2228 | goto nla_put_failure; |
| 2229 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2230 | } |
| 2231 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2232 | if (wdev->ssid_len) { |
| 2233 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2234 | goto nla_put_failure; |
| 2235 | } |
| 2236 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2237 | return genlmsg_end(msg, hdr); |
| 2238 | |
| 2239 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2240 | genlmsg_cancel(msg, hdr); |
| 2241 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2245 | { |
| 2246 | int wp_idx = 0; |
| 2247 | int if_idx = 0; |
| 2248 | int wp_start = cb->args[0]; |
| 2249 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2250 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2251 | struct wireless_dev *wdev; |
| 2252 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2253 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2254 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2255 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2256 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2257 | if (wp_idx < wp_start) { |
| 2258 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2259 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2260 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2261 | if_idx = 0; |
| 2262 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2263 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2264 | if (if_idx < if_start) { |
| 2265 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2266 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2267 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2268 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2269 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2270 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2271 | goto out; |
| 2272 | } |
| 2273 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2274 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2275 | |
| 2276 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2277 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2278 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2279 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2280 | |
| 2281 | cb->args[0] = wp_idx; |
| 2282 | cb->args[1] = if_idx; |
| 2283 | |
| 2284 | return skb->len; |
| 2285 | } |
| 2286 | |
| 2287 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2288 | { |
| 2289 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2290 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2291 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2292 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2293 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2294 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2295 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2296 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2297 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2298 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2299 | nlmsg_free(msg); |
| 2300 | return -ENOBUFS; |
| 2301 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2302 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2303 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2304 | } |
| 2305 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2306 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2307 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2308 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2309 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2310 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2311 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2312 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2313 | }; |
| 2314 | |
| 2315 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2316 | { |
| 2317 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2318 | int flag; |
| 2319 | |
| 2320 | *mntrflags = 0; |
| 2321 | |
| 2322 | if (!nla) |
| 2323 | return -EINVAL; |
| 2324 | |
| 2325 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2326 | nla, mntr_flags_policy)) |
| 2327 | return -EINVAL; |
| 2328 | |
| 2329 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2330 | if (flags[flag]) |
| 2331 | *mntrflags |= (1<<flag); |
| 2332 | |
| 2333 | return 0; |
| 2334 | } |
| 2335 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2336 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2337 | struct net_device *netdev, u8 use_4addr, |
| 2338 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2339 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2340 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2341 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2342 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2343 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2344 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2345 | |
| 2346 | switch (iftype) { |
| 2347 | case NL80211_IFTYPE_AP_VLAN: |
| 2348 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2349 | return 0; |
| 2350 | break; |
| 2351 | case NL80211_IFTYPE_STATION: |
| 2352 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2353 | return 0; |
| 2354 | break; |
| 2355 | default: |
| 2356 | break; |
| 2357 | } |
| 2358 | |
| 2359 | return -EOPNOTSUPP; |
| 2360 | } |
| 2361 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2362 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2363 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2364 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2365 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2366 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2367 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2368 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2369 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2370 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2371 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2372 | memset(¶ms, 0, sizeof(params)); |
| 2373 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2374 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2375 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2376 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2377 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2378 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2379 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2380 | if (ntype > NL80211_IFTYPE_MAX) |
| 2381 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2382 | } |
| 2383 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2384 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2385 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2386 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2387 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2388 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2389 | if (netif_running(dev)) |
| 2390 | return -EBUSY; |
| 2391 | |
| 2392 | wdev_lock(wdev); |
| 2393 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2394 | IEEE80211_MAX_MESH_ID_LEN); |
| 2395 | wdev->mesh_id_up_len = |
| 2396 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2397 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2398 | wdev->mesh_id_up_len); |
| 2399 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2400 | } |
| 2401 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2402 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2403 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2404 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2405 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2406 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2407 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2408 | } else { |
| 2409 | params.use_4addr = -1; |
| 2410 | } |
| 2411 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2412 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2413 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2414 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2415 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2416 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2417 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2418 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2419 | |
| 2420 | flags = &_flags; |
| 2421 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2422 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2423 | |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2424 | if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) && |
| 2425 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2426 | return -EOPNOTSUPP; |
| 2427 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2428 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2429 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2430 | else |
| 2431 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2432 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2433 | if (!err && params.use_4addr != -1) |
| 2434 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2435 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2436 | return err; |
| 2437 | } |
| 2438 | |
| 2439 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2440 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2441 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2442 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2443 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2444 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2445 | int err; |
| 2446 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2447 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2448 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2449 | memset(¶ms, 0, sizeof(params)); |
| 2450 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2451 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2452 | return -EINVAL; |
| 2453 | |
| 2454 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2455 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2456 | if (type > NL80211_IFTYPE_MAX) |
| 2457 | return -EINVAL; |
| 2458 | } |
| 2459 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2460 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2461 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2462 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2463 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2464 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2465 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2466 | ETH_ALEN); |
| 2467 | if (!is_valid_ether_addr(params.macaddr)) |
| 2468 | return -EADDRNOTAVAIL; |
| 2469 | } |
| 2470 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2471 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2472 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2473 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2474 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2475 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2476 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2477 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2478 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2479 | if (!msg) |
| 2480 | return -ENOMEM; |
| 2481 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2482 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2483 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2484 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2485 | |
| 2486 | if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) && |
| 2487 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2488 | return -EOPNOTSUPP; |
| 2489 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2490 | wdev = rdev_add_virtual_intf(rdev, |
| 2491 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2492 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2493 | if (IS_ERR(wdev)) { |
| 2494 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2495 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2496 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2497 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2498 | switch (type) { |
| 2499 | case NL80211_IFTYPE_MESH_POINT: |
| 2500 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2501 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2502 | wdev_lock(wdev); |
| 2503 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2504 | IEEE80211_MAX_MESH_ID_LEN); |
| 2505 | wdev->mesh_id_up_len = |
| 2506 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2507 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2508 | wdev->mesh_id_up_len); |
| 2509 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2510 | break; |
| 2511 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2512 | /* |
| 2513 | * P2P Device doesn't have a netdev, so doesn't go |
| 2514 | * through the netdev notifier and must be added here |
| 2515 | */ |
| 2516 | mutex_init(&wdev->mtx); |
| 2517 | INIT_LIST_HEAD(&wdev->event_list); |
| 2518 | spin_lock_init(&wdev->event_lock); |
| 2519 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2520 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2521 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2522 | wdev->identifier = ++rdev->wdev_id; |
| 2523 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2524 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2525 | break; |
| 2526 | default: |
| 2527 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2528 | } |
| 2529 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2530 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2531 | rdev, wdev) < 0) { |
| 2532 | nlmsg_free(msg); |
| 2533 | return -ENOBUFS; |
| 2534 | } |
| 2535 | |
| 2536 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2540 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2541 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2542 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2543 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2544 | if (!rdev->ops->del_virtual_intf) |
| 2545 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2546 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2547 | /* |
| 2548 | * If we remove a wireless device without a netdev then clear |
| 2549 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2550 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2551 | * since the wdev has been freed, unlike with a netdev where |
| 2552 | * we need the dev_put() for the netdev to really be freed. |
| 2553 | */ |
| 2554 | if (!wdev->netdev) |
| 2555 | info->user_ptr[1] = NULL; |
| 2556 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2557 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2558 | } |
| 2559 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2560 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2561 | { |
| 2562 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2563 | struct net_device *dev = info->user_ptr[1]; |
| 2564 | u16 noack_map; |
| 2565 | |
| 2566 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2567 | return -EINVAL; |
| 2568 | |
| 2569 | if (!rdev->ops->set_noack_map) |
| 2570 | return -EOPNOTSUPP; |
| 2571 | |
| 2572 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2573 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2574 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2575 | } |
| 2576 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2577 | struct get_key_cookie { |
| 2578 | struct sk_buff *msg; |
| 2579 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2580 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2581 | }; |
| 2582 | |
| 2583 | static void get_key_callback(void *c, struct key_params *params) |
| 2584 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2585 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2586 | struct get_key_cookie *cookie = c; |
| 2587 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2588 | if ((params->key && |
| 2589 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2590 | params->key_len, params->key)) || |
| 2591 | (params->seq && |
| 2592 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2593 | params->seq_len, params->seq)) || |
| 2594 | (params->cipher && |
| 2595 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2596 | params->cipher))) |
| 2597 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2598 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2599 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2600 | if (!key) |
| 2601 | goto nla_put_failure; |
| 2602 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2603 | if ((params->key && |
| 2604 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2605 | params->key_len, params->key)) || |
| 2606 | (params->seq && |
| 2607 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2608 | params->seq_len, params->seq)) || |
| 2609 | (params->cipher && |
| 2610 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2611 | params->cipher))) |
| 2612 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2613 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2614 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2615 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2616 | |
| 2617 | nla_nest_end(cookie->msg, key); |
| 2618 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2619 | return; |
| 2620 | nla_put_failure: |
| 2621 | cookie->error = 1; |
| 2622 | } |
| 2623 | |
| 2624 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2625 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2626 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2627 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2628 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2629 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2630 | const u8 *mac_addr = NULL; |
| 2631 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2632 | struct get_key_cookie cookie = { |
| 2633 | .error = 0, |
| 2634 | }; |
| 2635 | void *hdr; |
| 2636 | struct sk_buff *msg; |
| 2637 | |
| 2638 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2639 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2640 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2641 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2642 | return -EINVAL; |
| 2643 | |
| 2644 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2645 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2646 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2647 | pairwise = !!mac_addr; |
| 2648 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2649 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2650 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2651 | return -EINVAL; |
| 2652 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2653 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2654 | return -EINVAL; |
| 2655 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2656 | } |
| 2657 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2658 | if (!rdev->ops->get_key) |
| 2659 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2660 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2661 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2662 | if (!msg) |
| 2663 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2664 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2665 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2666 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2667 | if (!hdr) |
| 2668 | return -ENOBUFS; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2669 | |
| 2670 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2671 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2672 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2673 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2674 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2675 | goto nla_put_failure; |
| 2676 | if (mac_addr && |
| 2677 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2678 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2679 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2680 | if (pairwise && mac_addr && |
| 2681 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2682 | return -ENOENT; |
| 2683 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2684 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2685 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2686 | |
| 2687 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2688 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2689 | |
| 2690 | if (cookie.error) |
| 2691 | goto nla_put_failure; |
| 2692 | |
| 2693 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2694 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2695 | |
| 2696 | nla_put_failure: |
| 2697 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2698 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2699 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2700 | return err; |
| 2701 | } |
| 2702 | |
| 2703 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2704 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2705 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2706 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2707 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2708 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2709 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2710 | err = nl80211_parse_key(info, &key); |
| 2711 | if (err) |
| 2712 | return err; |
| 2713 | |
| 2714 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2715 | return -EINVAL; |
| 2716 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2717 | /* only support setting default key */ |
| 2718 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2719 | return -EINVAL; |
| 2720 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2721 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2722 | |
| 2723 | if (key.def) { |
| 2724 | if (!rdev->ops->set_default_key) { |
| 2725 | err = -EOPNOTSUPP; |
| 2726 | goto out; |
| 2727 | } |
| 2728 | |
| 2729 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2730 | if (err) |
| 2731 | goto out; |
| 2732 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2733 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2734 | key.def_uni, key.def_multi); |
| 2735 | |
| 2736 | if (err) |
| 2737 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2738 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2739 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2740 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2741 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2742 | } else { |
| 2743 | if (key.def_uni || !key.def_multi) { |
| 2744 | err = -EINVAL; |
| 2745 | goto out; |
| 2746 | } |
| 2747 | |
| 2748 | if (!rdev->ops->set_default_mgmt_key) { |
| 2749 | err = -EOPNOTSUPP; |
| 2750 | goto out; |
| 2751 | } |
| 2752 | |
| 2753 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2754 | if (err) |
| 2755 | goto out; |
| 2756 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2757 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2758 | if (err) |
| 2759 | goto out; |
| 2760 | |
| 2761 | #ifdef CONFIG_CFG80211_WEXT |
| 2762 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2763 | #endif |
| 2764 | } |
| 2765 | |
| 2766 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2767 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2768 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2769 | return err; |
| 2770 | } |
| 2771 | |
| 2772 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2773 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2774 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2775 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2776 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2777 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2778 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2779 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2780 | err = nl80211_parse_key(info, &key); |
| 2781 | if (err) |
| 2782 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2783 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2784 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2785 | return -EINVAL; |
| 2786 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2787 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2788 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2789 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2790 | if (key.type == -1) { |
| 2791 | if (mac_addr) |
| 2792 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2793 | else |
| 2794 | key.type = NL80211_KEYTYPE_GROUP; |
| 2795 | } |
| 2796 | |
| 2797 | /* for now */ |
| 2798 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2799 | key.type != NL80211_KEYTYPE_GROUP) |
| 2800 | return -EINVAL; |
| 2801 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2802 | if (!rdev->ops->add_key) |
| 2803 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2804 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2805 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2806 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2807 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2808 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2809 | |
| 2810 | wdev_lock(dev->ieee80211_ptr); |
| 2811 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2812 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2813 | err = rdev_add_key(rdev, dev, key.idx, |
| 2814 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2815 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2816 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2817 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2818 | return err; |
| 2819 | } |
| 2820 | |
| 2821 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2822 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2823 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2824 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2825 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2826 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2827 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2828 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2829 | err = nl80211_parse_key(info, &key); |
| 2830 | if (err) |
| 2831 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2832 | |
| 2833 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2834 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2835 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2836 | if (key.type == -1) { |
| 2837 | if (mac_addr) |
| 2838 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2839 | else |
| 2840 | key.type = NL80211_KEYTYPE_GROUP; |
| 2841 | } |
| 2842 | |
| 2843 | /* for now */ |
| 2844 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2845 | key.type != NL80211_KEYTYPE_GROUP) |
| 2846 | return -EINVAL; |
| 2847 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2848 | if (!rdev->ops->del_key) |
| 2849 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2850 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2851 | wdev_lock(dev->ieee80211_ptr); |
| 2852 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2853 | |
| 2854 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2855 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2856 | err = -ENOENT; |
| 2857 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2858 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2859 | err = rdev_del_key(rdev, dev, key.idx, |
| 2860 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2861 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2862 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2863 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2864 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2865 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2866 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2867 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2868 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2869 | } |
| 2870 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2871 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2872 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2873 | return err; |
| 2874 | } |
| 2875 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2876 | /* This function returns an error or the number of nested attributes */ |
| 2877 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2878 | { |
| 2879 | struct nlattr *attr; |
| 2880 | int n_entries = 0, tmp; |
| 2881 | |
| 2882 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2883 | if (nla_len(attr) != ETH_ALEN) |
| 2884 | return -EINVAL; |
| 2885 | |
| 2886 | n_entries++; |
| 2887 | } |
| 2888 | |
| 2889 | return n_entries; |
| 2890 | } |
| 2891 | |
| 2892 | /* |
| 2893 | * This function parses ACL information and allocates memory for ACL data. |
| 2894 | * On successful return, the calling function is responsible to free the |
| 2895 | * ACL buffer returned by this function. |
| 2896 | */ |
| 2897 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2898 | struct genl_info *info) |
| 2899 | { |
| 2900 | enum nl80211_acl_policy acl_policy; |
| 2901 | struct nlattr *attr; |
| 2902 | struct cfg80211_acl_data *acl; |
| 2903 | int i = 0, n_entries, tmp; |
| 2904 | |
| 2905 | if (!wiphy->max_acl_mac_addrs) |
| 2906 | return ERR_PTR(-EOPNOTSUPP); |
| 2907 | |
| 2908 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2909 | return ERR_PTR(-EINVAL); |
| 2910 | |
| 2911 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2912 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2913 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2914 | return ERR_PTR(-EINVAL); |
| 2915 | |
| 2916 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2917 | return ERR_PTR(-EINVAL); |
| 2918 | |
| 2919 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2920 | if (n_entries < 0) |
| 2921 | return ERR_PTR(n_entries); |
| 2922 | |
| 2923 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2924 | return ERR_PTR(-ENOTSUPP); |
| 2925 | |
| 2926 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2927 | GFP_KERNEL); |
| 2928 | if (!acl) |
| 2929 | return ERR_PTR(-ENOMEM); |
| 2930 | |
| 2931 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2932 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2933 | i++; |
| 2934 | } |
| 2935 | |
| 2936 | acl->n_acl_entries = n_entries; |
| 2937 | acl->acl_policy = acl_policy; |
| 2938 | |
| 2939 | return acl; |
| 2940 | } |
| 2941 | |
| 2942 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2943 | { |
| 2944 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2945 | struct net_device *dev = info->user_ptr[1]; |
| 2946 | struct cfg80211_acl_data *acl; |
| 2947 | int err; |
| 2948 | |
| 2949 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2950 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2951 | return -EOPNOTSUPP; |
| 2952 | |
| 2953 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2954 | return -EINVAL; |
| 2955 | |
| 2956 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2957 | if (IS_ERR(acl)) |
| 2958 | return PTR_ERR(acl); |
| 2959 | |
| 2960 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2961 | |
| 2962 | kfree(acl); |
| 2963 | |
| 2964 | return err; |
| 2965 | } |
| 2966 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2967 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2968 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2969 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2970 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2971 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2972 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2973 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 2974 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2975 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2976 | return -EINVAL; |
| 2977 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2978 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2979 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2980 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2981 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2982 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2983 | if (!bcn->head_len) |
| 2984 | return -EINVAL; |
| 2985 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2986 | } |
| 2987 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2988 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2989 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2990 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2991 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2992 | } |
| 2993 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2994 | if (!haveinfo) |
| 2995 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2996 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2997 | if (attrs[NL80211_ATTR_IE]) { |
| 2998 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 2999 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3000 | } |
| 3001 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3002 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3003 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3004 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3005 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3006 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3007 | } |
| 3008 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3009 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3010 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3011 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3012 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3013 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3014 | } |
| 3015 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3016 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3017 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3018 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3019 | } |
| 3020 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3021 | return 0; |
| 3022 | } |
| 3023 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3024 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3025 | struct cfg80211_ap_settings *params) |
| 3026 | { |
| 3027 | struct wireless_dev *wdev; |
| 3028 | bool ret = false; |
| 3029 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3030 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3031 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3032 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3033 | continue; |
| 3034 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3035 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3036 | continue; |
| 3037 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3038 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3039 | ret = true; |
| 3040 | break; |
| 3041 | } |
| 3042 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3043 | return ret; |
| 3044 | } |
| 3045 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3046 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3047 | enum nl80211_auth_type auth_type, |
| 3048 | enum nl80211_commands cmd) |
| 3049 | { |
| 3050 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3051 | return false; |
| 3052 | |
| 3053 | switch (cmd) { |
| 3054 | case NL80211_CMD_AUTHENTICATE: |
| 3055 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3056 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3057 | return false; |
| 3058 | return true; |
| 3059 | case NL80211_CMD_CONNECT: |
| 3060 | case NL80211_CMD_START_AP: |
| 3061 | /* SAE not supported yet */ |
| 3062 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3063 | return false; |
| 3064 | return true; |
| 3065 | default: |
| 3066 | return false; |
| 3067 | } |
| 3068 | } |
| 3069 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3070 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3071 | { |
| 3072 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3073 | struct net_device *dev = info->user_ptr[1]; |
| 3074 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3075 | struct cfg80211_ap_settings params; |
| 3076 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3077 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3078 | |
| 3079 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3080 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3081 | return -EOPNOTSUPP; |
| 3082 | |
| 3083 | if (!rdev->ops->start_ap) |
| 3084 | return -EOPNOTSUPP; |
| 3085 | |
| 3086 | if (wdev->beacon_interval) |
| 3087 | return -EALREADY; |
| 3088 | |
| 3089 | memset(¶ms, 0, sizeof(params)); |
| 3090 | |
| 3091 | /* these are required for START_AP */ |
| 3092 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3093 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3094 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3095 | return -EINVAL; |
| 3096 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3097 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3098 | if (err) |
| 3099 | return err; |
| 3100 | |
| 3101 | params.beacon_interval = |
| 3102 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3103 | params.dtim_period = |
| 3104 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3105 | |
| 3106 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3107 | if (err) |
| 3108 | return err; |
| 3109 | |
| 3110 | /* |
| 3111 | * In theory, some of these attributes should be required here |
| 3112 | * but since they were not used when the command was originally |
| 3113 | * added, keep them optional for old user space programs to let |
| 3114 | * them continue to work with drivers that do not need the |
| 3115 | * additional information -- drivers must check! |
| 3116 | */ |
| 3117 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3118 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3119 | params.ssid_len = |
| 3120 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3121 | if (params.ssid_len == 0 || |
| 3122 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3123 | return -EINVAL; |
| 3124 | } |
| 3125 | |
| 3126 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3127 | params.hidden_ssid = nla_get_u32( |
| 3128 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3129 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3130 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3131 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3132 | return -EINVAL; |
| 3133 | } |
| 3134 | |
| 3135 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3136 | |
| 3137 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3138 | params.auth_type = nla_get_u32( |
| 3139 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3140 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3141 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3142 | return -EINVAL; |
| 3143 | } else |
| 3144 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3145 | |
| 3146 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3147 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3148 | if (err) |
| 3149 | return err; |
| 3150 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3151 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3152 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3153 | return -EOPNOTSUPP; |
| 3154 | params.inactivity_timeout = nla_get_u16( |
| 3155 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3156 | } |
| 3157 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3158 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3159 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3160 | return -EINVAL; |
| 3161 | params.p2p_ctwindow = |
| 3162 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3163 | if (params.p2p_ctwindow > 127) |
| 3164 | return -EINVAL; |
| 3165 | if (params.p2p_ctwindow != 0 && |
| 3166 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3167 | return -EINVAL; |
| 3168 | } |
| 3169 | |
| 3170 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3171 | u8 tmp; |
| 3172 | |
| 3173 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3174 | return -EINVAL; |
| 3175 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3176 | if (tmp > 1) |
| 3177 | return -EINVAL; |
| 3178 | params.p2p_opp_ps = tmp; |
| 3179 | if (params.p2p_opp_ps != 0 && |
| 3180 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3181 | return -EINVAL; |
| 3182 | } |
| 3183 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3184 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3185 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3186 | if (err) |
| 3187 | return err; |
| 3188 | } else if (wdev->preset_chandef.chan) { |
| 3189 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3190 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3191 | return -EINVAL; |
| 3192 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3193 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3194 | return -EINVAL; |
| 3195 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3196 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3197 | if (err < 0) |
| 3198 | return err; |
| 3199 | if (err) { |
| 3200 | radar_detect_width = BIT(params.chandef.width); |
| 3201 | params.radar_required = true; |
| 3202 | } |
| 3203 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3204 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3205 | params.chandef.chan, |
| 3206 | CHAN_MODE_SHARED, |
| 3207 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3208 | if (err) |
| 3209 | return err; |
| 3210 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3211 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3212 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3213 | if (IS_ERR(params.acl)) |
| 3214 | return PTR_ERR(params.acl); |
| 3215 | } |
| 3216 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3217 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3218 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3219 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3220 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3221 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3222 | wdev->ssid_len = params.ssid_len; |
| 3223 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3224 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3225 | |
| 3226 | kfree(params.acl); |
| 3227 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3228 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3229 | } |
| 3230 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3231 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3232 | { |
| 3233 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3234 | struct net_device *dev = info->user_ptr[1]; |
| 3235 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3236 | struct cfg80211_beacon_data params; |
| 3237 | int err; |
| 3238 | |
| 3239 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3240 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3241 | return -EOPNOTSUPP; |
| 3242 | |
| 3243 | if (!rdev->ops->change_beacon) |
| 3244 | return -EOPNOTSUPP; |
| 3245 | |
| 3246 | if (!wdev->beacon_interval) |
| 3247 | return -EINVAL; |
| 3248 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3249 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3250 | if (err) |
| 3251 | return err; |
| 3252 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3253 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | 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] | 3257 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3258 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3259 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3260 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3261 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3262 | } |
| 3263 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3264 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3265 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3266 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3267 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3268 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3269 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3270 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3271 | }; |
| 3272 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3273 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3274 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3275 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3276 | { |
| 3277 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3278 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3279 | int flag; |
| 3280 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3281 | /* |
| 3282 | * Try parsing the new attribute first so userspace |
| 3283 | * can specify both for older kernels. |
| 3284 | */ |
| 3285 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3286 | if (nla) { |
| 3287 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3288 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3289 | sta_flags = nla_data(nla); |
| 3290 | params->sta_flags_mask = sta_flags->mask; |
| 3291 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3292 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3293 | if ((params->sta_flags_mask | |
| 3294 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3295 | return -EINVAL; |
| 3296 | return 0; |
| 3297 | } |
| 3298 | |
| 3299 | /* if present, parse the old attribute */ |
| 3300 | |
| 3301 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3302 | if (!nla) |
| 3303 | return 0; |
| 3304 | |
| 3305 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3306 | nla, sta_flags_policy)) |
| 3307 | return -EINVAL; |
| 3308 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3309 | /* |
| 3310 | * Only allow certain flags for interface types so that |
| 3311 | * other attributes are silently ignored. Remember that |
| 3312 | * this is backward compatibility code with old userspace |
| 3313 | * and shouldn't be hit in other cases anyway. |
| 3314 | */ |
| 3315 | switch (iftype) { |
| 3316 | case NL80211_IFTYPE_AP: |
| 3317 | case NL80211_IFTYPE_AP_VLAN: |
| 3318 | case NL80211_IFTYPE_P2P_GO: |
| 3319 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3320 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3321 | BIT(NL80211_STA_FLAG_WME) | |
| 3322 | BIT(NL80211_STA_FLAG_MFP); |
| 3323 | break; |
| 3324 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3325 | case NL80211_IFTYPE_STATION: |
| 3326 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3327 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3328 | break; |
| 3329 | case NL80211_IFTYPE_MESH_POINT: |
| 3330 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3331 | BIT(NL80211_STA_FLAG_MFP) | |
| 3332 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3333 | default: |
| 3334 | return -EINVAL; |
| 3335 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3336 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3337 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3338 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3339 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3340 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3341 | /* no longer support new API additions in old API */ |
| 3342 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3343 | return -EINVAL; |
| 3344 | } |
| 3345 | } |
| 3346 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3347 | return 0; |
| 3348 | } |
| 3349 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3350 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3351 | int attr) |
| 3352 | { |
| 3353 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3354 | u32 bitrate; |
| 3355 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3356 | |
| 3357 | rate = nla_nest_start(msg, attr); |
| 3358 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3359 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3360 | |
| 3361 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3362 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3363 | /* report 16-bit bitrate only if we can */ |
| 3364 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3365 | if (bitrate > 0 && |
| 3366 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3367 | return false; |
| 3368 | if (bitrate_compat > 0 && |
| 3369 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3370 | return false; |
| 3371 | |
| 3372 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3373 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3374 | return false; |
| 3375 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3376 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3377 | return false; |
| 3378 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3379 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3380 | return false; |
| 3381 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3382 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3383 | return false; |
| 3384 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 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_80_MHZ_WIDTH && |
| 3390 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3391 | return false; |
| 3392 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3393 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3394 | return false; |
| 3395 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3396 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3397 | return false; |
| 3398 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3399 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3400 | return false; |
| 3401 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3402 | |
| 3403 | nla_nest_end(msg, rate); |
| 3404 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3405 | } |
| 3406 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3407 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3408 | int id) |
| 3409 | { |
| 3410 | void *attr; |
| 3411 | int i = 0; |
| 3412 | |
| 3413 | if (!mask) |
| 3414 | return true; |
| 3415 | |
| 3416 | attr = nla_nest_start(msg, id); |
| 3417 | if (!attr) |
| 3418 | return false; |
| 3419 | |
| 3420 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3421 | if (!(mask & BIT(i))) |
| 3422 | continue; |
| 3423 | |
| 3424 | if (nla_put_u8(msg, i, signal[i])) |
| 3425 | return false; |
| 3426 | } |
| 3427 | |
| 3428 | nla_nest_end(msg, attr); |
| 3429 | |
| 3430 | return true; |
| 3431 | } |
| 3432 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3433 | 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] | 3434 | int flags, |
| 3435 | struct cfg80211_registered_device *rdev, |
| 3436 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3437 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3438 | { |
| 3439 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3440 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3441 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3442 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3443 | if (!hdr) |
| 3444 | return -1; |
| 3445 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3446 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3447 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3448 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3449 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3450 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3451 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3452 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3453 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3454 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3455 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3456 | sinfo->connected_time)) |
| 3457 | goto nla_put_failure; |
| 3458 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3459 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3460 | sinfo->inactive_time)) |
| 3461 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3462 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3463 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3464 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3465 | (u32)sinfo->rx_bytes)) |
| 3466 | goto nla_put_failure; |
| 3467 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3468 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3469 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3470 | (u32)sinfo->tx_bytes)) |
| 3471 | goto nla_put_failure; |
| 3472 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3473 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3474 | sinfo->rx_bytes)) |
| 3475 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3476 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3477 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3478 | sinfo->tx_bytes)) |
| 3479 | goto nla_put_failure; |
| 3480 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3481 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3482 | goto nla_put_failure; |
| 3483 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3484 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3485 | goto nla_put_failure; |
| 3486 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3487 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3488 | sinfo->plink_state)) |
| 3489 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3490 | switch (rdev->wiphy.signal_type) { |
| 3491 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3492 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3493 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3494 | sinfo->signal)) |
| 3495 | goto nla_put_failure; |
| 3496 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3497 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3498 | sinfo->signal_avg)) |
| 3499 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3500 | break; |
| 3501 | default: |
| 3502 | break; |
| 3503 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3504 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3505 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3506 | sinfo->chain_signal, |
| 3507 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3508 | goto nla_put_failure; |
| 3509 | } |
| 3510 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3511 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3512 | sinfo->chain_signal_avg, |
| 3513 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3514 | goto nla_put_failure; |
| 3515 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3516 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3517 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3518 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3519 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3520 | } |
| 3521 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3522 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3523 | NL80211_STA_INFO_RX_BITRATE)) |
| 3524 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3525 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3526 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3527 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3528 | sinfo->rx_packets)) |
| 3529 | goto nla_put_failure; |
| 3530 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3531 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3532 | sinfo->tx_packets)) |
| 3533 | goto nla_put_failure; |
| 3534 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3535 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3536 | sinfo->tx_retries)) |
| 3537 | goto nla_put_failure; |
| 3538 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3539 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3540 | sinfo->tx_failed)) |
| 3541 | goto nla_put_failure; |
| 3542 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3543 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3544 | sinfo->beacon_loss_count)) |
| 3545 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3546 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3547 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3548 | sinfo->local_pm)) |
| 3549 | goto nla_put_failure; |
| 3550 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3551 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3552 | sinfo->peer_pm)) |
| 3553 | goto nla_put_failure; |
| 3554 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3555 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3556 | sinfo->nonpeer_pm)) |
| 3557 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3558 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3559 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3560 | if (!bss_param) |
| 3561 | goto nla_put_failure; |
| 3562 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3563 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3564 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3565 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3566 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3567 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3568 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3569 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3570 | sinfo->bss_param.dtim_period) || |
| 3571 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3572 | sinfo->bss_param.beacon_interval)) |
| 3573 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3574 | |
| 3575 | nla_nest_end(msg, bss_param); |
| 3576 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3577 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3578 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3579 | sizeof(struct nl80211_sta_flag_update), |
| 3580 | &sinfo->sta_flags)) |
| 3581 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3582 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3583 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3584 | sinfo->t_offset)) |
| 3585 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3586 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3587 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3588 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3589 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3590 | sinfo->assoc_req_ies)) |
| 3591 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3592 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3593 | return genlmsg_end(msg, hdr); |
| 3594 | |
| 3595 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3596 | genlmsg_cancel(msg, hdr); |
| 3597 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3598 | } |
| 3599 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3600 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3601 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3602 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3603 | struct station_info sinfo; |
| 3604 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3605 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3606 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3607 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3608 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3609 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3610 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3611 | if (err) |
| 3612 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3613 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3614 | if (!wdev->netdev) { |
| 3615 | err = -EINVAL; |
| 3616 | goto out_err; |
| 3617 | } |
| 3618 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3619 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3620 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3621 | goto out_err; |
| 3622 | } |
| 3623 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3624 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3625 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3626 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3627 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3628 | if (err == -ENOENT) |
| 3629 | break; |
| 3630 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3631 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3632 | |
| 3633 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3634 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3635 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3636 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3637 | &sinfo) < 0) |
| 3638 | goto out; |
| 3639 | |
| 3640 | sta_idx++; |
| 3641 | } |
| 3642 | |
| 3643 | |
| 3644 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3645 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3646 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3647 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3648 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3649 | |
| 3650 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3651 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3652 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3653 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3654 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3656 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3657 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3658 | struct sk_buff *msg; |
| 3659 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3660 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3661 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3662 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3663 | |
| 3664 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3665 | return -EINVAL; |
| 3666 | |
| 3667 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3668 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3669 | if (!rdev->ops->get_station) |
| 3670 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3671 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3672 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3673 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3674 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3675 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3676 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3677 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3678 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3679 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3680 | 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] | 3681 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3682 | nlmsg_free(msg); |
| 3683 | return -ENOBUFS; |
| 3684 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3685 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3686 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3687 | } |
| 3688 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3689 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3690 | struct station_parameters *params, |
| 3691 | enum cfg80211_station_type statype) |
| 3692 | { |
| 3693 | if (params->listen_interval != -1) |
| 3694 | return -EINVAL; |
| 3695 | if (params->aid) |
| 3696 | return -EINVAL; |
| 3697 | |
| 3698 | /* When you run into this, adjust the code below for the new flag */ |
| 3699 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3700 | |
| 3701 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3702 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3703 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3704 | /* |
| 3705 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3706 | * code doesn't have the bug of including TDLS in the |
| 3707 | * mask everywhere. |
| 3708 | */ |
| 3709 | if (params->sta_flags_mask & |
| 3710 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3711 | BIT(NL80211_STA_FLAG_MFP) | |
| 3712 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3713 | return -EINVAL; |
| 3714 | break; |
| 3715 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3716 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3717 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3718 | return -EINVAL; |
| 3719 | /* ignore since it can't change */ |
| 3720 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3721 | break; |
| 3722 | default: |
| 3723 | /* disallow mesh-specific things */ |
| 3724 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3725 | return -EINVAL; |
| 3726 | if (params->local_pm) |
| 3727 | return -EINVAL; |
| 3728 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3729 | return -EINVAL; |
| 3730 | } |
| 3731 | |
| 3732 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3733 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3734 | /* TDLS can't be set, ... */ |
| 3735 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3736 | return -EINVAL; |
| 3737 | /* |
| 3738 | * ... but don't bother the driver with it. This works around |
| 3739 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3740 | * TLDS_PEER flag in the mask even for AP mode. |
| 3741 | */ |
| 3742 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3743 | } |
| 3744 | |
| 3745 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3746 | /* reject other things that can't change */ |
| 3747 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3748 | return -EINVAL; |
| 3749 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3750 | return -EINVAL; |
| 3751 | if (params->supported_rates) |
| 3752 | return -EINVAL; |
| 3753 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3754 | return -EINVAL; |
| 3755 | } |
| 3756 | |
| 3757 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3758 | if (params->vlan) |
| 3759 | return -EINVAL; |
| 3760 | } |
| 3761 | |
| 3762 | switch (statype) { |
| 3763 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3764 | /* Use this only for authorizing/unauthorizing a station */ |
| 3765 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3766 | return -EOPNOTSUPP; |
| 3767 | break; |
| 3768 | case CFG80211_STA_AP_CLIENT: |
| 3769 | /* accept only the listed bits */ |
| 3770 | if (params->sta_flags_mask & |
| 3771 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3772 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3773 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3774 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3775 | BIT(NL80211_STA_FLAG_WME) | |
| 3776 | BIT(NL80211_STA_FLAG_MFP))) |
| 3777 | return -EINVAL; |
| 3778 | |
| 3779 | /* but authenticated/associated only if driver handles it */ |
| 3780 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3781 | params->sta_flags_mask & |
| 3782 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3783 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3784 | return -EINVAL; |
| 3785 | break; |
| 3786 | case CFG80211_STA_IBSS: |
| 3787 | case CFG80211_STA_AP_STA: |
| 3788 | /* reject any changes other than AUTHORIZED */ |
| 3789 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3790 | return -EINVAL; |
| 3791 | break; |
| 3792 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3793 | /* reject any changes other than AUTHORIZED or WME */ |
| 3794 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3795 | BIT(NL80211_STA_FLAG_WME))) |
| 3796 | return -EINVAL; |
| 3797 | /* force (at least) rates when authorizing */ |
| 3798 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3799 | !params->supported_rates) |
| 3800 | return -EINVAL; |
| 3801 | break; |
| 3802 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3803 | /* reject any changes */ |
| 3804 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3805 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3806 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3807 | return -EINVAL; |
| 3808 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3809 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3810 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3811 | return -EINVAL; |
| 3812 | break; |
| 3813 | } |
| 3814 | |
| 3815 | return 0; |
| 3816 | } |
| 3817 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3818 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3819 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3820 | * 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] | 3821 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3822 | static struct net_device *get_vlan(struct genl_info *info, |
| 3823 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3824 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3825 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3826 | struct net_device *v; |
| 3827 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3828 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3829 | if (!vlanattr) |
| 3830 | return NULL; |
| 3831 | |
| 3832 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3833 | if (!v) |
| 3834 | return ERR_PTR(-ENODEV); |
| 3835 | |
| 3836 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3837 | ret = -EINVAL; |
| 3838 | goto error; |
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 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3841 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3842 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3843 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3844 | ret = -EINVAL; |
| 3845 | goto error; |
| 3846 | } |
| 3847 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3848 | if (!netif_running(v)) { |
| 3849 | ret = -ENETDOWN; |
| 3850 | goto error; |
| 3851 | } |
| 3852 | |
| 3853 | return v; |
| 3854 | error: |
| 3855 | dev_put(v); |
| 3856 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3857 | } |
| 3858 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3859 | static struct nla_policy |
| 3860 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3861 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3862 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3863 | }; |
| 3864 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3865 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3866 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3867 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3868 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3869 | struct nlattr *nla; |
| 3870 | int err; |
| 3871 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3872 | /* parse WME attributes if present */ |
| 3873 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3874 | return 0; |
| 3875 | |
| 3876 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3877 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3878 | nl80211_sta_wme_policy); |
| 3879 | if (err) |
| 3880 | return err; |
| 3881 | |
| 3882 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3883 | params->uapsd_queues = nla_get_u8( |
| 3884 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3885 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3886 | return -EINVAL; |
| 3887 | |
| 3888 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3889 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3890 | |
| 3891 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3892 | return -EINVAL; |
| 3893 | |
| 3894 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3895 | |
| 3896 | return 0; |
| 3897 | } |
| 3898 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3899 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3900 | struct station_parameters *params) |
| 3901 | { |
| 3902 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3903 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3904 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3905 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3906 | params->ht_capa = |
| 3907 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3908 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3909 | params->vht_capa = |
| 3910 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3911 | |
| 3912 | return nl80211_parse_sta_wme(info, params); |
| 3913 | } |
| 3914 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3915 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3916 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3917 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3918 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3919 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3920 | u8 *mac_addr; |
| 3921 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3922 | |
| 3923 | memset(¶ms, 0, sizeof(params)); |
| 3924 | |
| 3925 | params.listen_interval = -1; |
| 3926 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3927 | if (!rdev->ops->change_station) |
| 3928 | return -EOPNOTSUPP; |
| 3929 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3930 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3931 | return -EINVAL; |
| 3932 | |
| 3933 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3934 | return -EINVAL; |
| 3935 | |
| 3936 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3937 | |
| 3938 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3939 | params.supported_rates = |
| 3940 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3941 | params.supported_rates_len = |
| 3942 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3943 | } |
| 3944 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3945 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3946 | params.capability = |
| 3947 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3948 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3949 | } |
| 3950 | |
| 3951 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3952 | params.ext_capab = |
| 3953 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3954 | params.ext_capab_len = |
| 3955 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3956 | } |
| 3957 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3958 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3959 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3960 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3961 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3962 | return -EINVAL; |
| 3963 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3964 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3965 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3966 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3967 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3968 | return -EINVAL; |
| 3969 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3970 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3971 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3972 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3973 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3974 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 3975 | return -EINVAL; |
| 3976 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 3977 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3978 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3979 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3980 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3981 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3982 | |
| 3983 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3984 | pm > NL80211_MESH_POWER_MAX) |
| 3985 | return -EINVAL; |
| 3986 | |
| 3987 | params.local_pm = pm; |
| 3988 | } |
| 3989 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3990 | /* Include parameters for TDLS peer (will check later) */ |
| 3991 | err = nl80211_set_station_tdls(info, ¶ms); |
| 3992 | if (err) |
| 3993 | return err; |
| 3994 | |
| 3995 | params.vlan = get_vlan(info, rdev); |
| 3996 | if (IS_ERR(params.vlan)) |
| 3997 | return PTR_ERR(params.vlan); |
| 3998 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3999 | switch (dev->ieee80211_ptr->iftype) { |
| 4000 | case NL80211_IFTYPE_AP: |
| 4001 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4002 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4003 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4004 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4005 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4006 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4007 | break; |
| 4008 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4009 | err = -EOPNOTSUPP; |
| 4010 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4011 | } |
| 4012 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4013 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4014 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4015 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4016 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4017 | if (params.vlan) |
| 4018 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4019 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4020 | return err; |
| 4021 | } |
| 4022 | |
| 4023 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4024 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4025 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4026 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4027 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4028 | struct station_parameters params; |
| 4029 | u8 *mac_addr = NULL; |
| 4030 | |
| 4031 | memset(¶ms, 0, sizeof(params)); |
| 4032 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4033 | if (!rdev->ops->add_station) |
| 4034 | return -EOPNOTSUPP; |
| 4035 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4036 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4037 | return -EINVAL; |
| 4038 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4039 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4040 | return -EINVAL; |
| 4041 | |
| 4042 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4043 | return -EINVAL; |
| 4044 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4045 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4046 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4047 | return -EINVAL; |
| 4048 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4049 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4050 | params.supported_rates = |
| 4051 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4052 | params.supported_rates_len = |
| 4053 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4054 | params.listen_interval = |
| 4055 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4056 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4057 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4058 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4059 | else |
| 4060 | 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] | 4061 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4062 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4063 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4064 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4065 | params.capability = |
| 4066 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4067 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4068 | } |
| 4069 | |
| 4070 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4071 | params.ext_capab = |
| 4072 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4073 | params.ext_capab_len = |
| 4074 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4075 | } |
| 4076 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4077 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4078 | params.ht_capa = |
| 4079 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4080 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4081 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4082 | params.vht_capa = |
| 4083 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4084 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4085 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4086 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4087 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4088 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4089 | return -EINVAL; |
| 4090 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4091 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4092 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4093 | if (err) |
| 4094 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4095 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4096 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4097 | return -EINVAL; |
| 4098 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4099 | /* When you run into this, adjust the code below for the new flag */ |
| 4100 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4101 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4102 | switch (dev->ieee80211_ptr->iftype) { |
| 4103 | case NL80211_IFTYPE_AP: |
| 4104 | case NL80211_IFTYPE_AP_VLAN: |
| 4105 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4106 | /* ignore WME attributes if iface/sta is not capable */ |
| 4107 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4108 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4109 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4110 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4111 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4112 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4113 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4114 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4115 | /* but don't bother the driver with it */ |
| 4116 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4117 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4118 | /* allow authenticated/associated only if driver handles it */ |
| 4119 | if (!(rdev->wiphy.features & |
| 4120 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4121 | params.sta_flags_mask & |
| 4122 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4123 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4124 | return -EINVAL; |
| 4125 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4126 | /* must be last in here for error handling */ |
| 4127 | params.vlan = get_vlan(info, rdev); |
| 4128 | if (IS_ERR(params.vlan)) |
| 4129 | return PTR_ERR(params.vlan); |
| 4130 | break; |
| 4131 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4132 | /* ignore uAPSD data */ |
| 4133 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4134 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4135 | /* associated is disallowed */ |
| 4136 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4137 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4138 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4139 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4140 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4141 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4142 | break; |
| 4143 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4144 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4145 | /* ignore uAPSD data */ |
| 4146 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4147 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4148 | /* these are disallowed */ |
| 4149 | if (params.sta_flags_mask & |
| 4150 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4151 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4152 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4153 | /* Only TDLS peers can be added */ |
| 4154 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4155 | return -EINVAL; |
| 4156 | /* Can only add if TDLS ... */ |
| 4157 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4158 | return -EOPNOTSUPP; |
| 4159 | /* ... with external setup is supported */ |
| 4160 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4161 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4162 | /* |
| 4163 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4164 | * as authorized, but it shouldn't yet be. |
| 4165 | */ |
| 4166 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4167 | break; |
| 4168 | default: |
| 4169 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4170 | } |
| 4171 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4172 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4173 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4174 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4175 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4176 | if (params.vlan) |
| 4177 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4178 | return err; |
| 4179 | } |
| 4180 | |
| 4181 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4182 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4183 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4184 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4185 | u8 *mac_addr = NULL; |
| 4186 | |
| 4187 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4188 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4189 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4190 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4191 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4192 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4193 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4194 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4195 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4196 | if (!rdev->ops->del_station) |
| 4197 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4198 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4199 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4200 | } |
| 4201 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4202 | 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] | 4203 | int flags, struct net_device *dev, |
| 4204 | u8 *dst, u8 *next_hop, |
| 4205 | struct mpath_info *pinfo) |
| 4206 | { |
| 4207 | void *hdr; |
| 4208 | struct nlattr *pinfoattr; |
| 4209 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4210 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4211 | if (!hdr) |
| 4212 | return -1; |
| 4213 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4214 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4215 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4216 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4217 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4218 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4219 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4220 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4221 | if (!pinfoattr) |
| 4222 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4223 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4224 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4225 | pinfo->frame_qlen)) |
| 4226 | goto nla_put_failure; |
| 4227 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4228 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4229 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4230 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4231 | pinfo->metric)) || |
| 4232 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4233 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4234 | pinfo->exptime)) || |
| 4235 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4236 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4237 | pinfo->flags)) || |
| 4238 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4239 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4240 | pinfo->discovery_timeout)) || |
| 4241 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4242 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4243 | pinfo->discovery_retries))) |
| 4244 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4245 | |
| 4246 | nla_nest_end(msg, pinfoattr); |
| 4247 | |
| 4248 | return genlmsg_end(msg, hdr); |
| 4249 | |
| 4250 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4251 | genlmsg_cancel(msg, hdr); |
| 4252 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4256 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4257 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4258 | struct mpath_info pinfo; |
| 4259 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4260 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4261 | u8 dst[ETH_ALEN]; |
| 4262 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4263 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4264 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4265 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4266 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4267 | if (err) |
| 4268 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4269 | |
| 4270 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4271 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4272 | goto out_err; |
| 4273 | } |
| 4274 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4275 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4276 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4277 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4278 | } |
| 4279 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4280 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4281 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4282 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4283 | if (err == -ENOENT) |
| 4284 | break; |
| 4285 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4286 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4287 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4288 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4289 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4290 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4291 | &pinfo) < 0) |
| 4292 | goto out; |
| 4293 | |
| 4294 | path_idx++; |
| 4295 | } |
| 4296 | |
| 4297 | |
| 4298 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4299 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4300 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4301 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4302 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4303 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4307 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4308 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4309 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4310 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4311 | struct mpath_info pinfo; |
| 4312 | struct sk_buff *msg; |
| 4313 | u8 *dst = NULL; |
| 4314 | u8 next_hop[ETH_ALEN]; |
| 4315 | |
| 4316 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4317 | |
| 4318 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4319 | return -EINVAL; |
| 4320 | |
| 4321 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4322 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4323 | if (!rdev->ops->get_mpath) |
| 4324 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4325 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4326 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4327 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4328 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4329 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4330 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4331 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4332 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4333 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4334 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4335 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4336 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4337 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4338 | dev, dst, next_hop, &pinfo) < 0) { |
| 4339 | nlmsg_free(msg); |
| 4340 | return -ENOBUFS; |
| 4341 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4342 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4343 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4344 | } |
| 4345 | |
| 4346 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4347 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4348 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4349 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4350 | u8 *dst = NULL; |
| 4351 | u8 *next_hop = NULL; |
| 4352 | |
| 4353 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4354 | return -EINVAL; |
| 4355 | |
| 4356 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4357 | return -EINVAL; |
| 4358 | |
| 4359 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4360 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4361 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4362 | if (!rdev->ops->change_mpath) |
| 4363 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4364 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4365 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4366 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4367 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4368 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4369 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4370 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4371 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4372 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4373 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4374 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4375 | u8 *dst = NULL; |
| 4376 | u8 *next_hop = NULL; |
| 4377 | |
| 4378 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4379 | return -EINVAL; |
| 4380 | |
| 4381 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4382 | return -EINVAL; |
| 4383 | |
| 4384 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4385 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4386 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4387 | if (!rdev->ops->add_mpath) |
| 4388 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4389 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4390 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4391 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4392 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4393 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4394 | } |
| 4395 | |
| 4396 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4397 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4398 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4399 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4400 | u8 *dst = NULL; |
| 4401 | |
| 4402 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4403 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4404 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4405 | if (!rdev->ops->del_mpath) |
| 4406 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4407 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4408 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4409 | } |
| 4410 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4411 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4412 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4413 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4414 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4415 | struct bss_parameters params; |
| 4416 | |
| 4417 | memset(¶ms, 0, sizeof(params)); |
| 4418 | /* default to not changing parameters */ |
| 4419 | params.use_cts_prot = -1; |
| 4420 | params.use_short_preamble = -1; |
| 4421 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4422 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4423 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4424 | params.p2p_ctwindow = -1; |
| 4425 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4426 | |
| 4427 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4428 | params.use_cts_prot = |
| 4429 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4430 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4431 | params.use_short_preamble = |
| 4432 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4433 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4434 | params.use_short_slot_time = |
| 4435 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4436 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4437 | params.basic_rates = |
| 4438 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4439 | params.basic_rates_len = |
| 4440 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4441 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4442 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4443 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4444 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4445 | params.ht_opmode = |
| 4446 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4447 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4448 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4449 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4450 | return -EINVAL; |
| 4451 | params.p2p_ctwindow = |
| 4452 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4453 | if (params.p2p_ctwindow < 0) |
| 4454 | return -EINVAL; |
| 4455 | if (params.p2p_ctwindow != 0 && |
| 4456 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4457 | return -EINVAL; |
| 4458 | } |
| 4459 | |
| 4460 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4461 | u8 tmp; |
| 4462 | |
| 4463 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4464 | return -EINVAL; |
| 4465 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4466 | if (tmp > 1) |
| 4467 | return -EINVAL; |
| 4468 | params.p2p_opp_ps = tmp; |
| 4469 | if (params.p2p_opp_ps && |
| 4470 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4471 | return -EINVAL; |
| 4472 | } |
| 4473 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4474 | if (!rdev->ops->change_bss) |
| 4475 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4476 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4477 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4478 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4479 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4480 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4481 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4482 | } |
| 4483 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4484 | 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] | 4485 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4486 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4487 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4488 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4489 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4490 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4491 | }; |
| 4492 | |
| 4493 | static int parse_reg_rule(struct nlattr *tb[], |
| 4494 | struct ieee80211_reg_rule *reg_rule) |
| 4495 | { |
| 4496 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4497 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4498 | |
| 4499 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4500 | return -EINVAL; |
| 4501 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4502 | return -EINVAL; |
| 4503 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4504 | return -EINVAL; |
| 4505 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4506 | return -EINVAL; |
| 4507 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4508 | return -EINVAL; |
| 4509 | |
| 4510 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4511 | |
| 4512 | freq_range->start_freq_khz = |
| 4513 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4514 | freq_range->end_freq_khz = |
| 4515 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4516 | freq_range->max_bandwidth_khz = |
| 4517 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4518 | |
| 4519 | power_rule->max_eirp = |
| 4520 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4521 | |
| 4522 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4523 | power_rule->max_antenna_gain = |
| 4524 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4525 | |
| 4526 | return 0; |
| 4527 | } |
| 4528 | |
| 4529 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4530 | { |
| 4531 | int r; |
| 4532 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4533 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4534 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4535 | /* |
| 4536 | * You should only get this when cfg80211 hasn't yet initialized |
| 4537 | * completely when built-in to the kernel right between the time |
| 4538 | * window between nl80211_init() and regulatory_init(), if that is |
| 4539 | * even possible. |
| 4540 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4541 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4542 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4543 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4544 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4545 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4546 | |
| 4547 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4548 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4549 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4550 | user_reg_hint_type = |
| 4551 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4552 | else |
| 4553 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4554 | |
| 4555 | switch (user_reg_hint_type) { |
| 4556 | case NL80211_USER_REG_HINT_USER: |
| 4557 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4558 | break; |
| 4559 | default: |
| 4560 | return -EINVAL; |
| 4561 | } |
| 4562 | |
| 4563 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4564 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4565 | return r; |
| 4566 | } |
| 4567 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4568 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4569 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4570 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4571 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4572 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4573 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4574 | struct mesh_config cur_params; |
| 4575 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4576 | void *hdr; |
| 4577 | struct nlattr *pinfoattr; |
| 4578 | struct sk_buff *msg; |
| 4579 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4580 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4581 | return -EOPNOTSUPP; |
| 4582 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4583 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4584 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4585 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4586 | wdev_lock(wdev); |
| 4587 | /* If not connected, get default parameters */ |
| 4588 | if (!wdev->mesh_id_len) |
| 4589 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4590 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4591 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4592 | wdev_unlock(wdev); |
| 4593 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4594 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4595 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4596 | |
| 4597 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4598 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4599 | if (!msg) |
| 4600 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4601 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4602 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4603 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4604 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4605 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4606 | if (!pinfoattr) |
| 4607 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4608 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4609 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4610 | cur_params.dot11MeshRetryTimeout) || |
| 4611 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4612 | cur_params.dot11MeshConfirmTimeout) || |
| 4613 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4614 | cur_params.dot11MeshHoldingTimeout) || |
| 4615 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4616 | cur_params.dot11MeshMaxPeerLinks) || |
| 4617 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4618 | cur_params.dot11MeshMaxRetries) || |
| 4619 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4620 | cur_params.dot11MeshTTL) || |
| 4621 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4622 | cur_params.element_ttl) || |
| 4623 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4624 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4625 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4626 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4627 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4628 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4629 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4630 | cur_params.path_refresh_time) || |
| 4631 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4632 | cur_params.min_discovery_timeout) || |
| 4633 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4634 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4635 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4636 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4637 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4638 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4639 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4640 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4641 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4642 | cur_params.dot11MeshHWMPRootMode) || |
| 4643 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4644 | cur_params.dot11MeshHWMPRannInterval) || |
| 4645 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4646 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4647 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4648 | cur_params.dot11MeshForwarding) || |
| 4649 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4650 | cur_params.rssi_threshold) || |
| 4651 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4652 | cur_params.ht_opmode) || |
| 4653 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4654 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4655 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4656 | cur_params.dot11MeshHWMProotInterval) || |
| 4657 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4658 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4659 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4660 | cur_params.power_mode) || |
| 4661 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4662 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4663 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4664 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4665 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4666 | nla_nest_end(msg, pinfoattr); |
| 4667 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4668 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4669 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4670 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4671 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4672 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4673 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4674 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4675 | } |
| 4676 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4677 | 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] | 4678 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4679 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4680 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4681 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4682 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4683 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4684 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4685 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4686 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4687 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4688 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4689 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4690 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4691 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4692 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4693 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4694 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4695 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4696 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4697 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4698 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4699 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4700 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4701 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4702 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4703 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4704 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4705 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4706 | }; |
| 4707 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4708 | static const struct nla_policy |
| 4709 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4710 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4711 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4712 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4713 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4714 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4715 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4716 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4717 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4718 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4719 | }; |
| 4720 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4721 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4722 | struct mesh_config *cfg, |
| 4723 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4724 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4725 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4726 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4727 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4728 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4729 | do { \ |
| 4730 | if (tb[attr]) { \ |
| 4731 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4732 | return -EINVAL; \ |
| 4733 | cfg->param = fn(tb[attr]); \ |
| 4734 | mask |= (1 << (attr - 1)); \ |
| 4735 | } \ |
| 4736 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4737 | |
| 4738 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4739 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4740 | return -EINVAL; |
| 4741 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4742 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4743 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4744 | return -EINVAL; |
| 4745 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4746 | /* This makes sure that there aren't more than 32 mesh config |
| 4747 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4748 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4749 | |
| 4750 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4751 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4752 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4753 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4754 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4755 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4756 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4757 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4758 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4759 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4760 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4761 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4762 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4763 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4764 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4765 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4766 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4767 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4768 | 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] | 4769 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4770 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4771 | 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] | 4772 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4773 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4774 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4775 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4776 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4777 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4778 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4779 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4780 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4781 | 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] | 4782 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4783 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4784 | 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] | 4785 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4786 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4787 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4788 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4789 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4790 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4791 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4792 | 1, 65535, mask, |
| 4793 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4794 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4795 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4796 | 1, 65535, mask, |
| 4797 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4798 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4799 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4800 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4801 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4802 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4803 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4804 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4805 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4806 | nla_get_u8); |
| 4807 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4808 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4809 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4810 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4811 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4812 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4813 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4814 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4815 | mask, NL80211_MESHCONF_FORWARDING, |
| 4816 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4817 | 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] | 4818 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4819 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4820 | 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] | 4821 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4822 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4823 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4824 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4825 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4826 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4827 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4828 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4829 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4830 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4831 | dot11MeshHWMPconfirmationInterval, |
| 4832 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4833 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4834 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4835 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4836 | NL80211_MESH_POWER_ACTIVE, |
| 4837 | NL80211_MESH_POWER_MAX, |
| 4838 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4839 | nla_get_u32); |
| 4840 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4841 | 0, 65535, mask, |
| 4842 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4843 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4844 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4845 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4846 | if (mask_out) |
| 4847 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4848 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4849 | return 0; |
| 4850 | |
| 4851 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4852 | } |
| 4853 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4854 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4855 | struct mesh_setup *setup) |
| 4856 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4857 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4858 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4859 | |
| 4860 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4861 | return -EINVAL; |
| 4862 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4863 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4864 | nl80211_mesh_setup_params_policy)) |
| 4865 | return -EINVAL; |
| 4866 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4867 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4868 | setup->sync_method = |
| 4869 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4870 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4871 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4872 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4873 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4874 | setup->path_sel_proto = |
| 4875 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4876 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4877 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4878 | |
| 4879 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4880 | setup->path_metric = |
| 4881 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4882 | IEEE80211_PATH_METRIC_VENDOR : |
| 4883 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4884 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4885 | |
| 4886 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4887 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4888 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4889 | if (!is_valid_ie_attr(ieattr)) |
| 4890 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4891 | setup->ie = nla_data(ieattr); |
| 4892 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4893 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4894 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4895 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4896 | return -EINVAL; |
| 4897 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4898 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4899 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4900 | if (setup->is_secure) |
| 4901 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4902 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4903 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 4904 | if (!setup->user_mpm) |
| 4905 | return -EINVAL; |
| 4906 | setup->auth_id = |
| 4907 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 4908 | } |
| 4909 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4910 | return 0; |
| 4911 | } |
| 4912 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4913 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4914 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4915 | { |
| 4916 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4917 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4918 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4919 | struct mesh_config cfg; |
| 4920 | u32 mask; |
| 4921 | int err; |
| 4922 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4923 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4924 | return -EOPNOTSUPP; |
| 4925 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4926 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4927 | return -EOPNOTSUPP; |
| 4928 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4929 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4930 | if (err) |
| 4931 | return err; |
| 4932 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4933 | wdev_lock(wdev); |
| 4934 | if (!wdev->mesh_id_len) |
| 4935 | err = -ENOLINK; |
| 4936 | |
| 4937 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4938 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4939 | |
| 4940 | wdev_unlock(wdev); |
| 4941 | |
| 4942 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4943 | } |
| 4944 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4945 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4946 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4947 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4948 | struct sk_buff *msg; |
| 4949 | void *hdr = NULL; |
| 4950 | struct nlattr *nl_reg_rules; |
| 4951 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4952 | |
| 4953 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4954 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4955 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4956 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4957 | if (!msg) |
| 4958 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4959 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4960 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4961 | NL80211_CMD_GET_REG); |
| 4962 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4963 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4964 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4965 | if (reg_last_request_cell_base() && |
| 4966 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4967 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4968 | goto nla_put_failure; |
| 4969 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4970 | rcu_read_lock(); |
| 4971 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4972 | |
| 4973 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4974 | (regdom->dfs_region && |
| 4975 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4976 | goto nla_put_failure_rcu; |
| 4977 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4978 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4979 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4980 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4981 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4982 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4983 | struct nlattr *nl_reg_rule; |
| 4984 | const struct ieee80211_reg_rule *reg_rule; |
| 4985 | const struct ieee80211_freq_range *freq_range; |
| 4986 | const struct ieee80211_power_rule *power_rule; |
| 4987 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4988 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4989 | freq_range = ®_rule->freq_range; |
| 4990 | power_rule = ®_rule->power_rule; |
| 4991 | |
| 4992 | nl_reg_rule = nla_nest_start(msg, i); |
| 4993 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4994 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4995 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4996 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4997 | reg_rule->flags) || |
| 4998 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4999 | freq_range->start_freq_khz) || |
| 5000 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5001 | freq_range->end_freq_khz) || |
| 5002 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 5003 | freq_range->max_bandwidth_khz) || |
| 5004 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5005 | power_rule->max_antenna_gain) || |
| 5006 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 5007 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5008 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5009 | |
| 5010 | nla_nest_end(msg, nl_reg_rule); |
| 5011 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5012 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5013 | |
| 5014 | nla_nest_end(msg, nl_reg_rules); |
| 5015 | |
| 5016 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5017 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5018 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5019 | nla_put_failure_rcu: |
| 5020 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5021 | nla_put_failure: |
| 5022 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5023 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5024 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5025 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5026 | } |
| 5027 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5028 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5029 | { |
| 5030 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5031 | struct nlattr *nl_reg_rule; |
| 5032 | char *alpha2 = NULL; |
| 5033 | int rem_reg_rules = 0, r = 0; |
| 5034 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5035 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5036 | struct ieee80211_regdomain *rd = NULL; |
| 5037 | |
| 5038 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5039 | return -EINVAL; |
| 5040 | |
| 5041 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5042 | return -EINVAL; |
| 5043 | |
| 5044 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5045 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5046 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5047 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5048 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5049 | 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] | 5050 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5051 | num_rules++; |
| 5052 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5053 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5054 | } |
| 5055 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5056 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5057 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5058 | |
| 5059 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5060 | if (!rd) |
| 5061 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5062 | |
| 5063 | rd->n_reg_rules = num_rules; |
| 5064 | rd->alpha2[0] = alpha2[0]; |
| 5065 | rd->alpha2[1] = alpha2[1]; |
| 5066 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5067 | /* |
| 5068 | * Disable DFS master mode if the DFS region was |
| 5069 | * not supported or known on this kernel. |
| 5070 | */ |
| 5071 | if (reg_supported_dfs_region(dfs_region)) |
| 5072 | rd->dfs_region = dfs_region; |
| 5073 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5074 | 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] | 5075 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5076 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5077 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5078 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5079 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5080 | if (r) |
| 5081 | goto bad_reg; |
| 5082 | |
| 5083 | rule_idx++; |
| 5084 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5085 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5086 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5087 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5088 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5089 | } |
| 5090 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5091 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5092 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5093 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5094 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5095 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5096 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5097 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5098 | } |
| 5099 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5100 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5101 | { |
| 5102 | struct nlattr *attr1, *attr2; |
| 5103 | int n_channels = 0, tmp1, tmp2; |
| 5104 | |
| 5105 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5106 | n_channels++; |
| 5107 | /* |
| 5108 | * Some hardware has a limited channel list for |
| 5109 | * scanning, and it is pretty much nonsensical |
| 5110 | * to scan for a channel twice, so disallow that |
| 5111 | * and don't require drivers to check that the |
| 5112 | * channel list they get isn't longer than what |
| 5113 | * they can scan, as long as they can scan all |
| 5114 | * the channels they registered at once. |
| 5115 | */ |
| 5116 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5117 | if (attr1 != attr2 && |
| 5118 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5119 | return 0; |
| 5120 | } |
| 5121 | |
| 5122 | return n_channels; |
| 5123 | } |
| 5124 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5125 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5126 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5127 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5128 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5129 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5130 | struct nlattr *attr; |
| 5131 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5132 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5133 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5134 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5135 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5136 | return -EINVAL; |
| 5137 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5138 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5139 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5140 | if (!rdev->ops->scan) |
| 5141 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5142 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5143 | if (rdev->scan_req) { |
| 5144 | err = -EBUSY; |
| 5145 | goto unlock; |
| 5146 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5147 | |
| 5148 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5149 | n_channels = validate_scan_freqs( |
| 5150 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5151 | if (!n_channels) { |
| 5152 | err = -EINVAL; |
| 5153 | goto unlock; |
| 5154 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5155 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5156 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5157 | n_channels = 0; |
| 5158 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5159 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5160 | if (wiphy->bands[band]) |
| 5161 | n_channels += wiphy->bands[band]->n_channels; |
| 5162 | } |
| 5163 | |
| 5164 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5165 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5166 | n_ssids++; |
| 5167 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5168 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5169 | err = -EINVAL; |
| 5170 | goto unlock; |
| 5171 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5172 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5173 | if (info->attrs[NL80211_ATTR_IE]) |
| 5174 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5175 | else |
| 5176 | ie_len = 0; |
| 5177 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5178 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5179 | err = -EINVAL; |
| 5180 | goto unlock; |
| 5181 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5182 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5183 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5184 | + sizeof(*request->ssids) * n_ssids |
| 5185 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5186 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5187 | if (!request) { |
| 5188 | err = -ENOMEM; |
| 5189 | goto unlock; |
| 5190 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5191 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5192 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5193 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5194 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5195 | if (ie_len) { |
| 5196 | if (request->ssids) |
| 5197 | request->ie = (void *)(request->ssids + n_ssids); |
| 5198 | else |
| 5199 | request->ie = (void *)(request->channels + n_channels); |
| 5200 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5201 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5202 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5203 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5204 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5205 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5206 | struct ieee80211_channel *chan; |
| 5207 | |
| 5208 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5209 | |
| 5210 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5211 | err = -EINVAL; |
| 5212 | goto out_free; |
| 5213 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5214 | |
| 5215 | /* ignore disabled channels */ |
| 5216 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5217 | continue; |
| 5218 | |
| 5219 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5220 | i++; |
| 5221 | } |
| 5222 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5223 | enum ieee80211_band band; |
| 5224 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5225 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5226 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5227 | int j; |
| 5228 | if (!wiphy->bands[band]) |
| 5229 | continue; |
| 5230 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5231 | struct ieee80211_channel *chan; |
| 5232 | |
| 5233 | chan = &wiphy->bands[band]->channels[j]; |
| 5234 | |
| 5235 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5236 | continue; |
| 5237 | |
| 5238 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5239 | i++; |
| 5240 | } |
| 5241 | } |
| 5242 | } |
| 5243 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5244 | if (!i) { |
| 5245 | err = -EINVAL; |
| 5246 | goto out_free; |
| 5247 | } |
| 5248 | |
| 5249 | request->n_channels = i; |
| 5250 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5251 | i = 0; |
| 5252 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5253 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5254 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5255 | err = -EINVAL; |
| 5256 | goto out_free; |
| 5257 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5258 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5259 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5260 | i++; |
| 5261 | } |
| 5262 | } |
| 5263 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5264 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5265 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5266 | memcpy((void *)request->ie, |
| 5267 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5268 | request->ie_len); |
| 5269 | } |
| 5270 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5271 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5272 | if (wiphy->bands[i]) |
| 5273 | request->rates[i] = |
| 5274 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5275 | |
| 5276 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5277 | nla_for_each_nested(attr, |
| 5278 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5279 | tmp) { |
| 5280 | enum ieee80211_band band = nla_type(attr); |
| 5281 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5282 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5283 | err = -EINVAL; |
| 5284 | goto out_free; |
| 5285 | } |
| 5286 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5287 | nla_data(attr), |
| 5288 | nla_len(attr), |
| 5289 | &request->rates[band]); |
| 5290 | if (err) |
| 5291 | goto out_free; |
| 5292 | } |
| 5293 | } |
| 5294 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5295 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5296 | request->flags = nla_get_u32( |
| 5297 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5298 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5299 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5300 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5301 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5302 | err = -EOPNOTSUPP; |
| 5303 | goto out_free; |
| 5304 | } |
| 5305 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5306 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5307 | request->no_cck = |
| 5308 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5309 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5310 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5311 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5312 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5313 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5314 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5315 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5316 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5317 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5318 | nl80211_send_scan_start(rdev, wdev); |
| 5319 | if (wdev->netdev) |
| 5320 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5321 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5322 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5323 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5324 | kfree(request); |
| 5325 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5326 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5327 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5328 | return err; |
| 5329 | } |
| 5330 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5331 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5332 | struct genl_info *info) |
| 5333 | { |
| 5334 | struct cfg80211_sched_scan_request *request; |
| 5335 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5336 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5337 | struct nlattr *attr; |
| 5338 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5339 | 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] | 5340 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5341 | enum ieee80211_band band; |
| 5342 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5343 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5344 | |
| 5345 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5346 | !rdev->ops->sched_scan_start) |
| 5347 | return -EOPNOTSUPP; |
| 5348 | |
| 5349 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5350 | return -EINVAL; |
| 5351 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5352 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5353 | return -EINVAL; |
| 5354 | |
| 5355 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5356 | if (interval == 0) |
| 5357 | return -EINVAL; |
| 5358 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5359 | wiphy = &rdev->wiphy; |
| 5360 | |
| 5361 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5362 | n_channels = validate_scan_freqs( |
| 5363 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5364 | if (!n_channels) |
| 5365 | return -EINVAL; |
| 5366 | } else { |
| 5367 | n_channels = 0; |
| 5368 | |
| 5369 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5370 | if (wiphy->bands[band]) |
| 5371 | n_channels += wiphy->bands[band]->n_channels; |
| 5372 | } |
| 5373 | |
| 5374 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5375 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5376 | tmp) |
| 5377 | n_ssids++; |
| 5378 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5379 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5380 | return -EINVAL; |
| 5381 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5382 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5383 | nla_for_each_nested(attr, |
| 5384 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5385 | tmp) |
| 5386 | n_match_sets++; |
| 5387 | |
| 5388 | if (n_match_sets > wiphy->max_match_sets) |
| 5389 | return -EINVAL; |
| 5390 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5391 | if (info->attrs[NL80211_ATTR_IE]) |
| 5392 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5393 | else |
| 5394 | ie_len = 0; |
| 5395 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5396 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5397 | return -EINVAL; |
| 5398 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5399 | if (rdev->sched_scan_req) { |
| 5400 | err = -EINPROGRESS; |
| 5401 | goto out; |
| 5402 | } |
| 5403 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5404 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5405 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5406 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5407 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5408 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5409 | if (!request) { |
| 5410 | err = -ENOMEM; |
| 5411 | goto out; |
| 5412 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5413 | |
| 5414 | if (n_ssids) |
| 5415 | request->ssids = (void *)&request->channels[n_channels]; |
| 5416 | request->n_ssids = n_ssids; |
| 5417 | if (ie_len) { |
| 5418 | if (request->ssids) |
| 5419 | request->ie = (void *)(request->ssids + n_ssids); |
| 5420 | else |
| 5421 | request->ie = (void *)(request->channels + n_channels); |
| 5422 | } |
| 5423 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5424 | if (n_match_sets) { |
| 5425 | if (request->ie) |
| 5426 | request->match_sets = (void *)(request->ie + ie_len); |
| 5427 | else if (request->ssids) |
| 5428 | request->match_sets = |
| 5429 | (void *)(request->ssids + n_ssids); |
| 5430 | else |
| 5431 | request->match_sets = |
| 5432 | (void *)(request->channels + n_channels); |
| 5433 | } |
| 5434 | request->n_match_sets = n_match_sets; |
| 5435 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5436 | i = 0; |
| 5437 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5438 | /* user specified, bail out if channel not found */ |
| 5439 | nla_for_each_nested(attr, |
| 5440 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5441 | tmp) { |
| 5442 | struct ieee80211_channel *chan; |
| 5443 | |
| 5444 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5445 | |
| 5446 | if (!chan) { |
| 5447 | err = -EINVAL; |
| 5448 | goto out_free; |
| 5449 | } |
| 5450 | |
| 5451 | /* ignore disabled channels */ |
| 5452 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5453 | continue; |
| 5454 | |
| 5455 | request->channels[i] = chan; |
| 5456 | i++; |
| 5457 | } |
| 5458 | } else { |
| 5459 | /* all channels */ |
| 5460 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5461 | int j; |
| 5462 | if (!wiphy->bands[band]) |
| 5463 | continue; |
| 5464 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5465 | struct ieee80211_channel *chan; |
| 5466 | |
| 5467 | chan = &wiphy->bands[band]->channels[j]; |
| 5468 | |
| 5469 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5470 | continue; |
| 5471 | |
| 5472 | request->channels[i] = chan; |
| 5473 | i++; |
| 5474 | } |
| 5475 | } |
| 5476 | } |
| 5477 | |
| 5478 | if (!i) { |
| 5479 | err = -EINVAL; |
| 5480 | goto out_free; |
| 5481 | } |
| 5482 | |
| 5483 | request->n_channels = i; |
| 5484 | |
| 5485 | i = 0; |
| 5486 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5487 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5488 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5489 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5490 | err = -EINVAL; |
| 5491 | goto out_free; |
| 5492 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5493 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5494 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5495 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5496 | i++; |
| 5497 | } |
| 5498 | } |
| 5499 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5500 | i = 0; |
| 5501 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5502 | nla_for_each_nested(attr, |
| 5503 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5504 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5505 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5506 | |
| 5507 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5508 | nla_data(attr), nla_len(attr), |
| 5509 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5510 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5511 | if (ssid) { |
| 5512 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5513 | err = -EINVAL; |
| 5514 | goto out_free; |
| 5515 | } |
| 5516 | memcpy(request->match_sets[i].ssid.ssid, |
| 5517 | nla_data(ssid), nla_len(ssid)); |
| 5518 | request->match_sets[i].ssid.ssid_len = |
| 5519 | nla_len(ssid); |
| 5520 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5521 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5522 | if (rssi) |
| 5523 | request->rssi_thold = nla_get_u32(rssi); |
| 5524 | else |
| 5525 | request->rssi_thold = |
| 5526 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5527 | i++; |
| 5528 | } |
| 5529 | } |
| 5530 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5531 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5532 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5533 | memcpy((void *)request->ie, |
| 5534 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5535 | request->ie_len); |
| 5536 | } |
| 5537 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5538 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5539 | request->flags = nla_get_u32( |
| 5540 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5541 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5542 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5543 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5544 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5545 | err = -EOPNOTSUPP; |
| 5546 | goto out_free; |
| 5547 | } |
| 5548 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5549 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5550 | request->dev = dev; |
| 5551 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5552 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5553 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5554 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5555 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5556 | if (!err) { |
| 5557 | rdev->sched_scan_req = request; |
| 5558 | nl80211_send_sched_scan(rdev, dev, |
| 5559 | NL80211_CMD_START_SCHED_SCAN); |
| 5560 | goto out; |
| 5561 | } |
| 5562 | |
| 5563 | out_free: |
| 5564 | kfree(request); |
| 5565 | out: |
| 5566 | return err; |
| 5567 | } |
| 5568 | |
| 5569 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5570 | struct genl_info *info) |
| 5571 | { |
| 5572 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5573 | |
| 5574 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5575 | !rdev->ops->sched_scan_stop) |
| 5576 | return -EOPNOTSUPP; |
| 5577 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5578 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5579 | } |
| 5580 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5581 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5582 | struct genl_info *info) |
| 5583 | { |
| 5584 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5585 | struct net_device *dev = info->user_ptr[1]; |
| 5586 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5587 | struct cfg80211_chan_def chandef; |
| 5588 | int err; |
| 5589 | |
| 5590 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5591 | if (err) |
| 5592 | return err; |
| 5593 | |
| 5594 | if (wdev->cac_started) |
| 5595 | return -EBUSY; |
| 5596 | |
| 5597 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5598 | if (err < 0) |
| 5599 | return err; |
| 5600 | |
| 5601 | if (err == 0) |
| 5602 | return -EINVAL; |
| 5603 | |
| 5604 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5605 | return -EINVAL; |
| 5606 | |
| 5607 | if (!rdev->ops->start_radar_detection) |
| 5608 | return -EOPNOTSUPP; |
| 5609 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5610 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5611 | chandef.chan, CHAN_MODE_SHARED, |
| 5612 | BIT(chandef.width)); |
| 5613 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5614 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5615 | |
| 5616 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5617 | if (!err) { |
| 5618 | wdev->channel = chandef.chan; |
| 5619 | wdev->cac_started = true; |
| 5620 | wdev->cac_start_time = jiffies; |
| 5621 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5622 | return err; |
| 5623 | } |
| 5624 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5625 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5626 | { |
| 5627 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5628 | struct net_device *dev = info->user_ptr[1]; |
| 5629 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5630 | struct cfg80211_csa_settings params; |
| 5631 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5632 | * function is called under RTNL lock, so this should not be a problem. |
| 5633 | */ |
| 5634 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5635 | u8 radar_detect_width = 0; |
| 5636 | int err; |
| 5637 | |
| 5638 | if (!rdev->ops->channel_switch || |
| 5639 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5640 | return -EOPNOTSUPP; |
| 5641 | |
| 5642 | /* may add IBSS support later */ |
| 5643 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5644 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5645 | return -EOPNOTSUPP; |
| 5646 | |
| 5647 | memset(¶ms, 0, sizeof(params)); |
| 5648 | |
| 5649 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5650 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5651 | return -EINVAL; |
| 5652 | |
| 5653 | /* only important for AP, IBSS and mesh create IEs internally */ |
| 5654 | if (!info->attrs[NL80211_ATTR_CSA_IES]) |
| 5655 | return -EINVAL; |
| 5656 | |
| 5657 | /* useless if AP is not running */ |
| 5658 | if (!wdev->beacon_interval) |
| 5659 | return -EINVAL; |
| 5660 | |
| 5661 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5662 | |
| 5663 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5664 | if (err) |
| 5665 | return err; |
| 5666 | |
| 5667 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5668 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5669 | nl80211_policy); |
| 5670 | if (err) |
| 5671 | return err; |
| 5672 | |
| 5673 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5674 | if (err) |
| 5675 | return err; |
| 5676 | |
| 5677 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5678 | return -EINVAL; |
| 5679 | |
| 5680 | params.counter_offset_beacon = |
| 5681 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5682 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5683 | return -EINVAL; |
| 5684 | |
| 5685 | /* sanity check - counters should be the same */ |
| 5686 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5687 | params.count) |
| 5688 | return -EINVAL; |
| 5689 | |
| 5690 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5691 | params.counter_offset_presp = |
| 5692 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5693 | if (params.counter_offset_presp >= |
| 5694 | params.beacon_csa.probe_resp_len) |
| 5695 | return -EINVAL; |
| 5696 | |
| 5697 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5698 | params.count) |
| 5699 | return -EINVAL; |
| 5700 | } |
| 5701 | |
| 5702 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5703 | if (err) |
| 5704 | return err; |
| 5705 | |
| 5706 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5707 | return -EINVAL; |
| 5708 | |
| 5709 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 5710 | if (err < 0) { |
| 5711 | return err; |
| 5712 | } else if (err) { |
| 5713 | radar_detect_width = BIT(params.chandef.width); |
| 5714 | params.radar_required = true; |
| 5715 | } |
| 5716 | |
| 5717 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5718 | params.chandef.chan, |
| 5719 | CHAN_MODE_SHARED, |
| 5720 | radar_detect_width); |
| 5721 | if (err) |
| 5722 | return err; |
| 5723 | |
| 5724 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5725 | params.block_tx = true; |
| 5726 | |
| 5727 | return rdev_channel_switch(rdev, dev, ¶ms); |
| 5728 | } |
| 5729 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5730 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5731 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5732 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5733 | struct wireless_dev *wdev, |
| 5734 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5735 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5736 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5737 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5738 | void *hdr; |
| 5739 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5740 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5741 | |
| 5742 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5743 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5744 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5745 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5746 | if (!hdr) |
| 5747 | return -1; |
| 5748 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5749 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5750 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5751 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5752 | goto nla_put_failure; |
| 5753 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5754 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5755 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5756 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5757 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5758 | |
| 5759 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5760 | if (!bss) |
| 5761 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5762 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5763 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5764 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5765 | |
| 5766 | rcu_read_lock(); |
| 5767 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5768 | if (ies) { |
| 5769 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5770 | goto fail_unlock_rcu; |
| 5771 | tsf = true; |
| 5772 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5773 | ies->len, ies->data)) |
| 5774 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5775 | } |
| 5776 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5777 | if (ies) { |
| 5778 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5779 | goto fail_unlock_rcu; |
| 5780 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5781 | ies->len, ies->data)) |
| 5782 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5783 | } |
| 5784 | rcu_read_unlock(); |
| 5785 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5786 | if (res->beacon_interval && |
| 5787 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5788 | goto nla_put_failure; |
| 5789 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5790 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 5791 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5792 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5793 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5794 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5795 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5796 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5797 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5798 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5799 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5800 | break; |
| 5801 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5802 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5803 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5804 | break; |
| 5805 | default: |
| 5806 | break; |
| 5807 | } |
| 5808 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5809 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5810 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5811 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5812 | if (intbss == wdev->current_bss && |
| 5813 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5814 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5815 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5816 | break; |
| 5817 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5818 | if (intbss == wdev->current_bss && |
| 5819 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5820 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5821 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5822 | break; |
| 5823 | default: |
| 5824 | break; |
| 5825 | } |
| 5826 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5827 | nla_nest_end(msg, bss); |
| 5828 | |
| 5829 | return genlmsg_end(msg, hdr); |
| 5830 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5831 | fail_unlock_rcu: |
| 5832 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5833 | nla_put_failure: |
| 5834 | genlmsg_cancel(msg, hdr); |
| 5835 | return -EMSGSIZE; |
| 5836 | } |
| 5837 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5838 | 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] | 5839 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5840 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5841 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5842 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5843 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5844 | int err; |
| 5845 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5846 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5847 | if (err) |
| 5848 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5849 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5850 | wdev_lock(wdev); |
| 5851 | spin_lock_bh(&rdev->bss_lock); |
| 5852 | cfg80211_bss_expire(rdev); |
| 5853 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5854 | cb->seq = rdev->bss_generation; |
| 5855 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5856 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5857 | if (++idx <= start) |
| 5858 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5859 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5860 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5861 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5862 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5863 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5864 | } |
| 5865 | } |
| 5866 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5867 | spin_unlock_bh(&rdev->bss_lock); |
| 5868 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5869 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5870 | cb->args[2] = idx; |
| 5871 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5872 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5873 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5874 | } |
| 5875 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5876 | 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] | 5877 | int flags, struct net_device *dev, |
| 5878 | struct survey_info *survey) |
| 5879 | { |
| 5880 | void *hdr; |
| 5881 | struct nlattr *infoattr; |
| 5882 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5883 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5884 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5885 | if (!hdr) |
| 5886 | return -ENOMEM; |
| 5887 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5888 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5889 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5890 | |
| 5891 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5892 | if (!infoattr) |
| 5893 | goto nla_put_failure; |
| 5894 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5895 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5896 | survey->channel->center_freq)) |
| 5897 | goto nla_put_failure; |
| 5898 | |
| 5899 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5900 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5901 | goto nla_put_failure; |
| 5902 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5903 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5904 | goto nla_put_failure; |
| 5905 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5906 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5907 | survey->channel_time)) |
| 5908 | goto nla_put_failure; |
| 5909 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5910 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5911 | survey->channel_time_busy)) |
| 5912 | goto nla_put_failure; |
| 5913 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5914 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5915 | survey->channel_time_ext_busy)) |
| 5916 | goto nla_put_failure; |
| 5917 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5918 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5919 | survey->channel_time_rx)) |
| 5920 | goto nla_put_failure; |
| 5921 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5922 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5923 | survey->channel_time_tx)) |
| 5924 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5925 | |
| 5926 | nla_nest_end(msg, infoattr); |
| 5927 | |
| 5928 | return genlmsg_end(msg, hdr); |
| 5929 | |
| 5930 | nla_put_failure: |
| 5931 | genlmsg_cancel(msg, hdr); |
| 5932 | return -EMSGSIZE; |
| 5933 | } |
| 5934 | |
| 5935 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5936 | struct netlink_callback *cb) |
| 5937 | { |
| 5938 | struct survey_info survey; |
| 5939 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5940 | struct wireless_dev *wdev; |
| 5941 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5942 | int res; |
| 5943 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5944 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5945 | if (res) |
| 5946 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5947 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5948 | if (!wdev->netdev) { |
| 5949 | res = -EINVAL; |
| 5950 | goto out_err; |
| 5951 | } |
| 5952 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5953 | if (!dev->ops->dump_survey) { |
| 5954 | res = -EOPNOTSUPP; |
| 5955 | goto out_err; |
| 5956 | } |
| 5957 | |
| 5958 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5959 | struct ieee80211_channel *chan; |
| 5960 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5961 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5962 | if (res == -ENOENT) |
| 5963 | break; |
| 5964 | if (res) |
| 5965 | goto out_err; |
| 5966 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5967 | /* Survey without a channel doesn't make sense */ |
| 5968 | if (!survey.channel) { |
| 5969 | res = -EINVAL; |
| 5970 | goto out; |
| 5971 | } |
| 5972 | |
| 5973 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5974 | survey.channel->center_freq); |
| 5975 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5976 | survey_idx++; |
| 5977 | continue; |
| 5978 | } |
| 5979 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5980 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5981 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5982 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5983 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5984 | goto out; |
| 5985 | survey_idx++; |
| 5986 | } |
| 5987 | |
| 5988 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5989 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5990 | res = skb->len; |
| 5991 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5992 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5993 | return res; |
| 5994 | } |
| 5995 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5996 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5997 | { |
| 5998 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5999 | NL80211_WPA_VERSION_2)); |
| 6000 | } |
| 6001 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6002 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6003 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6005 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6006 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6007 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6008 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6009 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6010 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6011 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6012 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6013 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6014 | return -EINVAL; |
| 6015 | |
| 6016 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6017 | return -EINVAL; |
| 6018 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6019 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6020 | return -EINVAL; |
| 6021 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6022 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6023 | return -EINVAL; |
| 6024 | |
| 6025 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6026 | return -EINVAL; |
| 6027 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6028 | err = nl80211_parse_key(info, &key); |
| 6029 | if (err) |
| 6030 | return err; |
| 6031 | |
| 6032 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6033 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6034 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6035 | if (!key.p.key || !key.p.key_len) |
| 6036 | return -EINVAL; |
| 6037 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6038 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6039 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6040 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6041 | return -EINVAL; |
| 6042 | if (key.idx > 4) |
| 6043 | return -EINVAL; |
| 6044 | } else { |
| 6045 | key.p.key_len = 0; |
| 6046 | key.p.key = NULL; |
| 6047 | } |
| 6048 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6049 | if (key.idx >= 0) { |
| 6050 | int i; |
| 6051 | bool ok = false; |
| 6052 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6053 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6054 | ok = true; |
| 6055 | break; |
| 6056 | } |
| 6057 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6058 | if (!ok) |
| 6059 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6060 | } |
| 6061 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6062 | if (!rdev->ops->auth) |
| 6063 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6064 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6065 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6066 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6067 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6068 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6069 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6070 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6071 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6072 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6073 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6074 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6075 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6076 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6077 | |
| 6078 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6079 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6080 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6081 | } |
| 6082 | |
| 6083 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6084 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6085 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6086 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6087 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6088 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6089 | return -EINVAL; |
| 6090 | |
| 6091 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6092 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6093 | return -EINVAL; |
| 6094 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6095 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6096 | /* need to include at least Auth Transaction and Status Code */ |
| 6097 | if (sae_data_len < 4) |
| 6098 | return -EINVAL; |
| 6099 | } |
| 6100 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6101 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6102 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6103 | /* |
| 6104 | * Since we no longer track auth state, ignore |
| 6105 | * requests to only change local state. |
| 6106 | */ |
| 6107 | if (local_state_change) |
| 6108 | return 0; |
| 6109 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6110 | wdev_lock(dev->ieee80211_ptr); |
| 6111 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6112 | ssid, ssid_len, ie, ie_len, |
| 6113 | key.p.key, key.p.key_len, key.idx, |
| 6114 | sae_data, sae_data_len); |
| 6115 | wdev_unlock(dev->ieee80211_ptr); |
| 6116 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6117 | } |
| 6118 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6119 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6120 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6121 | struct cfg80211_crypto_settings *settings, |
| 6122 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6123 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6124 | memset(settings, 0, sizeof(*settings)); |
| 6125 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6126 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6127 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6128 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6129 | u16 proto; |
| 6130 | proto = nla_get_u16( |
| 6131 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6132 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6133 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6134 | proto != ETH_P_PAE) |
| 6135 | return -EINVAL; |
| 6136 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6137 | settings->control_port_no_encrypt = true; |
| 6138 | } else |
| 6139 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6140 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6141 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6142 | void *data; |
| 6143 | int len, i; |
| 6144 | |
| 6145 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6146 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6147 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6148 | |
| 6149 | if (len % sizeof(u32)) |
| 6150 | return -EINVAL; |
| 6151 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6152 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6153 | return -EINVAL; |
| 6154 | |
| 6155 | memcpy(settings->ciphers_pairwise, data, len); |
| 6156 | |
| 6157 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6158 | if (!cfg80211_supported_cipher_suite( |
| 6159 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6160 | settings->ciphers_pairwise[i])) |
| 6161 | return -EINVAL; |
| 6162 | } |
| 6163 | |
| 6164 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6165 | settings->cipher_group = |
| 6166 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6167 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6168 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6169 | return -EINVAL; |
| 6170 | } |
| 6171 | |
| 6172 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6173 | settings->wpa_versions = |
| 6174 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6175 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6176 | return -EINVAL; |
| 6177 | } |
| 6178 | |
| 6179 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6180 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6181 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6182 | |
| 6183 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6184 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6185 | settings->n_akm_suites = len / sizeof(u32); |
| 6186 | |
| 6187 | if (len % sizeof(u32)) |
| 6188 | return -EINVAL; |
| 6189 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6190 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6191 | return -EINVAL; |
| 6192 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6193 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6194 | } |
| 6195 | |
| 6196 | return 0; |
| 6197 | } |
| 6198 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6199 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6200 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6201 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6202 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6203 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6204 | struct cfg80211_assoc_request req = {}; |
| 6205 | const u8 *bssid, *ssid; |
| 6206 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6207 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6208 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6209 | return -EINVAL; |
| 6210 | |
| 6211 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6212 | !info->attrs[NL80211_ATTR_SSID] || |
| 6213 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6214 | return -EINVAL; |
| 6215 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6216 | if (!rdev->ops->assoc) |
| 6217 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6218 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6219 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6220 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6221 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6222 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6223 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6224 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6225 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6226 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6227 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6228 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6229 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6230 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6231 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6232 | |
| 6233 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6234 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6235 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6236 | } |
| 6237 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6238 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6239 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6240 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6241 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6242 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6243 | else if (mfp != NL80211_MFP_NO) |
| 6244 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6245 | } |
| 6246 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6247 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6248 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6249 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6250 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6251 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6252 | |
| 6253 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6254 | memcpy(&req.ht_capa_mask, |
| 6255 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6256 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6257 | |
| 6258 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6259 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6260 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6261 | memcpy(&req.ht_capa, |
| 6262 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6263 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6264 | } |
| 6265 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6266 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6267 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6268 | |
| 6269 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6270 | memcpy(&req.vht_capa_mask, |
| 6271 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6272 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6273 | |
| 6274 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6275 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6276 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6277 | memcpy(&req.vht_capa, |
| 6278 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6279 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6280 | } |
| 6281 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6282 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6283 | if (!err) { |
| 6284 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6285 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6286 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6287 | wdev_unlock(dev->ieee80211_ptr); |
| 6288 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6289 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6290 | return err; |
| 6291 | } |
| 6292 | |
| 6293 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6294 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6295 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6296 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6297 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6298 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6299 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6300 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6301 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6302 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6303 | return -EINVAL; |
| 6304 | |
| 6305 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6306 | return -EINVAL; |
| 6307 | |
| 6308 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6309 | return -EINVAL; |
| 6310 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6311 | if (!rdev->ops->deauth) |
| 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 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6321 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6322 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6323 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6324 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6325 | |
| 6326 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6327 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6328 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6329 | } |
| 6330 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6331 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6332 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6333 | wdev_lock(dev->ieee80211_ptr); |
| 6334 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6335 | local_state_change); |
| 6336 | wdev_unlock(dev->ieee80211_ptr); |
| 6337 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6338 | } |
| 6339 | |
| 6340 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6341 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6342 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6343 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6344 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6345 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6346 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6347 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6348 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6349 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6350 | return -EINVAL; |
| 6351 | |
| 6352 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6353 | return -EINVAL; |
| 6354 | |
| 6355 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6356 | return -EINVAL; |
| 6357 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6358 | if (!rdev->ops->disassoc) |
| 6359 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6360 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6361 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6362 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6363 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6364 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6365 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6366 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6367 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6368 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6369 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6370 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6371 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6372 | |
| 6373 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6374 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6375 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6376 | } |
| 6377 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6378 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6379 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6380 | wdev_lock(dev->ieee80211_ptr); |
| 6381 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6382 | local_state_change); |
| 6383 | wdev_unlock(dev->ieee80211_ptr); |
| 6384 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6385 | } |
| 6386 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6387 | static bool |
| 6388 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6389 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6390 | int rateval) |
| 6391 | { |
| 6392 | struct wiphy *wiphy = &rdev->wiphy; |
| 6393 | bool found = false; |
| 6394 | int band, i; |
| 6395 | |
| 6396 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6397 | struct ieee80211_supported_band *sband; |
| 6398 | |
| 6399 | sband = wiphy->bands[band]; |
| 6400 | if (!sband) |
| 6401 | continue; |
| 6402 | |
| 6403 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6404 | if (sband->bitrates[i].bitrate == rateval) { |
| 6405 | mcast_rate[band] = i + 1; |
| 6406 | found = true; |
| 6407 | break; |
| 6408 | } |
| 6409 | } |
| 6410 | } |
| 6411 | |
| 6412 | return found; |
| 6413 | } |
| 6414 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6415 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6416 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6417 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6418 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6419 | struct cfg80211_ibss_params ibss; |
| 6420 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6421 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6422 | int err; |
| 6423 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6424 | memset(&ibss, 0, sizeof(ibss)); |
| 6425 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6426 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6427 | return -EINVAL; |
| 6428 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6429 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6430 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6431 | return -EINVAL; |
| 6432 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6433 | ibss.beacon_interval = 100; |
| 6434 | |
| 6435 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6436 | ibss.beacon_interval = |
| 6437 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6438 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6439 | return -EINVAL; |
| 6440 | } |
| 6441 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6442 | if (!rdev->ops->join_ibss) |
| 6443 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6444 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6445 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6446 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6447 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6448 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6449 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6450 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6451 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6452 | |
| 6453 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6454 | return -EINVAL; |
| 6455 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6456 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6457 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6458 | |
| 6459 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6460 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6461 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6462 | } |
| 6463 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6464 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6465 | if (err) |
| 6466 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6467 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6468 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6469 | return -EINVAL; |
| 6470 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6471 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6472 | case NL80211_CHAN_WIDTH_5: |
| 6473 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6474 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6475 | break; |
| 6476 | case NL80211_CHAN_WIDTH_20: |
| 6477 | case NL80211_CHAN_WIDTH_40: |
| 6478 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6479 | break; |
| 6480 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6481 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6482 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6483 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6484 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6485 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6486 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6487 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6488 | u8 *rates = |
| 6489 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6490 | int n_rates = |
| 6491 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6492 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6493 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6494 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6495 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6496 | &ibss.basic_rates); |
| 6497 | if (err) |
| 6498 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6499 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6500 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6501 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6502 | memcpy(&ibss.ht_capa_mask, |
| 6503 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6504 | sizeof(ibss.ht_capa_mask)); |
| 6505 | |
| 6506 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6507 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6508 | return -EINVAL; |
| 6509 | memcpy(&ibss.ht_capa, |
| 6510 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6511 | sizeof(ibss.ht_capa)); |
| 6512 | } |
| 6513 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6514 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6515 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6516 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6517 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6518 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6519 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6520 | bool no_ht = false; |
| 6521 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6522 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6523 | info->attrs[NL80211_ATTR_KEYS], |
| 6524 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6525 | if (IS_ERR(connkeys)) |
| 6526 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6527 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6528 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6529 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6530 | kfree(connkeys); |
| 6531 | return -EINVAL; |
| 6532 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6533 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6534 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6535 | ibss.control_port = |
| 6536 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6537 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6538 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6539 | if (err) |
| 6540 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6541 | return err; |
| 6542 | } |
| 6543 | |
| 6544 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6545 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6546 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6547 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6548 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6549 | if (!rdev->ops->leave_ibss) |
| 6550 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6551 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6552 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6553 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6554 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6555 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6556 | } |
| 6557 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6558 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6559 | { |
| 6560 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6561 | struct net_device *dev = info->user_ptr[1]; |
| 6562 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6563 | u32 nla_rate; |
| 6564 | int err; |
| 6565 | |
| 6566 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6567 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6568 | return -EOPNOTSUPP; |
| 6569 | |
| 6570 | if (!rdev->ops->set_mcast_rate) |
| 6571 | return -EOPNOTSUPP; |
| 6572 | |
| 6573 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6574 | |
| 6575 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6576 | return -EINVAL; |
| 6577 | |
| 6578 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6579 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6580 | return -EINVAL; |
| 6581 | |
| 6582 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6583 | |
| 6584 | return err; |
| 6585 | } |
| 6586 | |
| 6587 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6588 | #ifdef CONFIG_NL80211_TESTMODE |
| 6589 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6590 | .name = "testmode", |
| 6591 | }; |
| 6592 | |
| 6593 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6594 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6595 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6596 | struct wireless_dev *wdev = |
| 6597 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6598 | int err; |
| 6599 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6600 | if (!rdev->ops->testmode_cmd) |
| 6601 | return -EOPNOTSUPP; |
| 6602 | |
| 6603 | if (IS_ERR(wdev)) { |
| 6604 | err = PTR_ERR(wdev); |
| 6605 | if (err != -EINVAL) |
| 6606 | return err; |
| 6607 | wdev = NULL; |
| 6608 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6609 | return -EINVAL; |
| 6610 | } |
| 6611 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6612 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6613 | return -EINVAL; |
| 6614 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6615 | rdev->testmode_info = info; |
| 6616 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6617 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6618 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6619 | rdev->testmode_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6620 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6621 | return err; |
| 6622 | } |
| 6623 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6624 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6625 | struct netlink_callback *cb) |
| 6626 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6627 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6628 | int err; |
| 6629 | long phy_idx; |
| 6630 | void *data = NULL; |
| 6631 | int data_len = 0; |
| 6632 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6633 | rtnl_lock(); |
| 6634 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6635 | if (cb->args[0]) { |
| 6636 | /* |
| 6637 | * 0 is a valid index, but not valid for args[0], |
| 6638 | * so we need to offset by 1. |
| 6639 | */ |
| 6640 | phy_idx = cb->args[0] - 1; |
| 6641 | } else { |
| 6642 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6643 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6644 | nl80211_policy); |
| 6645 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6646 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6647 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6648 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6649 | nl80211_fam.attrbuf); |
| 6650 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6651 | err = PTR_ERR(rdev); |
| 6652 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6653 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6654 | phy_idx = rdev->wiphy_idx; |
| 6655 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6656 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6657 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6658 | cb->args[1] = |
| 6659 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6660 | } |
| 6661 | |
| 6662 | if (cb->args[1]) { |
| 6663 | data = nla_data((void *)cb->args[1]); |
| 6664 | data_len = nla_len((void *)cb->args[1]); |
| 6665 | } |
| 6666 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6667 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6668 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6669 | err = -ENOENT; |
| 6670 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6671 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6672 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6673 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6674 | err = -EOPNOTSUPP; |
| 6675 | goto out_err; |
| 6676 | } |
| 6677 | |
| 6678 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6679 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6680 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6681 | NL80211_CMD_TESTMODE); |
| 6682 | struct nlattr *tmdata; |
| 6683 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 6684 | if (!hdr) |
| 6685 | break; |
| 6686 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6687 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6688 | genlmsg_cancel(skb, hdr); |
| 6689 | break; |
| 6690 | } |
| 6691 | |
| 6692 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6693 | if (!tmdata) { |
| 6694 | genlmsg_cancel(skb, hdr); |
| 6695 | break; |
| 6696 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6697 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6698 | nla_nest_end(skb, tmdata); |
| 6699 | |
| 6700 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6701 | genlmsg_cancel(skb, hdr); |
| 6702 | break; |
| 6703 | } else if (err) { |
| 6704 | genlmsg_cancel(skb, hdr); |
| 6705 | goto out_err; |
| 6706 | } |
| 6707 | |
| 6708 | genlmsg_end(skb, hdr); |
| 6709 | } |
| 6710 | |
| 6711 | err = skb->len; |
| 6712 | /* see above */ |
| 6713 | cb->args[0] = phy_idx + 1; |
| 6714 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6715 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6716 | return err; |
| 6717 | } |
| 6718 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6719 | static struct sk_buff * |
| 6720 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6721 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6722 | { |
| 6723 | struct sk_buff *skb; |
| 6724 | void *hdr; |
| 6725 | struct nlattr *data; |
| 6726 | |
| 6727 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6728 | if (!skb) |
| 6729 | return NULL; |
| 6730 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6731 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6732 | if (!hdr) { |
| 6733 | kfree_skb(skb); |
| 6734 | return NULL; |
| 6735 | } |
| 6736 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6737 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6738 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6739 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6740 | |
| 6741 | ((void **)skb->cb)[0] = rdev; |
| 6742 | ((void **)skb->cb)[1] = hdr; |
| 6743 | ((void **)skb->cb)[2] = data; |
| 6744 | |
| 6745 | return skb; |
| 6746 | |
| 6747 | nla_put_failure: |
| 6748 | kfree_skb(skb); |
| 6749 | return NULL; |
| 6750 | } |
| 6751 | |
| 6752 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6753 | int approxlen) |
| 6754 | { |
| 6755 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6756 | |
| 6757 | if (WARN_ON(!rdev->testmode_info)) |
| 6758 | return NULL; |
| 6759 | |
| 6760 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6761 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6762 | rdev->testmode_info->snd_seq, |
| 6763 | GFP_KERNEL); |
| 6764 | } |
| 6765 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6766 | |
| 6767 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6768 | { |
| 6769 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6770 | void *hdr = ((void **)skb->cb)[1]; |
| 6771 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6772 | |
| 6773 | if (WARN_ON(!rdev->testmode_info)) { |
| 6774 | kfree_skb(skb); |
| 6775 | return -EINVAL; |
| 6776 | } |
| 6777 | |
| 6778 | nla_nest_end(skb, data); |
| 6779 | genlmsg_end(skb, hdr); |
| 6780 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6781 | } |
| 6782 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6783 | |
| 6784 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6785 | int approxlen, gfp_t gfp) |
| 6786 | { |
| 6787 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6788 | |
| 6789 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6790 | } |
| 6791 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6792 | |
| 6793 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6794 | { |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6795 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6796 | void *hdr = ((void **)skb->cb)[1]; |
| 6797 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6798 | |
| 6799 | nla_nest_end(skb, data); |
| 6800 | genlmsg_end(skb, hdr); |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6801 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0, |
| 6802 | nl80211_testmode_mcgrp.id, gfp); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6803 | } |
| 6804 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6805 | #endif |
| 6806 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6807 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6808 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6809 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6810 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6811 | struct cfg80211_connect_params connect; |
| 6812 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6813 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6814 | int err; |
| 6815 | |
| 6816 | memset(&connect, 0, sizeof(connect)); |
| 6817 | |
| 6818 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6819 | return -EINVAL; |
| 6820 | |
| 6821 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6822 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6823 | return -EINVAL; |
| 6824 | |
| 6825 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6826 | connect.auth_type = |
| 6827 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6828 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6829 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6830 | return -EINVAL; |
| 6831 | } else |
| 6832 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6833 | |
| 6834 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6835 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6836 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6837 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6838 | if (err) |
| 6839 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6840 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6841 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6842 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6843 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6844 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6845 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6846 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6847 | connect.bg_scan_period = -1; |
| 6848 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6849 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6850 | connect.bg_scan_period = |
| 6851 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6852 | } |
| 6853 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6854 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6855 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6856 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6857 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6858 | |
| 6859 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6860 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6861 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6862 | } |
| 6863 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6864 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6865 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6866 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6867 | connect.mfp != NL80211_MFP_NO) |
| 6868 | return -EINVAL; |
| 6869 | } else { |
| 6870 | connect.mfp = NL80211_MFP_NO; |
| 6871 | } |
| 6872 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6873 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6874 | connect.channel = |
| 6875 | ieee80211_get_channel(wiphy, |
| 6876 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6877 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6878 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6879 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6880 | } |
| 6881 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6882 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6883 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6884 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6885 | if (IS_ERR(connkeys)) |
| 6886 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6887 | } |
| 6888 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6889 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6890 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6891 | |
| 6892 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6893 | memcpy(&connect.ht_capa_mask, |
| 6894 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6895 | sizeof(connect.ht_capa_mask)); |
| 6896 | |
| 6897 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6898 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6899 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6900 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6901 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6902 | memcpy(&connect.ht_capa, |
| 6903 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6904 | sizeof(connect.ht_capa)); |
| 6905 | } |
| 6906 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6907 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6908 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6909 | |
| 6910 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6911 | memcpy(&connect.vht_capa_mask, |
| 6912 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6913 | sizeof(connect.vht_capa_mask)); |
| 6914 | |
| 6915 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 6916 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 6917 | kfree(connkeys); |
| 6918 | return -EINVAL; |
| 6919 | } |
| 6920 | memcpy(&connect.vht_capa, |
| 6921 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6922 | sizeof(connect.vht_capa)); |
| 6923 | } |
| 6924 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6925 | wdev_lock(dev->ieee80211_ptr); |
| 6926 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 6927 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6928 | if (err) |
| 6929 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6930 | return err; |
| 6931 | } |
| 6932 | |
| 6933 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6934 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6935 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6936 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6937 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6938 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6939 | |
| 6940 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6941 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6942 | else |
| 6943 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6944 | |
| 6945 | if (reason == 0) |
| 6946 | return -EINVAL; |
| 6947 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6948 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6949 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6950 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6951 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6952 | wdev_lock(dev->ieee80211_ptr); |
| 6953 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 6954 | wdev_unlock(dev->ieee80211_ptr); |
| 6955 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6956 | } |
| 6957 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6958 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6959 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6960 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6961 | struct net *net; |
| 6962 | int err; |
| 6963 | u32 pid; |
| 6964 | |
| 6965 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6966 | return -EINVAL; |
| 6967 | |
| 6968 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6969 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6970 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6971 | if (IS_ERR(net)) |
| 6972 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6973 | |
| 6974 | err = 0; |
| 6975 | |
| 6976 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6977 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6978 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6979 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6980 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6981 | return err; |
| 6982 | } |
| 6983 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6984 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6985 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6986 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6987 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6988 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6989 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6990 | struct cfg80211_pmksa pmksa; |
| 6991 | |
| 6992 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6993 | |
| 6994 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6995 | return -EINVAL; |
| 6996 | |
| 6997 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6998 | return -EINVAL; |
| 6999 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7000 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7001 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7002 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7003 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7004 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7005 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7006 | |
| 7007 | switch (info->genlhdr->cmd) { |
| 7008 | case NL80211_CMD_SET_PMKSA: |
| 7009 | rdev_ops = rdev->ops->set_pmksa; |
| 7010 | break; |
| 7011 | case NL80211_CMD_DEL_PMKSA: |
| 7012 | rdev_ops = rdev->ops->del_pmksa; |
| 7013 | break; |
| 7014 | default: |
| 7015 | WARN_ON(1); |
| 7016 | break; |
| 7017 | } |
| 7018 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7019 | if (!rdev_ops) |
| 7020 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7021 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7022 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7023 | } |
| 7024 | |
| 7025 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7026 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7028 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7029 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7030 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7031 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7032 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7033 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7034 | if (!rdev->ops->flush_pmksa) |
| 7035 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7036 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7037 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7038 | } |
| 7039 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7040 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7041 | { |
| 7042 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7043 | struct net_device *dev = info->user_ptr[1]; |
| 7044 | u8 action_code, dialog_token; |
| 7045 | u16 status_code; |
| 7046 | u8 *peer; |
| 7047 | |
| 7048 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7049 | !rdev->ops->tdls_mgmt) |
| 7050 | return -EOPNOTSUPP; |
| 7051 | |
| 7052 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7053 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7054 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7055 | !info->attrs[NL80211_ATTR_IE] || |
| 7056 | !info->attrs[NL80211_ATTR_MAC]) |
| 7057 | return -EINVAL; |
| 7058 | |
| 7059 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7060 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7061 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7062 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 7063 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7064 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 7065 | dialog_token, status_code, |
| 7066 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7067 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7068 | } |
| 7069 | |
| 7070 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7071 | { |
| 7072 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7073 | struct net_device *dev = info->user_ptr[1]; |
| 7074 | enum nl80211_tdls_operation operation; |
| 7075 | u8 *peer; |
| 7076 | |
| 7077 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7078 | !rdev->ops->tdls_oper) |
| 7079 | return -EOPNOTSUPP; |
| 7080 | |
| 7081 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7082 | !info->attrs[NL80211_ATTR_MAC]) |
| 7083 | return -EINVAL; |
| 7084 | |
| 7085 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7086 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7087 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7088 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7089 | } |
| 7090 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7091 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7092 | struct genl_info *info) |
| 7093 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7094 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7095 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7096 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7097 | struct sk_buff *msg; |
| 7098 | void *hdr; |
| 7099 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7100 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7101 | int err; |
| 7102 | |
| 7103 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7104 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7105 | return -EINVAL; |
| 7106 | |
| 7107 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7108 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7109 | if (!rdev->ops->remain_on_channel || |
| 7110 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7111 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7112 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7113 | /* |
| 7114 | * We should be on that channel for at least a minimum amount of |
| 7115 | * time (10ms) but no longer than the driver supports. |
| 7116 | */ |
| 7117 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7118 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7119 | return -EINVAL; |
| 7120 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7121 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7122 | if (err) |
| 7123 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7124 | |
| 7125 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7126 | if (!msg) |
| 7127 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7128 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7129 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7130 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7131 | if (!hdr) { |
| 7132 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7133 | goto free_msg; |
| 7134 | } |
| 7135 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7136 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7137 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7138 | |
| 7139 | if (err) |
| 7140 | goto free_msg; |
| 7141 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7142 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7143 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7144 | |
| 7145 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7146 | |
| 7147 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7148 | |
| 7149 | nla_put_failure: |
| 7150 | err = -ENOBUFS; |
| 7151 | free_msg: |
| 7152 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7153 | return err; |
| 7154 | } |
| 7155 | |
| 7156 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7157 | struct genl_info *info) |
| 7158 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7159 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7160 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7161 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7162 | |
| 7163 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7164 | return -EINVAL; |
| 7165 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7166 | if (!rdev->ops->cancel_remain_on_channel) |
| 7167 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7168 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7169 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7170 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7171 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7172 | } |
| 7173 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7174 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7175 | u8 *rates, u8 rates_len) |
| 7176 | { |
| 7177 | u8 i; |
| 7178 | u32 mask = 0; |
| 7179 | |
| 7180 | for (i = 0; i < rates_len; i++) { |
| 7181 | int rate = (rates[i] & 0x7f) * 5; |
| 7182 | int ridx; |
| 7183 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7184 | struct ieee80211_rate *srate = |
| 7185 | &sband->bitrates[ridx]; |
| 7186 | if (rate == srate->bitrate) { |
| 7187 | mask |= 1 << ridx; |
| 7188 | break; |
| 7189 | } |
| 7190 | } |
| 7191 | if (ridx == sband->n_bitrates) |
| 7192 | return 0; /* rate not found */ |
| 7193 | } |
| 7194 | |
| 7195 | return mask; |
| 7196 | } |
| 7197 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7198 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7199 | u8 *rates, u8 rates_len, |
| 7200 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7201 | { |
| 7202 | u8 i; |
| 7203 | |
| 7204 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7205 | |
| 7206 | for (i = 0; i < rates_len; i++) { |
| 7207 | int ridx, rbit; |
| 7208 | |
| 7209 | ridx = rates[i] / 8; |
| 7210 | rbit = BIT(rates[i] % 8); |
| 7211 | |
| 7212 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7213 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7214 | return false; |
| 7215 | |
| 7216 | /* check availability */ |
| 7217 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7218 | mcs[ridx] |= rbit; |
| 7219 | else |
| 7220 | return false; |
| 7221 | } |
| 7222 | |
| 7223 | return true; |
| 7224 | } |
| 7225 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7226 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7227 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7228 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7229 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 7230 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7231 | }; |
| 7232 | |
| 7233 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7234 | struct genl_info *info) |
| 7235 | { |
| 7236 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7237 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7238 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7239 | int rem, i; |
| 7240 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7241 | struct nlattr *tx_rates; |
| 7242 | struct ieee80211_supported_band *sband; |
| 7243 | |
| 7244 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7245 | return -EINVAL; |
| 7246 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7247 | if (!rdev->ops->set_bitrate_mask) |
| 7248 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7249 | |
| 7250 | memset(&mask, 0, sizeof(mask)); |
| 7251 | /* Default to all rates enabled */ |
| 7252 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7253 | sband = rdev->wiphy.bands[i]; |
| 7254 | mask.control[i].legacy = |
| 7255 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7256 | if (sband) |
| 7257 | memcpy(mask.control[i].mcs, |
| 7258 | sband->ht_cap.mcs.rx_mask, |
| 7259 | sizeof(mask.control[i].mcs)); |
| 7260 | else |
| 7261 | memset(mask.control[i].mcs, 0, |
| 7262 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7263 | } |
| 7264 | |
| 7265 | /* |
| 7266 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7267 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7268 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7269 | 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] | 7270 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7271 | { |
| 7272 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7273 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7274 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7275 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7276 | if (sband == NULL) |
| 7277 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7278 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7279 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7280 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7281 | mask.control[band].legacy = rateset_to_mask( |
| 7282 | sband, |
| 7283 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7284 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7285 | if ((mask.control[band].legacy == 0) && |
| 7286 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7287 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7288 | } |
| 7289 | if (tb[NL80211_TXRATE_MCS]) { |
| 7290 | if (!ht_rateset_to_mask( |
| 7291 | sband, |
| 7292 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7293 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7294 | mask.control[band].mcs)) |
| 7295 | return -EINVAL; |
| 7296 | } |
| 7297 | |
| 7298 | if (mask.control[band].legacy == 0) { |
| 7299 | /* don't allow empty legacy rates if HT |
| 7300 | * is not even supported. */ |
| 7301 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7302 | return -EINVAL; |
| 7303 | |
| 7304 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7305 | if (mask.control[band].mcs[i]) |
| 7306 | break; |
| 7307 | |
| 7308 | /* legacy and mcs rates may not be both empty */ |
| 7309 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7310 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7311 | } |
| 7312 | } |
| 7313 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7314 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7315 | } |
| 7316 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7317 | 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] | 7318 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7319 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7320 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7321 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7322 | |
| 7323 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7324 | return -EINVAL; |
| 7325 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7326 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7327 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7328 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7329 | switch (wdev->iftype) { |
| 7330 | case NL80211_IFTYPE_STATION: |
| 7331 | case NL80211_IFTYPE_ADHOC: |
| 7332 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7333 | case NL80211_IFTYPE_AP: |
| 7334 | case NL80211_IFTYPE_AP_VLAN: |
| 7335 | case NL80211_IFTYPE_MESH_POINT: |
| 7336 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7337 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7338 | break; |
| 7339 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7340 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7341 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7342 | |
| 7343 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7344 | if (!rdev->ops->mgmt_tx) |
| 7345 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7346 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7347 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7348 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7349 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7350 | } |
| 7351 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7352 | 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] | 7353 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7354 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7355 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7356 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7357 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7358 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7359 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7360 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7361 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7362 | bool offchan, no_cck, dont_wait_for_ack; |
| 7363 | |
| 7364 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7365 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7366 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7367 | return -EINVAL; |
| 7368 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7369 | if (!rdev->ops->mgmt_tx) |
| 7370 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7371 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7372 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7373 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7374 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7375 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7376 | case NL80211_IFTYPE_STATION: |
| 7377 | case NL80211_IFTYPE_ADHOC: |
| 7378 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7379 | case NL80211_IFTYPE_AP: |
| 7380 | case NL80211_IFTYPE_AP_VLAN: |
| 7381 | case NL80211_IFTYPE_MESH_POINT: |
| 7382 | case NL80211_IFTYPE_P2P_GO: |
| 7383 | break; |
| 7384 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7385 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7386 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7387 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7388 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7389 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7390 | return -EINVAL; |
| 7391 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7392 | |
| 7393 | /* |
| 7394 | * We should wait on the channel for at least a minimum amount |
| 7395 | * of time (10ms) but no longer than the driver supports. |
| 7396 | */ |
| 7397 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7398 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7399 | return -EINVAL; |
| 7400 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7401 | } |
| 7402 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7403 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7404 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7405 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7406 | return -EINVAL; |
| 7407 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7408 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7409 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7410 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7411 | * the driver. The latter will use the current one |
| 7412 | */ |
| 7413 | chandef.chan = NULL; |
| 7414 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7415 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7416 | if (err) |
| 7417 | return err; |
| 7418 | } |
| 7419 | |
| 7420 | if (!chandef.chan && offchan) |
| 7421 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7422 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7423 | if (!dont_wait_for_ack) { |
| 7424 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7425 | if (!msg) |
| 7426 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7427 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7428 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7429 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7430 | if (!hdr) { |
| 7431 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7432 | goto free_msg; |
| 7433 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7434 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7435 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7436 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7437 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7438 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7439 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7440 | if (err) |
| 7441 | goto free_msg; |
| 7442 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7443 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7444 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7445 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7446 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7447 | genlmsg_end(msg, hdr); |
| 7448 | return genlmsg_reply(msg, info); |
| 7449 | } |
| 7450 | |
| 7451 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7452 | |
| 7453 | nla_put_failure: |
| 7454 | err = -ENOBUFS; |
| 7455 | free_msg: |
| 7456 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7457 | return err; |
| 7458 | } |
| 7459 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7460 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7461 | { |
| 7462 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7463 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7464 | u64 cookie; |
| 7465 | |
| 7466 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7467 | return -EINVAL; |
| 7468 | |
| 7469 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7470 | return -EOPNOTSUPP; |
| 7471 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7472 | switch (wdev->iftype) { |
| 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_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7479 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7480 | break; |
| 7481 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7482 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7483 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7484 | |
| 7485 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7486 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7487 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7488 | } |
| 7489 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7490 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7491 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7492 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7493 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7494 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7495 | u8 ps_state; |
| 7496 | bool state; |
| 7497 | int err; |
| 7498 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7499 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7500 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7501 | |
| 7502 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7503 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7504 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7505 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7506 | |
| 7507 | wdev = dev->ieee80211_ptr; |
| 7508 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7509 | if (!rdev->ops->set_power_mgmt) |
| 7510 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7511 | |
| 7512 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7513 | |
| 7514 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7515 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7516 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7517 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7518 | if (!err) |
| 7519 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7520 | return err; |
| 7521 | } |
| 7522 | |
| 7523 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7524 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7525 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7526 | enum nl80211_ps_state ps_state; |
| 7527 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7528 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7529 | struct sk_buff *msg; |
| 7530 | void *hdr; |
| 7531 | int err; |
| 7532 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7533 | wdev = dev->ieee80211_ptr; |
| 7534 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7535 | if (!rdev->ops->set_power_mgmt) |
| 7536 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7537 | |
| 7538 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7539 | if (!msg) |
| 7540 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7541 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7542 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7543 | NL80211_CMD_GET_POWER_SAVE); |
| 7544 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7545 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7546 | goto free_msg; |
| 7547 | } |
| 7548 | |
| 7549 | if (wdev->ps) |
| 7550 | ps_state = NL80211_PS_ENABLED; |
| 7551 | else |
| 7552 | ps_state = NL80211_PS_DISABLED; |
| 7553 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7554 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7555 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7556 | |
| 7557 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7558 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7559 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7560 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7561 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7562 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7563 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7564 | return err; |
| 7565 | } |
| 7566 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7567 | static struct nla_policy |
| 7568 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7569 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7570 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7571 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7572 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7573 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7574 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7575 | }; |
| 7576 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7577 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7578 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7579 | { |
| 7580 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7581 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7582 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7583 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7584 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7585 | return -EINVAL; |
| 7586 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7587 | if (!rdev->ops->set_cqm_txe_config) |
| 7588 | return -EOPNOTSUPP; |
| 7589 | |
| 7590 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7591 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7592 | return -EOPNOTSUPP; |
| 7593 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7594 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7595 | } |
| 7596 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7597 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7598 | s32 threshold, u32 hysteresis) |
| 7599 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7600 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7601 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7602 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7603 | |
| 7604 | if (threshold > 0) |
| 7605 | return -EINVAL; |
| 7606 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7607 | /* disabling - hysteresis should also be zero then */ |
| 7608 | if (threshold == 0) |
| 7609 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7610 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7611 | if (!rdev->ops->set_cqm_rssi_config) |
| 7612 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7613 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7614 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7615 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7616 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7617 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7618 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7619 | } |
| 7620 | |
| 7621 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7622 | { |
| 7623 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7624 | struct nlattr *cqm; |
| 7625 | int err; |
| 7626 | |
| 7627 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7628 | if (!cqm) |
| 7629 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7630 | |
| 7631 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7632 | nl80211_attr_cqm_policy); |
| 7633 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7634 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7635 | |
| 7636 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7637 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7638 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7639 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7640 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7641 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7642 | } |
| 7643 | |
| 7644 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7645 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7646 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7647 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7648 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7649 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7650 | |
| 7651 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 7652 | } |
| 7653 | |
| 7654 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7655 | } |
| 7656 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7657 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7658 | { |
| 7659 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7660 | struct net_device *dev = info->user_ptr[1]; |
| 7661 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7662 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7663 | int err; |
| 7664 | |
| 7665 | /* start with default */ |
| 7666 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7667 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7668 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7669 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7670 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7671 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7672 | if (err) |
| 7673 | return err; |
| 7674 | } |
| 7675 | |
| 7676 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7677 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7678 | return -EINVAL; |
| 7679 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7680 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7681 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7682 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7683 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7684 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7685 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7686 | return -EINVAL; |
| 7687 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7688 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7689 | setup.beacon_interval = |
| 7690 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7691 | if (setup.beacon_interval < 10 || |
| 7692 | setup.beacon_interval > 10000) |
| 7693 | return -EINVAL; |
| 7694 | } |
| 7695 | |
| 7696 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7697 | setup.dtim_period = |
| 7698 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7699 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7700 | return -EINVAL; |
| 7701 | } |
| 7702 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7703 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7704 | /* parse additional setup parameters if given */ |
| 7705 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7706 | if (err) |
| 7707 | return err; |
| 7708 | } |
| 7709 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7710 | if (setup.user_mpm) |
| 7711 | cfg.auto_open_plinks = false; |
| 7712 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7713 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7714 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7715 | if (err) |
| 7716 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7717 | } else { |
| 7718 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7719 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7720 | } |
| 7721 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7722 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7723 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7724 | int n_rates = |
| 7725 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7726 | struct ieee80211_supported_band *sband; |
| 7727 | |
| 7728 | if (!setup.chandef.chan) |
| 7729 | return -EINVAL; |
| 7730 | |
| 7731 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7732 | |
| 7733 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7734 | &setup.basic_rates); |
| 7735 | if (err) |
| 7736 | return err; |
| 7737 | } |
| 7738 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7739 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7740 | } |
| 7741 | |
| 7742 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7743 | { |
| 7744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7745 | struct net_device *dev = info->user_ptr[1]; |
| 7746 | |
| 7747 | return cfg80211_leave_mesh(rdev, dev); |
| 7748 | } |
| 7749 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7750 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7751 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7752 | struct cfg80211_registered_device *rdev) |
| 7753 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7754 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7755 | struct nlattr *nl_pats, *nl_pat; |
| 7756 | int i, pat_len; |
| 7757 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7758 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7759 | return 0; |
| 7760 | |
| 7761 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7762 | if (!nl_pats) |
| 7763 | return -ENOBUFS; |
| 7764 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7765 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7766 | nl_pat = nla_nest_start(msg, i + 1); |
| 7767 | if (!nl_pat) |
| 7768 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7769 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7770 | 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] | 7771 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7772 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 7773 | wowlan->patterns[i].pattern) || |
| 7774 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7775 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7776 | return -ENOBUFS; |
| 7777 | nla_nest_end(msg, nl_pat); |
| 7778 | } |
| 7779 | nla_nest_end(msg, nl_pats); |
| 7780 | |
| 7781 | return 0; |
| 7782 | } |
| 7783 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7784 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7785 | struct cfg80211_wowlan_tcp *tcp) |
| 7786 | { |
| 7787 | struct nlattr *nl_tcp; |
| 7788 | |
| 7789 | if (!tcp) |
| 7790 | return 0; |
| 7791 | |
| 7792 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7793 | if (!nl_tcp) |
| 7794 | return -ENOBUFS; |
| 7795 | |
| 7796 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7797 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7798 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7799 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7800 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7801 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7802 | tcp->payload_len, tcp->payload) || |
| 7803 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7804 | tcp->data_interval) || |
| 7805 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7806 | tcp->wake_len, tcp->wake_data) || |
| 7807 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7808 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7809 | return -ENOBUFS; |
| 7810 | |
| 7811 | if (tcp->payload_seq.len && |
| 7812 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7813 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7814 | return -ENOBUFS; |
| 7815 | |
| 7816 | if (tcp->payload_tok.len && |
| 7817 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7818 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7819 | &tcp->payload_tok)) |
| 7820 | return -ENOBUFS; |
| 7821 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 7822 | nla_nest_end(msg, nl_tcp); |
| 7823 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7824 | return 0; |
| 7825 | } |
| 7826 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7827 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7828 | { |
| 7829 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7830 | struct sk_buff *msg; |
| 7831 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7832 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7833 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7834 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7835 | return -EOPNOTSUPP; |
| 7836 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7837 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7838 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7839 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 7840 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 7841 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 7842 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7843 | } |
| 7844 | |
| 7845 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7846 | if (!msg) |
| 7847 | return -ENOMEM; |
| 7848 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7849 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7850 | NL80211_CMD_GET_WOWLAN); |
| 7851 | if (!hdr) |
| 7852 | goto nla_put_failure; |
| 7853 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7854 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7855 | struct nlattr *nl_wowlan; |
| 7856 | |
| 7857 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7858 | if (!nl_wowlan) |
| 7859 | goto nla_put_failure; |
| 7860 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7861 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7862 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7863 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7864 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7865 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7866 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7867 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7868 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7869 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7870 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7871 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7872 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7873 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7874 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7875 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7876 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7877 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7878 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7879 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7880 | if (nl80211_send_wowlan_tcp(msg, |
| 7881 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7882 | goto nla_put_failure; |
| 7883 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7884 | nla_nest_end(msg, nl_wowlan); |
| 7885 | } |
| 7886 | |
| 7887 | genlmsg_end(msg, hdr); |
| 7888 | return genlmsg_reply(msg, info); |
| 7889 | |
| 7890 | nla_put_failure: |
| 7891 | nlmsg_free(msg); |
| 7892 | return -ENOBUFS; |
| 7893 | } |
| 7894 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7895 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7896 | struct nlattr *attr, |
| 7897 | struct cfg80211_wowlan *trig) |
| 7898 | { |
| 7899 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7900 | struct cfg80211_wowlan_tcp *cfg; |
| 7901 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7902 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7903 | u32 size; |
| 7904 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7905 | int err, port; |
| 7906 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7907 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7908 | return -EINVAL; |
| 7909 | |
| 7910 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7911 | nla_data(attr), nla_len(attr), |
| 7912 | nl80211_wowlan_tcp_policy); |
| 7913 | if (err) |
| 7914 | return err; |
| 7915 | |
| 7916 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7917 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7918 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7919 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7920 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7921 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7922 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7923 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7924 | return -EINVAL; |
| 7925 | |
| 7926 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7927 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7928 | return -EINVAL; |
| 7929 | |
| 7930 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7931 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 7932 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7933 | return -EINVAL; |
| 7934 | |
| 7935 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7936 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7937 | return -EINVAL; |
| 7938 | |
| 7939 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7940 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7941 | return -EINVAL; |
| 7942 | |
| 7943 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7944 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7945 | |
| 7946 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7947 | tokens_size = tokln - sizeof(*tok); |
| 7948 | |
| 7949 | if (!tok->len || tokens_size % tok->len) |
| 7950 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7951 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7952 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7953 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7954 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7955 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7956 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7957 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7958 | return -EINVAL; |
| 7959 | if (tok->offset + tok->len > data_size) |
| 7960 | return -EINVAL; |
| 7961 | } |
| 7962 | |
| 7963 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7964 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7965 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7966 | return -EINVAL; |
| 7967 | if (seq->len == 0 || seq->len > 4) |
| 7968 | return -EINVAL; |
| 7969 | if (seq->len + seq->offset > data_size) |
| 7970 | return -EINVAL; |
| 7971 | } |
| 7972 | |
| 7973 | size = sizeof(*cfg); |
| 7974 | size += data_size; |
| 7975 | size += wake_size + wake_mask_size; |
| 7976 | size += tokens_size; |
| 7977 | |
| 7978 | cfg = kzalloc(size, GFP_KERNEL); |
| 7979 | if (!cfg) |
| 7980 | return -ENOMEM; |
| 7981 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7982 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7983 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7984 | ETH_ALEN); |
| 7985 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7986 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7987 | else |
| 7988 | port = 0; |
| 7989 | #ifdef CONFIG_INET |
| 7990 | /* allocate a socket and port for it and use it */ |
| 7991 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7992 | IPPROTO_TCP, &cfg->sock, 1); |
| 7993 | if (err) { |
| 7994 | kfree(cfg); |
| 7995 | return err; |
| 7996 | } |
| 7997 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7998 | sock_release(cfg->sock); |
| 7999 | kfree(cfg); |
| 8000 | return -EADDRINUSE; |
| 8001 | } |
| 8002 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8003 | #else |
| 8004 | if (!port) { |
| 8005 | kfree(cfg); |
| 8006 | return -EINVAL; |
| 8007 | } |
| 8008 | cfg->src_port = port; |
| 8009 | #endif |
| 8010 | |
| 8011 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8012 | cfg->payload_len = data_size; |
| 8013 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8014 | memcpy((void *)cfg->payload, |
| 8015 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8016 | data_size); |
| 8017 | if (seq) |
| 8018 | cfg->payload_seq = *seq; |
| 8019 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8020 | cfg->wake_len = wake_size; |
| 8021 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8022 | memcpy((void *)cfg->wake_data, |
| 8023 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8024 | wake_size); |
| 8025 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8026 | data_size + wake_size; |
| 8027 | memcpy((void *)cfg->wake_mask, |
| 8028 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8029 | wake_mask_size); |
| 8030 | if (tok) { |
| 8031 | cfg->tokens_size = tokens_size; |
| 8032 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8033 | } |
| 8034 | |
| 8035 | trig->tcp = cfg; |
| 8036 | |
| 8037 | return 0; |
| 8038 | } |
| 8039 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8040 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8041 | { |
| 8042 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8043 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8044 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8045 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8046 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8047 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8048 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8049 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8050 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8051 | return -EOPNOTSUPP; |
| 8052 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8053 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8054 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8055 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8056 | goto set_wakeup; |
| 8057 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8058 | |
| 8059 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8060 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8061 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8062 | nl80211_wowlan_policy); |
| 8063 | if (err) |
| 8064 | return err; |
| 8065 | |
| 8066 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8067 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8068 | return -EINVAL; |
| 8069 | new_triggers.any = true; |
| 8070 | } |
| 8071 | |
| 8072 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8073 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8074 | return -EINVAL; |
| 8075 | new_triggers.disconnect = true; |
| 8076 | } |
| 8077 | |
| 8078 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8079 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8080 | return -EINVAL; |
| 8081 | new_triggers.magic_pkt = true; |
| 8082 | } |
| 8083 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8084 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8085 | return -EINVAL; |
| 8086 | |
| 8087 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8088 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8089 | return -EINVAL; |
| 8090 | new_triggers.gtk_rekey_failure = true; |
| 8091 | } |
| 8092 | |
| 8093 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8094 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8095 | return -EINVAL; |
| 8096 | new_triggers.eap_identity_req = true; |
| 8097 | } |
| 8098 | |
| 8099 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8100 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8101 | return -EINVAL; |
| 8102 | new_triggers.four_way_handshake = true; |
| 8103 | } |
| 8104 | |
| 8105 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8106 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8107 | return -EINVAL; |
| 8108 | new_triggers.rfkill_release = true; |
| 8109 | } |
| 8110 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8111 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8112 | struct nlattr *pat; |
| 8113 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8114 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8115 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8116 | |
| 8117 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8118 | rem) |
| 8119 | n_patterns++; |
| 8120 | if (n_patterns > wowlan->n_patterns) |
| 8121 | return -EINVAL; |
| 8122 | |
| 8123 | new_triggers.patterns = kcalloc(n_patterns, |
| 8124 | sizeof(new_triggers.patterns[0]), |
| 8125 | GFP_KERNEL); |
| 8126 | if (!new_triggers.patterns) |
| 8127 | return -ENOMEM; |
| 8128 | |
| 8129 | new_triggers.n_patterns = n_patterns; |
| 8130 | i = 0; |
| 8131 | |
| 8132 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8133 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8134 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8135 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8136 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8137 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8138 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8139 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8140 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8141 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8142 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8143 | goto error; |
| 8144 | if (pat_len > wowlan->pattern_max_len || |
| 8145 | pat_len < wowlan->pattern_min_len) |
| 8146 | goto error; |
| 8147 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8148 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8149 | pkt_offset = 0; |
| 8150 | else |
| 8151 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8152 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8153 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8154 | goto error; |
| 8155 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8156 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8157 | new_triggers.patterns[i].mask = |
| 8158 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8159 | if (!new_triggers.patterns[i].mask) { |
| 8160 | err = -ENOMEM; |
| 8161 | goto error; |
| 8162 | } |
| 8163 | new_triggers.patterns[i].pattern = |
| 8164 | new_triggers.patterns[i].mask + mask_len; |
| 8165 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8166 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8167 | mask_len); |
| 8168 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8169 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8170 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8171 | pat_len); |
| 8172 | i++; |
| 8173 | } |
| 8174 | } |
| 8175 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8176 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8177 | err = nl80211_parse_wowlan_tcp( |
| 8178 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8179 | &new_triggers); |
| 8180 | if (err) |
| 8181 | goto error; |
| 8182 | } |
| 8183 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8184 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8185 | if (!ntrig) { |
| 8186 | err = -ENOMEM; |
| 8187 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8188 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8189 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8190 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8191 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8192 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8193 | if (rdev->ops->set_wakeup && |
| 8194 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8195 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8196 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8197 | return 0; |
| 8198 | error: |
| 8199 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8200 | kfree(new_triggers.patterns[i].mask); |
| 8201 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8202 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8203 | sock_release(new_triggers.tcp->sock); |
| 8204 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8205 | return err; |
| 8206 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8207 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8208 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8209 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8210 | struct cfg80211_registered_device *rdev) |
| 8211 | { |
| 8212 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8213 | int i, j, pat_len; |
| 8214 | struct cfg80211_coalesce_rules *rule; |
| 8215 | |
| 8216 | if (!rdev->coalesce->n_rules) |
| 8217 | return 0; |
| 8218 | |
| 8219 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8220 | if (!nl_rules) |
| 8221 | return -ENOBUFS; |
| 8222 | |
| 8223 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8224 | nl_rule = nla_nest_start(msg, i + 1); |
| 8225 | if (!nl_rule) |
| 8226 | return -ENOBUFS; |
| 8227 | |
| 8228 | rule = &rdev->coalesce->rules[i]; |
| 8229 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8230 | rule->delay)) |
| 8231 | return -ENOBUFS; |
| 8232 | |
| 8233 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8234 | rule->condition)) |
| 8235 | return -ENOBUFS; |
| 8236 | |
| 8237 | nl_pats = nla_nest_start(msg, |
| 8238 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8239 | if (!nl_pats) |
| 8240 | return -ENOBUFS; |
| 8241 | |
| 8242 | for (j = 0; j < rule->n_patterns; j++) { |
| 8243 | nl_pat = nla_nest_start(msg, j + 1); |
| 8244 | if (!nl_pat) |
| 8245 | return -ENOBUFS; |
| 8246 | pat_len = rule->patterns[j].pattern_len; |
| 8247 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8248 | DIV_ROUND_UP(pat_len, 8), |
| 8249 | rule->patterns[j].mask) || |
| 8250 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8251 | rule->patterns[j].pattern) || |
| 8252 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8253 | rule->patterns[j].pkt_offset)) |
| 8254 | return -ENOBUFS; |
| 8255 | nla_nest_end(msg, nl_pat); |
| 8256 | } |
| 8257 | nla_nest_end(msg, nl_pats); |
| 8258 | nla_nest_end(msg, nl_rule); |
| 8259 | } |
| 8260 | nla_nest_end(msg, nl_rules); |
| 8261 | |
| 8262 | return 0; |
| 8263 | } |
| 8264 | |
| 8265 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8266 | { |
| 8267 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8268 | struct sk_buff *msg; |
| 8269 | void *hdr; |
| 8270 | |
| 8271 | if (!rdev->wiphy.coalesce) |
| 8272 | return -EOPNOTSUPP; |
| 8273 | |
| 8274 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8275 | if (!msg) |
| 8276 | return -ENOMEM; |
| 8277 | |
| 8278 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8279 | NL80211_CMD_GET_COALESCE); |
| 8280 | if (!hdr) |
| 8281 | goto nla_put_failure; |
| 8282 | |
| 8283 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8284 | goto nla_put_failure; |
| 8285 | |
| 8286 | genlmsg_end(msg, hdr); |
| 8287 | return genlmsg_reply(msg, info); |
| 8288 | |
| 8289 | nla_put_failure: |
| 8290 | nlmsg_free(msg); |
| 8291 | return -ENOBUFS; |
| 8292 | } |
| 8293 | |
| 8294 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8295 | { |
| 8296 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8297 | int i, j; |
| 8298 | struct cfg80211_coalesce_rules *rule; |
| 8299 | |
| 8300 | if (!coalesce) |
| 8301 | return; |
| 8302 | |
| 8303 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8304 | rule = &coalesce->rules[i]; |
| 8305 | for (j = 0; j < rule->n_patterns; j++) |
| 8306 | kfree(rule->patterns[j].mask); |
| 8307 | kfree(rule->patterns); |
| 8308 | } |
| 8309 | kfree(coalesce->rules); |
| 8310 | kfree(coalesce); |
| 8311 | rdev->coalesce = NULL; |
| 8312 | } |
| 8313 | |
| 8314 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8315 | struct nlattr *rule, |
| 8316 | struct cfg80211_coalesce_rules *new_rule) |
| 8317 | { |
| 8318 | int err, i; |
| 8319 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8320 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8321 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8322 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8323 | |
| 8324 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8325 | nla_len(rule), nl80211_coalesce_policy); |
| 8326 | if (err) |
| 8327 | return err; |
| 8328 | |
| 8329 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8330 | new_rule->delay = |
| 8331 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8332 | if (new_rule->delay > coalesce->max_delay) |
| 8333 | return -EINVAL; |
| 8334 | |
| 8335 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8336 | new_rule->condition = |
| 8337 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8338 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8339 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8340 | return -EINVAL; |
| 8341 | |
| 8342 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8343 | return -EINVAL; |
| 8344 | |
| 8345 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8346 | rem) |
| 8347 | n_patterns++; |
| 8348 | if (n_patterns > coalesce->n_patterns) |
| 8349 | return -EINVAL; |
| 8350 | |
| 8351 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8352 | GFP_KERNEL); |
| 8353 | if (!new_rule->patterns) |
| 8354 | return -ENOMEM; |
| 8355 | |
| 8356 | new_rule->n_patterns = n_patterns; |
| 8357 | i = 0; |
| 8358 | |
| 8359 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8360 | rem) { |
| 8361 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8362 | nla_len(pat), NULL); |
| 8363 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8364 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8365 | return -EINVAL; |
| 8366 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8367 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8368 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8369 | return -EINVAL; |
| 8370 | if (pat_len > coalesce->pattern_max_len || |
| 8371 | pat_len < coalesce->pattern_min_len) |
| 8372 | return -EINVAL; |
| 8373 | |
| 8374 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8375 | pkt_offset = 0; |
| 8376 | else |
| 8377 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8378 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8379 | return -EINVAL; |
| 8380 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8381 | |
| 8382 | new_rule->patterns[i].mask = |
| 8383 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8384 | if (!new_rule->patterns[i].mask) |
| 8385 | return -ENOMEM; |
| 8386 | new_rule->patterns[i].pattern = |
| 8387 | new_rule->patterns[i].mask + mask_len; |
| 8388 | memcpy(new_rule->patterns[i].mask, |
| 8389 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8390 | new_rule->patterns[i].pattern_len = pat_len; |
| 8391 | memcpy(new_rule->patterns[i].pattern, |
| 8392 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8393 | i++; |
| 8394 | } |
| 8395 | |
| 8396 | return 0; |
| 8397 | } |
| 8398 | |
| 8399 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8400 | { |
| 8401 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8402 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8403 | struct cfg80211_coalesce new_coalesce = {}; |
| 8404 | struct cfg80211_coalesce *n_coalesce; |
| 8405 | int err, rem_rule, n_rules = 0, i, j; |
| 8406 | struct nlattr *rule; |
| 8407 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8408 | |
| 8409 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8410 | return -EOPNOTSUPP; |
| 8411 | |
| 8412 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8413 | cfg80211_rdev_free_coalesce(rdev); |
| 8414 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8415 | return 0; |
| 8416 | } |
| 8417 | |
| 8418 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8419 | rem_rule) |
| 8420 | n_rules++; |
| 8421 | if (n_rules > coalesce->n_rules) |
| 8422 | return -EINVAL; |
| 8423 | |
| 8424 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8425 | GFP_KERNEL); |
| 8426 | if (!new_coalesce.rules) |
| 8427 | return -ENOMEM; |
| 8428 | |
| 8429 | new_coalesce.n_rules = n_rules; |
| 8430 | i = 0; |
| 8431 | |
| 8432 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8433 | rem_rule) { |
| 8434 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8435 | &new_coalesce.rules[i]); |
| 8436 | if (err) |
| 8437 | goto error; |
| 8438 | |
| 8439 | i++; |
| 8440 | } |
| 8441 | |
| 8442 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8443 | if (err) |
| 8444 | goto error; |
| 8445 | |
| 8446 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8447 | if (!n_coalesce) { |
| 8448 | err = -ENOMEM; |
| 8449 | goto error; |
| 8450 | } |
| 8451 | cfg80211_rdev_free_coalesce(rdev); |
| 8452 | rdev->coalesce = n_coalesce; |
| 8453 | |
| 8454 | return 0; |
| 8455 | error: |
| 8456 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8457 | tmp_rule = &new_coalesce.rules[i]; |
| 8458 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8459 | kfree(tmp_rule->patterns[j].mask); |
| 8460 | kfree(tmp_rule->patterns); |
| 8461 | } |
| 8462 | kfree(new_coalesce.rules); |
| 8463 | |
| 8464 | return err; |
| 8465 | } |
| 8466 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8467 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8468 | { |
| 8469 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8470 | struct net_device *dev = info->user_ptr[1]; |
| 8471 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8472 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8473 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8474 | int err; |
| 8475 | |
| 8476 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8477 | return -EINVAL; |
| 8478 | |
| 8479 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8480 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8481 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8482 | nl80211_rekey_policy); |
| 8483 | if (err) |
| 8484 | return err; |
| 8485 | |
| 8486 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8487 | return -ERANGE; |
| 8488 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8489 | return -ERANGE; |
| 8490 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8491 | return -ERANGE; |
| 8492 | |
| 8493 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8494 | NL80211_KEK_LEN); |
| 8495 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8496 | NL80211_KCK_LEN); |
| 8497 | memcpy(rekey_data.replay_ctr, |
| 8498 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8499 | NL80211_REPLAY_CTR_LEN); |
| 8500 | |
| 8501 | wdev_lock(wdev); |
| 8502 | if (!wdev->current_bss) { |
| 8503 | err = -ENOTCONN; |
| 8504 | goto out; |
| 8505 | } |
| 8506 | |
| 8507 | if (!rdev->ops->set_rekey_data) { |
| 8508 | err = -EOPNOTSUPP; |
| 8509 | goto out; |
| 8510 | } |
| 8511 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8512 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8513 | out: |
| 8514 | wdev_unlock(wdev); |
| 8515 | return err; |
| 8516 | } |
| 8517 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8518 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8519 | struct genl_info *info) |
| 8520 | { |
| 8521 | struct net_device *dev = info->user_ptr[1]; |
| 8522 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8523 | |
| 8524 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8525 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8526 | return -EINVAL; |
| 8527 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8528 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8529 | return -EBUSY; |
| 8530 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8531 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8532 | return 0; |
| 8533 | } |
| 8534 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8535 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8536 | struct genl_info *info) |
| 8537 | { |
| 8538 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8539 | struct net_device *dev = info->user_ptr[1]; |
| 8540 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8541 | struct sk_buff *msg; |
| 8542 | void *hdr; |
| 8543 | const u8 *addr; |
| 8544 | u64 cookie; |
| 8545 | int err; |
| 8546 | |
| 8547 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8548 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8549 | return -EOPNOTSUPP; |
| 8550 | |
| 8551 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8552 | return -EINVAL; |
| 8553 | |
| 8554 | if (!rdev->ops->probe_client) |
| 8555 | return -EOPNOTSUPP; |
| 8556 | |
| 8557 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8558 | if (!msg) |
| 8559 | return -ENOMEM; |
| 8560 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8561 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8562 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8563 | if (!hdr) { |
| 8564 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8565 | goto free_msg; |
| 8566 | } |
| 8567 | |
| 8568 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8569 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8570 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8571 | if (err) |
| 8572 | goto free_msg; |
| 8573 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8574 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8575 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8576 | |
| 8577 | genlmsg_end(msg, hdr); |
| 8578 | |
| 8579 | return genlmsg_reply(msg, info); |
| 8580 | |
| 8581 | nla_put_failure: |
| 8582 | err = -ENOBUFS; |
| 8583 | free_msg: |
| 8584 | nlmsg_free(msg); |
| 8585 | return err; |
| 8586 | } |
| 8587 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8588 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8589 | { |
| 8590 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8591 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8592 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8593 | |
| 8594 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8595 | return -EOPNOTSUPP; |
| 8596 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8597 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8598 | if (!nreg) |
| 8599 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8600 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8601 | /* First, check if already registered. */ |
| 8602 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8603 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8604 | if (reg->nlportid == info->snd_portid) { |
| 8605 | rv = -EALREADY; |
| 8606 | goto out_err; |
| 8607 | } |
| 8608 | } |
| 8609 | /* Add it to the list */ |
| 8610 | nreg->nlportid = info->snd_portid; |
| 8611 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8612 | |
| 8613 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8614 | |
| 8615 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8616 | out_err: |
| 8617 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8618 | kfree(nreg); |
| 8619 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8620 | } |
| 8621 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8622 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8623 | { |
| 8624 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8625 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8626 | int err; |
| 8627 | |
| 8628 | if (!rdev->ops->start_p2p_device) |
| 8629 | return -EOPNOTSUPP; |
| 8630 | |
| 8631 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8632 | return -EOPNOTSUPP; |
| 8633 | |
| 8634 | if (wdev->p2p_started) |
| 8635 | return 0; |
| 8636 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8637 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8638 | if (err) |
| 8639 | return err; |
| 8640 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8641 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8642 | if (err) |
| 8643 | return err; |
| 8644 | |
| 8645 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8646 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8647 | |
| 8648 | return 0; |
| 8649 | } |
| 8650 | |
| 8651 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8652 | { |
| 8653 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8654 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8655 | |
| 8656 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8657 | return -EOPNOTSUPP; |
| 8658 | |
| 8659 | if (!rdev->ops->stop_p2p_device) |
| 8660 | return -EOPNOTSUPP; |
| 8661 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8662 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8663 | |
| 8664 | return 0; |
| 8665 | } |
| 8666 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8667 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8668 | struct genl_info *info) |
| 8669 | { |
| 8670 | void *hdr; |
| 8671 | struct sk_buff *msg; |
| 8672 | |
| 8673 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8674 | if (!msg) |
| 8675 | return -ENOMEM; |
| 8676 | |
| 8677 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8678 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8679 | if (!hdr) |
| 8680 | goto nla_put_failure; |
| 8681 | |
| 8682 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8683 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8684 | goto nla_put_failure; |
| 8685 | |
| 8686 | genlmsg_end(msg, hdr); |
| 8687 | return genlmsg_reply(msg, info); |
| 8688 | |
| 8689 | nla_put_failure: |
| 8690 | kfree_skb(msg); |
| 8691 | return -ENOBUFS; |
| 8692 | } |
| 8693 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8694 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8695 | { |
| 8696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8697 | struct cfg80211_update_ft_ies_params ft_params; |
| 8698 | struct net_device *dev = info->user_ptr[1]; |
| 8699 | |
| 8700 | if (!rdev->ops->update_ft_ies) |
| 8701 | return -EOPNOTSUPP; |
| 8702 | |
| 8703 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8704 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8705 | return -EINVAL; |
| 8706 | |
| 8707 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8708 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8709 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8710 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8711 | |
| 8712 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8713 | } |
| 8714 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8715 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8716 | struct genl_info *info) |
| 8717 | { |
| 8718 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8719 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8720 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8721 | u16 duration; |
| 8722 | int ret; |
| 8723 | |
| 8724 | if (!rdev->ops->crit_proto_start) |
| 8725 | return -EOPNOTSUPP; |
| 8726 | |
| 8727 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8728 | return -EINVAL; |
| 8729 | |
| 8730 | if (rdev->crit_proto_nlportid) |
| 8731 | return -EBUSY; |
| 8732 | |
| 8733 | /* determine protocol if provided */ |
| 8734 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8735 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8736 | |
| 8737 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8738 | return -EINVAL; |
| 8739 | |
| 8740 | /* timeout must be provided */ |
| 8741 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8742 | return -EINVAL; |
| 8743 | |
| 8744 | duration = |
| 8745 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8746 | |
| 8747 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8748 | return -ERANGE; |
| 8749 | |
| 8750 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8751 | if (!ret) |
| 8752 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8753 | |
| 8754 | return ret; |
| 8755 | } |
| 8756 | |
| 8757 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8758 | struct genl_info *info) |
| 8759 | { |
| 8760 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8761 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8762 | |
| 8763 | if (!rdev->ops->crit_proto_stop) |
| 8764 | return -EOPNOTSUPP; |
| 8765 | |
| 8766 | if (rdev->crit_proto_nlportid) { |
| 8767 | rdev->crit_proto_nlportid = 0; |
| 8768 | rdev_crit_proto_stop(rdev, wdev); |
| 8769 | } |
| 8770 | return 0; |
| 8771 | } |
| 8772 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8773 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8774 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8775 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8776 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8777 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8778 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8779 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8780 | /* 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] | 8781 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8782 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8783 | |
| 8784 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8785 | struct genl_info *info) |
| 8786 | { |
| 8787 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8788 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8789 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8790 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8791 | |
| 8792 | if (rtnl) |
| 8793 | rtnl_lock(); |
| 8794 | |
| 8795 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8796 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8797 | if (IS_ERR(rdev)) { |
| 8798 | if (rtnl) |
| 8799 | rtnl_unlock(); |
| 8800 | return PTR_ERR(rdev); |
| 8801 | } |
| 8802 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8803 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8804 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8805 | ASSERT_RTNL(); |
| 8806 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8807 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8808 | info->attrs); |
| 8809 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8810 | if (rtnl) |
| 8811 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8812 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8813 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8814 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8815 | dev = wdev->netdev; |
| 8816 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8817 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8818 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8819 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8820 | if (rtnl) |
| 8821 | rtnl_unlock(); |
| 8822 | return -EINVAL; |
| 8823 | } |
| 8824 | |
| 8825 | info->user_ptr[1] = dev; |
| 8826 | } else { |
| 8827 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8828 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8829 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8830 | if (dev) { |
| 8831 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8832 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8833 | if (rtnl) |
| 8834 | rtnl_unlock(); |
| 8835 | return -ENETDOWN; |
| 8836 | } |
| 8837 | |
| 8838 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8839 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8840 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8841 | if (rtnl) |
| 8842 | rtnl_unlock(); |
| 8843 | return -ENETDOWN; |
| 8844 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8845 | } |
| 8846 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8847 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8848 | } |
| 8849 | |
| 8850 | return 0; |
| 8851 | } |
| 8852 | |
| 8853 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8854 | struct genl_info *info) |
| 8855 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8856 | if (info->user_ptr[1]) { |
| 8857 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8858 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8859 | |
| 8860 | if (wdev->netdev) |
| 8861 | dev_put(wdev->netdev); |
| 8862 | } else { |
| 8863 | dev_put(info->user_ptr[1]); |
| 8864 | } |
| 8865 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8866 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8867 | rtnl_unlock(); |
| 8868 | } |
| 8869 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8870 | static struct genl_ops nl80211_ops[] = { |
| 8871 | { |
| 8872 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8873 | .doit = nl80211_get_wiphy, |
| 8874 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 8875 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8876 | .policy = nl80211_policy, |
| 8877 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8878 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8879 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8880 | }, |
| 8881 | { |
| 8882 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8883 | .doit = nl80211_set_wiphy, |
| 8884 | .policy = nl80211_policy, |
| 8885 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8886 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8887 | }, |
| 8888 | { |
| 8889 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8890 | .doit = nl80211_get_interface, |
| 8891 | .dumpit = nl80211_dump_interface, |
| 8892 | .policy = nl80211_policy, |
| 8893 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8894 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8895 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8896 | }, |
| 8897 | { |
| 8898 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8899 | .doit = nl80211_set_interface, |
| 8900 | .policy = nl80211_policy, |
| 8901 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8902 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8903 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8904 | }, |
| 8905 | { |
| 8906 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8907 | .doit = nl80211_new_interface, |
| 8908 | .policy = nl80211_policy, |
| 8909 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8910 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8911 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8912 | }, |
| 8913 | { |
| 8914 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 8915 | .doit = nl80211_del_interface, |
| 8916 | .policy = nl80211_policy, |
| 8917 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 8918 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8919 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8920 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8921 | { |
| 8922 | .cmd = NL80211_CMD_GET_KEY, |
| 8923 | .doit = nl80211_get_key, |
| 8924 | .policy = nl80211_policy, |
| 8925 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8926 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8927 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8928 | }, |
| 8929 | { |
| 8930 | .cmd = NL80211_CMD_SET_KEY, |
| 8931 | .doit = nl80211_set_key, |
| 8932 | .policy = nl80211_policy, |
| 8933 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8934 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8935 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8936 | }, |
| 8937 | { |
| 8938 | .cmd = NL80211_CMD_NEW_KEY, |
| 8939 | .doit = nl80211_new_key, |
| 8940 | .policy = nl80211_policy, |
| 8941 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8942 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8943 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8944 | }, |
| 8945 | { |
| 8946 | .cmd = NL80211_CMD_DEL_KEY, |
| 8947 | .doit = nl80211_del_key, |
| 8948 | .policy = nl80211_policy, |
| 8949 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8950 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8951 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8952 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8953 | { |
| 8954 | .cmd = NL80211_CMD_SET_BEACON, |
| 8955 | .policy = nl80211_policy, |
| 8956 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8957 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8958 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8959 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8960 | }, |
| 8961 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8962 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8963 | .policy = nl80211_policy, |
| 8964 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8965 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8966 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8967 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8968 | }, |
| 8969 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8970 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8971 | .policy = nl80211_policy, |
| 8972 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8973 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8974 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8975 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8976 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8977 | { |
| 8978 | .cmd = NL80211_CMD_GET_STATION, |
| 8979 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8980 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8981 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8982 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8983 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8984 | }, |
| 8985 | { |
| 8986 | .cmd = NL80211_CMD_SET_STATION, |
| 8987 | .doit = nl80211_set_station, |
| 8988 | .policy = nl80211_policy, |
| 8989 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8990 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8991 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8992 | }, |
| 8993 | { |
| 8994 | .cmd = NL80211_CMD_NEW_STATION, |
| 8995 | .doit = nl80211_new_station, |
| 8996 | .policy = nl80211_policy, |
| 8997 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8998 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8999 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9000 | }, |
| 9001 | { |
| 9002 | .cmd = NL80211_CMD_DEL_STATION, |
| 9003 | .doit = nl80211_del_station, |
| 9004 | .policy = nl80211_policy, |
| 9005 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9006 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9007 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9008 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9009 | { |
| 9010 | .cmd = NL80211_CMD_GET_MPATH, |
| 9011 | .doit = nl80211_get_mpath, |
| 9012 | .dumpit = nl80211_dump_mpath, |
| 9013 | .policy = nl80211_policy, |
| 9014 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9015 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9016 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9017 | }, |
| 9018 | { |
| 9019 | .cmd = NL80211_CMD_SET_MPATH, |
| 9020 | .doit = nl80211_set_mpath, |
| 9021 | .policy = nl80211_policy, |
| 9022 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +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, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9025 | }, |
| 9026 | { |
| 9027 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9028 | .doit = nl80211_new_mpath, |
| 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, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9033 | }, |
| 9034 | { |
| 9035 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9036 | .doit = nl80211_del_mpath, |
| 9037 | .policy = nl80211_policy, |
| 9038 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9041 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9042 | { |
| 9043 | .cmd = NL80211_CMD_SET_BSS, |
| 9044 | .doit = nl80211_set_bss, |
| 9045 | .policy = nl80211_policy, |
| 9046 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9049 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9050 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9051 | .cmd = NL80211_CMD_GET_REG, |
| 9052 | .doit = nl80211_get_reg, |
| 9053 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9054 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9055 | /* can be retrieved by unprivileged users */ |
| 9056 | }, |
| 9057 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9058 | .cmd = NL80211_CMD_SET_REG, |
| 9059 | .doit = nl80211_set_reg, |
| 9060 | .policy = nl80211_policy, |
| 9061 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9062 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9063 | }, |
| 9064 | { |
| 9065 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9066 | .doit = nl80211_req_set_reg, |
| 9067 | .policy = nl80211_policy, |
| 9068 | .flags = GENL_ADMIN_PERM, |
| 9069 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9070 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9071 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9072 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9073 | .policy = nl80211_policy, |
| 9074 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9075 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9076 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9077 | }, |
| 9078 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9079 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9080 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9081 | .policy = nl80211_policy, |
| 9082 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9083 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9084 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9085 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9086 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9087 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9088 | .doit = nl80211_trigger_scan, |
| 9089 | .policy = nl80211_policy, |
| 9090 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9091 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9092 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9093 | }, |
| 9094 | { |
| 9095 | .cmd = NL80211_CMD_GET_SCAN, |
| 9096 | .policy = nl80211_policy, |
| 9097 | .dumpit = nl80211_dump_scan, |
| 9098 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9099 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9100 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9101 | .doit = nl80211_start_sched_scan, |
| 9102 | .policy = nl80211_policy, |
| 9103 | .flags = GENL_ADMIN_PERM, |
| 9104 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9105 | NL80211_FLAG_NEED_RTNL, |
| 9106 | }, |
| 9107 | { |
| 9108 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9109 | .doit = nl80211_stop_sched_scan, |
| 9110 | .policy = nl80211_policy, |
| 9111 | .flags = GENL_ADMIN_PERM, |
| 9112 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9113 | NL80211_FLAG_NEED_RTNL, |
| 9114 | }, |
| 9115 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9116 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9117 | .doit = nl80211_authenticate, |
| 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, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9122 | }, |
| 9123 | { |
| 9124 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9125 | .doit = nl80211_associate, |
| 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, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9130 | }, |
| 9131 | { |
| 9132 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9133 | .doit = nl80211_deauthenticate, |
| 9134 | .policy = nl80211_policy, |
| 9135 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +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, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9138 | }, |
| 9139 | { |
| 9140 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9141 | .doit = nl80211_disassociate, |
| 9142 | .policy = nl80211_policy, |
| 9143 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +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 | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9146 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9147 | { |
| 9148 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9149 | .doit = nl80211_join_ibss, |
| 9150 | .policy = nl80211_policy, |
| 9151 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9152 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9153 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9154 | }, |
| 9155 | { |
| 9156 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9157 | .doit = nl80211_leave_ibss, |
| 9158 | .policy = nl80211_policy, |
| 9159 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9160 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9161 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9162 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9163 | #ifdef CONFIG_NL80211_TESTMODE |
| 9164 | { |
| 9165 | .cmd = NL80211_CMD_TESTMODE, |
| 9166 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9167 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9168 | .policy = nl80211_policy, |
| 9169 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9170 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9171 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9172 | }, |
| 9173 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9174 | { |
| 9175 | .cmd = NL80211_CMD_CONNECT, |
| 9176 | .doit = nl80211_connect, |
| 9177 | .policy = nl80211_policy, |
| 9178 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9179 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9180 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9181 | }, |
| 9182 | { |
| 9183 | .cmd = NL80211_CMD_DISCONNECT, |
| 9184 | .doit = nl80211_disconnect, |
| 9185 | .policy = nl80211_policy, |
| 9186 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9187 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9188 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9189 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9190 | { |
| 9191 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9192 | .doit = nl80211_wiphy_netns, |
| 9193 | .policy = nl80211_policy, |
| 9194 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9195 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9196 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9197 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9198 | { |
| 9199 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9200 | .policy = nl80211_policy, |
| 9201 | .dumpit = nl80211_dump_survey, |
| 9202 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9203 | { |
| 9204 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9205 | .doit = nl80211_setdel_pmksa, |
| 9206 | .policy = nl80211_policy, |
| 9207 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9208 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9209 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9210 | }, |
| 9211 | { |
| 9212 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9213 | .doit = nl80211_setdel_pmksa, |
| 9214 | .policy = nl80211_policy, |
| 9215 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9216 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9217 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9218 | }, |
| 9219 | { |
| 9220 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9221 | .doit = nl80211_flush_pmksa, |
| 9222 | .policy = nl80211_policy, |
| 9223 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9224 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9225 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9226 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9227 | { |
| 9228 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9229 | .doit = nl80211_remain_on_channel, |
| 9230 | .policy = nl80211_policy, |
| 9231 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9232 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9233 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9234 | }, |
| 9235 | { |
| 9236 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9237 | .doit = nl80211_cancel_remain_on_channel, |
| 9238 | .policy = nl80211_policy, |
| 9239 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9240 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9241 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9242 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9243 | { |
| 9244 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9245 | .doit = nl80211_set_tx_bitrate_mask, |
| 9246 | .policy = nl80211_policy, |
| 9247 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9248 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9249 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9250 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9251 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9252 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9253 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9254 | .policy = nl80211_policy, |
| 9255 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9256 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9257 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9258 | }, |
| 9259 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9260 | .cmd = NL80211_CMD_FRAME, |
| 9261 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9262 | .policy = nl80211_policy, |
| 9263 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9264 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9265 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9266 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9267 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9268 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9269 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9270 | .policy = nl80211_policy, |
| 9271 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9272 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9273 | NL80211_FLAG_NEED_RTNL, |
| 9274 | }, |
| 9275 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9276 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9277 | .doit = nl80211_set_power_save, |
| 9278 | .policy = nl80211_policy, |
| 9279 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9280 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9281 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9282 | }, |
| 9283 | { |
| 9284 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9285 | .doit = nl80211_get_power_save, |
| 9286 | .policy = nl80211_policy, |
| 9287 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9288 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9289 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9290 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9291 | { |
| 9292 | .cmd = NL80211_CMD_SET_CQM, |
| 9293 | .doit = nl80211_set_cqm, |
| 9294 | .policy = nl80211_policy, |
| 9295 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9296 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9297 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9298 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9299 | { |
| 9300 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9301 | .doit = nl80211_set_channel, |
| 9302 | .policy = nl80211_policy, |
| 9303 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9304 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9305 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9306 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9307 | { |
| 9308 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9309 | .doit = nl80211_set_wds_peer, |
| 9310 | .policy = nl80211_policy, |
| 9311 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9312 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9313 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9314 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9315 | { |
| 9316 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9317 | .doit = nl80211_join_mesh, |
| 9318 | .policy = nl80211_policy, |
| 9319 | .flags = GENL_ADMIN_PERM, |
| 9320 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9321 | NL80211_FLAG_NEED_RTNL, |
| 9322 | }, |
| 9323 | { |
| 9324 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9325 | .doit = nl80211_leave_mesh, |
| 9326 | .policy = nl80211_policy, |
| 9327 | .flags = GENL_ADMIN_PERM, |
| 9328 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9329 | NL80211_FLAG_NEED_RTNL, |
| 9330 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9331 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9332 | { |
| 9333 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9334 | .doit = nl80211_get_wowlan, |
| 9335 | .policy = nl80211_policy, |
| 9336 | /* can be retrieved by unprivileged users */ |
| 9337 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9338 | NL80211_FLAG_NEED_RTNL, |
| 9339 | }, |
| 9340 | { |
| 9341 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9342 | .doit = nl80211_set_wowlan, |
| 9343 | .policy = nl80211_policy, |
| 9344 | .flags = GENL_ADMIN_PERM, |
| 9345 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9346 | NL80211_FLAG_NEED_RTNL, |
| 9347 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9348 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9349 | { |
| 9350 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9351 | .doit = nl80211_set_rekey_data, |
| 9352 | .policy = nl80211_policy, |
| 9353 | .flags = GENL_ADMIN_PERM, |
| 9354 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9355 | NL80211_FLAG_NEED_RTNL, |
| 9356 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9357 | { |
| 9358 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9359 | .doit = nl80211_tdls_mgmt, |
| 9360 | .policy = nl80211_policy, |
| 9361 | .flags = GENL_ADMIN_PERM, |
| 9362 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9363 | NL80211_FLAG_NEED_RTNL, |
| 9364 | }, |
| 9365 | { |
| 9366 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9367 | .doit = nl80211_tdls_oper, |
| 9368 | .policy = nl80211_policy, |
| 9369 | .flags = GENL_ADMIN_PERM, |
| 9370 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9371 | NL80211_FLAG_NEED_RTNL, |
| 9372 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9373 | { |
| 9374 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9375 | .doit = nl80211_register_unexpected_frame, |
| 9376 | .policy = nl80211_policy, |
| 9377 | .flags = GENL_ADMIN_PERM, |
| 9378 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9379 | NL80211_FLAG_NEED_RTNL, |
| 9380 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9381 | { |
| 9382 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9383 | .doit = nl80211_probe_client, |
| 9384 | .policy = nl80211_policy, |
| 9385 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9386 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9387 | NL80211_FLAG_NEED_RTNL, |
| 9388 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9389 | { |
| 9390 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9391 | .doit = nl80211_register_beacons, |
| 9392 | .policy = nl80211_policy, |
| 9393 | .flags = GENL_ADMIN_PERM, |
| 9394 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9395 | NL80211_FLAG_NEED_RTNL, |
| 9396 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9397 | { |
| 9398 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9399 | .doit = nl80211_set_noack_map, |
| 9400 | .policy = nl80211_policy, |
| 9401 | .flags = GENL_ADMIN_PERM, |
| 9402 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9403 | NL80211_FLAG_NEED_RTNL, |
| 9404 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9405 | { |
| 9406 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9407 | .doit = nl80211_start_p2p_device, |
| 9408 | .policy = nl80211_policy, |
| 9409 | .flags = GENL_ADMIN_PERM, |
| 9410 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9411 | NL80211_FLAG_NEED_RTNL, |
| 9412 | }, |
| 9413 | { |
| 9414 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9415 | .doit = nl80211_stop_p2p_device, |
| 9416 | .policy = nl80211_policy, |
| 9417 | .flags = GENL_ADMIN_PERM, |
| 9418 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9419 | NL80211_FLAG_NEED_RTNL, |
| 9420 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9421 | { |
| 9422 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9423 | .doit = nl80211_set_mcast_rate, |
| 9424 | .policy = nl80211_policy, |
| 9425 | .flags = GENL_ADMIN_PERM, |
| 9426 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9427 | NL80211_FLAG_NEED_RTNL, |
| 9428 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9429 | { |
| 9430 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9431 | .doit = nl80211_set_mac_acl, |
| 9432 | .policy = nl80211_policy, |
| 9433 | .flags = GENL_ADMIN_PERM, |
| 9434 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9435 | NL80211_FLAG_NEED_RTNL, |
| 9436 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9437 | { |
| 9438 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9439 | .doit = nl80211_start_radar_detection, |
| 9440 | .policy = nl80211_policy, |
| 9441 | .flags = GENL_ADMIN_PERM, |
| 9442 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9443 | NL80211_FLAG_NEED_RTNL, |
| 9444 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9445 | { |
| 9446 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9447 | .doit = nl80211_get_protocol_features, |
| 9448 | .policy = nl80211_policy, |
| 9449 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9450 | { |
| 9451 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9452 | .doit = nl80211_update_ft_ies, |
| 9453 | .policy = nl80211_policy, |
| 9454 | .flags = GENL_ADMIN_PERM, |
| 9455 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9456 | NL80211_FLAG_NEED_RTNL, |
| 9457 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9458 | { |
| 9459 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9460 | .doit = nl80211_crit_protocol_start, |
| 9461 | .policy = nl80211_policy, |
| 9462 | .flags = GENL_ADMIN_PERM, |
| 9463 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9464 | NL80211_FLAG_NEED_RTNL, |
| 9465 | }, |
| 9466 | { |
| 9467 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9468 | .doit = nl80211_crit_protocol_stop, |
| 9469 | .policy = nl80211_policy, |
| 9470 | .flags = GENL_ADMIN_PERM, |
| 9471 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9472 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9473 | }, |
| 9474 | { |
| 9475 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9476 | .doit = nl80211_get_coalesce, |
| 9477 | .policy = nl80211_policy, |
| 9478 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9479 | NL80211_FLAG_NEED_RTNL, |
| 9480 | }, |
| 9481 | { |
| 9482 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9483 | .doit = nl80211_set_coalesce, |
| 9484 | .policy = nl80211_policy, |
| 9485 | .flags = GENL_ADMIN_PERM, |
| 9486 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9487 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9488 | }, |
| 9489 | { |
| 9490 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9491 | .doit = nl80211_channel_switch, |
| 9492 | .policy = nl80211_policy, |
| 9493 | .flags = GENL_ADMIN_PERM, |
| 9494 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9495 | NL80211_FLAG_NEED_RTNL, |
| 9496 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9497 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9498 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9499 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 9500 | .name = "mlme", |
| 9501 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9502 | |
| 9503 | /* multicast groups */ |
| 9504 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 9505 | .name = "config", |
| 9506 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9507 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 9508 | .name = "scan", |
| 9509 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9510 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 9511 | .name = "regulatory", |
| 9512 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9513 | |
| 9514 | /* notification functions */ |
| 9515 | |
| 9516 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9517 | { |
| 9518 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9519 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9520 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9521 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9522 | if (!msg) |
| 9523 | return; |
| 9524 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9525 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9526 | nlmsg_free(msg); |
| 9527 | return; |
| 9528 | } |
| 9529 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9530 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9531 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9532 | } |
| 9533 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9534 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9535 | struct cfg80211_registered_device *rdev) |
| 9536 | { |
| 9537 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9538 | struct nlattr *nest; |
| 9539 | int i; |
| 9540 | |
| 9541 | if (WARN_ON(!req)) |
| 9542 | return 0; |
| 9543 | |
| 9544 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9545 | if (!nest) |
| 9546 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9547 | for (i = 0; i < req->n_ssids; i++) { |
| 9548 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9549 | goto nla_put_failure; |
| 9550 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9551 | nla_nest_end(msg, nest); |
| 9552 | |
| 9553 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9554 | if (!nest) |
| 9555 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9556 | for (i = 0; i < req->n_channels; i++) { |
| 9557 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9558 | goto nla_put_failure; |
| 9559 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9560 | nla_nest_end(msg, nest); |
| 9561 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9562 | if (req->ie && |
| 9563 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9564 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9565 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9566 | if (req->flags) |
| 9567 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 9568 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9569 | return 0; |
| 9570 | nla_put_failure: |
| 9571 | return -ENOBUFS; |
| 9572 | } |
| 9573 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9574 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9575 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9576 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9577 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9578 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9579 | { |
| 9580 | void *hdr; |
| 9581 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9582 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9583 | if (!hdr) |
| 9584 | return -1; |
| 9585 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9586 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9587 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9588 | wdev->netdev->ifindex)) || |
| 9589 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9590 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9591 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9592 | /* ignore errors and send incomplete event anyway */ |
| 9593 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9594 | |
| 9595 | return genlmsg_end(msg, hdr); |
| 9596 | |
| 9597 | nla_put_failure: |
| 9598 | genlmsg_cancel(msg, hdr); |
| 9599 | return -EMSGSIZE; |
| 9600 | } |
| 9601 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9602 | static int |
| 9603 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9604 | struct cfg80211_registered_device *rdev, |
| 9605 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9606 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9607 | { |
| 9608 | void *hdr; |
| 9609 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9610 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9611 | if (!hdr) |
| 9612 | return -1; |
| 9613 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9614 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9615 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9616 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9617 | |
| 9618 | return genlmsg_end(msg, hdr); |
| 9619 | |
| 9620 | nla_put_failure: |
| 9621 | genlmsg_cancel(msg, hdr); |
| 9622 | return -EMSGSIZE; |
| 9623 | } |
| 9624 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9625 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9626 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9627 | { |
| 9628 | struct sk_buff *msg; |
| 9629 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9630 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9631 | if (!msg) |
| 9632 | return; |
| 9633 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9634 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9635 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9636 | nlmsg_free(msg); |
| 9637 | return; |
| 9638 | } |
| 9639 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9640 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9641 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9642 | } |
| 9643 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9644 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9645 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9646 | { |
| 9647 | struct sk_buff *msg; |
| 9648 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9649 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9650 | if (!msg) |
| 9651 | return; |
| 9652 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9653 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9654 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9655 | nlmsg_free(msg); |
| 9656 | return; |
| 9657 | } |
| 9658 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9659 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9660 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9661 | } |
| 9662 | |
| 9663 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9664 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9665 | { |
| 9666 | struct sk_buff *msg; |
| 9667 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9668 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9669 | if (!msg) |
| 9670 | return; |
| 9671 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9672 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9673 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9674 | nlmsg_free(msg); |
| 9675 | return; |
| 9676 | } |
| 9677 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9678 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9679 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9680 | } |
| 9681 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9682 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9683 | struct net_device *netdev) |
| 9684 | { |
| 9685 | struct sk_buff *msg; |
| 9686 | |
| 9687 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9688 | if (!msg) |
| 9689 | return; |
| 9690 | |
| 9691 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9692 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9693 | nlmsg_free(msg); |
| 9694 | return; |
| 9695 | } |
| 9696 | |
| 9697 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9698 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9699 | } |
| 9700 | |
| 9701 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9702 | struct net_device *netdev, u32 cmd) |
| 9703 | { |
| 9704 | struct sk_buff *msg; |
| 9705 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9706 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9707 | if (!msg) |
| 9708 | return; |
| 9709 | |
| 9710 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9711 | nlmsg_free(msg); |
| 9712 | return; |
| 9713 | } |
| 9714 | |
| 9715 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9716 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9717 | } |
| 9718 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9719 | /* |
| 9720 | * This can happen on global regulatory changes or device specific settings |
| 9721 | * based on custom world regulatory domains. |
| 9722 | */ |
| 9723 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9724 | { |
| 9725 | struct sk_buff *msg; |
| 9726 | void *hdr; |
| 9727 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9728 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9729 | if (!msg) |
| 9730 | return; |
| 9731 | |
| 9732 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9733 | if (!hdr) { |
| 9734 | nlmsg_free(msg); |
| 9735 | return; |
| 9736 | } |
| 9737 | |
| 9738 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9739 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9740 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9741 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9742 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9743 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9744 | NL80211_REGDOM_TYPE_WORLD)) |
| 9745 | goto nla_put_failure; |
| 9746 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9747 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9748 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9749 | goto nla_put_failure; |
| 9750 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9751 | request->intersect) { |
| 9752 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9753 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9754 | goto nla_put_failure; |
| 9755 | } else { |
| 9756 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9757 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9758 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9759 | request->alpha2)) |
| 9760 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9761 | } |
| 9762 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9763 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9764 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9765 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9766 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9767 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9768 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9769 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9770 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9771 | GFP_ATOMIC); |
| 9772 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9773 | |
| 9774 | return; |
| 9775 | |
| 9776 | nla_put_failure: |
| 9777 | genlmsg_cancel(msg, hdr); |
| 9778 | nlmsg_free(msg); |
| 9779 | } |
| 9780 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9781 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9782 | struct net_device *netdev, |
| 9783 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9784 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9785 | { |
| 9786 | struct sk_buff *msg; |
| 9787 | void *hdr; |
| 9788 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9789 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9790 | if (!msg) |
| 9791 | return; |
| 9792 | |
| 9793 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9794 | if (!hdr) { |
| 9795 | nlmsg_free(msg); |
| 9796 | return; |
| 9797 | } |
| 9798 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9799 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9800 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9801 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9802 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9803 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9804 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9805 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9806 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9807 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9808 | return; |
| 9809 | |
| 9810 | nla_put_failure: |
| 9811 | genlmsg_cancel(msg, hdr); |
| 9812 | nlmsg_free(msg); |
| 9813 | } |
| 9814 | |
| 9815 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9816 | struct net_device *netdev, const u8 *buf, |
| 9817 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9818 | { |
| 9819 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9820 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9821 | } |
| 9822 | |
| 9823 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9824 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9825 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9826 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9827 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9828 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9829 | } |
| 9830 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9831 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9832 | struct net_device *netdev, const u8 *buf, |
| 9833 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9834 | { |
| 9835 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9836 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9837 | } |
| 9838 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9839 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9840 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9841 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9842 | { |
| 9843 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9844 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9845 | } |
| 9846 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9847 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 9848 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9849 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9850 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9851 | struct wiphy *wiphy = wdev->wiphy; |
| 9852 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9853 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 9854 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9855 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9856 | if (WARN_ON(len < 2)) |
| 9857 | return; |
| 9858 | |
| 9859 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 9860 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 9861 | else |
| 9862 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 9863 | |
| 9864 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 9865 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9866 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9867 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9868 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9869 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9870 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9871 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9872 | { |
| 9873 | struct sk_buff *msg; |
| 9874 | void *hdr; |
| 9875 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9876 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9877 | if (!msg) |
| 9878 | return; |
| 9879 | |
| 9880 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9881 | if (!hdr) { |
| 9882 | nlmsg_free(msg); |
| 9883 | return; |
| 9884 | } |
| 9885 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9886 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9887 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9888 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9889 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9890 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9891 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9892 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9893 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9894 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9895 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9896 | return; |
| 9897 | |
| 9898 | nla_put_failure: |
| 9899 | genlmsg_cancel(msg, hdr); |
| 9900 | nlmsg_free(msg); |
| 9901 | } |
| 9902 | |
| 9903 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9904 | struct net_device *netdev, const u8 *addr, |
| 9905 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9906 | { |
| 9907 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9908 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9909 | } |
| 9910 | |
| 9911 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9912 | struct net_device *netdev, const u8 *addr, |
| 9913 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9914 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9915 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9916 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9917 | } |
| 9918 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9919 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9920 | struct net_device *netdev, const u8 *bssid, |
| 9921 | const u8 *req_ie, size_t req_ie_len, |
| 9922 | const u8 *resp_ie, size_t resp_ie_len, |
| 9923 | u16 status, gfp_t gfp) |
| 9924 | { |
| 9925 | struct sk_buff *msg; |
| 9926 | void *hdr; |
| 9927 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9928 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9929 | if (!msg) |
| 9930 | return; |
| 9931 | |
| 9932 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 9933 | if (!hdr) { |
| 9934 | nlmsg_free(msg); |
| 9935 | return; |
| 9936 | } |
| 9937 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9938 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9939 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9940 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 9941 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 9942 | (req_ie && |
| 9943 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9944 | (resp_ie && |
| 9945 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9946 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9947 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9948 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9949 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9950 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9951 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9952 | return; |
| 9953 | |
| 9954 | nla_put_failure: |
| 9955 | genlmsg_cancel(msg, hdr); |
| 9956 | nlmsg_free(msg); |
| 9957 | |
| 9958 | } |
| 9959 | |
| 9960 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 9961 | struct net_device *netdev, const u8 *bssid, |
| 9962 | const u8 *req_ie, size_t req_ie_len, |
| 9963 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 9964 | { |
| 9965 | struct sk_buff *msg; |
| 9966 | void *hdr; |
| 9967 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9968 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9969 | if (!msg) |
| 9970 | return; |
| 9971 | |
| 9972 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 9973 | if (!hdr) { |
| 9974 | nlmsg_free(msg); |
| 9975 | return; |
| 9976 | } |
| 9977 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9978 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9979 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9980 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 9981 | (req_ie && |
| 9982 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9983 | (resp_ie && |
| 9984 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9985 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9986 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9987 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9988 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9989 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9990 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9991 | return; |
| 9992 | |
| 9993 | nla_put_failure: |
| 9994 | genlmsg_cancel(msg, hdr); |
| 9995 | nlmsg_free(msg); |
| 9996 | |
| 9997 | } |
| 9998 | |
| 9999 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10000 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10001 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10002 | { |
| 10003 | struct sk_buff *msg; |
| 10004 | void *hdr; |
| 10005 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10006 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10007 | if (!msg) |
| 10008 | return; |
| 10009 | |
| 10010 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10011 | if (!hdr) { |
| 10012 | nlmsg_free(msg); |
| 10013 | return; |
| 10014 | } |
| 10015 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10016 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10017 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10018 | (from_ap && reason && |
| 10019 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10020 | (from_ap && |
| 10021 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10022 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10023 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10024 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10025 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10026 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10027 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10028 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10029 | return; |
| 10030 | |
| 10031 | nla_put_failure: |
| 10032 | genlmsg_cancel(msg, hdr); |
| 10033 | nlmsg_free(msg); |
| 10034 | |
| 10035 | } |
| 10036 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10037 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10038 | struct net_device *netdev, const u8 *bssid, |
| 10039 | gfp_t gfp) |
| 10040 | { |
| 10041 | struct sk_buff *msg; |
| 10042 | void *hdr; |
| 10043 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10044 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10045 | if (!msg) |
| 10046 | return; |
| 10047 | |
| 10048 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10049 | if (!hdr) { |
| 10050 | nlmsg_free(msg); |
| 10051 | return; |
| 10052 | } |
| 10053 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10054 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10055 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10056 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10057 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10058 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10059 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10060 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10061 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10062 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10063 | return; |
| 10064 | |
| 10065 | nla_put_failure: |
| 10066 | genlmsg_cancel(msg, hdr); |
| 10067 | nlmsg_free(msg); |
| 10068 | } |
| 10069 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10070 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10071 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10072 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10073 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10074 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10075 | struct sk_buff *msg; |
| 10076 | void *hdr; |
| 10077 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10078 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10079 | return; |
| 10080 | |
| 10081 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10082 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10083 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10084 | if (!msg) |
| 10085 | return; |
| 10086 | |
| 10087 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10088 | if (!hdr) { |
| 10089 | nlmsg_free(msg); |
| 10090 | return; |
| 10091 | } |
| 10092 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10093 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10094 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10095 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10096 | (ie_len && ie && |
| 10097 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10098 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10099 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10100 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10101 | |
| 10102 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10103 | nl80211_mlme_mcgrp.id, gfp); |
| 10104 | return; |
| 10105 | |
| 10106 | nla_put_failure: |
| 10107 | genlmsg_cancel(msg, hdr); |
| 10108 | nlmsg_free(msg); |
| 10109 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10110 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10111 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10112 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10113 | struct net_device *netdev, const u8 *addr, |
| 10114 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10115 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10116 | { |
| 10117 | struct sk_buff *msg; |
| 10118 | void *hdr; |
| 10119 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10120 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10121 | if (!msg) |
| 10122 | return; |
| 10123 | |
| 10124 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10125 | if (!hdr) { |
| 10126 | nlmsg_free(msg); |
| 10127 | return; |
| 10128 | } |
| 10129 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10130 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10131 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10132 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10133 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10134 | (key_id != -1 && |
| 10135 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10136 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10137 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10138 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10139 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10140 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10141 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10142 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10143 | return; |
| 10144 | |
| 10145 | nla_put_failure: |
| 10146 | genlmsg_cancel(msg, hdr); |
| 10147 | nlmsg_free(msg); |
| 10148 | } |
| 10149 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10150 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10151 | struct ieee80211_channel *channel_before, |
| 10152 | struct ieee80211_channel *channel_after) |
| 10153 | { |
| 10154 | struct sk_buff *msg; |
| 10155 | void *hdr; |
| 10156 | struct nlattr *nl_freq; |
| 10157 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10158 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10159 | if (!msg) |
| 10160 | return; |
| 10161 | |
| 10162 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10163 | if (!hdr) { |
| 10164 | nlmsg_free(msg); |
| 10165 | return; |
| 10166 | } |
| 10167 | |
| 10168 | /* |
| 10169 | * Since we are applying the beacon hint to a wiphy we know its |
| 10170 | * wiphy_idx is valid |
| 10171 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10172 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10173 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10174 | |
| 10175 | /* Before */ |
| 10176 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10177 | if (!nl_freq) |
| 10178 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10179 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10180 | goto nla_put_failure; |
| 10181 | nla_nest_end(msg, nl_freq); |
| 10182 | |
| 10183 | /* After */ |
| 10184 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10185 | if (!nl_freq) |
| 10186 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10187 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10188 | goto nla_put_failure; |
| 10189 | nla_nest_end(msg, nl_freq); |
| 10190 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10191 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10192 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10193 | rcu_read_lock(); |
| 10194 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 10195 | GFP_ATOMIC); |
| 10196 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10197 | |
| 10198 | return; |
| 10199 | |
| 10200 | nla_put_failure: |
| 10201 | genlmsg_cancel(msg, hdr); |
| 10202 | nlmsg_free(msg); |
| 10203 | } |
| 10204 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10205 | static void nl80211_send_remain_on_chan_event( |
| 10206 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10207 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10208 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10209 | unsigned int duration, gfp_t gfp) |
| 10210 | { |
| 10211 | struct sk_buff *msg; |
| 10212 | void *hdr; |
| 10213 | |
| 10214 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10215 | if (!msg) |
| 10216 | return; |
| 10217 | |
| 10218 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10219 | if (!hdr) { |
| 10220 | nlmsg_free(msg); |
| 10221 | return; |
| 10222 | } |
| 10223 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10224 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10225 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10226 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10227 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10228 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10229 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10230 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10231 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10232 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10233 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10234 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10235 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10236 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10237 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10238 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10239 | |
| 10240 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10241 | nl80211_mlme_mcgrp.id, gfp); |
| 10242 | return; |
| 10243 | |
| 10244 | nla_put_failure: |
| 10245 | genlmsg_cancel(msg, hdr); |
| 10246 | nlmsg_free(msg); |
| 10247 | } |
| 10248 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10249 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10250 | struct ieee80211_channel *chan, |
| 10251 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10252 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10253 | struct wiphy *wiphy = wdev->wiphy; |
| 10254 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10255 | |
| 10256 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10257 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10258 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10259 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10260 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10261 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10262 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10263 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10264 | struct ieee80211_channel *chan, |
| 10265 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10266 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10267 | struct wiphy *wiphy = wdev->wiphy; |
| 10268 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10269 | |
| 10270 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10271 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10272 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10273 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10274 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10275 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10276 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10277 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10278 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10279 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10280 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10281 | struct sk_buff *msg; |
| 10282 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10283 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10284 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10285 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10286 | if (!msg) |
| 10287 | return; |
| 10288 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10289 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10290 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10291 | nlmsg_free(msg); |
| 10292 | return; |
| 10293 | } |
| 10294 | |
| 10295 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10296 | nl80211_mlme_mcgrp.id, gfp); |
| 10297 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10298 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10299 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10300 | 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] | 10301 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10302 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10303 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10304 | struct sk_buff *msg; |
| 10305 | void *hdr; |
| 10306 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10307 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10308 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10309 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10310 | if (!msg) |
| 10311 | return; |
| 10312 | |
| 10313 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10314 | if (!hdr) { |
| 10315 | nlmsg_free(msg); |
| 10316 | return; |
| 10317 | } |
| 10318 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10319 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10320 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10321 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10322 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10323 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10324 | |
| 10325 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10326 | nl80211_mlme_mcgrp.id, gfp); |
| 10327 | return; |
| 10328 | |
| 10329 | nla_put_failure: |
| 10330 | genlmsg_cancel(msg, hdr); |
| 10331 | nlmsg_free(msg); |
| 10332 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10333 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10334 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10335 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10336 | enum nl80211_connect_failed_reason reason, |
| 10337 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10338 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10339 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10340 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10341 | struct sk_buff *msg; |
| 10342 | void *hdr; |
| 10343 | |
| 10344 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10345 | if (!msg) |
| 10346 | return; |
| 10347 | |
| 10348 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10349 | if (!hdr) { |
| 10350 | nlmsg_free(msg); |
| 10351 | return; |
| 10352 | } |
| 10353 | |
| 10354 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10355 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10356 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10357 | goto nla_put_failure; |
| 10358 | |
| 10359 | genlmsg_end(msg, hdr); |
| 10360 | |
| 10361 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10362 | nl80211_mlme_mcgrp.id, gfp); |
| 10363 | return; |
| 10364 | |
| 10365 | nla_put_failure: |
| 10366 | genlmsg_cancel(msg, hdr); |
| 10367 | nlmsg_free(msg); |
| 10368 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10369 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10370 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10371 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10372 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10373 | { |
| 10374 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10375 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10376 | struct sk_buff *msg; |
| 10377 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10378 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10379 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10380 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10381 | return false; |
| 10382 | |
| 10383 | msg = nlmsg_new(100, gfp); |
| 10384 | if (!msg) |
| 10385 | return true; |
| 10386 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10387 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10388 | if (!hdr) { |
| 10389 | nlmsg_free(msg); |
| 10390 | return true; |
| 10391 | } |
| 10392 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10393 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10394 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10395 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10396 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10397 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10398 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10399 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10400 | return true; |
| 10401 | |
| 10402 | nla_put_failure: |
| 10403 | genlmsg_cancel(msg, hdr); |
| 10404 | nlmsg_free(msg); |
| 10405 | return true; |
| 10406 | } |
| 10407 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10408 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10409 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10410 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10411 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10412 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10413 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10414 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10415 | |
| 10416 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10417 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10418 | trace_cfg80211_return_bool(false); |
| 10419 | return false; |
| 10420 | } |
| 10421 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10422 | addr, gfp); |
| 10423 | trace_cfg80211_return_bool(ret); |
| 10424 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10425 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10426 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10427 | |
| 10428 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10429 | const u8 *addr, gfp_t gfp) |
| 10430 | { |
| 10431 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10432 | bool ret; |
| 10433 | |
| 10434 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10435 | |
| 10436 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10437 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10438 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10439 | trace_cfg80211_return_bool(false); |
| 10440 | return false; |
| 10441 | } |
| 10442 | ret = __nl80211_unexpected_frame(dev, |
| 10443 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10444 | addr, gfp); |
| 10445 | trace_cfg80211_return_bool(ret); |
| 10446 | return ret; |
| 10447 | } |
| 10448 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10449 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10450 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10451 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10452 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10453 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10454 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10455 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10456 | struct sk_buff *msg; |
| 10457 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10458 | |
| 10459 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10460 | if (!msg) |
| 10461 | return -ENOMEM; |
| 10462 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10463 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10464 | if (!hdr) { |
| 10465 | nlmsg_free(msg); |
| 10466 | return -ENOMEM; |
| 10467 | } |
| 10468 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10469 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10470 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10471 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10472 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10473 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10474 | (sig_dbm && |
| 10475 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10476 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10477 | (flags && |
| 10478 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10479 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10480 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10481 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10482 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10483 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10484 | |
| 10485 | nla_put_failure: |
| 10486 | genlmsg_cancel(msg, hdr); |
| 10487 | nlmsg_free(msg); |
| 10488 | return -ENOBUFS; |
| 10489 | } |
| 10490 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10491 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10492 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10493 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10494 | struct wiphy *wiphy = wdev->wiphy; |
| 10495 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10496 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10497 | struct sk_buff *msg; |
| 10498 | void *hdr; |
| 10499 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10500 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10501 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10502 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10503 | if (!msg) |
| 10504 | return; |
| 10505 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10506 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10507 | if (!hdr) { |
| 10508 | nlmsg_free(msg); |
| 10509 | return; |
| 10510 | } |
| 10511 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10512 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10513 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10514 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10515 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10516 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10517 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10518 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10519 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10520 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10521 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10522 | |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 10523 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10524 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10525 | return; |
| 10526 | |
| 10527 | nla_put_failure: |
| 10528 | genlmsg_cancel(msg, hdr); |
| 10529 | nlmsg_free(msg); |
| 10530 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10531 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10532 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10533 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10534 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10535 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10536 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10537 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10538 | struct wiphy *wiphy = wdev->wiphy; |
| 10539 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10540 | struct sk_buff *msg; |
| 10541 | struct nlattr *pinfoattr; |
| 10542 | void *hdr; |
| 10543 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10544 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10545 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10546 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10547 | if (!msg) |
| 10548 | return; |
| 10549 | |
| 10550 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10551 | if (!hdr) { |
| 10552 | nlmsg_free(msg); |
| 10553 | return; |
| 10554 | } |
| 10555 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10556 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10557 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10558 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10559 | |
| 10560 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10561 | if (!pinfoattr) |
| 10562 | goto nla_put_failure; |
| 10563 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10564 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10565 | rssi_event)) |
| 10566 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10567 | |
| 10568 | nla_nest_end(msg, pinfoattr); |
| 10569 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10570 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10571 | |
| 10572 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10573 | nl80211_mlme_mcgrp.id, gfp); |
| 10574 | return; |
| 10575 | |
| 10576 | nla_put_failure: |
| 10577 | genlmsg_cancel(msg, hdr); |
| 10578 | nlmsg_free(msg); |
| 10579 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10580 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10581 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10582 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10583 | struct net_device *netdev, const u8 *bssid, |
| 10584 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10585 | { |
| 10586 | struct sk_buff *msg; |
| 10587 | struct nlattr *rekey_attr; |
| 10588 | void *hdr; |
| 10589 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10590 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10591 | if (!msg) |
| 10592 | return; |
| 10593 | |
| 10594 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10595 | if (!hdr) { |
| 10596 | nlmsg_free(msg); |
| 10597 | return; |
| 10598 | } |
| 10599 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10600 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10601 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10602 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10603 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10604 | |
| 10605 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10606 | if (!rekey_attr) |
| 10607 | goto nla_put_failure; |
| 10608 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10609 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10610 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10611 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10612 | |
| 10613 | nla_nest_end(msg, rekey_attr); |
| 10614 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10615 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10616 | |
| 10617 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10618 | nl80211_mlme_mcgrp.id, gfp); |
| 10619 | return; |
| 10620 | |
| 10621 | nla_put_failure: |
| 10622 | genlmsg_cancel(msg, hdr); |
| 10623 | nlmsg_free(msg); |
| 10624 | } |
| 10625 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10626 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10627 | const u8 *replay_ctr, gfp_t gfp) |
| 10628 | { |
| 10629 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10630 | struct wiphy *wiphy = wdev->wiphy; |
| 10631 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10632 | |
| 10633 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10634 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10635 | } |
| 10636 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10637 | |
| 10638 | static void |
| 10639 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10640 | struct net_device *netdev, int index, |
| 10641 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10642 | { |
| 10643 | struct sk_buff *msg; |
| 10644 | struct nlattr *attr; |
| 10645 | void *hdr; |
| 10646 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10647 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10648 | if (!msg) |
| 10649 | return; |
| 10650 | |
| 10651 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10652 | if (!hdr) { |
| 10653 | nlmsg_free(msg); |
| 10654 | return; |
| 10655 | } |
| 10656 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10657 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10658 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10659 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10660 | |
| 10661 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10662 | if (!attr) |
| 10663 | goto nla_put_failure; |
| 10664 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10665 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10666 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10667 | (preauth && |
| 10668 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10669 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10670 | |
| 10671 | nla_nest_end(msg, attr); |
| 10672 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10673 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10674 | |
| 10675 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10676 | nl80211_mlme_mcgrp.id, gfp); |
| 10677 | return; |
| 10678 | |
| 10679 | nla_put_failure: |
| 10680 | genlmsg_cancel(msg, hdr); |
| 10681 | nlmsg_free(msg); |
| 10682 | } |
| 10683 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10684 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10685 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10686 | { |
| 10687 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10688 | struct wiphy *wiphy = wdev->wiphy; |
| 10689 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10690 | |
| 10691 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10692 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10693 | } |
| 10694 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10695 | |
| 10696 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10697 | struct net_device *netdev, |
| 10698 | struct cfg80211_chan_def *chandef, |
| 10699 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10700 | { |
| 10701 | struct sk_buff *msg; |
| 10702 | void *hdr; |
| 10703 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10704 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10705 | if (!msg) |
| 10706 | return; |
| 10707 | |
| 10708 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10709 | if (!hdr) { |
| 10710 | nlmsg_free(msg); |
| 10711 | return; |
| 10712 | } |
| 10713 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10714 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10715 | goto nla_put_failure; |
| 10716 | |
| 10717 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10718 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10719 | |
| 10720 | genlmsg_end(msg, hdr); |
| 10721 | |
| 10722 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10723 | nl80211_mlme_mcgrp.id, gfp); |
| 10724 | return; |
| 10725 | |
| 10726 | nla_put_failure: |
| 10727 | genlmsg_cancel(msg, hdr); |
| 10728 | nlmsg_free(msg); |
| 10729 | } |
| 10730 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10731 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10732 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10733 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10734 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10735 | struct wiphy *wiphy = wdev->wiphy; |
| 10736 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10737 | |
| 10738 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10739 | |
| 10740 | wdev_lock(wdev); |
| 10741 | |
| 10742 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10743 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) |
| 10744 | goto out; |
| 10745 | |
| 10746 | wdev->channel = chandef->chan; |
| 10747 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10748 | out: |
| 10749 | wdev_unlock(wdev); |
| 10750 | return; |
| 10751 | } |
| 10752 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10753 | |
| 10754 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10755 | const u8 *peer, u32 num_packets, |
| 10756 | u32 rate, u32 intvl, gfp_t gfp) |
| 10757 | { |
| 10758 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10759 | struct wiphy *wiphy = wdev->wiphy; |
| 10760 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10761 | struct sk_buff *msg; |
| 10762 | struct nlattr *pinfoattr; |
| 10763 | void *hdr; |
| 10764 | |
| 10765 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10766 | if (!msg) |
| 10767 | return; |
| 10768 | |
| 10769 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10770 | if (!hdr) { |
| 10771 | nlmsg_free(msg); |
| 10772 | return; |
| 10773 | } |
| 10774 | |
| 10775 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10776 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10777 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10778 | goto nla_put_failure; |
| 10779 | |
| 10780 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10781 | if (!pinfoattr) |
| 10782 | goto nla_put_failure; |
| 10783 | |
| 10784 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10785 | goto nla_put_failure; |
| 10786 | |
| 10787 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10788 | goto nla_put_failure; |
| 10789 | |
| 10790 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10791 | goto nla_put_failure; |
| 10792 | |
| 10793 | nla_nest_end(msg, pinfoattr); |
| 10794 | |
| 10795 | genlmsg_end(msg, hdr); |
| 10796 | |
| 10797 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10798 | nl80211_mlme_mcgrp.id, gfp); |
| 10799 | return; |
| 10800 | |
| 10801 | nla_put_failure: |
| 10802 | genlmsg_cancel(msg, hdr); |
| 10803 | nlmsg_free(msg); |
| 10804 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10805 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10806 | |
| 10807 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10808 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 10809 | struct cfg80211_chan_def *chandef, |
| 10810 | enum nl80211_radar_event event, |
| 10811 | struct net_device *netdev, gfp_t gfp) |
| 10812 | { |
| 10813 | struct sk_buff *msg; |
| 10814 | void *hdr; |
| 10815 | |
| 10816 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10817 | if (!msg) |
| 10818 | return; |
| 10819 | |
| 10820 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10821 | if (!hdr) { |
| 10822 | nlmsg_free(msg); |
| 10823 | return; |
| 10824 | } |
| 10825 | |
| 10826 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10827 | goto nla_put_failure; |
| 10828 | |
| 10829 | /* NOP and radar events don't need a netdev parameter */ |
| 10830 | if (netdev) { |
| 10831 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10832 | |
| 10833 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10834 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10835 | goto nla_put_failure; |
| 10836 | } |
| 10837 | |
| 10838 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10839 | goto nla_put_failure; |
| 10840 | |
| 10841 | if (nl80211_send_chandef(msg, chandef)) |
| 10842 | goto nla_put_failure; |
| 10843 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10844 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10845 | |
| 10846 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10847 | nl80211_mlme_mcgrp.id, gfp); |
| 10848 | return; |
| 10849 | |
| 10850 | nla_put_failure: |
| 10851 | genlmsg_cancel(msg, hdr); |
| 10852 | nlmsg_free(msg); |
| 10853 | } |
| 10854 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10855 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10856 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10857 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10858 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10859 | struct wiphy *wiphy = wdev->wiphy; |
| 10860 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10861 | struct sk_buff *msg; |
| 10862 | struct nlattr *pinfoattr; |
| 10863 | void *hdr; |
| 10864 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10865 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10866 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10867 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10868 | if (!msg) |
| 10869 | return; |
| 10870 | |
| 10871 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10872 | if (!hdr) { |
| 10873 | nlmsg_free(msg); |
| 10874 | return; |
| 10875 | } |
| 10876 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10877 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10878 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10879 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10880 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10881 | |
| 10882 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10883 | if (!pinfoattr) |
| 10884 | goto nla_put_failure; |
| 10885 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10886 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10887 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10888 | |
| 10889 | nla_nest_end(msg, pinfoattr); |
| 10890 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10891 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 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_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10902 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10903 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10904 | u64 cookie, bool acked, gfp_t gfp) |
| 10905 | { |
| 10906 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10907 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10908 | struct sk_buff *msg; |
| 10909 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10910 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10911 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10912 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10913 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10914 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10915 | if (!msg) |
| 10916 | return; |
| 10917 | |
| 10918 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10919 | if (!hdr) { |
| 10920 | nlmsg_free(msg); |
| 10921 | return; |
| 10922 | } |
| 10923 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10924 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10925 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10926 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10927 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10928 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10929 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10930 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10931 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10932 | |
| 10933 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10934 | nl80211_mlme_mcgrp.id, gfp); |
| 10935 | return; |
| 10936 | |
| 10937 | nla_put_failure: |
| 10938 | genlmsg_cancel(msg, hdr); |
| 10939 | nlmsg_free(msg); |
| 10940 | } |
| 10941 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 10942 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10943 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 10944 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10945 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10946 | { |
| 10947 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10948 | struct sk_buff *msg; |
| 10949 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10950 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10951 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10952 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 10953 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10954 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10955 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10956 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 10957 | if (!msg) { |
| 10958 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10959 | return; |
| 10960 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10961 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10962 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 10963 | if (!hdr) |
| 10964 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10965 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10966 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10967 | (freq && |
| 10968 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 10969 | (sig_dbm && |
| 10970 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 10971 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 10972 | goto nla_put_failure; |
| 10973 | |
| 10974 | genlmsg_end(msg, hdr); |
| 10975 | |
| 10976 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10977 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10978 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10979 | return; |
| 10980 | |
| 10981 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10982 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10983 | if (hdr) |
| 10984 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10985 | nlmsg_free(msg); |
| 10986 | } |
| 10987 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 10988 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10989 | #ifdef CONFIG_PM |
| 10990 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 10991 | struct cfg80211_wowlan_wakeup *wakeup, |
| 10992 | gfp_t gfp) |
| 10993 | { |
| 10994 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10995 | struct sk_buff *msg; |
| 10996 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10997 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10998 | |
| 10999 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11000 | |
| 11001 | if (wakeup) |
| 11002 | size += wakeup->packet_present_len; |
| 11003 | |
| 11004 | msg = nlmsg_new(size, gfp); |
| 11005 | if (!msg) |
| 11006 | return; |
| 11007 | |
| 11008 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11009 | if (!hdr) |
| 11010 | goto free_msg; |
| 11011 | |
| 11012 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11013 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11014 | goto free_msg; |
| 11015 | |
| 11016 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11017 | wdev->netdev->ifindex)) |
| 11018 | goto free_msg; |
| 11019 | |
| 11020 | if (wakeup) { |
| 11021 | struct nlattr *reasons; |
| 11022 | |
| 11023 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 11024 | |
| 11025 | if (wakeup->disconnect && |
| 11026 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11027 | goto free_msg; |
| 11028 | if (wakeup->magic_pkt && |
| 11029 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11030 | goto free_msg; |
| 11031 | if (wakeup->gtk_rekey_failure && |
| 11032 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11033 | goto free_msg; |
| 11034 | if (wakeup->eap_identity_req && |
| 11035 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11036 | goto free_msg; |
| 11037 | if (wakeup->four_way_handshake && |
| 11038 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11039 | goto free_msg; |
| 11040 | if (wakeup->rfkill_release && |
| 11041 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11042 | goto free_msg; |
| 11043 | |
| 11044 | if (wakeup->pattern_idx >= 0 && |
| 11045 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11046 | wakeup->pattern_idx)) |
| 11047 | goto free_msg; |
| 11048 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11049 | if (wakeup->tcp_match) |
| 11050 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 11051 | |
| 11052 | if (wakeup->tcp_connlost) |
| 11053 | nla_put_flag(msg, |
| 11054 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 11055 | |
| 11056 | if (wakeup->tcp_nomoretokens) |
| 11057 | nla_put_flag(msg, |
| 11058 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 11059 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11060 | if (wakeup->packet) { |
| 11061 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11062 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11063 | |
| 11064 | if (!wakeup->packet_80211) { |
| 11065 | pkt_attr = |
| 11066 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11067 | len_attr = |
| 11068 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11069 | } |
| 11070 | |
| 11071 | if (wakeup->packet_len && |
| 11072 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11073 | goto free_msg; |
| 11074 | |
| 11075 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11076 | wakeup->packet)) |
| 11077 | goto free_msg; |
| 11078 | } |
| 11079 | |
| 11080 | nla_nest_end(msg, reasons); |
| 11081 | } |
| 11082 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11083 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11084 | |
| 11085 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11086 | nl80211_mlme_mcgrp.id, gfp); |
| 11087 | return; |
| 11088 | |
| 11089 | free_msg: |
| 11090 | nlmsg_free(msg); |
| 11091 | } |
| 11092 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11093 | #endif |
| 11094 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11095 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11096 | enum nl80211_tdls_operation oper, |
| 11097 | u16 reason_code, gfp_t gfp) |
| 11098 | { |
| 11099 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11100 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11101 | struct sk_buff *msg; |
| 11102 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11103 | |
| 11104 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11105 | reason_code); |
| 11106 | |
| 11107 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11108 | if (!msg) |
| 11109 | return; |
| 11110 | |
| 11111 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11112 | if (!hdr) { |
| 11113 | nlmsg_free(msg); |
| 11114 | return; |
| 11115 | } |
| 11116 | |
| 11117 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11118 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11119 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11120 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11121 | (reason_code > 0 && |
| 11122 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11123 | goto nla_put_failure; |
| 11124 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11125 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11126 | |
| 11127 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11128 | nl80211_mlme_mcgrp.id, gfp); |
| 11129 | return; |
| 11130 | |
| 11131 | nla_put_failure: |
| 11132 | genlmsg_cancel(msg, hdr); |
| 11133 | nlmsg_free(msg); |
| 11134 | } |
| 11135 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11136 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11137 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11138 | unsigned long state, |
| 11139 | void *_notify) |
| 11140 | { |
| 11141 | struct netlink_notify *notify = _notify; |
| 11142 | struct cfg80211_registered_device *rdev; |
| 11143 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11144 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11145 | |
| 11146 | if (state != NETLINK_URELEASE) |
| 11147 | return NOTIFY_DONE; |
| 11148 | |
| 11149 | rcu_read_lock(); |
| 11150 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11151 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11152 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11153 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11154 | |
| 11155 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11156 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11157 | list) { |
| 11158 | if (reg->nlportid == notify->portid) { |
| 11159 | list_del(®->list); |
| 11160 | kfree(reg); |
| 11161 | break; |
| 11162 | } |
| 11163 | } |
| 11164 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11165 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11166 | |
| 11167 | rcu_read_unlock(); |
| 11168 | |
| 11169 | return NOTIFY_DONE; |
| 11170 | } |
| 11171 | |
| 11172 | static struct notifier_block nl80211_netlink_notifier = { |
| 11173 | .notifier_call = nl80211_netlink_notify, |
| 11174 | }; |
| 11175 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11176 | void cfg80211_ft_event(struct net_device *netdev, |
| 11177 | struct cfg80211_ft_event_params *ft_event) |
| 11178 | { |
| 11179 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11180 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11181 | struct sk_buff *msg; |
| 11182 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11183 | |
| 11184 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11185 | |
| 11186 | if (!ft_event->target_ap) |
| 11187 | return; |
| 11188 | |
| 11189 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11190 | if (!msg) |
| 11191 | return; |
| 11192 | |
| 11193 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 11194 | if (!hdr) { |
| 11195 | nlmsg_free(msg); |
| 11196 | return; |
| 11197 | } |
| 11198 | |
| 11199 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 11200 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 11201 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 11202 | if (ft_event->ies) |
| 11203 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 11204 | if (ft_event->ric_ies) |
| 11205 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11206 | ft_event->ric_ies); |
| 11207 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11208 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11209 | |
| 11210 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11211 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 11212 | } |
| 11213 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11214 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11215 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11216 | { |
| 11217 | struct cfg80211_registered_device *rdev; |
| 11218 | struct sk_buff *msg; |
| 11219 | void *hdr; |
| 11220 | u32 nlportid; |
| 11221 | |
| 11222 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11223 | if (!rdev->crit_proto_nlportid) |
| 11224 | return; |
| 11225 | |
| 11226 | nlportid = rdev->crit_proto_nlportid; |
| 11227 | rdev->crit_proto_nlportid = 0; |
| 11228 | |
| 11229 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11230 | if (!msg) |
| 11231 | return; |
| 11232 | |
| 11233 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11234 | if (!hdr) |
| 11235 | goto nla_put_failure; |
| 11236 | |
| 11237 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11238 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11239 | goto nla_put_failure; |
| 11240 | |
| 11241 | genlmsg_end(msg, hdr); |
| 11242 | |
| 11243 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11244 | return; |
| 11245 | |
| 11246 | nla_put_failure: |
| 11247 | if (hdr) |
| 11248 | genlmsg_cancel(msg, hdr); |
| 11249 | nlmsg_free(msg); |
| 11250 | |
| 11251 | } |
| 11252 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11253 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11254 | /* initialisation/exit functions */ |
| 11255 | |
| 11256 | int nl80211_init(void) |
| 11257 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11258 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11259 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11260 | err = genl_register_family_with_ops(&nl80211_fam, |
| 11261 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11262 | if (err) |
| 11263 | return err; |
| 11264 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11265 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 11266 | if (err) |
| 11267 | goto err_out; |
| 11268 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11269 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 11270 | if (err) |
| 11271 | goto err_out; |
| 11272 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11273 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 11274 | if (err) |
| 11275 | goto err_out; |
| 11276 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11277 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 11278 | if (err) |
| 11279 | goto err_out; |
| 11280 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11281 | #ifdef CONFIG_NL80211_TESTMODE |
| 11282 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 11283 | if (err) |
| 11284 | goto err_out; |
| 11285 | #endif |
| 11286 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11287 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11288 | if (err) |
| 11289 | goto err_out; |
| 11290 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11291 | return 0; |
| 11292 | err_out: |
| 11293 | genl_unregister_family(&nl80211_fam); |
| 11294 | return err; |
| 11295 | } |
| 11296 | |
| 11297 | void nl80211_exit(void) |
| 11298 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11299 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11300 | genl_unregister_family(&nl80211_fam); |
| 11301 | } |