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 | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 253 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 254 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 255 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 256 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 257 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 258 | |
| 259 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 260 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 263 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 264 | |
| 265 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 266 | .len = IEEE80211_MAX_SSID_LEN }, |
| 267 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 268 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 270 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 271 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 272 | [NL80211_ATTR_STA_FLAGS2] = { |
| 273 | .len = sizeof(struct nl80211_sta_flag_update), |
| 274 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 275 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 276 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 277 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 278 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 279 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 280 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 281 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 283 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 284 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 285 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 286 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 287 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 289 | .len = IEEE80211_MAX_DATA_LEN }, |
| 290 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 291 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 292 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 294 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 296 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 298 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 300 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 303 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 304 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 308 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 309 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 310 | .len = IEEE80211_MAX_DATA_LEN }, |
| 311 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 312 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 313 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 315 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 317 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 318 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 319 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 320 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 323 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 324 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 325 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 326 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 327 | .len = NL80211_HT_CAPABILITY_LEN |
| 328 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 329 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 330 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 331 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 333 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 335 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 336 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 337 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 339 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 340 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 342 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 343 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 347 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 348 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 349 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 350 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 351 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 352 | }; |
| 353 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 354 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 355 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 356 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 357 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 358 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 359 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 360 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 361 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 362 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 363 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 364 | }; |
| 365 | |
| 366 | /* policy for the key default flags */ |
| 367 | static const struct nla_policy |
| 368 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 369 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 370 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 371 | }; |
| 372 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 373 | /* policy for WoWLAN attributes */ |
| 374 | static const struct nla_policy |
| 375 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 376 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 377 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 378 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 379 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 380 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 381 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 382 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 383 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 384 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 385 | }; |
| 386 | |
| 387 | static const struct nla_policy |
| 388 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 389 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 390 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 391 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 392 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 393 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 394 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 395 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 396 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 397 | }, |
| 398 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 399 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 400 | }, |
| 401 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 402 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 403 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 404 | }; |
| 405 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 406 | /* policy for GTK rekey offload attributes */ |
| 407 | static const struct nla_policy |
| 408 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 409 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 410 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 411 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 412 | }; |
| 413 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 414 | static const struct nla_policy |
| 415 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 416 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 417 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 418 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 419 | }; |
| 420 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 421 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 422 | struct netlink_callback *cb, |
| 423 | struct cfg80211_registered_device **rdev, |
| 424 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 425 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 426 | int err; |
| 427 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 428 | rtnl_lock(); |
| 429 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 430 | if (!cb->args[0]) { |
| 431 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 432 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 433 | nl80211_policy); |
| 434 | if (err) |
| 435 | goto out_unlock; |
| 436 | |
| 437 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 438 | nl80211_fam.attrbuf); |
| 439 | if (IS_ERR(*wdev)) { |
| 440 | err = PTR_ERR(*wdev); |
| 441 | goto out_unlock; |
| 442 | } |
| 443 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
| 444 | cb->args[0] = (*rdev)->wiphy_idx; |
| 445 | cb->args[1] = (*wdev)->identifier; |
| 446 | } else { |
| 447 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]); |
| 448 | struct wireless_dev *tmp; |
| 449 | |
| 450 | if (!wiphy) { |
| 451 | err = -ENODEV; |
| 452 | goto out_unlock; |
| 453 | } |
| 454 | *rdev = wiphy_to_dev(wiphy); |
| 455 | *wdev = NULL; |
| 456 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 457 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 458 | if (tmp->identifier == cb->args[1]) { |
| 459 | *wdev = tmp; |
| 460 | break; |
| 461 | } |
| 462 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 463 | |
| 464 | if (!*wdev) { |
| 465 | err = -ENODEV; |
| 466 | goto out_unlock; |
| 467 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 468 | } |
| 469 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 470 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 471 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 472 | rtnl_unlock(); |
| 473 | return err; |
| 474 | } |
| 475 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 476 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 477 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 478 | rtnl_unlock(); |
| 479 | } |
| 480 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 481 | /* IE validation */ |
| 482 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 483 | { |
| 484 | const u8 *pos; |
| 485 | int len; |
| 486 | |
| 487 | if (!attr) |
| 488 | return true; |
| 489 | |
| 490 | pos = nla_data(attr); |
| 491 | len = nla_len(attr); |
| 492 | |
| 493 | while (len) { |
| 494 | u8 elemlen; |
| 495 | |
| 496 | if (len < 2) |
| 497 | return false; |
| 498 | len -= 2; |
| 499 | |
| 500 | elemlen = pos[1]; |
| 501 | if (elemlen > len) |
| 502 | return false; |
| 503 | |
| 504 | len -= elemlen; |
| 505 | pos += 2 + elemlen; |
| 506 | } |
| 507 | |
| 508 | return true; |
| 509 | } |
| 510 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 511 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 512 | 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] | 513 | int flags, u8 cmd) |
| 514 | { |
| 515 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 516 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 517 | } |
| 518 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 519 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 520 | struct ieee80211_channel *chan, |
| 521 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 522 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 523 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 524 | chan->center_freq)) |
| 525 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 526 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 527 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 528 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 529 | goto nla_put_failure; |
| 530 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 531 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 532 | goto nla_put_failure; |
| 533 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 534 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 535 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 536 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 537 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 538 | goto nla_put_failure; |
| 539 | if (large) { |
| 540 | u32 time; |
| 541 | |
| 542 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 543 | |
| 544 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 545 | chan->dfs_state)) |
| 546 | goto nla_put_failure; |
| 547 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 548 | time)) |
| 549 | goto nla_put_failure; |
| 550 | } |
| 551 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 552 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 553 | if (large) { |
| 554 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 555 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 556 | goto nla_put_failure; |
| 557 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 558 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 559 | goto nla_put_failure; |
| 560 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 561 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 562 | goto nla_put_failure; |
| 563 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 564 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 565 | goto nla_put_failure; |
| 566 | } |
| 567 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 568 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 569 | DBM_TO_MBM(chan->max_power))) |
| 570 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 571 | |
| 572 | return 0; |
| 573 | |
| 574 | nla_put_failure: |
| 575 | return -ENOBUFS; |
| 576 | } |
| 577 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 578 | /* netlink command implementations */ |
| 579 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 580 | struct key_parse { |
| 581 | struct key_params p; |
| 582 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 583 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 584 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 585 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 586 | }; |
| 587 | |
| 588 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 589 | { |
| 590 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 591 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 592 | nl80211_key_policy); |
| 593 | if (err) |
| 594 | return err; |
| 595 | |
| 596 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 597 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 598 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 599 | if (k->def) { |
| 600 | k->def_uni = true; |
| 601 | k->def_multi = true; |
| 602 | } |
| 603 | if (k->defmgmt) |
| 604 | k->def_multi = true; |
| 605 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 606 | if (tb[NL80211_KEY_IDX]) |
| 607 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 608 | |
| 609 | if (tb[NL80211_KEY_DATA]) { |
| 610 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 611 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 612 | } |
| 613 | |
| 614 | if (tb[NL80211_KEY_SEQ]) { |
| 615 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 616 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 617 | } |
| 618 | |
| 619 | if (tb[NL80211_KEY_CIPHER]) |
| 620 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 621 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 622 | if (tb[NL80211_KEY_TYPE]) { |
| 623 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 624 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 625 | return -EINVAL; |
| 626 | } |
| 627 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 628 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 629 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 630 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 631 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 632 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 633 | if (err) |
| 634 | return err; |
| 635 | |
| 636 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 637 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 638 | } |
| 639 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 644 | { |
| 645 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 646 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 647 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 648 | } |
| 649 | |
| 650 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 651 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 652 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 653 | } |
| 654 | |
| 655 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 656 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 657 | |
| 658 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 659 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 660 | |
| 661 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 662 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 663 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 664 | if (k->def) { |
| 665 | k->def_uni = true; |
| 666 | k->def_multi = true; |
| 667 | } |
| 668 | if (k->defmgmt) |
| 669 | k->def_multi = true; |
| 670 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 671 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 672 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 673 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 674 | return -EINVAL; |
| 675 | } |
| 676 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 677 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 678 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 679 | int err = nla_parse_nested( |
| 680 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 681 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 682 | nl80211_key_default_policy); |
| 683 | if (err) |
| 684 | return err; |
| 685 | |
| 686 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 687 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 688 | } |
| 689 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 694 | { |
| 695 | int err; |
| 696 | |
| 697 | memset(k, 0, sizeof(*k)); |
| 698 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 699 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 700 | |
| 701 | if (info->attrs[NL80211_ATTR_KEY]) |
| 702 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 703 | else |
| 704 | err = nl80211_parse_key_old(info, k); |
| 705 | |
| 706 | if (err) |
| 707 | return err; |
| 708 | |
| 709 | if (k->def && k->defmgmt) |
| 710 | return -EINVAL; |
| 711 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 712 | if (k->defmgmt) { |
| 713 | if (k->def_uni || !k->def_multi) |
| 714 | return -EINVAL; |
| 715 | } |
| 716 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 717 | if (k->idx != -1) { |
| 718 | if (k->defmgmt) { |
| 719 | if (k->idx < 4 || k->idx > 5) |
| 720 | return -EINVAL; |
| 721 | } else if (k->def) { |
| 722 | if (k->idx < 0 || k->idx > 3) |
| 723 | return -EINVAL; |
| 724 | } else { |
| 725 | if (k->idx < 0 || k->idx > 5) |
| 726 | return -EINVAL; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 733 | static struct cfg80211_cached_keys * |
| 734 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 735 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 736 | { |
| 737 | struct key_parse parse; |
| 738 | struct nlattr *key; |
| 739 | struct cfg80211_cached_keys *result; |
| 740 | int rem, err, def = 0; |
| 741 | |
| 742 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 743 | if (!result) |
| 744 | return ERR_PTR(-ENOMEM); |
| 745 | |
| 746 | result->def = -1; |
| 747 | result->defmgmt = -1; |
| 748 | |
| 749 | nla_for_each_nested(key, keys, rem) { |
| 750 | memset(&parse, 0, sizeof(parse)); |
| 751 | parse.idx = -1; |
| 752 | |
| 753 | err = nl80211_parse_key_new(key, &parse); |
| 754 | if (err) |
| 755 | goto error; |
| 756 | err = -EINVAL; |
| 757 | if (!parse.p.key) |
| 758 | goto error; |
| 759 | if (parse.idx < 0 || parse.idx > 4) |
| 760 | goto error; |
| 761 | if (parse.def) { |
| 762 | if (def) |
| 763 | goto error; |
| 764 | def = 1; |
| 765 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 766 | if (!parse.def_uni || !parse.def_multi) |
| 767 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 768 | } else if (parse.defmgmt) |
| 769 | goto error; |
| 770 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 771 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 772 | if (err) |
| 773 | goto error; |
| 774 | result->params[parse.idx].cipher = parse.p.cipher; |
| 775 | result->params[parse.idx].key_len = parse.p.key_len; |
| 776 | result->params[parse.idx].key = result->data[parse.idx]; |
| 777 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 778 | |
| 779 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 780 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 781 | if (no_ht) |
| 782 | *no_ht = true; |
| 783 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | return result; |
| 787 | error: |
| 788 | kfree(result); |
| 789 | return ERR_PTR(err); |
| 790 | } |
| 791 | |
| 792 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 793 | { |
| 794 | ASSERT_WDEV_LOCK(wdev); |
| 795 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 796 | switch (wdev->iftype) { |
| 797 | case NL80211_IFTYPE_AP: |
| 798 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 799 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 800 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 801 | break; |
| 802 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 803 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 804 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 805 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 806 | return -ENOLINK; |
| 807 | break; |
| 808 | default: |
| 809 | return -EINVAL; |
| 810 | } |
| 811 | |
| 812 | return 0; |
| 813 | } |
| 814 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 815 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 816 | { |
| 817 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 818 | int i; |
| 819 | |
| 820 | if (!nl_modes) |
| 821 | goto nla_put_failure; |
| 822 | |
| 823 | i = 0; |
| 824 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 825 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 826 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 827 | ifmodes >>= 1; |
| 828 | i++; |
| 829 | } |
| 830 | |
| 831 | nla_nest_end(msg, nl_modes); |
| 832 | return 0; |
| 833 | |
| 834 | nla_put_failure: |
| 835 | return -ENOBUFS; |
| 836 | } |
| 837 | |
| 838 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 839 | struct sk_buff *msg, |
| 840 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 841 | { |
| 842 | struct nlattr *nl_combis; |
| 843 | int i, j; |
| 844 | |
| 845 | nl_combis = nla_nest_start(msg, |
| 846 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 847 | if (!nl_combis) |
| 848 | goto nla_put_failure; |
| 849 | |
| 850 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 851 | const struct ieee80211_iface_combination *c; |
| 852 | struct nlattr *nl_combi, *nl_limits; |
| 853 | |
| 854 | c = &wiphy->iface_combinations[i]; |
| 855 | |
| 856 | nl_combi = nla_nest_start(msg, i + 1); |
| 857 | if (!nl_combi) |
| 858 | goto nla_put_failure; |
| 859 | |
| 860 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 861 | if (!nl_limits) |
| 862 | goto nla_put_failure; |
| 863 | |
| 864 | for (j = 0; j < c->n_limits; j++) { |
| 865 | struct nlattr *nl_limit; |
| 866 | |
| 867 | nl_limit = nla_nest_start(msg, j + 1); |
| 868 | if (!nl_limit) |
| 869 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 870 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 871 | c->limits[j].max)) |
| 872 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 873 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 874 | c->limits[j].types)) |
| 875 | goto nla_put_failure; |
| 876 | nla_nest_end(msg, nl_limit); |
| 877 | } |
| 878 | |
| 879 | nla_nest_end(msg, nl_limits); |
| 880 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 881 | if (c->beacon_int_infra_match && |
| 882 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 883 | goto nla_put_failure; |
| 884 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 885 | c->num_different_channels) || |
| 886 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 887 | c->max_interfaces)) |
| 888 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 889 | if (large && |
| 890 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 891 | c->radar_detect_widths)) |
| 892 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 893 | |
| 894 | nla_nest_end(msg, nl_combi); |
| 895 | } |
| 896 | |
| 897 | nla_nest_end(msg, nl_combis); |
| 898 | |
| 899 | return 0; |
| 900 | nla_put_failure: |
| 901 | return -ENOBUFS; |
| 902 | } |
| 903 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 904 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 905 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 906 | struct sk_buff *msg) |
| 907 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 908 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 909 | struct nlattr *nl_tcp; |
| 910 | |
| 911 | if (!tcp) |
| 912 | return 0; |
| 913 | |
| 914 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 915 | if (!nl_tcp) |
| 916 | return -ENOBUFS; |
| 917 | |
| 918 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 919 | tcp->data_payload_max)) |
| 920 | return -ENOBUFS; |
| 921 | |
| 922 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 923 | tcp->data_payload_max)) |
| 924 | return -ENOBUFS; |
| 925 | |
| 926 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 927 | return -ENOBUFS; |
| 928 | |
| 929 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 930 | sizeof(*tcp->tok), tcp->tok)) |
| 931 | return -ENOBUFS; |
| 932 | |
| 933 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 934 | tcp->data_interval_max)) |
| 935 | return -ENOBUFS; |
| 936 | |
| 937 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 938 | tcp->wake_payload_max)) |
| 939 | return -ENOBUFS; |
| 940 | |
| 941 | nla_nest_end(msg, nl_tcp); |
| 942 | return 0; |
| 943 | } |
| 944 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 945 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 946 | struct cfg80211_registered_device *dev, |
| 947 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 948 | { |
| 949 | struct nlattr *nl_wowlan; |
| 950 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 951 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 952 | return 0; |
| 953 | |
| 954 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 955 | if (!nl_wowlan) |
| 956 | return -ENOBUFS; |
| 957 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 958 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 959 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 960 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 961 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 962 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 963 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 964 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 965 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 966 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 967 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 968 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 969 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 970 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 971 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 972 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 973 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 974 | return -ENOBUFS; |
| 975 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 976 | if (dev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame^] | 977 | struct nl80211_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 978 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 979 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 980 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 981 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 982 | }; |
| 983 | |
| 984 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 985 | sizeof(pat), &pat)) |
| 986 | return -ENOBUFS; |
| 987 | } |
| 988 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 989 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 990 | return -ENOBUFS; |
| 991 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 992 | nla_nest_end(msg, nl_wowlan); |
| 993 | |
| 994 | return 0; |
| 995 | } |
| 996 | #endif |
| 997 | |
| 998 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 999 | struct ieee80211_supported_band *sband) |
| 1000 | { |
| 1001 | struct nlattr *nl_rates, *nl_rate; |
| 1002 | struct ieee80211_rate *rate; |
| 1003 | int i; |
| 1004 | |
| 1005 | /* add HT info */ |
| 1006 | if (sband->ht_cap.ht_supported && |
| 1007 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1008 | sizeof(sband->ht_cap.mcs), |
| 1009 | &sband->ht_cap.mcs) || |
| 1010 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1011 | sband->ht_cap.cap) || |
| 1012 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1013 | sband->ht_cap.ampdu_factor) || |
| 1014 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1015 | sband->ht_cap.ampdu_density))) |
| 1016 | return -ENOBUFS; |
| 1017 | |
| 1018 | /* add VHT info */ |
| 1019 | if (sband->vht_cap.vht_supported && |
| 1020 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1021 | sizeof(sband->vht_cap.vht_mcs), |
| 1022 | &sband->vht_cap.vht_mcs) || |
| 1023 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1024 | sband->vht_cap.cap))) |
| 1025 | return -ENOBUFS; |
| 1026 | |
| 1027 | /* add bitrates */ |
| 1028 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1029 | if (!nl_rates) |
| 1030 | return -ENOBUFS; |
| 1031 | |
| 1032 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1033 | nl_rate = nla_nest_start(msg, i); |
| 1034 | if (!nl_rate) |
| 1035 | return -ENOBUFS; |
| 1036 | |
| 1037 | rate = &sband->bitrates[i]; |
| 1038 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1039 | rate->bitrate)) |
| 1040 | return -ENOBUFS; |
| 1041 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1042 | nla_put_flag(msg, |
| 1043 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1044 | return -ENOBUFS; |
| 1045 | |
| 1046 | nla_nest_end(msg, nl_rate); |
| 1047 | } |
| 1048 | |
| 1049 | nla_nest_end(msg, nl_rates); |
| 1050 | |
| 1051 | return 0; |
| 1052 | } |
| 1053 | |
| 1054 | static int |
| 1055 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1056 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1057 | { |
| 1058 | u16 stypes; |
| 1059 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1060 | enum nl80211_iftype ift; |
| 1061 | int i; |
| 1062 | |
| 1063 | if (!mgmt_stypes) |
| 1064 | return 0; |
| 1065 | |
| 1066 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1067 | if (!nl_ifs) |
| 1068 | return -ENOBUFS; |
| 1069 | |
| 1070 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1071 | nl_ftypes = nla_nest_start(msg, ift); |
| 1072 | if (!nl_ftypes) |
| 1073 | return -ENOBUFS; |
| 1074 | i = 0; |
| 1075 | stypes = mgmt_stypes[ift].tx; |
| 1076 | while (stypes) { |
| 1077 | if ((stypes & 1) && |
| 1078 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1079 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1080 | return -ENOBUFS; |
| 1081 | stypes >>= 1; |
| 1082 | i++; |
| 1083 | } |
| 1084 | nla_nest_end(msg, nl_ftypes); |
| 1085 | } |
| 1086 | |
| 1087 | nla_nest_end(msg, nl_ifs); |
| 1088 | |
| 1089 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1090 | if (!nl_ifs) |
| 1091 | return -ENOBUFS; |
| 1092 | |
| 1093 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1094 | nl_ftypes = nla_nest_start(msg, ift); |
| 1095 | if (!nl_ftypes) |
| 1096 | return -ENOBUFS; |
| 1097 | i = 0; |
| 1098 | stypes = mgmt_stypes[ift].rx; |
| 1099 | while (stypes) { |
| 1100 | if ((stypes & 1) && |
| 1101 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1102 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1103 | return -ENOBUFS; |
| 1104 | stypes >>= 1; |
| 1105 | i++; |
| 1106 | } |
| 1107 | nla_nest_end(msg, nl_ftypes); |
| 1108 | } |
| 1109 | nla_nest_end(msg, nl_ifs); |
| 1110 | |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1114 | struct nl80211_dump_wiphy_state { |
| 1115 | s64 filter_wiphy; |
| 1116 | long start; |
| 1117 | long split_start, band_start, chan_start; |
| 1118 | bool split; |
| 1119 | }; |
| 1120 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1121 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1122 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1123 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1124 | { |
| 1125 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1126 | struct nlattr *nl_bands, *nl_band; |
| 1127 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1128 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1129 | enum ieee80211_band band; |
| 1130 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1131 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1132 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1133 | dev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1134 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1135 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1136 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1137 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1138 | return -ENOBUFS; |
| 1139 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1140 | if (WARN_ON(!state)) |
| 1141 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1142 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1143 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1144 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1145 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1146 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1147 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1148 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1149 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1150 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1151 | case 0: |
| 1152 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1153 | dev->wiphy.retry_short) || |
| 1154 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1155 | dev->wiphy.retry_long) || |
| 1156 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1157 | dev->wiphy.frag_threshold) || |
| 1158 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1159 | dev->wiphy.rts_threshold) || |
| 1160 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1161 | dev->wiphy.coverage_class) || |
| 1162 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1163 | dev->wiphy.max_scan_ssids) || |
| 1164 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1165 | dev->wiphy.max_sched_scan_ssids) || |
| 1166 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1167 | dev->wiphy.max_scan_ie_len) || |
| 1168 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1169 | dev->wiphy.max_sched_scan_ie_len) || |
| 1170 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1171 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1172 | goto nla_put_failure; |
| 1173 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1174 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1175 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1176 | goto nla_put_failure; |
| 1177 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1178 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1179 | goto nla_put_failure; |
| 1180 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1181 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1182 | goto nla_put_failure; |
| 1183 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1184 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1185 | goto nla_put_failure; |
| 1186 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1187 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1188 | goto nla_put_failure; |
| 1189 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1190 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1191 | goto nla_put_failure; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1192 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1193 | nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1194 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1195 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1196 | state->split_start++; |
| 1197 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1198 | break; |
| 1199 | case 1: |
| 1200 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1201 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1202 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1203 | goto nla_put_failure; |
| 1204 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1205 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1206 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1207 | goto nla_put_failure; |
| 1208 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1209 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1210 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1211 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1212 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1213 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1214 | dev->wiphy.available_antennas_tx) || |
| 1215 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1216 | dev->wiphy.available_antennas_rx)) |
| 1217 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1218 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1219 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1220 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1221 | dev->wiphy.probe_resp_offload)) |
| 1222 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1223 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1224 | if ((dev->wiphy.available_antennas_tx || |
| 1225 | dev->wiphy.available_antennas_rx) && |
| 1226 | dev->ops->get_antenna) { |
| 1227 | u32 tx_ant = 0, rx_ant = 0; |
| 1228 | int res; |
| 1229 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1230 | if (!res) { |
| 1231 | if (nla_put_u32(msg, |
| 1232 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1233 | tx_ant) || |
| 1234 | nla_put_u32(msg, |
| 1235 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1236 | rx_ant)) |
| 1237 | goto nla_put_failure; |
| 1238 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1239 | } |
| 1240 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1241 | state->split_start++; |
| 1242 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1243 | break; |
| 1244 | case 2: |
| 1245 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1246 | dev->wiphy.interface_modes)) |
| 1247 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1248 | state->split_start++; |
| 1249 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1250 | break; |
| 1251 | case 3: |
| 1252 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1253 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1254 | goto nla_put_failure; |
| 1255 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1256 | for (band = state->band_start; |
| 1257 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1258 | struct ieee80211_supported_band *sband; |
| 1259 | |
| 1260 | sband = dev->wiphy.bands[band]; |
| 1261 | |
| 1262 | if (!sband) |
| 1263 | continue; |
| 1264 | |
| 1265 | nl_band = nla_nest_start(msg, band); |
| 1266 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1267 | goto nla_put_failure; |
| 1268 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1269 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1270 | case 0: |
| 1271 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1272 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1273 | state->chan_start++; |
| 1274 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1275 | break; |
| 1276 | default: |
| 1277 | /* add frequencies */ |
| 1278 | nl_freqs = nla_nest_start( |
| 1279 | msg, NL80211_BAND_ATTR_FREQS); |
| 1280 | if (!nl_freqs) |
| 1281 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1282 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1283 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1284 | i < sband->n_channels; |
| 1285 | i++) { |
| 1286 | nl_freq = nla_nest_start(msg, i); |
| 1287 | if (!nl_freq) |
| 1288 | goto nla_put_failure; |
| 1289 | |
| 1290 | chan = &sband->channels[i]; |
| 1291 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1292 | if (nl80211_msg_put_channel( |
| 1293 | msg, chan, |
| 1294 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1295 | goto nla_put_failure; |
| 1296 | |
| 1297 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1298 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1299 | break; |
| 1300 | } |
| 1301 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1302 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1303 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1304 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1305 | nla_nest_end(msg, nl_freqs); |
| 1306 | } |
| 1307 | |
| 1308 | nla_nest_end(msg, nl_band); |
| 1309 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1310 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1311 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1312 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1313 | band--; |
| 1314 | break; |
| 1315 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1316 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1317 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1318 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1319 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1320 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1321 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1322 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1323 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1324 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1325 | if (state->band_start == 0 && state->chan_start == 0) |
| 1326 | state->split_start++; |
| 1327 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1328 | break; |
| 1329 | case 4: |
| 1330 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1331 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1332 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1333 | |
| 1334 | i = 0; |
| 1335 | #define CMD(op, n) \ |
| 1336 | do { \ |
| 1337 | if (dev->ops->op) { \ |
| 1338 | i++; \ |
| 1339 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1340 | goto nla_put_failure; \ |
| 1341 | } \ |
| 1342 | } while (0) |
| 1343 | |
| 1344 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1345 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1346 | CMD(add_key, NEW_KEY); |
| 1347 | CMD(start_ap, START_AP); |
| 1348 | CMD(add_station, NEW_STATION); |
| 1349 | CMD(add_mpath, NEW_MPATH); |
| 1350 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1351 | CMD(change_bss, SET_BSS); |
| 1352 | CMD(auth, AUTHENTICATE); |
| 1353 | CMD(assoc, ASSOCIATE); |
| 1354 | CMD(deauth, DEAUTHENTICATE); |
| 1355 | CMD(disassoc, DISASSOCIATE); |
| 1356 | CMD(join_ibss, JOIN_IBSS); |
| 1357 | CMD(join_mesh, JOIN_MESH); |
| 1358 | CMD(set_pmksa, SET_PMKSA); |
| 1359 | CMD(del_pmksa, DEL_PMKSA); |
| 1360 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1361 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1362 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1363 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1364 | CMD(mgmt_tx, FRAME); |
| 1365 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1366 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1367 | i++; |
| 1368 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1369 | goto nla_put_failure; |
| 1370 | } |
| 1371 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1372 | dev->ops->join_mesh) { |
| 1373 | i++; |
| 1374 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1375 | goto nla_put_failure; |
| 1376 | } |
| 1377 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1378 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1379 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1380 | CMD(tdls_oper, TDLS_OPER); |
| 1381 | } |
| 1382 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1383 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1384 | CMD(probe_client, PROBE_CLIENT); |
| 1385 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1386 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1387 | i++; |
| 1388 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1389 | goto nla_put_failure; |
| 1390 | } |
| 1391 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1392 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1393 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1394 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1395 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
| 1396 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1397 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1398 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1399 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1400 | #endif |
| 1401 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1402 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1403 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1404 | if (dev->ops->connect || dev->ops->auth) { |
| 1405 | i++; |
| 1406 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1407 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1408 | } |
| 1409 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1410 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1411 | i++; |
| 1412 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1413 | goto nla_put_failure; |
| 1414 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1415 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1416 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1417 | state->split_start++; |
| 1418 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1419 | break; |
| 1420 | case 5: |
| 1421 | if (dev->ops->remain_on_channel && |
| 1422 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1423 | nla_put_u32(msg, |
| 1424 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1425 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1426 | goto nla_put_failure; |
| 1427 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1428 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1429 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1430 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1431 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1432 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1433 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1434 | state->split_start++; |
| 1435 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1436 | break; |
| 1437 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1438 | #ifdef CONFIG_PM |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1439 | if (nl80211_send_wowlan(msg, dev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1440 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1441 | state->split_start++; |
| 1442 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1443 | break; |
| 1444 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1445 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1446 | #endif |
| 1447 | case 7: |
| 1448 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1449 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1450 | goto nla_put_failure; |
| 1451 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1452 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
| 1453 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1454 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1455 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1456 | state->split_start++; |
| 1457 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1458 | break; |
| 1459 | case 8: |
| 1460 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1461 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1462 | dev->wiphy.ap_sme_capa)) |
| 1463 | goto nla_put_failure; |
| 1464 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1465 | features = dev->wiphy.features; |
| 1466 | /* |
| 1467 | * We can only add the per-channel limit information if the |
| 1468 | * dump is split, otherwise it makes it too big. Therefore |
| 1469 | * only advertise it in that case. |
| 1470 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1471 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1472 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1473 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1474 | goto nla_put_failure; |
| 1475 | |
| 1476 | if (dev->wiphy.ht_capa_mod_mask && |
| 1477 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1478 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1479 | dev->wiphy.ht_capa_mod_mask)) |
| 1480 | goto nla_put_failure; |
| 1481 | |
| 1482 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1483 | dev->wiphy.max_acl_mac_addrs && |
| 1484 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1485 | dev->wiphy.max_acl_mac_addrs)) |
| 1486 | goto nla_put_failure; |
| 1487 | |
| 1488 | /* |
| 1489 | * Any information below this point is only available to |
| 1490 | * applications that can deal with it being split. This |
| 1491 | * helps ensure that newly added capabilities don't break |
| 1492 | * older tools by overrunning their buffers. |
| 1493 | * |
| 1494 | * We still increment split_start so that in the split |
| 1495 | * case we'll continue with more data in the next round, |
| 1496 | * but break unconditionally so unsplit data stops here. |
| 1497 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1498 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1499 | break; |
| 1500 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1501 | if (dev->wiphy.extended_capabilities && |
| 1502 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1503 | dev->wiphy.extended_capabilities_len, |
| 1504 | dev->wiphy.extended_capabilities) || |
| 1505 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1506 | dev->wiphy.extended_capabilities_len, |
| 1507 | dev->wiphy.extended_capabilities_mask))) |
| 1508 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1509 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1510 | if (dev->wiphy.vht_capa_mod_mask && |
| 1511 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1512 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1513 | dev->wiphy.vht_capa_mod_mask)) |
| 1514 | goto nla_put_failure; |
| 1515 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1516 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1517 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1518 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1519 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1520 | return genlmsg_end(msg, hdr); |
| 1521 | |
| 1522 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1523 | genlmsg_cancel(msg, hdr); |
| 1524 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1525 | } |
| 1526 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1527 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1528 | struct netlink_callback *cb, |
| 1529 | struct nl80211_dump_wiphy_state *state) |
| 1530 | { |
| 1531 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1532 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1533 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1534 | /* ignore parse errors for backward compatibility */ |
| 1535 | if (ret) |
| 1536 | return 0; |
| 1537 | |
| 1538 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1539 | if (tb[NL80211_ATTR_WIPHY]) |
| 1540 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1541 | if (tb[NL80211_ATTR_WDEV]) |
| 1542 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1543 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1544 | struct net_device *netdev; |
| 1545 | struct cfg80211_registered_device *rdev; |
| 1546 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1547 | |
| 1548 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1549 | if (!netdev) |
| 1550 | return -ENODEV; |
| 1551 | if (netdev->ieee80211_ptr) { |
| 1552 | rdev = wiphy_to_dev( |
| 1553 | netdev->ieee80211_ptr->wiphy); |
| 1554 | state->filter_wiphy = rdev->wiphy_idx; |
| 1555 | } |
| 1556 | dev_put(netdev); |
| 1557 | } |
| 1558 | |
| 1559 | return 0; |
| 1560 | } |
| 1561 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1562 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1563 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1564 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1565 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1566 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1567 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1568 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1569 | if (!state) { |
| 1570 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1571 | if (!state) { |
| 1572 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1573 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1574 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1575 | state->filter_wiphy = -1; |
| 1576 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1577 | if (ret) { |
| 1578 | kfree(state); |
| 1579 | rtnl_unlock(); |
| 1580 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1581 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1582 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1583 | } |
| 1584 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1585 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1586 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1587 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1588 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1589 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1590 | if (state->filter_wiphy != -1 && |
| 1591 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1592 | continue; |
| 1593 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1594 | do { |
| 1595 | ret = nl80211_send_wiphy(dev, skb, |
| 1596 | NETLINK_CB(cb->skb).portid, |
| 1597 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1598 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1599 | if (ret < 0) { |
| 1600 | /* |
| 1601 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1602 | * or EMSGSIZE returned), this SKB is still |
| 1603 | * empty (so it's not too big because another |
| 1604 | * wiphy dataset is already in the skb) and |
| 1605 | * we've not tried to adjust the dump allocation |
| 1606 | * yet ... then adjust the alloc size to be |
| 1607 | * bigger, and return 1 but with the empty skb. |
| 1608 | * This results in an empty message being RX'ed |
| 1609 | * in userspace, but that is ignored. |
| 1610 | * |
| 1611 | * We can then retry with the larger buffer. |
| 1612 | */ |
| 1613 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1614 | !skb->len && |
| 1615 | cb->min_dump_alloc < 4096) { |
| 1616 | cb->min_dump_alloc = 4096; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1617 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1618 | return 1; |
| 1619 | } |
| 1620 | idx--; |
| 1621 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1622 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1623 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1624 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1625 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1626 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1627 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1628 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1629 | |
| 1630 | return skb->len; |
| 1631 | } |
| 1632 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1633 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1634 | { |
| 1635 | kfree((void *)cb->args[0]); |
| 1636 | return 0; |
| 1637 | } |
| 1638 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1639 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1640 | { |
| 1641 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1642 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1643 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1644 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1645 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1646 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1647 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1648 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1649 | 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] | 1650 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1651 | nlmsg_free(msg); |
| 1652 | return -ENOBUFS; |
| 1653 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1654 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1655 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1656 | } |
| 1657 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1658 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1659 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1660 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1661 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1662 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1663 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1664 | }; |
| 1665 | |
| 1666 | static int parse_txq_params(struct nlattr *tb[], |
| 1667 | struct ieee80211_txq_params *txq_params) |
| 1668 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1669 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1670 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1671 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1672 | return -EINVAL; |
| 1673 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1674 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1675 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1676 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1677 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1678 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1679 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1680 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1681 | return -EINVAL; |
| 1682 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1683 | return 0; |
| 1684 | } |
| 1685 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1686 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1687 | { |
| 1688 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1689 | * You can only set the channel explicitly for WDS interfaces, |
| 1690 | * all others have their channel managed via their respective |
| 1691 | * "establish a connection" command (connect, join, ...) |
| 1692 | * |
| 1693 | * For AP/GO and mesh mode, the channel can be set with the |
| 1694 | * channel userspace API, but is only stored and passed to the |
| 1695 | * low-level driver when the AP starts or the mesh is joined. |
| 1696 | * This is for backward compatibility, userspace can also give |
| 1697 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1698 | * |
| 1699 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1700 | * whatever else is going on, so they have their own special |
| 1701 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1702 | */ |
| 1703 | return !wdev || |
| 1704 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1705 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1706 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1707 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1708 | } |
| 1709 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1710 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1711 | struct genl_info *info, |
| 1712 | struct cfg80211_chan_def *chandef) |
| 1713 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1714 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1715 | |
| 1716 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1717 | return -EINVAL; |
| 1718 | |
| 1719 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1720 | |
| 1721 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1722 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1723 | chandef->center_freq1 = control_freq; |
| 1724 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1725 | |
| 1726 | /* Primary channel not allowed */ |
| 1727 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1728 | return -EINVAL; |
| 1729 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1730 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1731 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1732 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1733 | chantype = nla_get_u32( |
| 1734 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1735 | |
| 1736 | switch (chantype) { |
| 1737 | case NL80211_CHAN_NO_HT: |
| 1738 | case NL80211_CHAN_HT20: |
| 1739 | case NL80211_CHAN_HT40PLUS: |
| 1740 | case NL80211_CHAN_HT40MINUS: |
| 1741 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1742 | chantype); |
| 1743 | break; |
| 1744 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1745 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1746 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1747 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1748 | chandef->width = |
| 1749 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1750 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1751 | chandef->center_freq1 = |
| 1752 | nla_get_u32( |
| 1753 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1754 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1755 | chandef->center_freq2 = |
| 1756 | nla_get_u32( |
| 1757 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1758 | } |
| 1759 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1760 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1761 | return -EINVAL; |
| 1762 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1763 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1764 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1765 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1766 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1767 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1768 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1769 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1770 | return -EINVAL; |
| 1771 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1772 | return 0; |
| 1773 | } |
| 1774 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1775 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1776 | struct wireless_dev *wdev, |
| 1777 | struct genl_info *info) |
| 1778 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1779 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1780 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1781 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1782 | |
| 1783 | if (wdev) |
| 1784 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1785 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1786 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1787 | return -EOPNOTSUPP; |
| 1788 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1789 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1790 | if (result) |
| 1791 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1792 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1793 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1794 | case NL80211_IFTYPE_AP: |
| 1795 | case NL80211_IFTYPE_P2P_GO: |
| 1796 | if (wdev->beacon_interval) { |
| 1797 | result = -EBUSY; |
| 1798 | break; |
| 1799 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1800 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1801 | result = -EINVAL; |
| 1802 | break; |
| 1803 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1804 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1805 | result = 0; |
| 1806 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1807 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1808 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1809 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1810 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1811 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1812 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1813 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1814 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1815 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1816 | |
| 1817 | return result; |
| 1818 | } |
| 1819 | |
| 1820 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1821 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1823 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1824 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1825 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1826 | } |
| 1827 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1828 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1829 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1830 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1831 | struct net_device *dev = info->user_ptr[1]; |
| 1832 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1833 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1834 | |
| 1835 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1836 | return -EINVAL; |
| 1837 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1838 | if (netif_running(dev)) |
| 1839 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1840 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1841 | if (!rdev->ops->set_wds_peer) |
| 1842 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1843 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1844 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1845 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1846 | |
| 1847 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1848 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1852 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1853 | { |
| 1854 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1855 | struct net_device *netdev = NULL; |
| 1856 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1857 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1858 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1859 | u32 changed; |
| 1860 | u8 retry_short = 0, retry_long = 0; |
| 1861 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1862 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1863 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1864 | ASSERT_RTNL(); |
| 1865 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1866 | /* |
| 1867 | * Try to find the wiphy and netdev. Normally this |
| 1868 | * function shouldn't need the netdev, but this is |
| 1869 | * done for backward compatibility -- previously |
| 1870 | * setting the channel was done per wiphy, but now |
| 1871 | * it is per netdev. Previous userland like hostapd |
| 1872 | * also passed a netdev to set_wiphy, so that it is |
| 1873 | * possible to let that go to the right netdev! |
| 1874 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1875 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1876 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1877 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1878 | |
| 1879 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1880 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1881 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1882 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1883 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1884 | } |
| 1885 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1886 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1887 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1888 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1889 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1890 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1891 | wdev = NULL; |
| 1892 | netdev = NULL; |
| 1893 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1894 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1895 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1896 | |
| 1897 | /* |
| 1898 | * end workaround code, by now the rdev is available |
| 1899 | * and locked, and wdev may or may not be NULL. |
| 1900 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1901 | |
| 1902 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1903 | result = cfg80211_dev_rename( |
| 1904 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1905 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1906 | if (result) |
| 1907 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1908 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1909 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1910 | struct ieee80211_txq_params txq_params; |
| 1911 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1912 | |
| 1913 | if (!rdev->ops->set_txq_params) { |
| 1914 | result = -EOPNOTSUPP; |
| 1915 | goto bad_res; |
| 1916 | } |
| 1917 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1918 | if (!netdev) { |
| 1919 | result = -EINVAL; |
| 1920 | goto bad_res; |
| 1921 | } |
| 1922 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1923 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1924 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1925 | result = -EINVAL; |
| 1926 | goto bad_res; |
| 1927 | } |
| 1928 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1929 | if (!netif_running(netdev)) { |
| 1930 | result = -ENETDOWN; |
| 1931 | goto bad_res; |
| 1932 | } |
| 1933 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1934 | nla_for_each_nested(nl_txq_params, |
| 1935 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1936 | rem_txq_params) { |
| 1937 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1938 | nla_data(nl_txq_params), |
| 1939 | nla_len(nl_txq_params), |
| 1940 | txq_params_policy); |
| 1941 | result = parse_txq_params(tb, &txq_params); |
| 1942 | if (result) |
| 1943 | goto bad_res; |
| 1944 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1945 | result = rdev_set_txq_params(rdev, netdev, |
| 1946 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1947 | if (result) |
| 1948 | goto bad_res; |
| 1949 | } |
| 1950 | } |
| 1951 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1952 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1953 | result = __nl80211_set_channel(rdev, |
| 1954 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1955 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1956 | if (result) |
| 1957 | goto bad_res; |
| 1958 | } |
| 1959 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1960 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1961 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1962 | enum nl80211_tx_power_setting type; |
| 1963 | int idx, mbm = 0; |
| 1964 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1965 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1966 | txp_wdev = NULL; |
| 1967 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1968 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1969 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1970 | goto bad_res; |
| 1971 | } |
| 1972 | |
| 1973 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1974 | type = nla_get_u32(info->attrs[idx]); |
| 1975 | |
| 1976 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1977 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1978 | result = -EINVAL; |
| 1979 | goto bad_res; |
| 1980 | } |
| 1981 | |
| 1982 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1983 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1984 | mbm = nla_get_u32(info->attrs[idx]); |
| 1985 | } |
| 1986 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1987 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1988 | if (result) |
| 1989 | goto bad_res; |
| 1990 | } |
| 1991 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1992 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1993 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1994 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1995 | if ((!rdev->wiphy.available_antennas_tx && |
| 1996 | !rdev->wiphy.available_antennas_rx) || |
| 1997 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1998 | result = -EOPNOTSUPP; |
| 1999 | goto bad_res; |
| 2000 | } |
| 2001 | |
| 2002 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2003 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2004 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2005 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2006 | * available antenna masks, except for the "all" mask */ |
| 2007 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2008 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2009 | result = -EINVAL; |
| 2010 | goto bad_res; |
| 2011 | } |
| 2012 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2013 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2014 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2015 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2016 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2017 | if (result) |
| 2018 | goto bad_res; |
| 2019 | } |
| 2020 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2021 | changed = 0; |
| 2022 | |
| 2023 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2024 | retry_short = nla_get_u8( |
| 2025 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2026 | if (retry_short == 0) { |
| 2027 | result = -EINVAL; |
| 2028 | goto bad_res; |
| 2029 | } |
| 2030 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2031 | } |
| 2032 | |
| 2033 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2034 | retry_long = nla_get_u8( |
| 2035 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2036 | if (retry_long == 0) { |
| 2037 | result = -EINVAL; |
| 2038 | goto bad_res; |
| 2039 | } |
| 2040 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2041 | } |
| 2042 | |
| 2043 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2044 | frag_threshold = nla_get_u32( |
| 2045 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2046 | if (frag_threshold < 256) { |
| 2047 | result = -EINVAL; |
| 2048 | goto bad_res; |
| 2049 | } |
| 2050 | if (frag_threshold != (u32) -1) { |
| 2051 | /* |
| 2052 | * Fragments (apart from the last one) are required to |
| 2053 | * have even length. Make the fragmentation code |
| 2054 | * simpler by stripping LSB should someone try to use |
| 2055 | * odd threshold value. |
| 2056 | */ |
| 2057 | frag_threshold &= ~0x1; |
| 2058 | } |
| 2059 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2060 | } |
| 2061 | |
| 2062 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2063 | rts_threshold = nla_get_u32( |
| 2064 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2065 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2066 | } |
| 2067 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2068 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2069 | coverage_class = nla_get_u8( |
| 2070 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2071 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2072 | } |
| 2073 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2074 | if (changed) { |
| 2075 | u8 old_retry_short, old_retry_long; |
| 2076 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2077 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2078 | |
| 2079 | if (!rdev->ops->set_wiphy_params) { |
| 2080 | result = -EOPNOTSUPP; |
| 2081 | goto bad_res; |
| 2082 | } |
| 2083 | |
| 2084 | old_retry_short = rdev->wiphy.retry_short; |
| 2085 | old_retry_long = rdev->wiphy.retry_long; |
| 2086 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2087 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2088 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2089 | |
| 2090 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2091 | rdev->wiphy.retry_short = retry_short; |
| 2092 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2093 | rdev->wiphy.retry_long = retry_long; |
| 2094 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2095 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2096 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2097 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2098 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2099 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2100 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2101 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2102 | if (result) { |
| 2103 | rdev->wiphy.retry_short = old_retry_short; |
| 2104 | rdev->wiphy.retry_long = old_retry_long; |
| 2105 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2106 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2107 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2108 | } |
| 2109 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2110 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2111 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2112 | if (netdev) |
| 2113 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2114 | return result; |
| 2115 | } |
| 2116 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2117 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2118 | { |
| 2119 | return (u64)wdev->identifier | |
| 2120 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2121 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2122 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2123 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 2124 | struct cfg80211_chan_def *chandef) |
| 2125 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2126 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2127 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2128 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2129 | chandef->chan->center_freq)) |
| 2130 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2131 | switch (chandef->width) { |
| 2132 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2133 | case NL80211_CHAN_WIDTH_20: |
| 2134 | case NL80211_CHAN_WIDTH_40: |
| 2135 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2136 | cfg80211_get_chandef_type(chandef))) |
| 2137 | return -ENOBUFS; |
| 2138 | break; |
| 2139 | default: |
| 2140 | break; |
| 2141 | } |
| 2142 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2143 | return -ENOBUFS; |
| 2144 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2145 | return -ENOBUFS; |
| 2146 | if (chandef->center_freq2 && |
| 2147 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2148 | return -ENOBUFS; |
| 2149 | return 0; |
| 2150 | } |
| 2151 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2152 | 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] | 2153 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2154 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2155 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2156 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2157 | void *hdr; |
| 2158 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2159 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2160 | if (!hdr) |
| 2161 | return -1; |
| 2162 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2163 | if (dev && |
| 2164 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2165 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2166 | goto nla_put_failure; |
| 2167 | |
| 2168 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2169 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2170 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2171 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2172 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2173 | rdev->devlist_generation ^ |
| 2174 | (cfg80211_rdev_list_generation << 2))) |
| 2175 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2176 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2177 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2178 | int ret; |
| 2179 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2180 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2181 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2182 | if (ret == 0) { |
| 2183 | if (nl80211_send_chandef(msg, &chandef)) |
| 2184 | goto nla_put_failure; |
| 2185 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2186 | } |
| 2187 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2188 | if (wdev->ssid_len) { |
| 2189 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2190 | goto nla_put_failure; |
| 2191 | } |
| 2192 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2193 | return genlmsg_end(msg, hdr); |
| 2194 | |
| 2195 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2196 | genlmsg_cancel(msg, hdr); |
| 2197 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2201 | { |
| 2202 | int wp_idx = 0; |
| 2203 | int if_idx = 0; |
| 2204 | int wp_start = cb->args[0]; |
| 2205 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2206 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2207 | struct wireless_dev *wdev; |
| 2208 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2209 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2210 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2211 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2212 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2213 | if (wp_idx < wp_start) { |
| 2214 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2215 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2216 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2217 | if_idx = 0; |
| 2218 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2219 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2220 | if (if_idx < if_start) { |
| 2221 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2222 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2223 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2224 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2225 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2226 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2227 | goto out; |
| 2228 | } |
| 2229 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2230 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2231 | |
| 2232 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2233 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2234 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2235 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2236 | |
| 2237 | cb->args[0] = wp_idx; |
| 2238 | cb->args[1] = if_idx; |
| 2239 | |
| 2240 | return skb->len; |
| 2241 | } |
| 2242 | |
| 2243 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2244 | { |
| 2245 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2246 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2247 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2248 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2249 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2250 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2251 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2252 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2253 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2254 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2255 | nlmsg_free(msg); |
| 2256 | return -ENOBUFS; |
| 2257 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2258 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2259 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2260 | } |
| 2261 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2262 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2263 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2264 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2265 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2266 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2267 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2268 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2269 | }; |
| 2270 | |
| 2271 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2272 | { |
| 2273 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2274 | int flag; |
| 2275 | |
| 2276 | *mntrflags = 0; |
| 2277 | |
| 2278 | if (!nla) |
| 2279 | return -EINVAL; |
| 2280 | |
| 2281 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2282 | nla, mntr_flags_policy)) |
| 2283 | return -EINVAL; |
| 2284 | |
| 2285 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2286 | if (flags[flag]) |
| 2287 | *mntrflags |= (1<<flag); |
| 2288 | |
| 2289 | return 0; |
| 2290 | } |
| 2291 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2292 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2293 | struct net_device *netdev, u8 use_4addr, |
| 2294 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2295 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2296 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2297 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2298 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2299 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2300 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2301 | |
| 2302 | switch (iftype) { |
| 2303 | case NL80211_IFTYPE_AP_VLAN: |
| 2304 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2305 | return 0; |
| 2306 | break; |
| 2307 | case NL80211_IFTYPE_STATION: |
| 2308 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2309 | return 0; |
| 2310 | break; |
| 2311 | default: |
| 2312 | break; |
| 2313 | } |
| 2314 | |
| 2315 | return -EOPNOTSUPP; |
| 2316 | } |
| 2317 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2318 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2319 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2321 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2322 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2323 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2324 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2325 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2326 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2327 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2328 | memset(¶ms, 0, sizeof(params)); |
| 2329 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2330 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2331 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2332 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2333 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2334 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2335 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2336 | if (ntype > NL80211_IFTYPE_MAX) |
| 2337 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2338 | } |
| 2339 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2340 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2341 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2342 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2343 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2344 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2345 | if (netif_running(dev)) |
| 2346 | return -EBUSY; |
| 2347 | |
| 2348 | wdev_lock(wdev); |
| 2349 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2350 | IEEE80211_MAX_MESH_ID_LEN); |
| 2351 | wdev->mesh_id_up_len = |
| 2352 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2353 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2354 | wdev->mesh_id_up_len); |
| 2355 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2356 | } |
| 2357 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2358 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2359 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2360 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2361 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2362 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2363 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2364 | } else { |
| 2365 | params.use_4addr = -1; |
| 2366 | } |
| 2367 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2368 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2369 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2370 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2371 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2372 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2373 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2374 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2375 | |
| 2376 | flags = &_flags; |
| 2377 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2378 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2379 | |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2380 | if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) && |
| 2381 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2382 | return -EOPNOTSUPP; |
| 2383 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2384 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2385 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2386 | else |
| 2387 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2388 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2389 | if (!err && params.use_4addr != -1) |
| 2390 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2391 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2392 | return err; |
| 2393 | } |
| 2394 | |
| 2395 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2396 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2397 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2398 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2399 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2400 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2401 | int err; |
| 2402 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2403 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2404 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2405 | memset(¶ms, 0, sizeof(params)); |
| 2406 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2407 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2408 | return -EINVAL; |
| 2409 | |
| 2410 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2411 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2412 | if (type > NL80211_IFTYPE_MAX) |
| 2413 | return -EINVAL; |
| 2414 | } |
| 2415 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2416 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2417 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2418 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2419 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2420 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2421 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2422 | ETH_ALEN); |
| 2423 | if (!is_valid_ether_addr(params.macaddr)) |
| 2424 | return -EADDRNOTAVAIL; |
| 2425 | } |
| 2426 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2427 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2428 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2429 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2430 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2431 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2432 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2433 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2434 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2435 | if (!msg) |
| 2436 | return -ENOMEM; |
| 2437 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2438 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2439 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2440 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2441 | |
| 2442 | if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) && |
| 2443 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2444 | return -EOPNOTSUPP; |
| 2445 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2446 | wdev = rdev_add_virtual_intf(rdev, |
| 2447 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2448 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2449 | if (IS_ERR(wdev)) { |
| 2450 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2451 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2452 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2453 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2454 | switch (type) { |
| 2455 | case NL80211_IFTYPE_MESH_POINT: |
| 2456 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2457 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2458 | wdev_lock(wdev); |
| 2459 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2460 | IEEE80211_MAX_MESH_ID_LEN); |
| 2461 | wdev->mesh_id_up_len = |
| 2462 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2463 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2464 | wdev->mesh_id_up_len); |
| 2465 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2466 | break; |
| 2467 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2468 | /* |
| 2469 | * P2P Device doesn't have a netdev, so doesn't go |
| 2470 | * through the netdev notifier and must be added here |
| 2471 | */ |
| 2472 | mutex_init(&wdev->mtx); |
| 2473 | INIT_LIST_HEAD(&wdev->event_list); |
| 2474 | spin_lock_init(&wdev->event_lock); |
| 2475 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2476 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2477 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2478 | wdev->identifier = ++rdev->wdev_id; |
| 2479 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2480 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2481 | break; |
| 2482 | default: |
| 2483 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2484 | } |
| 2485 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2486 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2487 | rdev, wdev) < 0) { |
| 2488 | nlmsg_free(msg); |
| 2489 | return -ENOBUFS; |
| 2490 | } |
| 2491 | |
| 2492 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2496 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2497 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2498 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2499 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2500 | if (!rdev->ops->del_virtual_intf) |
| 2501 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2502 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2503 | /* |
| 2504 | * If we remove a wireless device without a netdev then clear |
| 2505 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2506 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2507 | * since the wdev has been freed, unlike with a netdev where |
| 2508 | * we need the dev_put() for the netdev to really be freed. |
| 2509 | */ |
| 2510 | if (!wdev->netdev) |
| 2511 | info->user_ptr[1] = NULL; |
| 2512 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2513 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2514 | } |
| 2515 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2516 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2517 | { |
| 2518 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2519 | struct net_device *dev = info->user_ptr[1]; |
| 2520 | u16 noack_map; |
| 2521 | |
| 2522 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2523 | return -EINVAL; |
| 2524 | |
| 2525 | if (!rdev->ops->set_noack_map) |
| 2526 | return -EOPNOTSUPP; |
| 2527 | |
| 2528 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2529 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2530 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2531 | } |
| 2532 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2533 | struct get_key_cookie { |
| 2534 | struct sk_buff *msg; |
| 2535 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2536 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2537 | }; |
| 2538 | |
| 2539 | static void get_key_callback(void *c, struct key_params *params) |
| 2540 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2541 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2542 | struct get_key_cookie *cookie = c; |
| 2543 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2544 | if ((params->key && |
| 2545 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2546 | params->key_len, params->key)) || |
| 2547 | (params->seq && |
| 2548 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2549 | params->seq_len, params->seq)) || |
| 2550 | (params->cipher && |
| 2551 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2552 | params->cipher))) |
| 2553 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2554 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2555 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2556 | if (!key) |
| 2557 | goto nla_put_failure; |
| 2558 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2559 | if ((params->key && |
| 2560 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2561 | params->key_len, params->key)) || |
| 2562 | (params->seq && |
| 2563 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2564 | params->seq_len, params->seq)) || |
| 2565 | (params->cipher && |
| 2566 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2567 | params->cipher))) |
| 2568 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2569 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2570 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2571 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2572 | |
| 2573 | nla_nest_end(cookie->msg, key); |
| 2574 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2575 | return; |
| 2576 | nla_put_failure: |
| 2577 | cookie->error = 1; |
| 2578 | } |
| 2579 | |
| 2580 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2581 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2582 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2583 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2584 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2585 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2586 | const u8 *mac_addr = NULL; |
| 2587 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2588 | struct get_key_cookie cookie = { |
| 2589 | .error = 0, |
| 2590 | }; |
| 2591 | void *hdr; |
| 2592 | struct sk_buff *msg; |
| 2593 | |
| 2594 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2595 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2596 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2597 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2598 | return -EINVAL; |
| 2599 | |
| 2600 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2601 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2602 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2603 | pairwise = !!mac_addr; |
| 2604 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2605 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2606 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2607 | return -EINVAL; |
| 2608 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2609 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2610 | return -EINVAL; |
| 2611 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2612 | } |
| 2613 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2614 | if (!rdev->ops->get_key) |
| 2615 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2616 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2617 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2618 | if (!msg) |
| 2619 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2620 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2621 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2622 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2623 | if (IS_ERR(hdr)) |
| 2624 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2625 | |
| 2626 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2627 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2628 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2629 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2630 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2631 | goto nla_put_failure; |
| 2632 | if (mac_addr && |
| 2633 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2634 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2635 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2636 | if (pairwise && mac_addr && |
| 2637 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2638 | return -ENOENT; |
| 2639 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2640 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2641 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2642 | |
| 2643 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2644 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2645 | |
| 2646 | if (cookie.error) |
| 2647 | goto nla_put_failure; |
| 2648 | |
| 2649 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2650 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2651 | |
| 2652 | nla_put_failure: |
| 2653 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2654 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2655 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2656 | return err; |
| 2657 | } |
| 2658 | |
| 2659 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2660 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2661 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2662 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2663 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2664 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2665 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2666 | err = nl80211_parse_key(info, &key); |
| 2667 | if (err) |
| 2668 | return err; |
| 2669 | |
| 2670 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2671 | return -EINVAL; |
| 2672 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2673 | /* only support setting default key */ |
| 2674 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2675 | return -EINVAL; |
| 2676 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2677 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2678 | |
| 2679 | if (key.def) { |
| 2680 | if (!rdev->ops->set_default_key) { |
| 2681 | err = -EOPNOTSUPP; |
| 2682 | goto out; |
| 2683 | } |
| 2684 | |
| 2685 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2686 | if (err) |
| 2687 | goto out; |
| 2688 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2689 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2690 | key.def_uni, key.def_multi); |
| 2691 | |
| 2692 | if (err) |
| 2693 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2694 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2695 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2696 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2697 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2698 | } else { |
| 2699 | if (key.def_uni || !key.def_multi) { |
| 2700 | err = -EINVAL; |
| 2701 | goto out; |
| 2702 | } |
| 2703 | |
| 2704 | if (!rdev->ops->set_default_mgmt_key) { |
| 2705 | err = -EOPNOTSUPP; |
| 2706 | goto out; |
| 2707 | } |
| 2708 | |
| 2709 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2710 | if (err) |
| 2711 | goto out; |
| 2712 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2713 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2714 | if (err) |
| 2715 | goto out; |
| 2716 | |
| 2717 | #ifdef CONFIG_CFG80211_WEXT |
| 2718 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2719 | #endif |
| 2720 | } |
| 2721 | |
| 2722 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2723 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2724 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2725 | return err; |
| 2726 | } |
| 2727 | |
| 2728 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2729 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2730 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2731 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2732 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2733 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2734 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2735 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2736 | err = nl80211_parse_key(info, &key); |
| 2737 | if (err) |
| 2738 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2739 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2740 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2741 | return -EINVAL; |
| 2742 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2743 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2744 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2745 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2746 | if (key.type == -1) { |
| 2747 | if (mac_addr) |
| 2748 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2749 | else |
| 2750 | key.type = NL80211_KEYTYPE_GROUP; |
| 2751 | } |
| 2752 | |
| 2753 | /* for now */ |
| 2754 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2755 | key.type != NL80211_KEYTYPE_GROUP) |
| 2756 | return -EINVAL; |
| 2757 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2758 | if (!rdev->ops->add_key) |
| 2759 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2760 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2761 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2762 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2763 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2764 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2765 | |
| 2766 | wdev_lock(dev->ieee80211_ptr); |
| 2767 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2768 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2769 | err = rdev_add_key(rdev, dev, key.idx, |
| 2770 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2771 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2772 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2773 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2774 | return err; |
| 2775 | } |
| 2776 | |
| 2777 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2778 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2779 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2780 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2781 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2782 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2783 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2784 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2785 | err = nl80211_parse_key(info, &key); |
| 2786 | if (err) |
| 2787 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2788 | |
| 2789 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2790 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2791 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2792 | if (key.type == -1) { |
| 2793 | if (mac_addr) |
| 2794 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2795 | else |
| 2796 | key.type = NL80211_KEYTYPE_GROUP; |
| 2797 | } |
| 2798 | |
| 2799 | /* for now */ |
| 2800 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2801 | key.type != NL80211_KEYTYPE_GROUP) |
| 2802 | return -EINVAL; |
| 2803 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2804 | if (!rdev->ops->del_key) |
| 2805 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2806 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2807 | wdev_lock(dev->ieee80211_ptr); |
| 2808 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2809 | |
| 2810 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2811 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2812 | err = -ENOENT; |
| 2813 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2814 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2815 | err = rdev_del_key(rdev, dev, key.idx, |
| 2816 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2817 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2818 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2819 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2820 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2821 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2822 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2823 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2824 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2825 | } |
| 2826 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2827 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2828 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2829 | return err; |
| 2830 | } |
| 2831 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2832 | /* This function returns an error or the number of nested attributes */ |
| 2833 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2834 | { |
| 2835 | struct nlattr *attr; |
| 2836 | int n_entries = 0, tmp; |
| 2837 | |
| 2838 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2839 | if (nla_len(attr) != ETH_ALEN) |
| 2840 | return -EINVAL; |
| 2841 | |
| 2842 | n_entries++; |
| 2843 | } |
| 2844 | |
| 2845 | return n_entries; |
| 2846 | } |
| 2847 | |
| 2848 | /* |
| 2849 | * This function parses ACL information and allocates memory for ACL data. |
| 2850 | * On successful return, the calling function is responsible to free the |
| 2851 | * ACL buffer returned by this function. |
| 2852 | */ |
| 2853 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2854 | struct genl_info *info) |
| 2855 | { |
| 2856 | enum nl80211_acl_policy acl_policy; |
| 2857 | struct nlattr *attr; |
| 2858 | struct cfg80211_acl_data *acl; |
| 2859 | int i = 0, n_entries, tmp; |
| 2860 | |
| 2861 | if (!wiphy->max_acl_mac_addrs) |
| 2862 | return ERR_PTR(-EOPNOTSUPP); |
| 2863 | |
| 2864 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2865 | return ERR_PTR(-EINVAL); |
| 2866 | |
| 2867 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2868 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2869 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2870 | return ERR_PTR(-EINVAL); |
| 2871 | |
| 2872 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2873 | return ERR_PTR(-EINVAL); |
| 2874 | |
| 2875 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2876 | if (n_entries < 0) |
| 2877 | return ERR_PTR(n_entries); |
| 2878 | |
| 2879 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2880 | return ERR_PTR(-ENOTSUPP); |
| 2881 | |
| 2882 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2883 | GFP_KERNEL); |
| 2884 | if (!acl) |
| 2885 | return ERR_PTR(-ENOMEM); |
| 2886 | |
| 2887 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2888 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2889 | i++; |
| 2890 | } |
| 2891 | |
| 2892 | acl->n_acl_entries = n_entries; |
| 2893 | acl->acl_policy = acl_policy; |
| 2894 | |
| 2895 | return acl; |
| 2896 | } |
| 2897 | |
| 2898 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2899 | { |
| 2900 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2901 | struct net_device *dev = info->user_ptr[1]; |
| 2902 | struct cfg80211_acl_data *acl; |
| 2903 | int err; |
| 2904 | |
| 2905 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2906 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2907 | return -EOPNOTSUPP; |
| 2908 | |
| 2909 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2910 | return -EINVAL; |
| 2911 | |
| 2912 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2913 | if (IS_ERR(acl)) |
| 2914 | return PTR_ERR(acl); |
| 2915 | |
| 2916 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2917 | |
| 2918 | kfree(acl); |
| 2919 | |
| 2920 | return err; |
| 2921 | } |
| 2922 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2923 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2924 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2925 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2926 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2927 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2928 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2929 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 2930 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2931 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2932 | return -EINVAL; |
| 2933 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2934 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2935 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2936 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2937 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2938 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2939 | if (!bcn->head_len) |
| 2940 | return -EINVAL; |
| 2941 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2942 | } |
| 2943 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2944 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2945 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2946 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2947 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2948 | } |
| 2949 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2950 | if (!haveinfo) |
| 2951 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2952 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2953 | if (attrs[NL80211_ATTR_IE]) { |
| 2954 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 2955 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2956 | } |
| 2957 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2958 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2959 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2960 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2961 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2962 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2963 | } |
| 2964 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2965 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2966 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2967 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2968 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2969 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2970 | } |
| 2971 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2972 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 2973 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 2974 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2975 | } |
| 2976 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2977 | return 0; |
| 2978 | } |
| 2979 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2980 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2981 | struct cfg80211_ap_settings *params) |
| 2982 | { |
| 2983 | struct wireless_dev *wdev; |
| 2984 | bool ret = false; |
| 2985 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2986 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2987 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2988 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2989 | continue; |
| 2990 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2991 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2992 | continue; |
| 2993 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2994 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2995 | ret = true; |
| 2996 | break; |
| 2997 | } |
| 2998 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2999 | return ret; |
| 3000 | } |
| 3001 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3002 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3003 | enum nl80211_auth_type auth_type, |
| 3004 | enum nl80211_commands cmd) |
| 3005 | { |
| 3006 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3007 | return false; |
| 3008 | |
| 3009 | switch (cmd) { |
| 3010 | case NL80211_CMD_AUTHENTICATE: |
| 3011 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3012 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3013 | return false; |
| 3014 | return true; |
| 3015 | case NL80211_CMD_CONNECT: |
| 3016 | case NL80211_CMD_START_AP: |
| 3017 | /* SAE not supported yet */ |
| 3018 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3019 | return false; |
| 3020 | return true; |
| 3021 | default: |
| 3022 | return false; |
| 3023 | } |
| 3024 | } |
| 3025 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3026 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3027 | { |
| 3028 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3029 | struct net_device *dev = info->user_ptr[1]; |
| 3030 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3031 | struct cfg80211_ap_settings params; |
| 3032 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3033 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3034 | |
| 3035 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3036 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3037 | return -EOPNOTSUPP; |
| 3038 | |
| 3039 | if (!rdev->ops->start_ap) |
| 3040 | return -EOPNOTSUPP; |
| 3041 | |
| 3042 | if (wdev->beacon_interval) |
| 3043 | return -EALREADY; |
| 3044 | |
| 3045 | memset(¶ms, 0, sizeof(params)); |
| 3046 | |
| 3047 | /* these are required for START_AP */ |
| 3048 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3049 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3050 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3051 | return -EINVAL; |
| 3052 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3053 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3054 | if (err) |
| 3055 | return err; |
| 3056 | |
| 3057 | params.beacon_interval = |
| 3058 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3059 | params.dtim_period = |
| 3060 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3061 | |
| 3062 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3063 | if (err) |
| 3064 | return err; |
| 3065 | |
| 3066 | /* |
| 3067 | * In theory, some of these attributes should be required here |
| 3068 | * but since they were not used when the command was originally |
| 3069 | * added, keep them optional for old user space programs to let |
| 3070 | * them continue to work with drivers that do not need the |
| 3071 | * additional information -- drivers must check! |
| 3072 | */ |
| 3073 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3074 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3075 | params.ssid_len = |
| 3076 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3077 | if (params.ssid_len == 0 || |
| 3078 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3079 | return -EINVAL; |
| 3080 | } |
| 3081 | |
| 3082 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3083 | params.hidden_ssid = nla_get_u32( |
| 3084 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3085 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3086 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3087 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3088 | return -EINVAL; |
| 3089 | } |
| 3090 | |
| 3091 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3092 | |
| 3093 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3094 | params.auth_type = nla_get_u32( |
| 3095 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3096 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3097 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3098 | return -EINVAL; |
| 3099 | } else |
| 3100 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3101 | |
| 3102 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3103 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3104 | if (err) |
| 3105 | return err; |
| 3106 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3107 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3108 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3109 | return -EOPNOTSUPP; |
| 3110 | params.inactivity_timeout = nla_get_u16( |
| 3111 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3112 | } |
| 3113 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3114 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3115 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3116 | return -EINVAL; |
| 3117 | params.p2p_ctwindow = |
| 3118 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3119 | if (params.p2p_ctwindow > 127) |
| 3120 | return -EINVAL; |
| 3121 | if (params.p2p_ctwindow != 0 && |
| 3122 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3123 | return -EINVAL; |
| 3124 | } |
| 3125 | |
| 3126 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3127 | u8 tmp; |
| 3128 | |
| 3129 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3130 | return -EINVAL; |
| 3131 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3132 | if (tmp > 1) |
| 3133 | return -EINVAL; |
| 3134 | params.p2p_opp_ps = tmp; |
| 3135 | if (params.p2p_opp_ps != 0 && |
| 3136 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3137 | return -EINVAL; |
| 3138 | } |
| 3139 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3140 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3141 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3142 | if (err) |
| 3143 | return err; |
| 3144 | } else if (wdev->preset_chandef.chan) { |
| 3145 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3146 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3147 | return -EINVAL; |
| 3148 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3149 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3150 | return -EINVAL; |
| 3151 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3152 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3153 | if (err < 0) |
| 3154 | return err; |
| 3155 | if (err) { |
| 3156 | radar_detect_width = BIT(params.chandef.width); |
| 3157 | params.radar_required = true; |
| 3158 | } |
| 3159 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3160 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3161 | params.chandef.chan, |
| 3162 | CHAN_MODE_SHARED, |
| 3163 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3164 | if (err) |
| 3165 | return err; |
| 3166 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3167 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3168 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3169 | if (IS_ERR(params.acl)) |
| 3170 | return PTR_ERR(params.acl); |
| 3171 | } |
| 3172 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3173 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3174 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3175 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3176 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3177 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3178 | wdev->ssid_len = params.ssid_len; |
| 3179 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3180 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3181 | |
| 3182 | kfree(params.acl); |
| 3183 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3184 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3185 | } |
| 3186 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3187 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3188 | { |
| 3189 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3190 | struct net_device *dev = info->user_ptr[1]; |
| 3191 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3192 | struct cfg80211_beacon_data params; |
| 3193 | int err; |
| 3194 | |
| 3195 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3196 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3197 | return -EOPNOTSUPP; |
| 3198 | |
| 3199 | if (!rdev->ops->change_beacon) |
| 3200 | return -EOPNOTSUPP; |
| 3201 | |
| 3202 | if (!wdev->beacon_interval) |
| 3203 | return -EINVAL; |
| 3204 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3205 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3206 | if (err) |
| 3207 | return err; |
| 3208 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3209 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | 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] | 3213 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3215 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3216 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3217 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3218 | } |
| 3219 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3220 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3221 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3222 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3223 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3224 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3225 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3226 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3227 | }; |
| 3228 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3229 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3230 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3231 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3232 | { |
| 3233 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3234 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3235 | int flag; |
| 3236 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3237 | /* |
| 3238 | * Try parsing the new attribute first so userspace |
| 3239 | * can specify both for older kernels. |
| 3240 | */ |
| 3241 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3242 | if (nla) { |
| 3243 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3244 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3245 | sta_flags = nla_data(nla); |
| 3246 | params->sta_flags_mask = sta_flags->mask; |
| 3247 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3248 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3249 | if ((params->sta_flags_mask | |
| 3250 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3251 | return -EINVAL; |
| 3252 | return 0; |
| 3253 | } |
| 3254 | |
| 3255 | /* if present, parse the old attribute */ |
| 3256 | |
| 3257 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3258 | if (!nla) |
| 3259 | return 0; |
| 3260 | |
| 3261 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3262 | nla, sta_flags_policy)) |
| 3263 | return -EINVAL; |
| 3264 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3265 | /* |
| 3266 | * Only allow certain flags for interface types so that |
| 3267 | * other attributes are silently ignored. Remember that |
| 3268 | * this is backward compatibility code with old userspace |
| 3269 | * and shouldn't be hit in other cases anyway. |
| 3270 | */ |
| 3271 | switch (iftype) { |
| 3272 | case NL80211_IFTYPE_AP: |
| 3273 | case NL80211_IFTYPE_AP_VLAN: |
| 3274 | case NL80211_IFTYPE_P2P_GO: |
| 3275 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3276 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3277 | BIT(NL80211_STA_FLAG_WME) | |
| 3278 | BIT(NL80211_STA_FLAG_MFP); |
| 3279 | break; |
| 3280 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3281 | case NL80211_IFTYPE_STATION: |
| 3282 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3283 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3284 | break; |
| 3285 | case NL80211_IFTYPE_MESH_POINT: |
| 3286 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3287 | BIT(NL80211_STA_FLAG_MFP) | |
| 3288 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3289 | default: |
| 3290 | return -EINVAL; |
| 3291 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3292 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3293 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3294 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3295 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3296 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3297 | /* no longer support new API additions in old API */ |
| 3298 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3299 | return -EINVAL; |
| 3300 | } |
| 3301 | } |
| 3302 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3303 | return 0; |
| 3304 | } |
| 3305 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3306 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3307 | int attr) |
| 3308 | { |
| 3309 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3310 | u32 bitrate; |
| 3311 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3312 | |
| 3313 | rate = nla_nest_start(msg, attr); |
| 3314 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3315 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3316 | |
| 3317 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3318 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3319 | /* report 16-bit bitrate only if we can */ |
| 3320 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3321 | if (bitrate > 0 && |
| 3322 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3323 | return false; |
| 3324 | if (bitrate_compat > 0 && |
| 3325 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3326 | return false; |
| 3327 | |
| 3328 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3329 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3330 | return false; |
| 3331 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3332 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3333 | return false; |
| 3334 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3335 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3336 | return false; |
| 3337 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3338 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3339 | return false; |
| 3340 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3341 | return false; |
| 3342 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3343 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3344 | return false; |
| 3345 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3346 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3347 | return false; |
| 3348 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3349 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3350 | return false; |
| 3351 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3352 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3353 | return false; |
| 3354 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3355 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3356 | return false; |
| 3357 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3358 | |
| 3359 | nla_nest_end(msg, rate); |
| 3360 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3361 | } |
| 3362 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3363 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3364 | int id) |
| 3365 | { |
| 3366 | void *attr; |
| 3367 | int i = 0; |
| 3368 | |
| 3369 | if (!mask) |
| 3370 | return true; |
| 3371 | |
| 3372 | attr = nla_nest_start(msg, id); |
| 3373 | if (!attr) |
| 3374 | return false; |
| 3375 | |
| 3376 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3377 | if (!(mask & BIT(i))) |
| 3378 | continue; |
| 3379 | |
| 3380 | if (nla_put_u8(msg, i, signal[i])) |
| 3381 | return false; |
| 3382 | } |
| 3383 | |
| 3384 | nla_nest_end(msg, attr); |
| 3385 | |
| 3386 | return true; |
| 3387 | } |
| 3388 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3389 | 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] | 3390 | int flags, |
| 3391 | struct cfg80211_registered_device *rdev, |
| 3392 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3393 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3394 | { |
| 3395 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3396 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3397 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3398 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3399 | if (!hdr) |
| 3400 | return -1; |
| 3401 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3402 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3403 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3404 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3405 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3406 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3407 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3408 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3409 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3410 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3411 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3412 | sinfo->connected_time)) |
| 3413 | goto nla_put_failure; |
| 3414 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3415 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3416 | sinfo->inactive_time)) |
| 3417 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3418 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3419 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3420 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3421 | (u32)sinfo->rx_bytes)) |
| 3422 | goto nla_put_failure; |
| 3423 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3424 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3425 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3426 | (u32)sinfo->tx_bytes)) |
| 3427 | goto nla_put_failure; |
| 3428 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3429 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3430 | sinfo->rx_bytes)) |
| 3431 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3432 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3433 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3434 | sinfo->tx_bytes)) |
| 3435 | goto nla_put_failure; |
| 3436 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3437 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3438 | goto nla_put_failure; |
| 3439 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3440 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3441 | goto nla_put_failure; |
| 3442 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3443 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3444 | sinfo->plink_state)) |
| 3445 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3446 | switch (rdev->wiphy.signal_type) { |
| 3447 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3448 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3449 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3450 | sinfo->signal)) |
| 3451 | goto nla_put_failure; |
| 3452 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3453 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3454 | sinfo->signal_avg)) |
| 3455 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3456 | break; |
| 3457 | default: |
| 3458 | break; |
| 3459 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3460 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3461 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3462 | sinfo->chain_signal, |
| 3463 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3464 | goto nla_put_failure; |
| 3465 | } |
| 3466 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3467 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3468 | sinfo->chain_signal_avg, |
| 3469 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3470 | goto nla_put_failure; |
| 3471 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3472 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3473 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3474 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3475 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3476 | } |
| 3477 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3478 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3479 | NL80211_STA_INFO_RX_BITRATE)) |
| 3480 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3481 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3482 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3483 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3484 | sinfo->rx_packets)) |
| 3485 | goto nla_put_failure; |
| 3486 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3487 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3488 | sinfo->tx_packets)) |
| 3489 | goto nla_put_failure; |
| 3490 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3491 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3492 | sinfo->tx_retries)) |
| 3493 | goto nla_put_failure; |
| 3494 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3495 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3496 | sinfo->tx_failed)) |
| 3497 | goto nla_put_failure; |
| 3498 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3499 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3500 | sinfo->beacon_loss_count)) |
| 3501 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3502 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3503 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3504 | sinfo->local_pm)) |
| 3505 | goto nla_put_failure; |
| 3506 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3507 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3508 | sinfo->peer_pm)) |
| 3509 | goto nla_put_failure; |
| 3510 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3511 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3512 | sinfo->nonpeer_pm)) |
| 3513 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3514 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3515 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3516 | if (!bss_param) |
| 3517 | goto nla_put_failure; |
| 3518 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3519 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3520 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3521 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3522 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3523 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3524 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3525 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3526 | sinfo->bss_param.dtim_period) || |
| 3527 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3528 | sinfo->bss_param.beacon_interval)) |
| 3529 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3530 | |
| 3531 | nla_nest_end(msg, bss_param); |
| 3532 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3533 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3534 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3535 | sizeof(struct nl80211_sta_flag_update), |
| 3536 | &sinfo->sta_flags)) |
| 3537 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3538 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3539 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3540 | sinfo->t_offset)) |
| 3541 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3542 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3543 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3544 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3545 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3546 | sinfo->assoc_req_ies)) |
| 3547 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3548 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3549 | return genlmsg_end(msg, hdr); |
| 3550 | |
| 3551 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3552 | genlmsg_cancel(msg, hdr); |
| 3553 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3554 | } |
| 3555 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3556 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3557 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3558 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3559 | struct station_info sinfo; |
| 3560 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3561 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3562 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3563 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3564 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3565 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3566 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3567 | if (err) |
| 3568 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3569 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3570 | if (!wdev->netdev) { |
| 3571 | err = -EINVAL; |
| 3572 | goto out_err; |
| 3573 | } |
| 3574 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3575 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3576 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3577 | goto out_err; |
| 3578 | } |
| 3579 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3580 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3581 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3582 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3583 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3584 | if (err == -ENOENT) |
| 3585 | break; |
| 3586 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3587 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3588 | |
| 3589 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3590 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3591 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3592 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3593 | &sinfo) < 0) |
| 3594 | goto out; |
| 3595 | |
| 3596 | sta_idx++; |
| 3597 | } |
| 3598 | |
| 3599 | |
| 3600 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3601 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3602 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3603 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3604 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3605 | |
| 3606 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3607 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3608 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3609 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3610 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3611 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3612 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3613 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3614 | struct sk_buff *msg; |
| 3615 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3616 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3617 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3618 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3619 | |
| 3620 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3621 | return -EINVAL; |
| 3622 | |
| 3623 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3624 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3625 | if (!rdev->ops->get_station) |
| 3626 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3627 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3628 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3629 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3630 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3631 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3632 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3633 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3634 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3635 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3636 | 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] | 3637 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3638 | nlmsg_free(msg); |
| 3639 | return -ENOBUFS; |
| 3640 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3641 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3642 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3643 | } |
| 3644 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3645 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3646 | struct station_parameters *params, |
| 3647 | enum cfg80211_station_type statype) |
| 3648 | { |
| 3649 | if (params->listen_interval != -1) |
| 3650 | return -EINVAL; |
| 3651 | if (params->aid) |
| 3652 | return -EINVAL; |
| 3653 | |
| 3654 | /* When you run into this, adjust the code below for the new flag */ |
| 3655 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3656 | |
| 3657 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3658 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3659 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3660 | /* |
| 3661 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3662 | * code doesn't have the bug of including TDLS in the |
| 3663 | * mask everywhere. |
| 3664 | */ |
| 3665 | if (params->sta_flags_mask & |
| 3666 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3667 | BIT(NL80211_STA_FLAG_MFP) | |
| 3668 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3669 | return -EINVAL; |
| 3670 | break; |
| 3671 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3672 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3673 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3674 | return -EINVAL; |
| 3675 | /* ignore since it can't change */ |
| 3676 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3677 | break; |
| 3678 | default: |
| 3679 | /* disallow mesh-specific things */ |
| 3680 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3681 | return -EINVAL; |
| 3682 | if (params->local_pm) |
| 3683 | return -EINVAL; |
| 3684 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3685 | return -EINVAL; |
| 3686 | } |
| 3687 | |
| 3688 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3689 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3690 | /* TDLS can't be set, ... */ |
| 3691 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3692 | return -EINVAL; |
| 3693 | /* |
| 3694 | * ... but don't bother the driver with it. This works around |
| 3695 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3696 | * TLDS_PEER flag in the mask even for AP mode. |
| 3697 | */ |
| 3698 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3699 | } |
| 3700 | |
| 3701 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3702 | /* reject other things that can't change */ |
| 3703 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3704 | return -EINVAL; |
| 3705 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3706 | return -EINVAL; |
| 3707 | if (params->supported_rates) |
| 3708 | return -EINVAL; |
| 3709 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3710 | return -EINVAL; |
| 3711 | } |
| 3712 | |
| 3713 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3714 | if (params->vlan) |
| 3715 | return -EINVAL; |
| 3716 | } |
| 3717 | |
| 3718 | switch (statype) { |
| 3719 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3720 | /* Use this only for authorizing/unauthorizing a station */ |
| 3721 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3722 | return -EOPNOTSUPP; |
| 3723 | break; |
| 3724 | case CFG80211_STA_AP_CLIENT: |
| 3725 | /* accept only the listed bits */ |
| 3726 | if (params->sta_flags_mask & |
| 3727 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3728 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3729 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3730 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3731 | BIT(NL80211_STA_FLAG_WME) | |
| 3732 | BIT(NL80211_STA_FLAG_MFP))) |
| 3733 | return -EINVAL; |
| 3734 | |
| 3735 | /* but authenticated/associated only if driver handles it */ |
| 3736 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3737 | params->sta_flags_mask & |
| 3738 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3739 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3740 | return -EINVAL; |
| 3741 | break; |
| 3742 | case CFG80211_STA_IBSS: |
| 3743 | case CFG80211_STA_AP_STA: |
| 3744 | /* reject any changes other than AUTHORIZED */ |
| 3745 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3746 | return -EINVAL; |
| 3747 | break; |
| 3748 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3749 | /* reject any changes other than AUTHORIZED or WME */ |
| 3750 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3751 | BIT(NL80211_STA_FLAG_WME))) |
| 3752 | return -EINVAL; |
| 3753 | /* force (at least) rates when authorizing */ |
| 3754 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3755 | !params->supported_rates) |
| 3756 | return -EINVAL; |
| 3757 | break; |
| 3758 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3759 | /* reject any changes */ |
| 3760 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3761 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3762 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3763 | return -EINVAL; |
| 3764 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3765 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3766 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3767 | return -EINVAL; |
| 3768 | break; |
| 3769 | } |
| 3770 | |
| 3771 | return 0; |
| 3772 | } |
| 3773 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3774 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3775 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3776 | * 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] | 3777 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3778 | static struct net_device *get_vlan(struct genl_info *info, |
| 3779 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3780 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3781 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3782 | struct net_device *v; |
| 3783 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3784 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3785 | if (!vlanattr) |
| 3786 | return NULL; |
| 3787 | |
| 3788 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3789 | if (!v) |
| 3790 | return ERR_PTR(-ENODEV); |
| 3791 | |
| 3792 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3793 | ret = -EINVAL; |
| 3794 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3795 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3796 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3797 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3798 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3799 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3800 | ret = -EINVAL; |
| 3801 | goto error; |
| 3802 | } |
| 3803 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3804 | if (!netif_running(v)) { |
| 3805 | ret = -ENETDOWN; |
| 3806 | goto error; |
| 3807 | } |
| 3808 | |
| 3809 | return v; |
| 3810 | error: |
| 3811 | dev_put(v); |
| 3812 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3813 | } |
| 3814 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3815 | static struct nla_policy |
| 3816 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3817 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3818 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3819 | }; |
| 3820 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3821 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3822 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3823 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3824 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3825 | struct nlattr *nla; |
| 3826 | int err; |
| 3827 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3828 | /* parse WME attributes if present */ |
| 3829 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3830 | return 0; |
| 3831 | |
| 3832 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3833 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3834 | nl80211_sta_wme_policy); |
| 3835 | if (err) |
| 3836 | return err; |
| 3837 | |
| 3838 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3839 | params->uapsd_queues = nla_get_u8( |
| 3840 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3841 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3842 | return -EINVAL; |
| 3843 | |
| 3844 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3845 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3846 | |
| 3847 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3848 | return -EINVAL; |
| 3849 | |
| 3850 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3851 | |
| 3852 | return 0; |
| 3853 | } |
| 3854 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3855 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3856 | struct station_parameters *params) |
| 3857 | { |
| 3858 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3859 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3860 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3861 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3862 | params->ht_capa = |
| 3863 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3864 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3865 | params->vht_capa = |
| 3866 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3867 | |
| 3868 | return nl80211_parse_sta_wme(info, params); |
| 3869 | } |
| 3870 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3871 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3872 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3873 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3874 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3875 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3876 | u8 *mac_addr; |
| 3877 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3878 | |
| 3879 | memset(¶ms, 0, sizeof(params)); |
| 3880 | |
| 3881 | params.listen_interval = -1; |
| 3882 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3883 | if (!rdev->ops->change_station) |
| 3884 | return -EOPNOTSUPP; |
| 3885 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3886 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3887 | return -EINVAL; |
| 3888 | |
| 3889 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3890 | return -EINVAL; |
| 3891 | |
| 3892 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3893 | |
| 3894 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3895 | params.supported_rates = |
| 3896 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3897 | params.supported_rates_len = |
| 3898 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3899 | } |
| 3900 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3901 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3902 | params.capability = |
| 3903 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3904 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3905 | } |
| 3906 | |
| 3907 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3908 | params.ext_capab = |
| 3909 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3910 | params.ext_capab_len = |
| 3911 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3912 | } |
| 3913 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3914 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3915 | return -EINVAL; |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3916 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3917 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3918 | return -EINVAL; |
| 3919 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3920 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3921 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3922 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3923 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3924 | return -EINVAL; |
| 3925 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3926 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3927 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3928 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3929 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3930 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 3931 | return -EINVAL; |
| 3932 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 3933 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3934 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3935 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3936 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3937 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3938 | |
| 3939 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3940 | pm > NL80211_MESH_POWER_MAX) |
| 3941 | return -EINVAL; |
| 3942 | |
| 3943 | params.local_pm = pm; |
| 3944 | } |
| 3945 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3946 | /* Include parameters for TDLS peer (will check later) */ |
| 3947 | err = nl80211_set_station_tdls(info, ¶ms); |
| 3948 | if (err) |
| 3949 | return err; |
| 3950 | |
| 3951 | params.vlan = get_vlan(info, rdev); |
| 3952 | if (IS_ERR(params.vlan)) |
| 3953 | return PTR_ERR(params.vlan); |
| 3954 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3955 | switch (dev->ieee80211_ptr->iftype) { |
| 3956 | case NL80211_IFTYPE_AP: |
| 3957 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3958 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3959 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3960 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3961 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3962 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3963 | break; |
| 3964 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3965 | err = -EOPNOTSUPP; |
| 3966 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3967 | } |
| 3968 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3969 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3970 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3971 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3972 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3973 | if (params.vlan) |
| 3974 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3975 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3976 | return err; |
| 3977 | } |
| 3978 | |
| 3979 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3980 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3982 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3983 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3984 | struct station_parameters params; |
| 3985 | u8 *mac_addr = NULL; |
| 3986 | |
| 3987 | memset(¶ms, 0, sizeof(params)); |
| 3988 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 3989 | if (!rdev->ops->add_station) |
| 3990 | return -EOPNOTSUPP; |
| 3991 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3992 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3993 | return -EINVAL; |
| 3994 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3995 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3996 | return -EINVAL; |
| 3997 | |
| 3998 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3999 | return -EINVAL; |
| 4000 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4001 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4002 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4003 | return -EINVAL; |
| 4004 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4005 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4006 | params.supported_rates = |
| 4007 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4008 | params.supported_rates_len = |
| 4009 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4010 | params.listen_interval = |
| 4011 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4012 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4013 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4014 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4015 | else |
| 4016 | 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] | 4017 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4018 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4019 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4020 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4021 | params.capability = |
| 4022 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4023 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4024 | } |
| 4025 | |
| 4026 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4027 | params.ext_capab = |
| 4028 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4029 | params.ext_capab_len = |
| 4030 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4031 | } |
| 4032 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4033 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4034 | params.ht_capa = |
| 4035 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4036 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4037 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4038 | params.vht_capa = |
| 4039 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4040 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4041 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4042 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4043 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4044 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4045 | return -EINVAL; |
| 4046 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4047 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4048 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4049 | if (err) |
| 4050 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4051 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4052 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4053 | return -EINVAL; |
| 4054 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4055 | /* When you run into this, adjust the code below for the new flag */ |
| 4056 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4057 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4058 | switch (dev->ieee80211_ptr->iftype) { |
| 4059 | case NL80211_IFTYPE_AP: |
| 4060 | case NL80211_IFTYPE_AP_VLAN: |
| 4061 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4062 | /* ignore WME attributes if iface/sta is not capable */ |
| 4063 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4064 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4065 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4066 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4067 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4068 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4069 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4070 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4071 | /* but don't bother the driver with it */ |
| 4072 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4073 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4074 | /* allow authenticated/associated only if driver handles it */ |
| 4075 | if (!(rdev->wiphy.features & |
| 4076 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4077 | params.sta_flags_mask & |
| 4078 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4079 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4080 | return -EINVAL; |
| 4081 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4082 | /* must be last in here for error handling */ |
| 4083 | params.vlan = get_vlan(info, rdev); |
| 4084 | if (IS_ERR(params.vlan)) |
| 4085 | return PTR_ERR(params.vlan); |
| 4086 | break; |
| 4087 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4088 | /* ignore uAPSD data */ |
| 4089 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4090 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4091 | /* associated is disallowed */ |
| 4092 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4093 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4094 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4095 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4096 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4097 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4098 | break; |
| 4099 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4100 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4101 | /* ignore uAPSD data */ |
| 4102 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4103 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4104 | /* these are disallowed */ |
| 4105 | if (params.sta_flags_mask & |
| 4106 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4107 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4108 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4109 | /* Only TDLS peers can be added */ |
| 4110 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4111 | return -EINVAL; |
| 4112 | /* Can only add if TDLS ... */ |
| 4113 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4114 | return -EOPNOTSUPP; |
| 4115 | /* ... with external setup is supported */ |
| 4116 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4117 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4118 | /* |
| 4119 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4120 | * as authorized, but it shouldn't yet be. |
| 4121 | */ |
| 4122 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4123 | break; |
| 4124 | default: |
| 4125 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4126 | } |
| 4127 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4128 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4129 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4130 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4131 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4132 | if (params.vlan) |
| 4133 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4134 | return err; |
| 4135 | } |
| 4136 | |
| 4137 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4138 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4139 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4140 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4141 | u8 *mac_addr = NULL; |
| 4142 | |
| 4143 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4144 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4145 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4146 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4147 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4148 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4149 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4150 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4151 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4152 | if (!rdev->ops->del_station) |
| 4153 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4154 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4155 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4156 | } |
| 4157 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4158 | 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] | 4159 | int flags, struct net_device *dev, |
| 4160 | u8 *dst, u8 *next_hop, |
| 4161 | struct mpath_info *pinfo) |
| 4162 | { |
| 4163 | void *hdr; |
| 4164 | struct nlattr *pinfoattr; |
| 4165 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4166 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4167 | if (!hdr) |
| 4168 | return -1; |
| 4169 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4170 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4171 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4172 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4173 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4174 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4175 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4176 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4177 | if (!pinfoattr) |
| 4178 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4179 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4180 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4181 | pinfo->frame_qlen)) |
| 4182 | goto nla_put_failure; |
| 4183 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4184 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4185 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4186 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4187 | pinfo->metric)) || |
| 4188 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4189 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4190 | pinfo->exptime)) || |
| 4191 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4192 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4193 | pinfo->flags)) || |
| 4194 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4195 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4196 | pinfo->discovery_timeout)) || |
| 4197 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4198 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4199 | pinfo->discovery_retries))) |
| 4200 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4201 | |
| 4202 | nla_nest_end(msg, pinfoattr); |
| 4203 | |
| 4204 | return genlmsg_end(msg, hdr); |
| 4205 | |
| 4206 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4207 | genlmsg_cancel(msg, hdr); |
| 4208 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4209 | } |
| 4210 | |
| 4211 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4212 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4213 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4214 | struct mpath_info pinfo; |
| 4215 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4216 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4217 | u8 dst[ETH_ALEN]; |
| 4218 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4219 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4220 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4221 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4222 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4223 | if (err) |
| 4224 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4225 | |
| 4226 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4227 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4228 | goto out_err; |
| 4229 | } |
| 4230 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4231 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4232 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4233 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4234 | } |
| 4235 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4236 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4237 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4238 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4239 | if (err == -ENOENT) |
| 4240 | break; |
| 4241 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4242 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4243 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4244 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4245 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4246 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4247 | &pinfo) < 0) |
| 4248 | goto out; |
| 4249 | |
| 4250 | path_idx++; |
| 4251 | } |
| 4252 | |
| 4253 | |
| 4254 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4255 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4256 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4257 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4258 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4259 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4260 | } |
| 4261 | |
| 4262 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4263 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4264 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4265 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4266 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4267 | struct mpath_info pinfo; |
| 4268 | struct sk_buff *msg; |
| 4269 | u8 *dst = NULL; |
| 4270 | u8 next_hop[ETH_ALEN]; |
| 4271 | |
| 4272 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4273 | |
| 4274 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4275 | return -EINVAL; |
| 4276 | |
| 4277 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4278 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4279 | if (!rdev->ops->get_mpath) |
| 4280 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4281 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4282 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4283 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4284 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4285 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4286 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4287 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4288 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4289 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4290 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4291 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4292 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4293 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4294 | dev, dst, next_hop, &pinfo) < 0) { |
| 4295 | nlmsg_free(msg); |
| 4296 | return -ENOBUFS; |
| 4297 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4298 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4299 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4300 | } |
| 4301 | |
| 4302 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4303 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4304 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4305 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4306 | u8 *dst = NULL; |
| 4307 | u8 *next_hop = NULL; |
| 4308 | |
| 4309 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4310 | return -EINVAL; |
| 4311 | |
| 4312 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4313 | return -EINVAL; |
| 4314 | |
| 4315 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4316 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4317 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4318 | if (!rdev->ops->change_mpath) |
| 4319 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4320 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4321 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4322 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4323 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4324 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4325 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4326 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4327 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4328 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4330 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4331 | u8 *dst = NULL; |
| 4332 | u8 *next_hop = NULL; |
| 4333 | |
| 4334 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4335 | return -EINVAL; |
| 4336 | |
| 4337 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4338 | return -EINVAL; |
| 4339 | |
| 4340 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4341 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4342 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4343 | if (!rdev->ops->add_mpath) |
| 4344 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4345 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4346 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4347 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4348 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4349 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4353 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4354 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4355 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4356 | u8 *dst = NULL; |
| 4357 | |
| 4358 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4359 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4360 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4361 | if (!rdev->ops->del_mpath) |
| 4362 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4363 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4364 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4365 | } |
| 4366 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4367 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4368 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4369 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4370 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4371 | struct bss_parameters params; |
| 4372 | |
| 4373 | memset(¶ms, 0, sizeof(params)); |
| 4374 | /* default to not changing parameters */ |
| 4375 | params.use_cts_prot = -1; |
| 4376 | params.use_short_preamble = -1; |
| 4377 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4378 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4379 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4380 | params.p2p_ctwindow = -1; |
| 4381 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4382 | |
| 4383 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4384 | params.use_cts_prot = |
| 4385 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4386 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4387 | params.use_short_preamble = |
| 4388 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4389 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4390 | params.use_short_slot_time = |
| 4391 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4392 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4393 | params.basic_rates = |
| 4394 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4395 | params.basic_rates_len = |
| 4396 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4397 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4398 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4399 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4400 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4401 | params.ht_opmode = |
| 4402 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4403 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4404 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4405 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4406 | return -EINVAL; |
| 4407 | params.p2p_ctwindow = |
| 4408 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4409 | if (params.p2p_ctwindow < 0) |
| 4410 | return -EINVAL; |
| 4411 | if (params.p2p_ctwindow != 0 && |
| 4412 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4413 | return -EINVAL; |
| 4414 | } |
| 4415 | |
| 4416 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4417 | u8 tmp; |
| 4418 | |
| 4419 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4420 | return -EINVAL; |
| 4421 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4422 | if (tmp > 1) |
| 4423 | return -EINVAL; |
| 4424 | params.p2p_opp_ps = tmp; |
| 4425 | if (params.p2p_opp_ps && |
| 4426 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4427 | return -EINVAL; |
| 4428 | } |
| 4429 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4430 | if (!rdev->ops->change_bss) |
| 4431 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4432 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4433 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4434 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4435 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4436 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4437 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4438 | } |
| 4439 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4440 | 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] | 4441 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4442 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4443 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4444 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4445 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4446 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4447 | }; |
| 4448 | |
| 4449 | static int parse_reg_rule(struct nlattr *tb[], |
| 4450 | struct ieee80211_reg_rule *reg_rule) |
| 4451 | { |
| 4452 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4453 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4454 | |
| 4455 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4456 | return -EINVAL; |
| 4457 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4458 | return -EINVAL; |
| 4459 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4460 | return -EINVAL; |
| 4461 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4462 | return -EINVAL; |
| 4463 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4464 | return -EINVAL; |
| 4465 | |
| 4466 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4467 | |
| 4468 | freq_range->start_freq_khz = |
| 4469 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4470 | freq_range->end_freq_khz = |
| 4471 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4472 | freq_range->max_bandwidth_khz = |
| 4473 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4474 | |
| 4475 | power_rule->max_eirp = |
| 4476 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4477 | |
| 4478 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4479 | power_rule->max_antenna_gain = |
| 4480 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4481 | |
| 4482 | return 0; |
| 4483 | } |
| 4484 | |
| 4485 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4486 | { |
| 4487 | int r; |
| 4488 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4489 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4490 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4491 | /* |
| 4492 | * You should only get this when cfg80211 hasn't yet initialized |
| 4493 | * completely when built-in to the kernel right between the time |
| 4494 | * window between nl80211_init() and regulatory_init(), if that is |
| 4495 | * even possible. |
| 4496 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4497 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4498 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4499 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4500 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4501 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4502 | |
| 4503 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4504 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4505 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4506 | user_reg_hint_type = |
| 4507 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4508 | else |
| 4509 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4510 | |
| 4511 | switch (user_reg_hint_type) { |
| 4512 | case NL80211_USER_REG_HINT_USER: |
| 4513 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4514 | break; |
| 4515 | default: |
| 4516 | return -EINVAL; |
| 4517 | } |
| 4518 | |
| 4519 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4520 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4521 | return r; |
| 4522 | } |
| 4523 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4524 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4525 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4526 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4527 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4528 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4529 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4530 | struct mesh_config cur_params; |
| 4531 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4532 | void *hdr; |
| 4533 | struct nlattr *pinfoattr; |
| 4534 | struct sk_buff *msg; |
| 4535 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4536 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4537 | return -EOPNOTSUPP; |
| 4538 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4539 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4540 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4541 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4542 | wdev_lock(wdev); |
| 4543 | /* If not connected, get default parameters */ |
| 4544 | if (!wdev->mesh_id_len) |
| 4545 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4546 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4547 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4548 | wdev_unlock(wdev); |
| 4549 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4550 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4551 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4552 | |
| 4553 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4554 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4555 | if (!msg) |
| 4556 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4557 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4558 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4559 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4560 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4561 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4562 | if (!pinfoattr) |
| 4563 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4564 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4565 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4566 | cur_params.dot11MeshRetryTimeout) || |
| 4567 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4568 | cur_params.dot11MeshConfirmTimeout) || |
| 4569 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4570 | cur_params.dot11MeshHoldingTimeout) || |
| 4571 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4572 | cur_params.dot11MeshMaxPeerLinks) || |
| 4573 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4574 | cur_params.dot11MeshMaxRetries) || |
| 4575 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4576 | cur_params.dot11MeshTTL) || |
| 4577 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4578 | cur_params.element_ttl) || |
| 4579 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4580 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4581 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4582 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4583 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4584 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4585 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4586 | cur_params.path_refresh_time) || |
| 4587 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4588 | cur_params.min_discovery_timeout) || |
| 4589 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4590 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4591 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4592 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4593 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4594 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4595 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4596 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4597 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4598 | cur_params.dot11MeshHWMPRootMode) || |
| 4599 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4600 | cur_params.dot11MeshHWMPRannInterval) || |
| 4601 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4602 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4603 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4604 | cur_params.dot11MeshForwarding) || |
| 4605 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4606 | cur_params.rssi_threshold) || |
| 4607 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4608 | cur_params.ht_opmode) || |
| 4609 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4610 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4611 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4612 | cur_params.dot11MeshHWMProotInterval) || |
| 4613 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4614 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4615 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4616 | cur_params.power_mode) || |
| 4617 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4618 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4619 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4620 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4621 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4622 | nla_nest_end(msg, pinfoattr); |
| 4623 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4624 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4625 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4626 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4627 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4628 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4629 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4630 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4631 | } |
| 4632 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4633 | 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] | 4634 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4635 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4636 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4637 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4638 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4639 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4640 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4641 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4642 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4643 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4644 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4645 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4646 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4647 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4648 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4649 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4650 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4651 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4652 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4653 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4654 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4655 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4656 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4657 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4658 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4659 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4660 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4661 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4662 | }; |
| 4663 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4664 | static const struct nla_policy |
| 4665 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4666 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4667 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4668 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4669 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4670 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4671 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4672 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4673 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4674 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4675 | }; |
| 4676 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4677 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4678 | struct mesh_config *cfg, |
| 4679 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4680 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4681 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4682 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4683 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4684 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4685 | do { \ |
| 4686 | if (tb[attr]) { \ |
| 4687 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4688 | return -EINVAL; \ |
| 4689 | cfg->param = fn(tb[attr]); \ |
| 4690 | mask |= (1 << (attr - 1)); \ |
| 4691 | } \ |
| 4692 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4693 | |
| 4694 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4695 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4696 | return -EINVAL; |
| 4697 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4698 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4699 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4700 | return -EINVAL; |
| 4701 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4702 | /* This makes sure that there aren't more than 32 mesh config |
| 4703 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4704 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4705 | |
| 4706 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4707 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4708 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4709 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4710 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4711 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4712 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4713 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4714 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4715 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4716 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4717 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4718 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4719 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4720 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4721 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4722 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4723 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4724 | 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] | 4725 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4726 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4727 | 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] | 4728 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4729 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4730 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4731 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4732 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4733 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4734 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4735 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4736 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4737 | 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] | 4738 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4739 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4740 | 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] | 4741 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4742 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4743 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4744 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4745 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4746 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4747 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4748 | 1, 65535, mask, |
| 4749 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4750 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4751 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4752 | 1, 65535, mask, |
| 4753 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4754 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4755 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4756 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4757 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4758 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 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, dot11MeshHWMPRootMode, 0, 4, |
| 4761 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4762 | nla_get_u8); |
| 4763 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4764 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4765 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4766 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4767 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4768 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4769 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4770 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4771 | mask, NL80211_MESHCONF_FORWARDING, |
| 4772 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4773 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4774 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4775 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4776 | 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] | 4777 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4778 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4779 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4780 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4781 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4782 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4783 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4784 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4785 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4786 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4787 | dot11MeshHWMPconfirmationInterval, |
| 4788 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4789 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4790 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4791 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4792 | NL80211_MESH_POWER_ACTIVE, |
| 4793 | NL80211_MESH_POWER_MAX, |
| 4794 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4795 | nla_get_u32); |
| 4796 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4797 | 0, 65535, mask, |
| 4798 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4799 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4800 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4801 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4802 | if (mask_out) |
| 4803 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4804 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4805 | return 0; |
| 4806 | |
| 4807 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4808 | } |
| 4809 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4810 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4811 | struct mesh_setup *setup) |
| 4812 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4813 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4814 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4815 | |
| 4816 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4817 | return -EINVAL; |
| 4818 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4819 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4820 | nl80211_mesh_setup_params_policy)) |
| 4821 | return -EINVAL; |
| 4822 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4823 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4824 | setup->sync_method = |
| 4825 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4826 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4827 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4828 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4829 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4830 | setup->path_sel_proto = |
| 4831 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4832 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4833 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4834 | |
| 4835 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4836 | setup->path_metric = |
| 4837 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4838 | IEEE80211_PATH_METRIC_VENDOR : |
| 4839 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4840 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4841 | |
| 4842 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4843 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4844 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4845 | if (!is_valid_ie_attr(ieattr)) |
| 4846 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4847 | setup->ie = nla_data(ieattr); |
| 4848 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4849 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4850 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4851 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4852 | return -EINVAL; |
| 4853 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4854 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4855 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4856 | if (setup->is_secure) |
| 4857 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4858 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4859 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 4860 | if (!setup->user_mpm) |
| 4861 | return -EINVAL; |
| 4862 | setup->auth_id = |
| 4863 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 4864 | } |
| 4865 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4866 | return 0; |
| 4867 | } |
| 4868 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4869 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4870 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4871 | { |
| 4872 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4873 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4874 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4875 | struct mesh_config cfg; |
| 4876 | u32 mask; |
| 4877 | int err; |
| 4878 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4879 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4880 | return -EOPNOTSUPP; |
| 4881 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4882 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4883 | return -EOPNOTSUPP; |
| 4884 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4885 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4886 | if (err) |
| 4887 | return err; |
| 4888 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4889 | wdev_lock(wdev); |
| 4890 | if (!wdev->mesh_id_len) |
| 4891 | err = -ENOLINK; |
| 4892 | |
| 4893 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4894 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4895 | |
| 4896 | wdev_unlock(wdev); |
| 4897 | |
| 4898 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4899 | } |
| 4900 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4901 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4902 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4903 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4904 | struct sk_buff *msg; |
| 4905 | void *hdr = NULL; |
| 4906 | struct nlattr *nl_reg_rules; |
| 4907 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4908 | |
| 4909 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4910 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4911 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4912 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4913 | if (!msg) |
| 4914 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4915 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4916 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4917 | NL80211_CMD_GET_REG); |
| 4918 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4919 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4920 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4921 | if (reg_last_request_cell_base() && |
| 4922 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4923 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4924 | goto nla_put_failure; |
| 4925 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4926 | rcu_read_lock(); |
| 4927 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4928 | |
| 4929 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4930 | (regdom->dfs_region && |
| 4931 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4932 | goto nla_put_failure_rcu; |
| 4933 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4934 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4935 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4936 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4937 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4938 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4939 | struct nlattr *nl_reg_rule; |
| 4940 | const struct ieee80211_reg_rule *reg_rule; |
| 4941 | const struct ieee80211_freq_range *freq_range; |
| 4942 | const struct ieee80211_power_rule *power_rule; |
| 4943 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4944 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4945 | freq_range = ®_rule->freq_range; |
| 4946 | power_rule = ®_rule->power_rule; |
| 4947 | |
| 4948 | nl_reg_rule = nla_nest_start(msg, i); |
| 4949 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4950 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4951 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4952 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4953 | reg_rule->flags) || |
| 4954 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4955 | freq_range->start_freq_khz) || |
| 4956 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4957 | freq_range->end_freq_khz) || |
| 4958 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4959 | freq_range->max_bandwidth_khz) || |
| 4960 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4961 | power_rule->max_antenna_gain) || |
| 4962 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4963 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4964 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4965 | |
| 4966 | nla_nest_end(msg, nl_reg_rule); |
| 4967 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4968 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4969 | |
| 4970 | nla_nest_end(msg, nl_reg_rules); |
| 4971 | |
| 4972 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4973 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4974 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4975 | nla_put_failure_rcu: |
| 4976 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4977 | nla_put_failure: |
| 4978 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4979 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4980 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4981 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4982 | } |
| 4983 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4984 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4985 | { |
| 4986 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4987 | struct nlattr *nl_reg_rule; |
| 4988 | char *alpha2 = NULL; |
| 4989 | int rem_reg_rules = 0, r = 0; |
| 4990 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4991 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4992 | struct ieee80211_regdomain *rd = NULL; |
| 4993 | |
| 4994 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4995 | return -EINVAL; |
| 4996 | |
| 4997 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4998 | return -EINVAL; |
| 4999 | |
| 5000 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5001 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5002 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5003 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5004 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5005 | 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] | 5006 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5007 | num_rules++; |
| 5008 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5009 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5010 | } |
| 5011 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5012 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5013 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5014 | |
| 5015 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5016 | if (!rd) |
| 5017 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5018 | |
| 5019 | rd->n_reg_rules = num_rules; |
| 5020 | rd->alpha2[0] = alpha2[0]; |
| 5021 | rd->alpha2[1] = alpha2[1]; |
| 5022 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5023 | /* |
| 5024 | * Disable DFS master mode if the DFS region was |
| 5025 | * not supported or known on this kernel. |
| 5026 | */ |
| 5027 | if (reg_supported_dfs_region(dfs_region)) |
| 5028 | rd->dfs_region = dfs_region; |
| 5029 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5030 | 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] | 5031 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5032 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5033 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5034 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5035 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5036 | if (r) |
| 5037 | goto bad_reg; |
| 5038 | |
| 5039 | rule_idx++; |
| 5040 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5041 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5042 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5043 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5044 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5045 | } |
| 5046 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5047 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5048 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5049 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5050 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5051 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5052 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5053 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5054 | } |
| 5055 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5056 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5057 | { |
| 5058 | struct nlattr *attr1, *attr2; |
| 5059 | int n_channels = 0, tmp1, tmp2; |
| 5060 | |
| 5061 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5062 | n_channels++; |
| 5063 | /* |
| 5064 | * Some hardware has a limited channel list for |
| 5065 | * scanning, and it is pretty much nonsensical |
| 5066 | * to scan for a channel twice, so disallow that |
| 5067 | * and don't require drivers to check that the |
| 5068 | * channel list they get isn't longer than what |
| 5069 | * they can scan, as long as they can scan all |
| 5070 | * the channels they registered at once. |
| 5071 | */ |
| 5072 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5073 | if (attr1 != attr2 && |
| 5074 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5075 | return 0; |
| 5076 | } |
| 5077 | |
| 5078 | return n_channels; |
| 5079 | } |
| 5080 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5081 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5082 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5083 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5084 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5085 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5086 | struct nlattr *attr; |
| 5087 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5088 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5089 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5090 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5091 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5092 | return -EINVAL; |
| 5093 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5094 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5095 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5096 | if (!rdev->ops->scan) |
| 5097 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5098 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5099 | if (rdev->scan_req) { |
| 5100 | err = -EBUSY; |
| 5101 | goto unlock; |
| 5102 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5103 | |
| 5104 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5105 | n_channels = validate_scan_freqs( |
| 5106 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5107 | if (!n_channels) { |
| 5108 | err = -EINVAL; |
| 5109 | goto unlock; |
| 5110 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5111 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5112 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5113 | n_channels = 0; |
| 5114 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5115 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5116 | if (wiphy->bands[band]) |
| 5117 | n_channels += wiphy->bands[band]->n_channels; |
| 5118 | } |
| 5119 | |
| 5120 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5121 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5122 | n_ssids++; |
| 5123 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5124 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5125 | err = -EINVAL; |
| 5126 | goto unlock; |
| 5127 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5128 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5129 | if (info->attrs[NL80211_ATTR_IE]) |
| 5130 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5131 | else |
| 5132 | ie_len = 0; |
| 5133 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5134 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5135 | err = -EINVAL; |
| 5136 | goto unlock; |
| 5137 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5138 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5139 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5140 | + sizeof(*request->ssids) * n_ssids |
| 5141 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5142 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5143 | if (!request) { |
| 5144 | err = -ENOMEM; |
| 5145 | goto unlock; |
| 5146 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5147 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5148 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5149 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5150 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5151 | if (ie_len) { |
| 5152 | if (request->ssids) |
| 5153 | request->ie = (void *)(request->ssids + n_ssids); |
| 5154 | else |
| 5155 | request->ie = (void *)(request->channels + n_channels); |
| 5156 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5157 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5158 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5159 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5160 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5161 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5162 | struct ieee80211_channel *chan; |
| 5163 | |
| 5164 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5165 | |
| 5166 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5167 | err = -EINVAL; |
| 5168 | goto out_free; |
| 5169 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5170 | |
| 5171 | /* ignore disabled channels */ |
| 5172 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5173 | continue; |
| 5174 | |
| 5175 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5176 | i++; |
| 5177 | } |
| 5178 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5179 | enum ieee80211_band band; |
| 5180 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5181 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5182 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5183 | int j; |
| 5184 | if (!wiphy->bands[band]) |
| 5185 | continue; |
| 5186 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5187 | struct ieee80211_channel *chan; |
| 5188 | |
| 5189 | chan = &wiphy->bands[band]->channels[j]; |
| 5190 | |
| 5191 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5192 | continue; |
| 5193 | |
| 5194 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5195 | i++; |
| 5196 | } |
| 5197 | } |
| 5198 | } |
| 5199 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5200 | if (!i) { |
| 5201 | err = -EINVAL; |
| 5202 | goto out_free; |
| 5203 | } |
| 5204 | |
| 5205 | request->n_channels = i; |
| 5206 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5207 | i = 0; |
| 5208 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5209 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5210 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5211 | err = -EINVAL; |
| 5212 | goto out_free; |
| 5213 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5214 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5215 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5216 | i++; |
| 5217 | } |
| 5218 | } |
| 5219 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5220 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5221 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5222 | memcpy((void *)request->ie, |
| 5223 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5224 | request->ie_len); |
| 5225 | } |
| 5226 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5227 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5228 | if (wiphy->bands[i]) |
| 5229 | request->rates[i] = |
| 5230 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5231 | |
| 5232 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5233 | nla_for_each_nested(attr, |
| 5234 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5235 | tmp) { |
| 5236 | enum ieee80211_band band = nla_type(attr); |
| 5237 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5238 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5239 | err = -EINVAL; |
| 5240 | goto out_free; |
| 5241 | } |
| 5242 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5243 | nla_data(attr), |
| 5244 | nla_len(attr), |
| 5245 | &request->rates[band]); |
| 5246 | if (err) |
| 5247 | goto out_free; |
| 5248 | } |
| 5249 | } |
| 5250 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5251 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5252 | request->flags = nla_get_u32( |
| 5253 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5254 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5255 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5256 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5257 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5258 | err = -EOPNOTSUPP; |
| 5259 | goto out_free; |
| 5260 | } |
| 5261 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5262 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5263 | request->no_cck = |
| 5264 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5265 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5266 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5267 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5268 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5269 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5270 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5271 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5272 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5273 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5274 | nl80211_send_scan_start(rdev, wdev); |
| 5275 | if (wdev->netdev) |
| 5276 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5277 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5278 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5279 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5280 | kfree(request); |
| 5281 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5282 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5283 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5284 | return err; |
| 5285 | } |
| 5286 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5287 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5288 | struct genl_info *info) |
| 5289 | { |
| 5290 | struct cfg80211_sched_scan_request *request; |
| 5291 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5292 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5293 | struct nlattr *attr; |
| 5294 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5295 | 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] | 5296 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5297 | enum ieee80211_band band; |
| 5298 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5299 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5300 | |
| 5301 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5302 | !rdev->ops->sched_scan_start) |
| 5303 | return -EOPNOTSUPP; |
| 5304 | |
| 5305 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5306 | return -EINVAL; |
| 5307 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5308 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5309 | return -EINVAL; |
| 5310 | |
| 5311 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5312 | if (interval == 0) |
| 5313 | return -EINVAL; |
| 5314 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5315 | wiphy = &rdev->wiphy; |
| 5316 | |
| 5317 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5318 | n_channels = validate_scan_freqs( |
| 5319 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5320 | if (!n_channels) |
| 5321 | return -EINVAL; |
| 5322 | } else { |
| 5323 | n_channels = 0; |
| 5324 | |
| 5325 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5326 | if (wiphy->bands[band]) |
| 5327 | n_channels += wiphy->bands[band]->n_channels; |
| 5328 | } |
| 5329 | |
| 5330 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5331 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5332 | tmp) |
| 5333 | n_ssids++; |
| 5334 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5335 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5336 | return -EINVAL; |
| 5337 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5338 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5339 | nla_for_each_nested(attr, |
| 5340 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5341 | tmp) |
| 5342 | n_match_sets++; |
| 5343 | |
| 5344 | if (n_match_sets > wiphy->max_match_sets) |
| 5345 | return -EINVAL; |
| 5346 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5347 | if (info->attrs[NL80211_ATTR_IE]) |
| 5348 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5349 | else |
| 5350 | ie_len = 0; |
| 5351 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5352 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5353 | return -EINVAL; |
| 5354 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5355 | if (rdev->sched_scan_req) { |
| 5356 | err = -EINPROGRESS; |
| 5357 | goto out; |
| 5358 | } |
| 5359 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5360 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5361 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5362 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5363 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5364 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5365 | if (!request) { |
| 5366 | err = -ENOMEM; |
| 5367 | goto out; |
| 5368 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5369 | |
| 5370 | if (n_ssids) |
| 5371 | request->ssids = (void *)&request->channels[n_channels]; |
| 5372 | request->n_ssids = n_ssids; |
| 5373 | if (ie_len) { |
| 5374 | if (request->ssids) |
| 5375 | request->ie = (void *)(request->ssids + n_ssids); |
| 5376 | else |
| 5377 | request->ie = (void *)(request->channels + n_channels); |
| 5378 | } |
| 5379 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5380 | if (n_match_sets) { |
| 5381 | if (request->ie) |
| 5382 | request->match_sets = (void *)(request->ie + ie_len); |
| 5383 | else if (request->ssids) |
| 5384 | request->match_sets = |
| 5385 | (void *)(request->ssids + n_ssids); |
| 5386 | else |
| 5387 | request->match_sets = |
| 5388 | (void *)(request->channels + n_channels); |
| 5389 | } |
| 5390 | request->n_match_sets = n_match_sets; |
| 5391 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5392 | i = 0; |
| 5393 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5394 | /* user specified, bail out if channel not found */ |
| 5395 | nla_for_each_nested(attr, |
| 5396 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5397 | tmp) { |
| 5398 | struct ieee80211_channel *chan; |
| 5399 | |
| 5400 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5401 | |
| 5402 | if (!chan) { |
| 5403 | err = -EINVAL; |
| 5404 | goto out_free; |
| 5405 | } |
| 5406 | |
| 5407 | /* ignore disabled channels */ |
| 5408 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5409 | continue; |
| 5410 | |
| 5411 | request->channels[i] = chan; |
| 5412 | i++; |
| 5413 | } |
| 5414 | } else { |
| 5415 | /* all channels */ |
| 5416 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5417 | int j; |
| 5418 | if (!wiphy->bands[band]) |
| 5419 | continue; |
| 5420 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5421 | struct ieee80211_channel *chan; |
| 5422 | |
| 5423 | chan = &wiphy->bands[band]->channels[j]; |
| 5424 | |
| 5425 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5426 | continue; |
| 5427 | |
| 5428 | request->channels[i] = chan; |
| 5429 | i++; |
| 5430 | } |
| 5431 | } |
| 5432 | } |
| 5433 | |
| 5434 | if (!i) { |
| 5435 | err = -EINVAL; |
| 5436 | goto out_free; |
| 5437 | } |
| 5438 | |
| 5439 | request->n_channels = i; |
| 5440 | |
| 5441 | i = 0; |
| 5442 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5443 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5444 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5445 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5446 | err = -EINVAL; |
| 5447 | goto out_free; |
| 5448 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5449 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5450 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5451 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5452 | i++; |
| 5453 | } |
| 5454 | } |
| 5455 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5456 | i = 0; |
| 5457 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5458 | nla_for_each_nested(attr, |
| 5459 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5460 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5461 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5462 | |
| 5463 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5464 | nla_data(attr), nla_len(attr), |
| 5465 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5466 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5467 | if (ssid) { |
| 5468 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5469 | err = -EINVAL; |
| 5470 | goto out_free; |
| 5471 | } |
| 5472 | memcpy(request->match_sets[i].ssid.ssid, |
| 5473 | nla_data(ssid), nla_len(ssid)); |
| 5474 | request->match_sets[i].ssid.ssid_len = |
| 5475 | nla_len(ssid); |
| 5476 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5477 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5478 | if (rssi) |
| 5479 | request->rssi_thold = nla_get_u32(rssi); |
| 5480 | else |
| 5481 | request->rssi_thold = |
| 5482 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5483 | i++; |
| 5484 | } |
| 5485 | } |
| 5486 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5487 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5488 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5489 | memcpy((void *)request->ie, |
| 5490 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5491 | request->ie_len); |
| 5492 | } |
| 5493 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5494 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5495 | request->flags = nla_get_u32( |
| 5496 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5497 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5498 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5499 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5500 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5501 | err = -EOPNOTSUPP; |
| 5502 | goto out_free; |
| 5503 | } |
| 5504 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5505 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5506 | request->dev = dev; |
| 5507 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5508 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5509 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5510 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5511 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5512 | if (!err) { |
| 5513 | rdev->sched_scan_req = request; |
| 5514 | nl80211_send_sched_scan(rdev, dev, |
| 5515 | NL80211_CMD_START_SCHED_SCAN); |
| 5516 | goto out; |
| 5517 | } |
| 5518 | |
| 5519 | out_free: |
| 5520 | kfree(request); |
| 5521 | out: |
| 5522 | return err; |
| 5523 | } |
| 5524 | |
| 5525 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5526 | struct genl_info *info) |
| 5527 | { |
| 5528 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5529 | |
| 5530 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5531 | !rdev->ops->sched_scan_stop) |
| 5532 | return -EOPNOTSUPP; |
| 5533 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5534 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5535 | } |
| 5536 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5537 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5538 | struct genl_info *info) |
| 5539 | { |
| 5540 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5541 | struct net_device *dev = info->user_ptr[1]; |
| 5542 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5543 | struct cfg80211_chan_def chandef; |
| 5544 | int err; |
| 5545 | |
| 5546 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5547 | if (err) |
| 5548 | return err; |
| 5549 | |
| 5550 | if (wdev->cac_started) |
| 5551 | return -EBUSY; |
| 5552 | |
| 5553 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5554 | if (err < 0) |
| 5555 | return err; |
| 5556 | |
| 5557 | if (err == 0) |
| 5558 | return -EINVAL; |
| 5559 | |
| 5560 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5561 | return -EINVAL; |
| 5562 | |
| 5563 | if (!rdev->ops->start_radar_detection) |
| 5564 | return -EOPNOTSUPP; |
| 5565 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5566 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5567 | chandef.chan, CHAN_MODE_SHARED, |
| 5568 | BIT(chandef.width)); |
| 5569 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5570 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5571 | |
| 5572 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5573 | if (!err) { |
| 5574 | wdev->channel = chandef.chan; |
| 5575 | wdev->cac_started = true; |
| 5576 | wdev->cac_start_time = jiffies; |
| 5577 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5578 | return err; |
| 5579 | } |
| 5580 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5581 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5582 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5583 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5584 | struct wireless_dev *wdev, |
| 5585 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5586 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5587 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5588 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5589 | void *hdr; |
| 5590 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5591 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5592 | |
| 5593 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5594 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5595 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5596 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5597 | if (!hdr) |
| 5598 | return -1; |
| 5599 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5600 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5601 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5602 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5603 | goto nla_put_failure; |
| 5604 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5605 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5606 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5607 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5608 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5609 | |
| 5610 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5611 | if (!bss) |
| 5612 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5613 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5614 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5615 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5616 | |
| 5617 | rcu_read_lock(); |
| 5618 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5619 | if (ies) { |
| 5620 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5621 | goto fail_unlock_rcu; |
| 5622 | tsf = true; |
| 5623 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5624 | ies->len, ies->data)) |
| 5625 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5626 | } |
| 5627 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5628 | if (ies) { |
| 5629 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5630 | goto fail_unlock_rcu; |
| 5631 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5632 | ies->len, ies->data)) |
| 5633 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5634 | } |
| 5635 | rcu_read_unlock(); |
| 5636 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5637 | if (res->beacon_interval && |
| 5638 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5639 | goto nla_put_failure; |
| 5640 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5641 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5642 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5643 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5644 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5645 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5646 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5647 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5648 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5649 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5650 | break; |
| 5651 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5652 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5653 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5654 | break; |
| 5655 | default: |
| 5656 | break; |
| 5657 | } |
| 5658 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5659 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5660 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5661 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5662 | if (intbss == wdev->current_bss && |
| 5663 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5664 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5665 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5666 | break; |
| 5667 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5668 | if (intbss == wdev->current_bss && |
| 5669 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5670 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5671 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5672 | break; |
| 5673 | default: |
| 5674 | break; |
| 5675 | } |
| 5676 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5677 | nla_nest_end(msg, bss); |
| 5678 | |
| 5679 | return genlmsg_end(msg, hdr); |
| 5680 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5681 | fail_unlock_rcu: |
| 5682 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5683 | nla_put_failure: |
| 5684 | genlmsg_cancel(msg, hdr); |
| 5685 | return -EMSGSIZE; |
| 5686 | } |
| 5687 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5688 | 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] | 5689 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5690 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5691 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5692 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5693 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5694 | int err; |
| 5695 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5696 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5697 | if (err) |
| 5698 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5699 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5700 | wdev_lock(wdev); |
| 5701 | spin_lock_bh(&rdev->bss_lock); |
| 5702 | cfg80211_bss_expire(rdev); |
| 5703 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5704 | cb->seq = rdev->bss_generation; |
| 5705 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5706 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5707 | if (++idx <= start) |
| 5708 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5709 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5710 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5711 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5712 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5713 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5714 | } |
| 5715 | } |
| 5716 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5717 | spin_unlock_bh(&rdev->bss_lock); |
| 5718 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5719 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5720 | cb->args[2] = idx; |
| 5721 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5722 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5723 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5724 | } |
| 5725 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5726 | 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] | 5727 | int flags, struct net_device *dev, |
| 5728 | struct survey_info *survey) |
| 5729 | { |
| 5730 | void *hdr; |
| 5731 | struct nlattr *infoattr; |
| 5732 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5733 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5734 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5735 | if (!hdr) |
| 5736 | return -ENOMEM; |
| 5737 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5738 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5739 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5740 | |
| 5741 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5742 | if (!infoattr) |
| 5743 | goto nla_put_failure; |
| 5744 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5745 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5746 | survey->channel->center_freq)) |
| 5747 | goto nla_put_failure; |
| 5748 | |
| 5749 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5750 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5751 | goto nla_put_failure; |
| 5752 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5753 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5754 | goto nla_put_failure; |
| 5755 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5756 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5757 | survey->channel_time)) |
| 5758 | goto nla_put_failure; |
| 5759 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5760 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5761 | survey->channel_time_busy)) |
| 5762 | goto nla_put_failure; |
| 5763 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5764 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5765 | survey->channel_time_ext_busy)) |
| 5766 | goto nla_put_failure; |
| 5767 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5768 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5769 | survey->channel_time_rx)) |
| 5770 | goto nla_put_failure; |
| 5771 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5772 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5773 | survey->channel_time_tx)) |
| 5774 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5775 | |
| 5776 | nla_nest_end(msg, infoattr); |
| 5777 | |
| 5778 | return genlmsg_end(msg, hdr); |
| 5779 | |
| 5780 | nla_put_failure: |
| 5781 | genlmsg_cancel(msg, hdr); |
| 5782 | return -EMSGSIZE; |
| 5783 | } |
| 5784 | |
| 5785 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5786 | struct netlink_callback *cb) |
| 5787 | { |
| 5788 | struct survey_info survey; |
| 5789 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5790 | struct wireless_dev *wdev; |
| 5791 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5792 | int res; |
| 5793 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5794 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5795 | if (res) |
| 5796 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5797 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5798 | if (!wdev->netdev) { |
| 5799 | res = -EINVAL; |
| 5800 | goto out_err; |
| 5801 | } |
| 5802 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5803 | if (!dev->ops->dump_survey) { |
| 5804 | res = -EOPNOTSUPP; |
| 5805 | goto out_err; |
| 5806 | } |
| 5807 | |
| 5808 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5809 | struct ieee80211_channel *chan; |
| 5810 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5811 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5812 | if (res == -ENOENT) |
| 5813 | break; |
| 5814 | if (res) |
| 5815 | goto out_err; |
| 5816 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5817 | /* Survey without a channel doesn't make sense */ |
| 5818 | if (!survey.channel) { |
| 5819 | res = -EINVAL; |
| 5820 | goto out; |
| 5821 | } |
| 5822 | |
| 5823 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5824 | survey.channel->center_freq); |
| 5825 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5826 | survey_idx++; |
| 5827 | continue; |
| 5828 | } |
| 5829 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5830 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5831 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5832 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5833 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5834 | goto out; |
| 5835 | survey_idx++; |
| 5836 | } |
| 5837 | |
| 5838 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5839 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5840 | res = skb->len; |
| 5841 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5842 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5843 | return res; |
| 5844 | } |
| 5845 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5846 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5847 | { |
| 5848 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5849 | NL80211_WPA_VERSION_2)); |
| 5850 | } |
| 5851 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5852 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5853 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5854 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5855 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5856 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5857 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5858 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5859 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5860 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5861 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5862 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5863 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5864 | return -EINVAL; |
| 5865 | |
| 5866 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5867 | return -EINVAL; |
| 5868 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5869 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5870 | return -EINVAL; |
| 5871 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5872 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5873 | return -EINVAL; |
| 5874 | |
| 5875 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5876 | return -EINVAL; |
| 5877 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5878 | err = nl80211_parse_key(info, &key); |
| 5879 | if (err) |
| 5880 | return err; |
| 5881 | |
| 5882 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5883 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5884 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5885 | if (!key.p.key || !key.p.key_len) |
| 5886 | return -EINVAL; |
| 5887 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5888 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5889 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5890 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5891 | return -EINVAL; |
| 5892 | if (key.idx > 4) |
| 5893 | return -EINVAL; |
| 5894 | } else { |
| 5895 | key.p.key_len = 0; |
| 5896 | key.p.key = NULL; |
| 5897 | } |
| 5898 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5899 | if (key.idx >= 0) { |
| 5900 | int i; |
| 5901 | bool ok = false; |
| 5902 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5903 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5904 | ok = true; |
| 5905 | break; |
| 5906 | } |
| 5907 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5908 | if (!ok) |
| 5909 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5910 | } |
| 5911 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5912 | if (!rdev->ops->auth) |
| 5913 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5914 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5915 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5916 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5917 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5918 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5919 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5920 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5921 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5922 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5923 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5924 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5925 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5926 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5927 | |
| 5928 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5929 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5930 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5931 | } |
| 5932 | |
| 5933 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5934 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5935 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5936 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5937 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5938 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5939 | return -EINVAL; |
| 5940 | |
| 5941 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5942 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5943 | return -EINVAL; |
| 5944 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5945 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5946 | /* need to include at least Auth Transaction and Status Code */ |
| 5947 | if (sae_data_len < 4) |
| 5948 | return -EINVAL; |
| 5949 | } |
| 5950 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5951 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5952 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5953 | /* |
| 5954 | * Since we no longer track auth state, ignore |
| 5955 | * requests to only change local state. |
| 5956 | */ |
| 5957 | if (local_state_change) |
| 5958 | return 0; |
| 5959 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 5960 | wdev_lock(dev->ieee80211_ptr); |
| 5961 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5962 | ssid, ssid_len, ie, ie_len, |
| 5963 | key.p.key, key.p.key_len, key.idx, |
| 5964 | sae_data, sae_data_len); |
| 5965 | wdev_unlock(dev->ieee80211_ptr); |
| 5966 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5967 | } |
| 5968 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5969 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5970 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5971 | struct cfg80211_crypto_settings *settings, |
| 5972 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5973 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5974 | memset(settings, 0, sizeof(*settings)); |
| 5975 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5976 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5977 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5978 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5979 | u16 proto; |
| 5980 | proto = nla_get_u16( |
| 5981 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5982 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5983 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5984 | proto != ETH_P_PAE) |
| 5985 | return -EINVAL; |
| 5986 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5987 | settings->control_port_no_encrypt = true; |
| 5988 | } else |
| 5989 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5990 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5991 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5992 | void *data; |
| 5993 | int len, i; |
| 5994 | |
| 5995 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5996 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5997 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5998 | |
| 5999 | if (len % sizeof(u32)) |
| 6000 | return -EINVAL; |
| 6001 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6002 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6003 | return -EINVAL; |
| 6004 | |
| 6005 | memcpy(settings->ciphers_pairwise, data, len); |
| 6006 | |
| 6007 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6008 | if (!cfg80211_supported_cipher_suite( |
| 6009 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6010 | settings->ciphers_pairwise[i])) |
| 6011 | return -EINVAL; |
| 6012 | } |
| 6013 | |
| 6014 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6015 | settings->cipher_group = |
| 6016 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6017 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6018 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6019 | return -EINVAL; |
| 6020 | } |
| 6021 | |
| 6022 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6023 | settings->wpa_versions = |
| 6024 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6025 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6026 | return -EINVAL; |
| 6027 | } |
| 6028 | |
| 6029 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6030 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6031 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6032 | |
| 6033 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6034 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6035 | settings->n_akm_suites = len / sizeof(u32); |
| 6036 | |
| 6037 | if (len % sizeof(u32)) |
| 6038 | return -EINVAL; |
| 6039 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6040 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6041 | return -EINVAL; |
| 6042 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6043 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6044 | } |
| 6045 | |
| 6046 | return 0; |
| 6047 | } |
| 6048 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6049 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6050 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6051 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6052 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6053 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6054 | struct cfg80211_assoc_request req = {}; |
| 6055 | const u8 *bssid, *ssid; |
| 6056 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6057 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6058 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6059 | return -EINVAL; |
| 6060 | |
| 6061 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6062 | !info->attrs[NL80211_ATTR_SSID] || |
| 6063 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6064 | return -EINVAL; |
| 6065 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6066 | if (!rdev->ops->assoc) |
| 6067 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6068 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6069 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6070 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6071 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6072 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6073 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
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 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6076 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6077 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6078 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6079 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6080 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6081 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6082 | |
| 6083 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6084 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6085 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6086 | } |
| 6087 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6088 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6089 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6090 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6091 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6092 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6093 | else if (mfp != NL80211_MFP_NO) |
| 6094 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6095 | } |
| 6096 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6097 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6098 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6099 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6100 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6101 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6102 | |
| 6103 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6104 | memcpy(&req.ht_capa_mask, |
| 6105 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6106 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6107 | |
| 6108 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6109 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6110 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6111 | memcpy(&req.ht_capa, |
| 6112 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6113 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6114 | } |
| 6115 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6116 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6117 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6118 | |
| 6119 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6120 | memcpy(&req.vht_capa_mask, |
| 6121 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6122 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6123 | |
| 6124 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6125 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6126 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6127 | memcpy(&req.vht_capa, |
| 6128 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6129 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6130 | } |
| 6131 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6132 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6133 | if (!err) { |
| 6134 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6135 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6136 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6137 | wdev_unlock(dev->ieee80211_ptr); |
| 6138 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6139 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6140 | return err; |
| 6141 | } |
| 6142 | |
| 6143 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6144 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6145 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6146 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6147 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6148 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6149 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6150 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6151 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6152 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6153 | return -EINVAL; |
| 6154 | |
| 6155 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6156 | return -EINVAL; |
| 6157 | |
| 6158 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6159 | return -EINVAL; |
| 6160 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6161 | if (!rdev->ops->deauth) |
| 6162 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6163 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6164 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6165 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6166 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6167 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6168 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6169 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6170 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6171 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6172 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6173 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6174 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6175 | |
| 6176 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6177 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6178 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6179 | } |
| 6180 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6181 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6182 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6183 | wdev_lock(dev->ieee80211_ptr); |
| 6184 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6185 | local_state_change); |
| 6186 | wdev_unlock(dev->ieee80211_ptr); |
| 6187 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6188 | } |
| 6189 | |
| 6190 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6191 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6192 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6193 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6194 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6195 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6196 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6197 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6198 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6199 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6200 | return -EINVAL; |
| 6201 | |
| 6202 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6203 | return -EINVAL; |
| 6204 | |
| 6205 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6206 | return -EINVAL; |
| 6207 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6208 | if (!rdev->ops->disassoc) |
| 6209 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6210 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6211 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6212 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6213 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6214 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6215 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6216 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6217 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6218 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6219 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6220 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6221 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6222 | |
| 6223 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6224 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6225 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6226 | } |
| 6227 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6228 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6229 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6230 | wdev_lock(dev->ieee80211_ptr); |
| 6231 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6232 | local_state_change); |
| 6233 | wdev_unlock(dev->ieee80211_ptr); |
| 6234 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6235 | } |
| 6236 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6237 | static bool |
| 6238 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6239 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6240 | int rateval) |
| 6241 | { |
| 6242 | struct wiphy *wiphy = &rdev->wiphy; |
| 6243 | bool found = false; |
| 6244 | int band, i; |
| 6245 | |
| 6246 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6247 | struct ieee80211_supported_band *sband; |
| 6248 | |
| 6249 | sband = wiphy->bands[band]; |
| 6250 | if (!sband) |
| 6251 | continue; |
| 6252 | |
| 6253 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6254 | if (sband->bitrates[i].bitrate == rateval) { |
| 6255 | mcast_rate[band] = i + 1; |
| 6256 | found = true; |
| 6257 | break; |
| 6258 | } |
| 6259 | } |
| 6260 | } |
| 6261 | |
| 6262 | return found; |
| 6263 | } |
| 6264 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6265 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6266 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6267 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6268 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6269 | struct cfg80211_ibss_params ibss; |
| 6270 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6271 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6272 | int err; |
| 6273 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6274 | memset(&ibss, 0, sizeof(ibss)); |
| 6275 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6276 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6277 | return -EINVAL; |
| 6278 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6279 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6280 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6281 | return -EINVAL; |
| 6282 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6283 | ibss.beacon_interval = 100; |
| 6284 | |
| 6285 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6286 | ibss.beacon_interval = |
| 6287 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6288 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6289 | return -EINVAL; |
| 6290 | } |
| 6291 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6292 | if (!rdev->ops->join_ibss) |
| 6293 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6294 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6295 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6296 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6297 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6298 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6299 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6300 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6301 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6302 | |
| 6303 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6304 | return -EINVAL; |
| 6305 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6306 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6307 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6308 | |
| 6309 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6310 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6311 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6312 | } |
| 6313 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6314 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6315 | if (err) |
| 6316 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6317 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6318 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6319 | return -EINVAL; |
| 6320 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6321 | switch (ibss.chandef.width) { |
| 6322 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6323 | break; |
| 6324 | case NL80211_CHAN_WIDTH_20: |
| 6325 | case NL80211_CHAN_WIDTH_40: |
| 6326 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6327 | break; |
| 6328 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6329 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6330 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6331 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6332 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6333 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6334 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6335 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6336 | u8 *rates = |
| 6337 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6338 | int n_rates = |
| 6339 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6340 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6341 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6342 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6343 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6344 | &ibss.basic_rates); |
| 6345 | if (err) |
| 6346 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6347 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6348 | |
| 6349 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6350 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6351 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6352 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6353 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6354 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6355 | bool no_ht = false; |
| 6356 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6357 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6358 | info->attrs[NL80211_ATTR_KEYS], |
| 6359 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6360 | if (IS_ERR(connkeys)) |
| 6361 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6362 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6363 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6364 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6365 | kfree(connkeys); |
| 6366 | return -EINVAL; |
| 6367 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6368 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6369 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6370 | ibss.control_port = |
| 6371 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6372 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6373 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6374 | if (err) |
| 6375 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6376 | return err; |
| 6377 | } |
| 6378 | |
| 6379 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6380 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6381 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6382 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6383 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6384 | if (!rdev->ops->leave_ibss) |
| 6385 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6386 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6387 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6388 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6389 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6390 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6391 | } |
| 6392 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6393 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6394 | { |
| 6395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6396 | struct net_device *dev = info->user_ptr[1]; |
| 6397 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6398 | u32 nla_rate; |
| 6399 | int err; |
| 6400 | |
| 6401 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6402 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6403 | return -EOPNOTSUPP; |
| 6404 | |
| 6405 | if (!rdev->ops->set_mcast_rate) |
| 6406 | return -EOPNOTSUPP; |
| 6407 | |
| 6408 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6409 | |
| 6410 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6411 | return -EINVAL; |
| 6412 | |
| 6413 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6414 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6415 | return -EINVAL; |
| 6416 | |
| 6417 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6418 | |
| 6419 | return err; |
| 6420 | } |
| 6421 | |
| 6422 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6423 | #ifdef CONFIG_NL80211_TESTMODE |
| 6424 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6425 | .name = "testmode", |
| 6426 | }; |
| 6427 | |
| 6428 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6429 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6431 | int err; |
| 6432 | |
| 6433 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6434 | return -EINVAL; |
| 6435 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6436 | err = -EOPNOTSUPP; |
| 6437 | if (rdev->ops->testmode_cmd) { |
| 6438 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6439 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6440 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6441 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 6442 | rdev->testmode_info = NULL; |
| 6443 | } |
| 6444 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6445 | return err; |
| 6446 | } |
| 6447 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6448 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6449 | struct netlink_callback *cb) |
| 6450 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6451 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6452 | int err; |
| 6453 | long phy_idx; |
| 6454 | void *data = NULL; |
| 6455 | int data_len = 0; |
| 6456 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6457 | rtnl_lock(); |
| 6458 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6459 | if (cb->args[0]) { |
| 6460 | /* |
| 6461 | * 0 is a valid index, but not valid for args[0], |
| 6462 | * so we need to offset by 1. |
| 6463 | */ |
| 6464 | phy_idx = cb->args[0] - 1; |
| 6465 | } else { |
| 6466 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6467 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6468 | nl80211_policy); |
| 6469 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6470 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6471 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6472 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6473 | nl80211_fam.attrbuf); |
| 6474 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6475 | err = PTR_ERR(rdev); |
| 6476 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6477 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6478 | phy_idx = rdev->wiphy_idx; |
| 6479 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6480 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6481 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6482 | cb->args[1] = |
| 6483 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6484 | } |
| 6485 | |
| 6486 | if (cb->args[1]) { |
| 6487 | data = nla_data((void *)cb->args[1]); |
| 6488 | data_len = nla_len((void *)cb->args[1]); |
| 6489 | } |
| 6490 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6491 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6492 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6493 | err = -ENOENT; |
| 6494 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6495 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6496 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6497 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6498 | err = -EOPNOTSUPP; |
| 6499 | goto out_err; |
| 6500 | } |
| 6501 | |
| 6502 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6503 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6504 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6505 | NL80211_CMD_TESTMODE); |
| 6506 | struct nlattr *tmdata; |
| 6507 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6508 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6509 | genlmsg_cancel(skb, hdr); |
| 6510 | break; |
| 6511 | } |
| 6512 | |
| 6513 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6514 | if (!tmdata) { |
| 6515 | genlmsg_cancel(skb, hdr); |
| 6516 | break; |
| 6517 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6518 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6519 | nla_nest_end(skb, tmdata); |
| 6520 | |
| 6521 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6522 | genlmsg_cancel(skb, hdr); |
| 6523 | break; |
| 6524 | } else if (err) { |
| 6525 | genlmsg_cancel(skb, hdr); |
| 6526 | goto out_err; |
| 6527 | } |
| 6528 | |
| 6529 | genlmsg_end(skb, hdr); |
| 6530 | } |
| 6531 | |
| 6532 | err = skb->len; |
| 6533 | /* see above */ |
| 6534 | cb->args[0] = phy_idx + 1; |
| 6535 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6536 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6537 | return err; |
| 6538 | } |
| 6539 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6540 | static struct sk_buff * |
| 6541 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6542 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6543 | { |
| 6544 | struct sk_buff *skb; |
| 6545 | void *hdr; |
| 6546 | struct nlattr *data; |
| 6547 | |
| 6548 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6549 | if (!skb) |
| 6550 | return NULL; |
| 6551 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6552 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6553 | if (!hdr) { |
| 6554 | kfree_skb(skb); |
| 6555 | return NULL; |
| 6556 | } |
| 6557 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6558 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6559 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6560 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6561 | |
| 6562 | ((void **)skb->cb)[0] = rdev; |
| 6563 | ((void **)skb->cb)[1] = hdr; |
| 6564 | ((void **)skb->cb)[2] = data; |
| 6565 | |
| 6566 | return skb; |
| 6567 | |
| 6568 | nla_put_failure: |
| 6569 | kfree_skb(skb); |
| 6570 | return NULL; |
| 6571 | } |
| 6572 | |
| 6573 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6574 | int approxlen) |
| 6575 | { |
| 6576 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6577 | |
| 6578 | if (WARN_ON(!rdev->testmode_info)) |
| 6579 | return NULL; |
| 6580 | |
| 6581 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6582 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6583 | rdev->testmode_info->snd_seq, |
| 6584 | GFP_KERNEL); |
| 6585 | } |
| 6586 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6587 | |
| 6588 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6589 | { |
| 6590 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6591 | void *hdr = ((void **)skb->cb)[1]; |
| 6592 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6593 | |
| 6594 | if (WARN_ON(!rdev->testmode_info)) { |
| 6595 | kfree_skb(skb); |
| 6596 | return -EINVAL; |
| 6597 | } |
| 6598 | |
| 6599 | nla_nest_end(skb, data); |
| 6600 | genlmsg_end(skb, hdr); |
| 6601 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6602 | } |
| 6603 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6604 | |
| 6605 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6606 | int approxlen, gfp_t gfp) |
| 6607 | { |
| 6608 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6609 | |
| 6610 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6611 | } |
| 6612 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6613 | |
| 6614 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6615 | { |
| 6616 | void *hdr = ((void **)skb->cb)[1]; |
| 6617 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6618 | |
| 6619 | nla_nest_end(skb, data); |
| 6620 | genlmsg_end(skb, hdr); |
| 6621 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6622 | } |
| 6623 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6624 | #endif |
| 6625 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6626 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6627 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6628 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6629 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6630 | struct cfg80211_connect_params connect; |
| 6631 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6632 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6633 | int err; |
| 6634 | |
| 6635 | memset(&connect, 0, sizeof(connect)); |
| 6636 | |
| 6637 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6638 | return -EINVAL; |
| 6639 | |
| 6640 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6641 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6642 | return -EINVAL; |
| 6643 | |
| 6644 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6645 | connect.auth_type = |
| 6646 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6647 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6648 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6649 | return -EINVAL; |
| 6650 | } else |
| 6651 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6652 | |
| 6653 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6654 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6655 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6656 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6657 | if (err) |
| 6658 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6659 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6660 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6661 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6662 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6663 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6664 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6665 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6666 | connect.bg_scan_period = -1; |
| 6667 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6668 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6669 | connect.bg_scan_period = |
| 6670 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6671 | } |
| 6672 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6673 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6674 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6675 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6676 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6677 | |
| 6678 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6679 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6680 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6681 | } |
| 6682 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6683 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6684 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6685 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6686 | connect.mfp != NL80211_MFP_NO) |
| 6687 | return -EINVAL; |
| 6688 | } else { |
| 6689 | connect.mfp = NL80211_MFP_NO; |
| 6690 | } |
| 6691 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6692 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6693 | connect.channel = |
| 6694 | ieee80211_get_channel(wiphy, |
| 6695 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6696 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6697 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6698 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6699 | } |
| 6700 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6701 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6702 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6703 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6704 | if (IS_ERR(connkeys)) |
| 6705 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6706 | } |
| 6707 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6708 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6709 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6710 | |
| 6711 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6712 | memcpy(&connect.ht_capa_mask, |
| 6713 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6714 | sizeof(connect.ht_capa_mask)); |
| 6715 | |
| 6716 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6717 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6718 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6719 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6720 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6721 | memcpy(&connect.ht_capa, |
| 6722 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6723 | sizeof(connect.ht_capa)); |
| 6724 | } |
| 6725 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6726 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6727 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6728 | |
| 6729 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6730 | memcpy(&connect.vht_capa_mask, |
| 6731 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6732 | sizeof(connect.vht_capa_mask)); |
| 6733 | |
| 6734 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 6735 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 6736 | kfree(connkeys); |
| 6737 | return -EINVAL; |
| 6738 | } |
| 6739 | memcpy(&connect.vht_capa, |
| 6740 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6741 | sizeof(connect.vht_capa)); |
| 6742 | } |
| 6743 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6744 | wdev_lock(dev->ieee80211_ptr); |
| 6745 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 6746 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6747 | if (err) |
| 6748 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6749 | return err; |
| 6750 | } |
| 6751 | |
| 6752 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6753 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6754 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6755 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6756 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6757 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6758 | |
| 6759 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6760 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6761 | else |
| 6762 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6763 | |
| 6764 | if (reason == 0) |
| 6765 | return -EINVAL; |
| 6766 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6767 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6768 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6769 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6770 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6771 | wdev_lock(dev->ieee80211_ptr); |
| 6772 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 6773 | wdev_unlock(dev->ieee80211_ptr); |
| 6774 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6775 | } |
| 6776 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6777 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6778 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6779 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6780 | struct net *net; |
| 6781 | int err; |
| 6782 | u32 pid; |
| 6783 | |
| 6784 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6785 | return -EINVAL; |
| 6786 | |
| 6787 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6788 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6789 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6790 | if (IS_ERR(net)) |
| 6791 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6792 | |
| 6793 | err = 0; |
| 6794 | |
| 6795 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6796 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6797 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6798 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6799 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6800 | return err; |
| 6801 | } |
| 6802 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6803 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6804 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6805 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6806 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6807 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6808 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6809 | struct cfg80211_pmksa pmksa; |
| 6810 | |
| 6811 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6812 | |
| 6813 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6814 | return -EINVAL; |
| 6815 | |
| 6816 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6817 | return -EINVAL; |
| 6818 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6819 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6820 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6821 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6822 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6823 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6824 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6825 | |
| 6826 | switch (info->genlhdr->cmd) { |
| 6827 | case NL80211_CMD_SET_PMKSA: |
| 6828 | rdev_ops = rdev->ops->set_pmksa; |
| 6829 | break; |
| 6830 | case NL80211_CMD_DEL_PMKSA: |
| 6831 | rdev_ops = rdev->ops->del_pmksa; |
| 6832 | break; |
| 6833 | default: |
| 6834 | WARN_ON(1); |
| 6835 | break; |
| 6836 | } |
| 6837 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6838 | if (!rdev_ops) |
| 6839 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6840 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6841 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6842 | } |
| 6843 | |
| 6844 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6845 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6846 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6847 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6848 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6849 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6850 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6851 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6852 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6853 | if (!rdev->ops->flush_pmksa) |
| 6854 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6855 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6856 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6857 | } |
| 6858 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6859 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6860 | { |
| 6861 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6862 | struct net_device *dev = info->user_ptr[1]; |
| 6863 | u8 action_code, dialog_token; |
| 6864 | u16 status_code; |
| 6865 | u8 *peer; |
| 6866 | |
| 6867 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6868 | !rdev->ops->tdls_mgmt) |
| 6869 | return -EOPNOTSUPP; |
| 6870 | |
| 6871 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6872 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6873 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6874 | !info->attrs[NL80211_ATTR_IE] || |
| 6875 | !info->attrs[NL80211_ATTR_MAC]) |
| 6876 | return -EINVAL; |
| 6877 | |
| 6878 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6879 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6880 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6881 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6882 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6883 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6884 | dialog_token, status_code, |
| 6885 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6886 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6887 | } |
| 6888 | |
| 6889 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6890 | { |
| 6891 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6892 | struct net_device *dev = info->user_ptr[1]; |
| 6893 | enum nl80211_tdls_operation operation; |
| 6894 | u8 *peer; |
| 6895 | |
| 6896 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6897 | !rdev->ops->tdls_oper) |
| 6898 | return -EOPNOTSUPP; |
| 6899 | |
| 6900 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6901 | !info->attrs[NL80211_ATTR_MAC]) |
| 6902 | return -EINVAL; |
| 6903 | |
| 6904 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6905 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6906 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6907 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6908 | } |
| 6909 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6910 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6911 | struct genl_info *info) |
| 6912 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6913 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6914 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6915 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6916 | struct sk_buff *msg; |
| 6917 | void *hdr; |
| 6918 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6919 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6920 | int err; |
| 6921 | |
| 6922 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6923 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6924 | return -EINVAL; |
| 6925 | |
| 6926 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6927 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6928 | if (!rdev->ops->remain_on_channel || |
| 6929 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6930 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6931 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6932 | /* |
| 6933 | * We should be on that channel for at least a minimum amount of |
| 6934 | * time (10ms) but no longer than the driver supports. |
| 6935 | */ |
| 6936 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6937 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6938 | return -EINVAL; |
| 6939 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6940 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6941 | if (err) |
| 6942 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6943 | |
| 6944 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6945 | if (!msg) |
| 6946 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6947 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6948 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6949 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6950 | |
| 6951 | if (IS_ERR(hdr)) { |
| 6952 | err = PTR_ERR(hdr); |
| 6953 | goto free_msg; |
| 6954 | } |
| 6955 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6956 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6957 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6958 | |
| 6959 | if (err) |
| 6960 | goto free_msg; |
| 6961 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6962 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6963 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6964 | |
| 6965 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6966 | |
| 6967 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6968 | |
| 6969 | nla_put_failure: |
| 6970 | err = -ENOBUFS; |
| 6971 | free_msg: |
| 6972 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6973 | return err; |
| 6974 | } |
| 6975 | |
| 6976 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6977 | struct genl_info *info) |
| 6978 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6979 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6980 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6981 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6982 | |
| 6983 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6984 | return -EINVAL; |
| 6985 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6986 | if (!rdev->ops->cancel_remain_on_channel) |
| 6987 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6988 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6989 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6990 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6991 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6992 | } |
| 6993 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6994 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6995 | u8 *rates, u8 rates_len) |
| 6996 | { |
| 6997 | u8 i; |
| 6998 | u32 mask = 0; |
| 6999 | |
| 7000 | for (i = 0; i < rates_len; i++) { |
| 7001 | int rate = (rates[i] & 0x7f) * 5; |
| 7002 | int ridx; |
| 7003 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7004 | struct ieee80211_rate *srate = |
| 7005 | &sband->bitrates[ridx]; |
| 7006 | if (rate == srate->bitrate) { |
| 7007 | mask |= 1 << ridx; |
| 7008 | break; |
| 7009 | } |
| 7010 | } |
| 7011 | if (ridx == sband->n_bitrates) |
| 7012 | return 0; /* rate not found */ |
| 7013 | } |
| 7014 | |
| 7015 | return mask; |
| 7016 | } |
| 7017 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7018 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7019 | u8 *rates, u8 rates_len, |
| 7020 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7021 | { |
| 7022 | u8 i; |
| 7023 | |
| 7024 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7025 | |
| 7026 | for (i = 0; i < rates_len; i++) { |
| 7027 | int ridx, rbit; |
| 7028 | |
| 7029 | ridx = rates[i] / 8; |
| 7030 | rbit = BIT(rates[i] % 8); |
| 7031 | |
| 7032 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7033 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7034 | return false; |
| 7035 | |
| 7036 | /* check availability */ |
| 7037 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7038 | mcs[ridx] |= rbit; |
| 7039 | else |
| 7040 | return false; |
| 7041 | } |
| 7042 | |
| 7043 | return true; |
| 7044 | } |
| 7045 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7046 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7047 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7048 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7049 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 7050 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7051 | }; |
| 7052 | |
| 7053 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7054 | struct genl_info *info) |
| 7055 | { |
| 7056 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7057 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7058 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7059 | int rem, i; |
| 7060 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7061 | struct nlattr *tx_rates; |
| 7062 | struct ieee80211_supported_band *sband; |
| 7063 | |
| 7064 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7065 | return -EINVAL; |
| 7066 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7067 | if (!rdev->ops->set_bitrate_mask) |
| 7068 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7069 | |
| 7070 | memset(&mask, 0, sizeof(mask)); |
| 7071 | /* Default to all rates enabled */ |
| 7072 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7073 | sband = rdev->wiphy.bands[i]; |
| 7074 | mask.control[i].legacy = |
| 7075 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7076 | if (sband) |
| 7077 | memcpy(mask.control[i].mcs, |
| 7078 | sband->ht_cap.mcs.rx_mask, |
| 7079 | sizeof(mask.control[i].mcs)); |
| 7080 | else |
| 7081 | memset(mask.control[i].mcs, 0, |
| 7082 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7083 | } |
| 7084 | |
| 7085 | /* |
| 7086 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7087 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7088 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7089 | 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] | 7090 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7091 | { |
| 7092 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7093 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7094 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7095 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7096 | if (sband == NULL) |
| 7097 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7098 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7099 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7100 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7101 | mask.control[band].legacy = rateset_to_mask( |
| 7102 | sband, |
| 7103 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7104 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7105 | if ((mask.control[band].legacy == 0) && |
| 7106 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7107 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7108 | } |
| 7109 | if (tb[NL80211_TXRATE_MCS]) { |
| 7110 | if (!ht_rateset_to_mask( |
| 7111 | sband, |
| 7112 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7113 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7114 | mask.control[band].mcs)) |
| 7115 | return -EINVAL; |
| 7116 | } |
| 7117 | |
| 7118 | if (mask.control[band].legacy == 0) { |
| 7119 | /* don't allow empty legacy rates if HT |
| 7120 | * is not even supported. */ |
| 7121 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7122 | return -EINVAL; |
| 7123 | |
| 7124 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7125 | if (mask.control[band].mcs[i]) |
| 7126 | break; |
| 7127 | |
| 7128 | /* legacy and mcs rates may not be both empty */ |
| 7129 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7130 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7131 | } |
| 7132 | } |
| 7133 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7134 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7135 | } |
| 7136 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7137 | 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] | 7138 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7139 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7140 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7141 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7142 | |
| 7143 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7144 | return -EINVAL; |
| 7145 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7146 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7147 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7148 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7149 | switch (wdev->iftype) { |
| 7150 | case NL80211_IFTYPE_STATION: |
| 7151 | case NL80211_IFTYPE_ADHOC: |
| 7152 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7153 | case NL80211_IFTYPE_AP: |
| 7154 | case NL80211_IFTYPE_AP_VLAN: |
| 7155 | case NL80211_IFTYPE_MESH_POINT: |
| 7156 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7157 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7158 | break; |
| 7159 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7160 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7161 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7162 | |
| 7163 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7164 | if (!rdev->ops->mgmt_tx) |
| 7165 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7166 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7167 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7168 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7169 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7170 | } |
| 7171 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7172 | 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] | 7173 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7174 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7175 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7176 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7177 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7178 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7179 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7180 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7181 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7182 | bool offchan, no_cck, dont_wait_for_ack; |
| 7183 | |
| 7184 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7185 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7186 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7187 | return -EINVAL; |
| 7188 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7189 | if (!rdev->ops->mgmt_tx) |
| 7190 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7191 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7192 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7193 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7194 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7195 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7196 | case NL80211_IFTYPE_STATION: |
| 7197 | case NL80211_IFTYPE_ADHOC: |
| 7198 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7199 | case NL80211_IFTYPE_AP: |
| 7200 | case NL80211_IFTYPE_AP_VLAN: |
| 7201 | case NL80211_IFTYPE_MESH_POINT: |
| 7202 | case NL80211_IFTYPE_P2P_GO: |
| 7203 | break; |
| 7204 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7205 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7206 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7207 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7208 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7209 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7210 | return -EINVAL; |
| 7211 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7212 | |
| 7213 | /* |
| 7214 | * We should wait on the channel for at least a minimum amount |
| 7215 | * of time (10ms) but no longer than the driver supports. |
| 7216 | */ |
| 7217 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7218 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7219 | return -EINVAL; |
| 7220 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7221 | } |
| 7222 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7223 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7224 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7225 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7226 | return -EINVAL; |
| 7227 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7228 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7229 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7230 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7231 | * the driver. The latter will use the current one |
| 7232 | */ |
| 7233 | chandef.chan = NULL; |
| 7234 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7235 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7236 | if (err) |
| 7237 | return err; |
| 7238 | } |
| 7239 | |
| 7240 | if (!chandef.chan && offchan) |
| 7241 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7242 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7243 | if (!dont_wait_for_ack) { |
| 7244 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7245 | if (!msg) |
| 7246 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7247 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7248 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7249 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7250 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7251 | if (IS_ERR(hdr)) { |
| 7252 | err = PTR_ERR(hdr); |
| 7253 | goto free_msg; |
| 7254 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7255 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7256 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7257 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7258 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7259 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7260 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7261 | if (err) |
| 7262 | goto free_msg; |
| 7263 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7264 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7265 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7266 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7267 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7268 | genlmsg_end(msg, hdr); |
| 7269 | return genlmsg_reply(msg, info); |
| 7270 | } |
| 7271 | |
| 7272 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7273 | |
| 7274 | nla_put_failure: |
| 7275 | err = -ENOBUFS; |
| 7276 | free_msg: |
| 7277 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7278 | return err; |
| 7279 | } |
| 7280 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7281 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7282 | { |
| 7283 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7284 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7285 | u64 cookie; |
| 7286 | |
| 7287 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7288 | return -EINVAL; |
| 7289 | |
| 7290 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7291 | return -EOPNOTSUPP; |
| 7292 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7293 | switch (wdev->iftype) { |
| 7294 | case NL80211_IFTYPE_STATION: |
| 7295 | case NL80211_IFTYPE_ADHOC: |
| 7296 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7297 | case NL80211_IFTYPE_AP: |
| 7298 | case NL80211_IFTYPE_AP_VLAN: |
| 7299 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7300 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7301 | break; |
| 7302 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7303 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7304 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7305 | |
| 7306 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7307 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7308 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7309 | } |
| 7310 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7311 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7312 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7313 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7314 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7315 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7316 | u8 ps_state; |
| 7317 | bool state; |
| 7318 | int err; |
| 7319 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7320 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7321 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7322 | |
| 7323 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7324 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7325 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7326 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7327 | |
| 7328 | wdev = dev->ieee80211_ptr; |
| 7329 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7330 | if (!rdev->ops->set_power_mgmt) |
| 7331 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7332 | |
| 7333 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7334 | |
| 7335 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7336 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7337 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7338 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7339 | if (!err) |
| 7340 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7341 | return err; |
| 7342 | } |
| 7343 | |
| 7344 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7345 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7346 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7347 | enum nl80211_ps_state ps_state; |
| 7348 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7349 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7350 | struct sk_buff *msg; |
| 7351 | void *hdr; |
| 7352 | int err; |
| 7353 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7354 | wdev = dev->ieee80211_ptr; |
| 7355 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7356 | if (!rdev->ops->set_power_mgmt) |
| 7357 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7358 | |
| 7359 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7360 | if (!msg) |
| 7361 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7362 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7363 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7364 | NL80211_CMD_GET_POWER_SAVE); |
| 7365 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7366 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7367 | goto free_msg; |
| 7368 | } |
| 7369 | |
| 7370 | if (wdev->ps) |
| 7371 | ps_state = NL80211_PS_ENABLED; |
| 7372 | else |
| 7373 | ps_state = NL80211_PS_DISABLED; |
| 7374 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7375 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7376 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7377 | |
| 7378 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7379 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7380 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7381 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7382 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7383 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7384 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7385 | return err; |
| 7386 | } |
| 7387 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7388 | static struct nla_policy |
| 7389 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7390 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7391 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7392 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7393 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7394 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7395 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7396 | }; |
| 7397 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7398 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7399 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7400 | { |
| 7401 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7402 | struct wireless_dev *wdev; |
| 7403 | struct net_device *dev = info->user_ptr[1]; |
| 7404 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7405 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7406 | return -EINVAL; |
| 7407 | |
| 7408 | wdev = dev->ieee80211_ptr; |
| 7409 | |
| 7410 | if (!rdev->ops->set_cqm_txe_config) |
| 7411 | return -EOPNOTSUPP; |
| 7412 | |
| 7413 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7414 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7415 | return -EOPNOTSUPP; |
| 7416 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7417 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7418 | } |
| 7419 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7420 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7421 | s32 threshold, u32 hysteresis) |
| 7422 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7423 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7424 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7425 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7426 | |
| 7427 | if (threshold > 0) |
| 7428 | return -EINVAL; |
| 7429 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7430 | wdev = dev->ieee80211_ptr; |
| 7431 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7432 | if (!rdev->ops->set_cqm_rssi_config) |
| 7433 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7434 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7435 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7436 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7437 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7438 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7439 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7440 | } |
| 7441 | |
| 7442 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7443 | { |
| 7444 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7445 | struct nlattr *cqm; |
| 7446 | int err; |
| 7447 | |
| 7448 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 7449 | if (!cqm) { |
| 7450 | err = -EINVAL; |
| 7451 | goto out; |
| 7452 | } |
| 7453 | |
| 7454 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7455 | nl80211_attr_cqm_policy); |
| 7456 | if (err) |
| 7457 | goto out; |
| 7458 | |
| 7459 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7460 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 7461 | s32 threshold; |
| 7462 | u32 hysteresis; |
| 7463 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7464 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 7465 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7466 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7467 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7468 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7469 | u32 rate, pkts, intvl; |
| 7470 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7471 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7472 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7473 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7474 | } else |
| 7475 | err = -EINVAL; |
| 7476 | |
| 7477 | out: |
| 7478 | return err; |
| 7479 | } |
| 7480 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7481 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7482 | { |
| 7483 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7484 | struct net_device *dev = info->user_ptr[1]; |
| 7485 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7486 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7487 | int err; |
| 7488 | |
| 7489 | /* start with default */ |
| 7490 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7491 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7492 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7493 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7494 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7495 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7496 | if (err) |
| 7497 | return err; |
| 7498 | } |
| 7499 | |
| 7500 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7501 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7502 | return -EINVAL; |
| 7503 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7504 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7505 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7506 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7507 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7508 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7509 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7510 | return -EINVAL; |
| 7511 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7512 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7513 | setup.beacon_interval = |
| 7514 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7515 | if (setup.beacon_interval < 10 || |
| 7516 | setup.beacon_interval > 10000) |
| 7517 | return -EINVAL; |
| 7518 | } |
| 7519 | |
| 7520 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7521 | setup.dtim_period = |
| 7522 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7523 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7524 | return -EINVAL; |
| 7525 | } |
| 7526 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7527 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7528 | /* parse additional setup parameters if given */ |
| 7529 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7530 | if (err) |
| 7531 | return err; |
| 7532 | } |
| 7533 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7534 | if (setup.user_mpm) |
| 7535 | cfg.auto_open_plinks = false; |
| 7536 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7537 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7538 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7539 | if (err) |
| 7540 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7541 | } else { |
| 7542 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7543 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7544 | } |
| 7545 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7546 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7547 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7548 | int n_rates = |
| 7549 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7550 | struct ieee80211_supported_band *sband; |
| 7551 | |
| 7552 | if (!setup.chandef.chan) |
| 7553 | return -EINVAL; |
| 7554 | |
| 7555 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7556 | |
| 7557 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7558 | &setup.basic_rates); |
| 7559 | if (err) |
| 7560 | return err; |
| 7561 | } |
| 7562 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7563 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7564 | } |
| 7565 | |
| 7566 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7567 | { |
| 7568 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7569 | struct net_device *dev = info->user_ptr[1]; |
| 7570 | |
| 7571 | return cfg80211_leave_mesh(rdev, dev); |
| 7572 | } |
| 7573 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7574 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7575 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7576 | struct cfg80211_registered_device *rdev) |
| 7577 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7578 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7579 | struct nlattr *nl_pats, *nl_pat; |
| 7580 | int i, pat_len; |
| 7581 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7582 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7583 | return 0; |
| 7584 | |
| 7585 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7586 | if (!nl_pats) |
| 7587 | return -ENOBUFS; |
| 7588 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7589 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7590 | nl_pat = nla_nest_start(msg, i + 1); |
| 7591 | if (!nl_pat) |
| 7592 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7593 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame^] | 7594 | 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] | 7595 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame^] | 7596 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 7597 | wowlan->patterns[i].pattern) || |
| 7598 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7599 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7600 | return -ENOBUFS; |
| 7601 | nla_nest_end(msg, nl_pat); |
| 7602 | } |
| 7603 | nla_nest_end(msg, nl_pats); |
| 7604 | |
| 7605 | return 0; |
| 7606 | } |
| 7607 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7608 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7609 | struct cfg80211_wowlan_tcp *tcp) |
| 7610 | { |
| 7611 | struct nlattr *nl_tcp; |
| 7612 | |
| 7613 | if (!tcp) |
| 7614 | return 0; |
| 7615 | |
| 7616 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7617 | if (!nl_tcp) |
| 7618 | return -ENOBUFS; |
| 7619 | |
| 7620 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7621 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7622 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7623 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7624 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7625 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7626 | tcp->payload_len, tcp->payload) || |
| 7627 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7628 | tcp->data_interval) || |
| 7629 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7630 | tcp->wake_len, tcp->wake_data) || |
| 7631 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7632 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7633 | return -ENOBUFS; |
| 7634 | |
| 7635 | if (tcp->payload_seq.len && |
| 7636 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7637 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7638 | return -ENOBUFS; |
| 7639 | |
| 7640 | if (tcp->payload_tok.len && |
| 7641 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7642 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7643 | &tcp->payload_tok)) |
| 7644 | return -ENOBUFS; |
| 7645 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 7646 | nla_nest_end(msg, nl_tcp); |
| 7647 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7648 | return 0; |
| 7649 | } |
| 7650 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7651 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7652 | { |
| 7653 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7654 | struct sk_buff *msg; |
| 7655 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7656 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7657 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7658 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7659 | return -EOPNOTSUPP; |
| 7660 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7661 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7662 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7663 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 7664 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 7665 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 7666 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7667 | } |
| 7668 | |
| 7669 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7670 | if (!msg) |
| 7671 | return -ENOMEM; |
| 7672 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7673 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7674 | NL80211_CMD_GET_WOWLAN); |
| 7675 | if (!hdr) |
| 7676 | goto nla_put_failure; |
| 7677 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7678 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7679 | struct nlattr *nl_wowlan; |
| 7680 | |
| 7681 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7682 | if (!nl_wowlan) |
| 7683 | goto nla_put_failure; |
| 7684 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7685 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7686 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7687 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7688 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7689 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7690 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7691 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7692 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7693 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7694 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7695 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7696 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7697 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7698 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7699 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7700 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7701 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7702 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7703 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7704 | if (nl80211_send_wowlan_tcp(msg, |
| 7705 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7706 | goto nla_put_failure; |
| 7707 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7708 | nla_nest_end(msg, nl_wowlan); |
| 7709 | } |
| 7710 | |
| 7711 | genlmsg_end(msg, hdr); |
| 7712 | return genlmsg_reply(msg, info); |
| 7713 | |
| 7714 | nla_put_failure: |
| 7715 | nlmsg_free(msg); |
| 7716 | return -ENOBUFS; |
| 7717 | } |
| 7718 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7719 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7720 | struct nlattr *attr, |
| 7721 | struct cfg80211_wowlan *trig) |
| 7722 | { |
| 7723 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7724 | struct cfg80211_wowlan_tcp *cfg; |
| 7725 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7726 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7727 | u32 size; |
| 7728 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7729 | int err, port; |
| 7730 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7731 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7732 | return -EINVAL; |
| 7733 | |
| 7734 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7735 | nla_data(attr), nla_len(attr), |
| 7736 | nl80211_wowlan_tcp_policy); |
| 7737 | if (err) |
| 7738 | return err; |
| 7739 | |
| 7740 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7741 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7742 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7743 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7744 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7745 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7746 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7747 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7748 | return -EINVAL; |
| 7749 | |
| 7750 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7751 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7752 | return -EINVAL; |
| 7753 | |
| 7754 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7755 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 7756 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7757 | return -EINVAL; |
| 7758 | |
| 7759 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7760 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7761 | return -EINVAL; |
| 7762 | |
| 7763 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7764 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7765 | return -EINVAL; |
| 7766 | |
| 7767 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7768 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7769 | |
| 7770 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7771 | tokens_size = tokln - sizeof(*tok); |
| 7772 | |
| 7773 | if (!tok->len || tokens_size % tok->len) |
| 7774 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7775 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7776 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7777 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7778 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7779 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7780 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7781 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7782 | return -EINVAL; |
| 7783 | if (tok->offset + tok->len > data_size) |
| 7784 | return -EINVAL; |
| 7785 | } |
| 7786 | |
| 7787 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7788 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7789 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7790 | return -EINVAL; |
| 7791 | if (seq->len == 0 || seq->len > 4) |
| 7792 | return -EINVAL; |
| 7793 | if (seq->len + seq->offset > data_size) |
| 7794 | return -EINVAL; |
| 7795 | } |
| 7796 | |
| 7797 | size = sizeof(*cfg); |
| 7798 | size += data_size; |
| 7799 | size += wake_size + wake_mask_size; |
| 7800 | size += tokens_size; |
| 7801 | |
| 7802 | cfg = kzalloc(size, GFP_KERNEL); |
| 7803 | if (!cfg) |
| 7804 | return -ENOMEM; |
| 7805 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7806 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7807 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7808 | ETH_ALEN); |
| 7809 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7810 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7811 | else |
| 7812 | port = 0; |
| 7813 | #ifdef CONFIG_INET |
| 7814 | /* allocate a socket and port for it and use it */ |
| 7815 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7816 | IPPROTO_TCP, &cfg->sock, 1); |
| 7817 | if (err) { |
| 7818 | kfree(cfg); |
| 7819 | return err; |
| 7820 | } |
| 7821 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7822 | sock_release(cfg->sock); |
| 7823 | kfree(cfg); |
| 7824 | return -EADDRINUSE; |
| 7825 | } |
| 7826 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7827 | #else |
| 7828 | if (!port) { |
| 7829 | kfree(cfg); |
| 7830 | return -EINVAL; |
| 7831 | } |
| 7832 | cfg->src_port = port; |
| 7833 | #endif |
| 7834 | |
| 7835 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7836 | cfg->payload_len = data_size; |
| 7837 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7838 | memcpy((void *)cfg->payload, |
| 7839 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7840 | data_size); |
| 7841 | if (seq) |
| 7842 | cfg->payload_seq = *seq; |
| 7843 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7844 | cfg->wake_len = wake_size; |
| 7845 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7846 | memcpy((void *)cfg->wake_data, |
| 7847 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7848 | wake_size); |
| 7849 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7850 | data_size + wake_size; |
| 7851 | memcpy((void *)cfg->wake_mask, |
| 7852 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7853 | wake_mask_size); |
| 7854 | if (tok) { |
| 7855 | cfg->tokens_size = tokens_size; |
| 7856 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7857 | } |
| 7858 | |
| 7859 | trig->tcp = cfg; |
| 7860 | |
| 7861 | return 0; |
| 7862 | } |
| 7863 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7864 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7865 | { |
| 7866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7867 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7868 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7869 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7870 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7871 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7872 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7873 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7874 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7875 | return -EOPNOTSUPP; |
| 7876 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7877 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7878 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7879 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7880 | goto set_wakeup; |
| 7881 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7882 | |
| 7883 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7884 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7885 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7886 | nl80211_wowlan_policy); |
| 7887 | if (err) |
| 7888 | return err; |
| 7889 | |
| 7890 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7891 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7892 | return -EINVAL; |
| 7893 | new_triggers.any = true; |
| 7894 | } |
| 7895 | |
| 7896 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7897 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7898 | return -EINVAL; |
| 7899 | new_triggers.disconnect = true; |
| 7900 | } |
| 7901 | |
| 7902 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7903 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7904 | return -EINVAL; |
| 7905 | new_triggers.magic_pkt = true; |
| 7906 | } |
| 7907 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7908 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7909 | return -EINVAL; |
| 7910 | |
| 7911 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7912 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7913 | return -EINVAL; |
| 7914 | new_triggers.gtk_rekey_failure = true; |
| 7915 | } |
| 7916 | |
| 7917 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7918 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7919 | return -EINVAL; |
| 7920 | new_triggers.eap_identity_req = true; |
| 7921 | } |
| 7922 | |
| 7923 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7924 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7925 | return -EINVAL; |
| 7926 | new_triggers.four_way_handshake = true; |
| 7927 | } |
| 7928 | |
| 7929 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7930 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7931 | return -EINVAL; |
| 7932 | new_triggers.rfkill_release = true; |
| 7933 | } |
| 7934 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7935 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7936 | struct nlattr *pat; |
| 7937 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7938 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame^] | 7939 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7940 | |
| 7941 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7942 | rem) |
| 7943 | n_patterns++; |
| 7944 | if (n_patterns > wowlan->n_patterns) |
| 7945 | return -EINVAL; |
| 7946 | |
| 7947 | new_triggers.patterns = kcalloc(n_patterns, |
| 7948 | sizeof(new_triggers.patterns[0]), |
| 7949 | GFP_KERNEL); |
| 7950 | if (!new_triggers.patterns) |
| 7951 | return -ENOMEM; |
| 7952 | |
| 7953 | new_triggers.n_patterns = n_patterns; |
| 7954 | i = 0; |
| 7955 | |
| 7956 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7957 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame^] | 7958 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 7959 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7960 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame^] | 7961 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 7962 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7963 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame^] | 7964 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7965 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame^] | 7966 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7967 | goto error; |
| 7968 | if (pat_len > wowlan->pattern_max_len || |
| 7969 | pat_len < wowlan->pattern_min_len) |
| 7970 | goto error; |
| 7971 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame^] | 7972 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7973 | pkt_offset = 0; |
| 7974 | else |
| 7975 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame^] | 7976 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7977 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7978 | goto error; |
| 7979 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7980 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7981 | new_triggers.patterns[i].mask = |
| 7982 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7983 | if (!new_triggers.patterns[i].mask) { |
| 7984 | err = -ENOMEM; |
| 7985 | goto error; |
| 7986 | } |
| 7987 | new_triggers.patterns[i].pattern = |
| 7988 | new_triggers.patterns[i].mask + mask_len; |
| 7989 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame^] | 7990 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7991 | mask_len); |
| 7992 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7993 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame^] | 7994 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7995 | pat_len); |
| 7996 | i++; |
| 7997 | } |
| 7998 | } |
| 7999 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8000 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8001 | err = nl80211_parse_wowlan_tcp( |
| 8002 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8003 | &new_triggers); |
| 8004 | if (err) |
| 8005 | goto error; |
| 8006 | } |
| 8007 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8008 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8009 | if (!ntrig) { |
| 8010 | err = -ENOMEM; |
| 8011 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8012 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8013 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8014 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8015 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8016 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8017 | if (rdev->ops->set_wakeup && |
| 8018 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8019 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8020 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8021 | return 0; |
| 8022 | error: |
| 8023 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8024 | kfree(new_triggers.patterns[i].mask); |
| 8025 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8026 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8027 | sock_release(new_triggers.tcp->sock); |
| 8028 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8029 | return err; |
| 8030 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8031 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8032 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8033 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8034 | { |
| 8035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8036 | struct net_device *dev = info->user_ptr[1]; |
| 8037 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8038 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8039 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8040 | int err; |
| 8041 | |
| 8042 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8043 | return -EINVAL; |
| 8044 | |
| 8045 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8046 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8047 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8048 | nl80211_rekey_policy); |
| 8049 | if (err) |
| 8050 | return err; |
| 8051 | |
| 8052 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8053 | return -ERANGE; |
| 8054 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8055 | return -ERANGE; |
| 8056 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8057 | return -ERANGE; |
| 8058 | |
| 8059 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8060 | NL80211_KEK_LEN); |
| 8061 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8062 | NL80211_KCK_LEN); |
| 8063 | memcpy(rekey_data.replay_ctr, |
| 8064 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8065 | NL80211_REPLAY_CTR_LEN); |
| 8066 | |
| 8067 | wdev_lock(wdev); |
| 8068 | if (!wdev->current_bss) { |
| 8069 | err = -ENOTCONN; |
| 8070 | goto out; |
| 8071 | } |
| 8072 | |
| 8073 | if (!rdev->ops->set_rekey_data) { |
| 8074 | err = -EOPNOTSUPP; |
| 8075 | goto out; |
| 8076 | } |
| 8077 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8078 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8079 | out: |
| 8080 | wdev_unlock(wdev); |
| 8081 | return err; |
| 8082 | } |
| 8083 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8084 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8085 | struct genl_info *info) |
| 8086 | { |
| 8087 | struct net_device *dev = info->user_ptr[1]; |
| 8088 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8089 | |
| 8090 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8091 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8092 | return -EINVAL; |
| 8093 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8094 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8095 | return -EBUSY; |
| 8096 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8097 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8098 | return 0; |
| 8099 | } |
| 8100 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8101 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8102 | struct genl_info *info) |
| 8103 | { |
| 8104 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8105 | struct net_device *dev = info->user_ptr[1]; |
| 8106 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8107 | struct sk_buff *msg; |
| 8108 | void *hdr; |
| 8109 | const u8 *addr; |
| 8110 | u64 cookie; |
| 8111 | int err; |
| 8112 | |
| 8113 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8114 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8115 | return -EOPNOTSUPP; |
| 8116 | |
| 8117 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8118 | return -EINVAL; |
| 8119 | |
| 8120 | if (!rdev->ops->probe_client) |
| 8121 | return -EOPNOTSUPP; |
| 8122 | |
| 8123 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8124 | if (!msg) |
| 8125 | return -ENOMEM; |
| 8126 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8127 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8128 | NL80211_CMD_PROBE_CLIENT); |
| 8129 | |
| 8130 | if (IS_ERR(hdr)) { |
| 8131 | err = PTR_ERR(hdr); |
| 8132 | goto free_msg; |
| 8133 | } |
| 8134 | |
| 8135 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8136 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8137 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8138 | if (err) |
| 8139 | goto free_msg; |
| 8140 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8141 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8142 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8143 | |
| 8144 | genlmsg_end(msg, hdr); |
| 8145 | |
| 8146 | return genlmsg_reply(msg, info); |
| 8147 | |
| 8148 | nla_put_failure: |
| 8149 | err = -ENOBUFS; |
| 8150 | free_msg: |
| 8151 | nlmsg_free(msg); |
| 8152 | return err; |
| 8153 | } |
| 8154 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8155 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8156 | { |
| 8157 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8158 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8159 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8160 | |
| 8161 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8162 | return -EOPNOTSUPP; |
| 8163 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8164 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8165 | if (!nreg) |
| 8166 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8167 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8168 | /* First, check if already registered. */ |
| 8169 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8170 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8171 | if (reg->nlportid == info->snd_portid) { |
| 8172 | rv = -EALREADY; |
| 8173 | goto out_err; |
| 8174 | } |
| 8175 | } |
| 8176 | /* Add it to the list */ |
| 8177 | nreg->nlportid = info->snd_portid; |
| 8178 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8179 | |
| 8180 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8181 | |
| 8182 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8183 | out_err: |
| 8184 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8185 | kfree(nreg); |
| 8186 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8187 | } |
| 8188 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8189 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8190 | { |
| 8191 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8192 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8193 | int err; |
| 8194 | |
| 8195 | if (!rdev->ops->start_p2p_device) |
| 8196 | return -EOPNOTSUPP; |
| 8197 | |
| 8198 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8199 | return -EOPNOTSUPP; |
| 8200 | |
| 8201 | if (wdev->p2p_started) |
| 8202 | return 0; |
| 8203 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8204 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8205 | if (err) |
| 8206 | return err; |
| 8207 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8208 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8209 | if (err) |
| 8210 | return err; |
| 8211 | |
| 8212 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8213 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8214 | |
| 8215 | return 0; |
| 8216 | } |
| 8217 | |
| 8218 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8219 | { |
| 8220 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8221 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8222 | |
| 8223 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8224 | return -EOPNOTSUPP; |
| 8225 | |
| 8226 | if (!rdev->ops->stop_p2p_device) |
| 8227 | return -EOPNOTSUPP; |
| 8228 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8229 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8230 | |
| 8231 | return 0; |
| 8232 | } |
| 8233 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8234 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8235 | struct genl_info *info) |
| 8236 | { |
| 8237 | void *hdr; |
| 8238 | struct sk_buff *msg; |
| 8239 | |
| 8240 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8241 | if (!msg) |
| 8242 | return -ENOMEM; |
| 8243 | |
| 8244 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8245 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8246 | if (!hdr) |
| 8247 | goto nla_put_failure; |
| 8248 | |
| 8249 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8250 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8251 | goto nla_put_failure; |
| 8252 | |
| 8253 | genlmsg_end(msg, hdr); |
| 8254 | return genlmsg_reply(msg, info); |
| 8255 | |
| 8256 | nla_put_failure: |
| 8257 | kfree_skb(msg); |
| 8258 | return -ENOBUFS; |
| 8259 | } |
| 8260 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8261 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8262 | { |
| 8263 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8264 | struct cfg80211_update_ft_ies_params ft_params; |
| 8265 | struct net_device *dev = info->user_ptr[1]; |
| 8266 | |
| 8267 | if (!rdev->ops->update_ft_ies) |
| 8268 | return -EOPNOTSUPP; |
| 8269 | |
| 8270 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8271 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8272 | return -EINVAL; |
| 8273 | |
| 8274 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8275 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8276 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8277 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8278 | |
| 8279 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8280 | } |
| 8281 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8282 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8283 | struct genl_info *info) |
| 8284 | { |
| 8285 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8286 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8287 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8288 | u16 duration; |
| 8289 | int ret; |
| 8290 | |
| 8291 | if (!rdev->ops->crit_proto_start) |
| 8292 | return -EOPNOTSUPP; |
| 8293 | |
| 8294 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8295 | return -EINVAL; |
| 8296 | |
| 8297 | if (rdev->crit_proto_nlportid) |
| 8298 | return -EBUSY; |
| 8299 | |
| 8300 | /* determine protocol if provided */ |
| 8301 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8302 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8303 | |
| 8304 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8305 | return -EINVAL; |
| 8306 | |
| 8307 | /* timeout must be provided */ |
| 8308 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8309 | return -EINVAL; |
| 8310 | |
| 8311 | duration = |
| 8312 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8313 | |
| 8314 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8315 | return -ERANGE; |
| 8316 | |
| 8317 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8318 | if (!ret) |
| 8319 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8320 | |
| 8321 | return ret; |
| 8322 | } |
| 8323 | |
| 8324 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8325 | struct genl_info *info) |
| 8326 | { |
| 8327 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8328 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8329 | |
| 8330 | if (!rdev->ops->crit_proto_stop) |
| 8331 | return -EOPNOTSUPP; |
| 8332 | |
| 8333 | if (rdev->crit_proto_nlportid) { |
| 8334 | rdev->crit_proto_nlportid = 0; |
| 8335 | rdev_crit_proto_stop(rdev, wdev); |
| 8336 | } |
| 8337 | return 0; |
| 8338 | } |
| 8339 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8340 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8341 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8342 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8343 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8344 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8345 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8346 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8347 | /* 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] | 8348 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8349 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8350 | |
| 8351 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8352 | struct genl_info *info) |
| 8353 | { |
| 8354 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8355 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8356 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8357 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8358 | |
| 8359 | if (rtnl) |
| 8360 | rtnl_lock(); |
| 8361 | |
| 8362 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8363 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8364 | if (IS_ERR(rdev)) { |
| 8365 | if (rtnl) |
| 8366 | rtnl_unlock(); |
| 8367 | return PTR_ERR(rdev); |
| 8368 | } |
| 8369 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8370 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8371 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8372 | ASSERT_RTNL(); |
| 8373 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8374 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8375 | info->attrs); |
| 8376 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8377 | if (rtnl) |
| 8378 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8379 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8380 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8381 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8382 | dev = wdev->netdev; |
| 8383 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8384 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8385 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8386 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8387 | if (rtnl) |
| 8388 | rtnl_unlock(); |
| 8389 | return -EINVAL; |
| 8390 | } |
| 8391 | |
| 8392 | info->user_ptr[1] = dev; |
| 8393 | } else { |
| 8394 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8395 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8396 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8397 | if (dev) { |
| 8398 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8399 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8400 | if (rtnl) |
| 8401 | rtnl_unlock(); |
| 8402 | return -ENETDOWN; |
| 8403 | } |
| 8404 | |
| 8405 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8406 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8407 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8408 | if (rtnl) |
| 8409 | rtnl_unlock(); |
| 8410 | return -ENETDOWN; |
| 8411 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8412 | } |
| 8413 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8414 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8415 | } |
| 8416 | |
| 8417 | return 0; |
| 8418 | } |
| 8419 | |
| 8420 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8421 | struct genl_info *info) |
| 8422 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8423 | if (info->user_ptr[1]) { |
| 8424 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8425 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8426 | |
| 8427 | if (wdev->netdev) |
| 8428 | dev_put(wdev->netdev); |
| 8429 | } else { |
| 8430 | dev_put(info->user_ptr[1]); |
| 8431 | } |
| 8432 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8433 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8434 | rtnl_unlock(); |
| 8435 | } |
| 8436 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8437 | static struct genl_ops nl80211_ops[] = { |
| 8438 | { |
| 8439 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8440 | .doit = nl80211_get_wiphy, |
| 8441 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 8442 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8443 | .policy = nl80211_policy, |
| 8444 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8445 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8446 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8447 | }, |
| 8448 | { |
| 8449 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8450 | .doit = nl80211_set_wiphy, |
| 8451 | .policy = nl80211_policy, |
| 8452 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8453 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8454 | }, |
| 8455 | { |
| 8456 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8457 | .doit = nl80211_get_interface, |
| 8458 | .dumpit = nl80211_dump_interface, |
| 8459 | .policy = nl80211_policy, |
| 8460 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8461 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8462 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8463 | }, |
| 8464 | { |
| 8465 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8466 | .doit = nl80211_set_interface, |
| 8467 | .policy = nl80211_policy, |
| 8468 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8469 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8470 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8471 | }, |
| 8472 | { |
| 8473 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8474 | .doit = nl80211_new_interface, |
| 8475 | .policy = nl80211_policy, |
| 8476 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8477 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8478 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8479 | }, |
| 8480 | { |
| 8481 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 8482 | .doit = nl80211_del_interface, |
| 8483 | .policy = nl80211_policy, |
| 8484 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 8485 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8486 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8487 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8488 | { |
| 8489 | .cmd = NL80211_CMD_GET_KEY, |
| 8490 | .doit = nl80211_get_key, |
| 8491 | .policy = nl80211_policy, |
| 8492 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8493 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8494 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8495 | }, |
| 8496 | { |
| 8497 | .cmd = NL80211_CMD_SET_KEY, |
| 8498 | .doit = nl80211_set_key, |
| 8499 | .policy = nl80211_policy, |
| 8500 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8501 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8502 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8503 | }, |
| 8504 | { |
| 8505 | .cmd = NL80211_CMD_NEW_KEY, |
| 8506 | .doit = nl80211_new_key, |
| 8507 | .policy = nl80211_policy, |
| 8508 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8509 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8510 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8511 | }, |
| 8512 | { |
| 8513 | .cmd = NL80211_CMD_DEL_KEY, |
| 8514 | .doit = nl80211_del_key, |
| 8515 | .policy = nl80211_policy, |
| 8516 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8517 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8518 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8519 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8520 | { |
| 8521 | .cmd = NL80211_CMD_SET_BEACON, |
| 8522 | .policy = nl80211_policy, |
| 8523 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8524 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8525 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8526 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8527 | }, |
| 8528 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8529 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8530 | .policy = nl80211_policy, |
| 8531 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8532 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8533 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8534 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8535 | }, |
| 8536 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8537 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8538 | .policy = nl80211_policy, |
| 8539 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8540 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8541 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8542 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8543 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8544 | { |
| 8545 | .cmd = NL80211_CMD_GET_STATION, |
| 8546 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8547 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8548 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8549 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8550 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8551 | }, |
| 8552 | { |
| 8553 | .cmd = NL80211_CMD_SET_STATION, |
| 8554 | .doit = nl80211_set_station, |
| 8555 | .policy = nl80211_policy, |
| 8556 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8557 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8558 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8559 | }, |
| 8560 | { |
| 8561 | .cmd = NL80211_CMD_NEW_STATION, |
| 8562 | .doit = nl80211_new_station, |
| 8563 | .policy = nl80211_policy, |
| 8564 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8565 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8566 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8567 | }, |
| 8568 | { |
| 8569 | .cmd = NL80211_CMD_DEL_STATION, |
| 8570 | .doit = nl80211_del_station, |
| 8571 | .policy = nl80211_policy, |
| 8572 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8573 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8574 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8575 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8576 | { |
| 8577 | .cmd = NL80211_CMD_GET_MPATH, |
| 8578 | .doit = nl80211_get_mpath, |
| 8579 | .dumpit = nl80211_dump_mpath, |
| 8580 | .policy = nl80211_policy, |
| 8581 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8582 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8583 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8584 | }, |
| 8585 | { |
| 8586 | .cmd = NL80211_CMD_SET_MPATH, |
| 8587 | .doit = nl80211_set_mpath, |
| 8588 | .policy = nl80211_policy, |
| 8589 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8590 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8591 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8592 | }, |
| 8593 | { |
| 8594 | .cmd = NL80211_CMD_NEW_MPATH, |
| 8595 | .doit = nl80211_new_mpath, |
| 8596 | .policy = nl80211_policy, |
| 8597 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8598 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8599 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8600 | }, |
| 8601 | { |
| 8602 | .cmd = NL80211_CMD_DEL_MPATH, |
| 8603 | .doit = nl80211_del_mpath, |
| 8604 | .policy = nl80211_policy, |
| 8605 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8606 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8607 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8608 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8609 | { |
| 8610 | .cmd = NL80211_CMD_SET_BSS, |
| 8611 | .doit = nl80211_set_bss, |
| 8612 | .policy = nl80211_policy, |
| 8613 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8614 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8615 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8616 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8617 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8618 | .cmd = NL80211_CMD_GET_REG, |
| 8619 | .doit = nl80211_get_reg, |
| 8620 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8621 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8622 | /* can be retrieved by unprivileged users */ |
| 8623 | }, |
| 8624 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8625 | .cmd = NL80211_CMD_SET_REG, |
| 8626 | .doit = nl80211_set_reg, |
| 8627 | .policy = nl80211_policy, |
| 8628 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8629 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8630 | }, |
| 8631 | { |
| 8632 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8633 | .doit = nl80211_req_set_reg, |
| 8634 | .policy = nl80211_policy, |
| 8635 | .flags = GENL_ADMIN_PERM, |
| 8636 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8637 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8638 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8639 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8640 | .policy = nl80211_policy, |
| 8641 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8642 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8643 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8644 | }, |
| 8645 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8646 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8647 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8648 | .policy = nl80211_policy, |
| 8649 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8650 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8651 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8652 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8653 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8654 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8655 | .doit = nl80211_trigger_scan, |
| 8656 | .policy = nl80211_policy, |
| 8657 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8658 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8659 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8660 | }, |
| 8661 | { |
| 8662 | .cmd = NL80211_CMD_GET_SCAN, |
| 8663 | .policy = nl80211_policy, |
| 8664 | .dumpit = nl80211_dump_scan, |
| 8665 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8666 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8667 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8668 | .doit = nl80211_start_sched_scan, |
| 8669 | .policy = nl80211_policy, |
| 8670 | .flags = GENL_ADMIN_PERM, |
| 8671 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8672 | NL80211_FLAG_NEED_RTNL, |
| 8673 | }, |
| 8674 | { |
| 8675 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8676 | .doit = nl80211_stop_sched_scan, |
| 8677 | .policy = nl80211_policy, |
| 8678 | .flags = GENL_ADMIN_PERM, |
| 8679 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8680 | NL80211_FLAG_NEED_RTNL, |
| 8681 | }, |
| 8682 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8683 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8684 | .doit = nl80211_authenticate, |
| 8685 | .policy = nl80211_policy, |
| 8686 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8687 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8688 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8689 | }, |
| 8690 | { |
| 8691 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8692 | .doit = nl80211_associate, |
| 8693 | .policy = nl80211_policy, |
| 8694 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8695 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8696 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8697 | }, |
| 8698 | { |
| 8699 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8700 | .doit = nl80211_deauthenticate, |
| 8701 | .policy = nl80211_policy, |
| 8702 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8703 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8704 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8705 | }, |
| 8706 | { |
| 8707 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8708 | .doit = nl80211_disassociate, |
| 8709 | .policy = nl80211_policy, |
| 8710 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8711 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8712 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8713 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8714 | { |
| 8715 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8716 | .doit = nl80211_join_ibss, |
| 8717 | .policy = nl80211_policy, |
| 8718 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8719 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8720 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8721 | }, |
| 8722 | { |
| 8723 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8724 | .doit = nl80211_leave_ibss, |
| 8725 | .policy = nl80211_policy, |
| 8726 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8727 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8728 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8729 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8730 | #ifdef CONFIG_NL80211_TESTMODE |
| 8731 | { |
| 8732 | .cmd = NL80211_CMD_TESTMODE, |
| 8733 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8734 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8735 | .policy = nl80211_policy, |
| 8736 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8737 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8738 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8739 | }, |
| 8740 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8741 | { |
| 8742 | .cmd = NL80211_CMD_CONNECT, |
| 8743 | .doit = nl80211_connect, |
| 8744 | .policy = nl80211_policy, |
| 8745 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8746 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8747 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8748 | }, |
| 8749 | { |
| 8750 | .cmd = NL80211_CMD_DISCONNECT, |
| 8751 | .doit = nl80211_disconnect, |
| 8752 | .policy = nl80211_policy, |
| 8753 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8754 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8755 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8756 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8757 | { |
| 8758 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8759 | .doit = nl80211_wiphy_netns, |
| 8760 | .policy = nl80211_policy, |
| 8761 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8762 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8763 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8764 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8765 | { |
| 8766 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8767 | .policy = nl80211_policy, |
| 8768 | .dumpit = nl80211_dump_survey, |
| 8769 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8770 | { |
| 8771 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8772 | .doit = nl80211_setdel_pmksa, |
| 8773 | .policy = nl80211_policy, |
| 8774 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8775 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8776 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8777 | }, |
| 8778 | { |
| 8779 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8780 | .doit = nl80211_setdel_pmksa, |
| 8781 | .policy = nl80211_policy, |
| 8782 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8783 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8784 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8785 | }, |
| 8786 | { |
| 8787 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8788 | .doit = nl80211_flush_pmksa, |
| 8789 | .policy = nl80211_policy, |
| 8790 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8791 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8792 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8793 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8794 | { |
| 8795 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8796 | .doit = nl80211_remain_on_channel, |
| 8797 | .policy = nl80211_policy, |
| 8798 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8799 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8800 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8801 | }, |
| 8802 | { |
| 8803 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8804 | .doit = nl80211_cancel_remain_on_channel, |
| 8805 | .policy = nl80211_policy, |
| 8806 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8807 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8808 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8809 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8810 | { |
| 8811 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8812 | .doit = nl80211_set_tx_bitrate_mask, |
| 8813 | .policy = nl80211_policy, |
| 8814 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8815 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8816 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8817 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8818 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8819 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8820 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8821 | .policy = nl80211_policy, |
| 8822 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8823 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8824 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8825 | }, |
| 8826 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8827 | .cmd = NL80211_CMD_FRAME, |
| 8828 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8829 | .policy = nl80211_policy, |
| 8830 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8831 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8832 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8833 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8834 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8835 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8836 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8837 | .policy = nl80211_policy, |
| 8838 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8839 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8840 | NL80211_FLAG_NEED_RTNL, |
| 8841 | }, |
| 8842 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8843 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8844 | .doit = nl80211_set_power_save, |
| 8845 | .policy = nl80211_policy, |
| 8846 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8847 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8848 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8849 | }, |
| 8850 | { |
| 8851 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8852 | .doit = nl80211_get_power_save, |
| 8853 | .policy = nl80211_policy, |
| 8854 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8855 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8856 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8857 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8858 | { |
| 8859 | .cmd = NL80211_CMD_SET_CQM, |
| 8860 | .doit = nl80211_set_cqm, |
| 8861 | .policy = nl80211_policy, |
| 8862 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8863 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8864 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8865 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8866 | { |
| 8867 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8868 | .doit = nl80211_set_channel, |
| 8869 | .policy = nl80211_policy, |
| 8870 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8871 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8872 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8873 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8874 | { |
| 8875 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8876 | .doit = nl80211_set_wds_peer, |
| 8877 | .policy = nl80211_policy, |
| 8878 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8879 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8880 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8881 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8882 | { |
| 8883 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8884 | .doit = nl80211_join_mesh, |
| 8885 | .policy = nl80211_policy, |
| 8886 | .flags = GENL_ADMIN_PERM, |
| 8887 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8888 | NL80211_FLAG_NEED_RTNL, |
| 8889 | }, |
| 8890 | { |
| 8891 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8892 | .doit = nl80211_leave_mesh, |
| 8893 | .policy = nl80211_policy, |
| 8894 | .flags = GENL_ADMIN_PERM, |
| 8895 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8896 | NL80211_FLAG_NEED_RTNL, |
| 8897 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8898 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8899 | { |
| 8900 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8901 | .doit = nl80211_get_wowlan, |
| 8902 | .policy = nl80211_policy, |
| 8903 | /* can be retrieved by unprivileged users */ |
| 8904 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8905 | NL80211_FLAG_NEED_RTNL, |
| 8906 | }, |
| 8907 | { |
| 8908 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8909 | .doit = nl80211_set_wowlan, |
| 8910 | .policy = nl80211_policy, |
| 8911 | .flags = GENL_ADMIN_PERM, |
| 8912 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8913 | NL80211_FLAG_NEED_RTNL, |
| 8914 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8915 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8916 | { |
| 8917 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8918 | .doit = nl80211_set_rekey_data, |
| 8919 | .policy = nl80211_policy, |
| 8920 | .flags = GENL_ADMIN_PERM, |
| 8921 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8922 | NL80211_FLAG_NEED_RTNL, |
| 8923 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8924 | { |
| 8925 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8926 | .doit = nl80211_tdls_mgmt, |
| 8927 | .policy = nl80211_policy, |
| 8928 | .flags = GENL_ADMIN_PERM, |
| 8929 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8930 | NL80211_FLAG_NEED_RTNL, |
| 8931 | }, |
| 8932 | { |
| 8933 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8934 | .doit = nl80211_tdls_oper, |
| 8935 | .policy = nl80211_policy, |
| 8936 | .flags = GENL_ADMIN_PERM, |
| 8937 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8938 | NL80211_FLAG_NEED_RTNL, |
| 8939 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8940 | { |
| 8941 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8942 | .doit = nl80211_register_unexpected_frame, |
| 8943 | .policy = nl80211_policy, |
| 8944 | .flags = GENL_ADMIN_PERM, |
| 8945 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8946 | NL80211_FLAG_NEED_RTNL, |
| 8947 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8948 | { |
| 8949 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8950 | .doit = nl80211_probe_client, |
| 8951 | .policy = nl80211_policy, |
| 8952 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8953 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8954 | NL80211_FLAG_NEED_RTNL, |
| 8955 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8956 | { |
| 8957 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8958 | .doit = nl80211_register_beacons, |
| 8959 | .policy = nl80211_policy, |
| 8960 | .flags = GENL_ADMIN_PERM, |
| 8961 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8962 | NL80211_FLAG_NEED_RTNL, |
| 8963 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8964 | { |
| 8965 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8966 | .doit = nl80211_set_noack_map, |
| 8967 | .policy = nl80211_policy, |
| 8968 | .flags = GENL_ADMIN_PERM, |
| 8969 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8970 | NL80211_FLAG_NEED_RTNL, |
| 8971 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8972 | { |
| 8973 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8974 | .doit = nl80211_start_p2p_device, |
| 8975 | .policy = nl80211_policy, |
| 8976 | .flags = GENL_ADMIN_PERM, |
| 8977 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8978 | NL80211_FLAG_NEED_RTNL, |
| 8979 | }, |
| 8980 | { |
| 8981 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8982 | .doit = nl80211_stop_p2p_device, |
| 8983 | .policy = nl80211_policy, |
| 8984 | .flags = GENL_ADMIN_PERM, |
| 8985 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8986 | NL80211_FLAG_NEED_RTNL, |
| 8987 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8988 | { |
| 8989 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8990 | .doit = nl80211_set_mcast_rate, |
| 8991 | .policy = nl80211_policy, |
| 8992 | .flags = GENL_ADMIN_PERM, |
| 8993 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8994 | NL80211_FLAG_NEED_RTNL, |
| 8995 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8996 | { |
| 8997 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8998 | .doit = nl80211_set_mac_acl, |
| 8999 | .policy = nl80211_policy, |
| 9000 | .flags = GENL_ADMIN_PERM, |
| 9001 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9002 | NL80211_FLAG_NEED_RTNL, |
| 9003 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9004 | { |
| 9005 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9006 | .doit = nl80211_start_radar_detection, |
| 9007 | .policy = nl80211_policy, |
| 9008 | .flags = GENL_ADMIN_PERM, |
| 9009 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9010 | NL80211_FLAG_NEED_RTNL, |
| 9011 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9012 | { |
| 9013 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9014 | .doit = nl80211_get_protocol_features, |
| 9015 | .policy = nl80211_policy, |
| 9016 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9017 | { |
| 9018 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9019 | .doit = nl80211_update_ft_ies, |
| 9020 | .policy = nl80211_policy, |
| 9021 | .flags = GENL_ADMIN_PERM, |
| 9022 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9023 | NL80211_FLAG_NEED_RTNL, |
| 9024 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9025 | { |
| 9026 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9027 | .doit = nl80211_crit_protocol_start, |
| 9028 | .policy = nl80211_policy, |
| 9029 | .flags = GENL_ADMIN_PERM, |
| 9030 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9031 | NL80211_FLAG_NEED_RTNL, |
| 9032 | }, |
| 9033 | { |
| 9034 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9035 | .doit = nl80211_crit_protocol_stop, |
| 9036 | .policy = nl80211_policy, |
| 9037 | .flags = GENL_ADMIN_PERM, |
| 9038 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9039 | NL80211_FLAG_NEED_RTNL, |
| 9040 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9041 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9042 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9043 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 9044 | .name = "mlme", |
| 9045 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9046 | |
| 9047 | /* multicast groups */ |
| 9048 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 9049 | .name = "config", |
| 9050 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9051 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 9052 | .name = "scan", |
| 9053 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9054 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 9055 | .name = "regulatory", |
| 9056 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9057 | |
| 9058 | /* notification functions */ |
| 9059 | |
| 9060 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9061 | { |
| 9062 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9063 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9064 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9065 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9066 | if (!msg) |
| 9067 | return; |
| 9068 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9069 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9070 | nlmsg_free(msg); |
| 9071 | return; |
| 9072 | } |
| 9073 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9074 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9075 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9076 | } |
| 9077 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9078 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9079 | struct cfg80211_registered_device *rdev) |
| 9080 | { |
| 9081 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9082 | struct nlattr *nest; |
| 9083 | int i; |
| 9084 | |
| 9085 | if (WARN_ON(!req)) |
| 9086 | return 0; |
| 9087 | |
| 9088 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9089 | if (!nest) |
| 9090 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9091 | for (i = 0; i < req->n_ssids; i++) { |
| 9092 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9093 | goto nla_put_failure; |
| 9094 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9095 | nla_nest_end(msg, nest); |
| 9096 | |
| 9097 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9098 | if (!nest) |
| 9099 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9100 | for (i = 0; i < req->n_channels; i++) { |
| 9101 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9102 | goto nla_put_failure; |
| 9103 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9104 | nla_nest_end(msg, nest); |
| 9105 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9106 | if (req->ie && |
| 9107 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9108 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9109 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9110 | if (req->flags) |
| 9111 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 9112 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9113 | return 0; |
| 9114 | nla_put_failure: |
| 9115 | return -ENOBUFS; |
| 9116 | } |
| 9117 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9118 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9119 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9120 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9121 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9122 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9123 | { |
| 9124 | void *hdr; |
| 9125 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9126 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9127 | if (!hdr) |
| 9128 | return -1; |
| 9129 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9130 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9131 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9132 | wdev->netdev->ifindex)) || |
| 9133 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9134 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9135 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9136 | /* ignore errors and send incomplete event anyway */ |
| 9137 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9138 | |
| 9139 | return genlmsg_end(msg, hdr); |
| 9140 | |
| 9141 | nla_put_failure: |
| 9142 | genlmsg_cancel(msg, hdr); |
| 9143 | return -EMSGSIZE; |
| 9144 | } |
| 9145 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9146 | static int |
| 9147 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9148 | struct cfg80211_registered_device *rdev, |
| 9149 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9150 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9151 | { |
| 9152 | void *hdr; |
| 9153 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9154 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9155 | if (!hdr) |
| 9156 | return -1; |
| 9157 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9158 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9159 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9160 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9161 | |
| 9162 | return genlmsg_end(msg, hdr); |
| 9163 | |
| 9164 | nla_put_failure: |
| 9165 | genlmsg_cancel(msg, hdr); |
| 9166 | return -EMSGSIZE; |
| 9167 | } |
| 9168 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9169 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9170 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9171 | { |
| 9172 | struct sk_buff *msg; |
| 9173 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9174 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9175 | if (!msg) |
| 9176 | return; |
| 9177 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9178 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9179 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9180 | nlmsg_free(msg); |
| 9181 | return; |
| 9182 | } |
| 9183 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9184 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9185 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9186 | } |
| 9187 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9188 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9189 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9190 | { |
| 9191 | struct sk_buff *msg; |
| 9192 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9193 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9194 | if (!msg) |
| 9195 | return; |
| 9196 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9197 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9198 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9199 | nlmsg_free(msg); |
| 9200 | return; |
| 9201 | } |
| 9202 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9203 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9204 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9205 | } |
| 9206 | |
| 9207 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9208 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9209 | { |
| 9210 | struct sk_buff *msg; |
| 9211 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9212 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9213 | if (!msg) |
| 9214 | return; |
| 9215 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9216 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9217 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9218 | nlmsg_free(msg); |
| 9219 | return; |
| 9220 | } |
| 9221 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9222 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9223 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9224 | } |
| 9225 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9226 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9227 | struct net_device *netdev) |
| 9228 | { |
| 9229 | struct sk_buff *msg; |
| 9230 | |
| 9231 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9232 | if (!msg) |
| 9233 | return; |
| 9234 | |
| 9235 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9236 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9237 | nlmsg_free(msg); |
| 9238 | return; |
| 9239 | } |
| 9240 | |
| 9241 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9242 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9243 | } |
| 9244 | |
| 9245 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9246 | struct net_device *netdev, u32 cmd) |
| 9247 | { |
| 9248 | struct sk_buff *msg; |
| 9249 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9250 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9251 | if (!msg) |
| 9252 | return; |
| 9253 | |
| 9254 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9255 | nlmsg_free(msg); |
| 9256 | return; |
| 9257 | } |
| 9258 | |
| 9259 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9260 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9261 | } |
| 9262 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9263 | /* |
| 9264 | * This can happen on global regulatory changes or device specific settings |
| 9265 | * based on custom world regulatory domains. |
| 9266 | */ |
| 9267 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9268 | { |
| 9269 | struct sk_buff *msg; |
| 9270 | void *hdr; |
| 9271 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9272 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9273 | if (!msg) |
| 9274 | return; |
| 9275 | |
| 9276 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9277 | if (!hdr) { |
| 9278 | nlmsg_free(msg); |
| 9279 | return; |
| 9280 | } |
| 9281 | |
| 9282 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9283 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9284 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9285 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9286 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9287 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9288 | NL80211_REGDOM_TYPE_WORLD)) |
| 9289 | goto nla_put_failure; |
| 9290 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9291 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9292 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9293 | goto nla_put_failure; |
| 9294 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9295 | request->intersect) { |
| 9296 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9297 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9298 | goto nla_put_failure; |
| 9299 | } else { |
| 9300 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9301 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9302 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9303 | request->alpha2)) |
| 9304 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9305 | } |
| 9306 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9307 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9308 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9309 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9310 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9311 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9312 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9313 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9314 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9315 | GFP_ATOMIC); |
| 9316 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9317 | |
| 9318 | return; |
| 9319 | |
| 9320 | nla_put_failure: |
| 9321 | genlmsg_cancel(msg, hdr); |
| 9322 | nlmsg_free(msg); |
| 9323 | } |
| 9324 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9325 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9326 | struct net_device *netdev, |
| 9327 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9328 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9329 | { |
| 9330 | struct sk_buff *msg; |
| 9331 | void *hdr; |
| 9332 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9333 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9334 | if (!msg) |
| 9335 | return; |
| 9336 | |
| 9337 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9338 | if (!hdr) { |
| 9339 | nlmsg_free(msg); |
| 9340 | return; |
| 9341 | } |
| 9342 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9343 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9344 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9345 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9346 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9347 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9348 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9349 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9350 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9351 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9352 | return; |
| 9353 | |
| 9354 | nla_put_failure: |
| 9355 | genlmsg_cancel(msg, hdr); |
| 9356 | nlmsg_free(msg); |
| 9357 | } |
| 9358 | |
| 9359 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9360 | struct net_device *netdev, const u8 *buf, |
| 9361 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9362 | { |
| 9363 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9364 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9365 | } |
| 9366 | |
| 9367 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9368 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9369 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9370 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9371 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9372 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9373 | } |
| 9374 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9375 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9376 | struct net_device *netdev, const u8 *buf, |
| 9377 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9378 | { |
| 9379 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9380 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9381 | } |
| 9382 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9383 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9384 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9385 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9386 | { |
| 9387 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9388 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9389 | } |
| 9390 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9391 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 9392 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9393 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9394 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9395 | struct wiphy *wiphy = wdev->wiphy; |
| 9396 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9397 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 9398 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9399 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9400 | if (WARN_ON(len < 2)) |
| 9401 | return; |
| 9402 | |
| 9403 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 9404 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 9405 | else |
| 9406 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 9407 | |
| 9408 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 9409 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9410 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9411 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9412 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9413 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9414 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9415 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9416 | { |
| 9417 | struct sk_buff *msg; |
| 9418 | void *hdr; |
| 9419 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9420 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9421 | if (!msg) |
| 9422 | return; |
| 9423 | |
| 9424 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9425 | if (!hdr) { |
| 9426 | nlmsg_free(msg); |
| 9427 | return; |
| 9428 | } |
| 9429 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9430 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9431 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9432 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9433 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9434 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9435 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9436 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9437 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9438 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9439 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9440 | return; |
| 9441 | |
| 9442 | nla_put_failure: |
| 9443 | genlmsg_cancel(msg, hdr); |
| 9444 | nlmsg_free(msg); |
| 9445 | } |
| 9446 | |
| 9447 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9448 | struct net_device *netdev, const u8 *addr, |
| 9449 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9450 | { |
| 9451 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9452 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9453 | } |
| 9454 | |
| 9455 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9456 | struct net_device *netdev, const u8 *addr, |
| 9457 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9458 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9459 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9460 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9461 | } |
| 9462 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9463 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9464 | struct net_device *netdev, const u8 *bssid, |
| 9465 | const u8 *req_ie, size_t req_ie_len, |
| 9466 | const u8 *resp_ie, size_t resp_ie_len, |
| 9467 | u16 status, gfp_t gfp) |
| 9468 | { |
| 9469 | struct sk_buff *msg; |
| 9470 | void *hdr; |
| 9471 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9472 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9473 | if (!msg) |
| 9474 | return; |
| 9475 | |
| 9476 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 9477 | if (!hdr) { |
| 9478 | nlmsg_free(msg); |
| 9479 | return; |
| 9480 | } |
| 9481 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9482 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9483 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9484 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 9485 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 9486 | (req_ie && |
| 9487 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9488 | (resp_ie && |
| 9489 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9490 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9491 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9492 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9493 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9494 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9495 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9496 | return; |
| 9497 | |
| 9498 | nla_put_failure: |
| 9499 | genlmsg_cancel(msg, hdr); |
| 9500 | nlmsg_free(msg); |
| 9501 | |
| 9502 | } |
| 9503 | |
| 9504 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 9505 | struct net_device *netdev, const u8 *bssid, |
| 9506 | const u8 *req_ie, size_t req_ie_len, |
| 9507 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 9508 | { |
| 9509 | struct sk_buff *msg; |
| 9510 | void *hdr; |
| 9511 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9512 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9513 | if (!msg) |
| 9514 | return; |
| 9515 | |
| 9516 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 9517 | if (!hdr) { |
| 9518 | nlmsg_free(msg); |
| 9519 | return; |
| 9520 | } |
| 9521 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9522 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9523 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9524 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 9525 | (req_ie && |
| 9526 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9527 | (resp_ie && |
| 9528 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9529 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9530 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9531 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9532 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9533 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9534 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9535 | return; |
| 9536 | |
| 9537 | nla_put_failure: |
| 9538 | genlmsg_cancel(msg, hdr); |
| 9539 | nlmsg_free(msg); |
| 9540 | |
| 9541 | } |
| 9542 | |
| 9543 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 9544 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 9545 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9546 | { |
| 9547 | struct sk_buff *msg; |
| 9548 | void *hdr; |
| 9549 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9550 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9551 | if (!msg) |
| 9552 | return; |
| 9553 | |
| 9554 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 9555 | if (!hdr) { |
| 9556 | nlmsg_free(msg); |
| 9557 | return; |
| 9558 | } |
| 9559 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9560 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9561 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9562 | (from_ap && reason && |
| 9563 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 9564 | (from_ap && |
| 9565 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 9566 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 9567 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9568 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9569 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9570 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9571 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9572 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9573 | return; |
| 9574 | |
| 9575 | nla_put_failure: |
| 9576 | genlmsg_cancel(msg, hdr); |
| 9577 | nlmsg_free(msg); |
| 9578 | |
| 9579 | } |
| 9580 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9581 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 9582 | struct net_device *netdev, const u8 *bssid, |
| 9583 | gfp_t gfp) |
| 9584 | { |
| 9585 | struct sk_buff *msg; |
| 9586 | void *hdr; |
| 9587 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9588 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9589 | if (!msg) |
| 9590 | return; |
| 9591 | |
| 9592 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 9593 | if (!hdr) { |
| 9594 | nlmsg_free(msg); |
| 9595 | return; |
| 9596 | } |
| 9597 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9598 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9599 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9600 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9601 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9602 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9603 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9604 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9605 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9606 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9607 | return; |
| 9608 | |
| 9609 | nla_put_failure: |
| 9610 | genlmsg_cancel(msg, hdr); |
| 9611 | nlmsg_free(msg); |
| 9612 | } |
| 9613 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9614 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 9615 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9616 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9617 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9618 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9619 | struct sk_buff *msg; |
| 9620 | void *hdr; |
| 9621 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9622 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 9623 | return; |
| 9624 | |
| 9625 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 9626 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9627 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9628 | if (!msg) |
| 9629 | return; |
| 9630 | |
| 9631 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 9632 | if (!hdr) { |
| 9633 | nlmsg_free(msg); |
| 9634 | return; |
| 9635 | } |
| 9636 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9637 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9638 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9639 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9640 | (ie_len && ie && |
| 9641 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 9642 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9643 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9644 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9645 | |
| 9646 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9647 | nl80211_mlme_mcgrp.id, gfp); |
| 9648 | return; |
| 9649 | |
| 9650 | nla_put_failure: |
| 9651 | genlmsg_cancel(msg, hdr); |
| 9652 | nlmsg_free(msg); |
| 9653 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9654 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9655 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9656 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 9657 | struct net_device *netdev, const u8 *addr, |
| 9658 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9659 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9660 | { |
| 9661 | struct sk_buff *msg; |
| 9662 | void *hdr; |
| 9663 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9664 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9665 | if (!msg) |
| 9666 | return; |
| 9667 | |
| 9668 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9669 | if (!hdr) { |
| 9670 | nlmsg_free(msg); |
| 9671 | return; |
| 9672 | } |
| 9673 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9674 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9675 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9676 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9677 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9678 | (key_id != -1 && |
| 9679 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9680 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9681 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9682 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9683 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9684 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9685 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9686 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9687 | return; |
| 9688 | |
| 9689 | nla_put_failure: |
| 9690 | genlmsg_cancel(msg, hdr); |
| 9691 | nlmsg_free(msg); |
| 9692 | } |
| 9693 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9694 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9695 | struct ieee80211_channel *channel_before, |
| 9696 | struct ieee80211_channel *channel_after) |
| 9697 | { |
| 9698 | struct sk_buff *msg; |
| 9699 | void *hdr; |
| 9700 | struct nlattr *nl_freq; |
| 9701 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9703 | if (!msg) |
| 9704 | return; |
| 9705 | |
| 9706 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9707 | if (!hdr) { |
| 9708 | nlmsg_free(msg); |
| 9709 | return; |
| 9710 | } |
| 9711 | |
| 9712 | /* |
| 9713 | * Since we are applying the beacon hint to a wiphy we know its |
| 9714 | * wiphy_idx is valid |
| 9715 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9716 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9717 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9718 | |
| 9719 | /* Before */ |
| 9720 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9721 | if (!nl_freq) |
| 9722 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9723 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9724 | goto nla_put_failure; |
| 9725 | nla_nest_end(msg, nl_freq); |
| 9726 | |
| 9727 | /* After */ |
| 9728 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9729 | if (!nl_freq) |
| 9730 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9731 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9732 | goto nla_put_failure; |
| 9733 | nla_nest_end(msg, nl_freq); |
| 9734 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9735 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9736 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9737 | rcu_read_lock(); |
| 9738 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9739 | GFP_ATOMIC); |
| 9740 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9741 | |
| 9742 | return; |
| 9743 | |
| 9744 | nla_put_failure: |
| 9745 | genlmsg_cancel(msg, hdr); |
| 9746 | nlmsg_free(msg); |
| 9747 | } |
| 9748 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9749 | static void nl80211_send_remain_on_chan_event( |
| 9750 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9751 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9752 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9753 | unsigned int duration, gfp_t gfp) |
| 9754 | { |
| 9755 | struct sk_buff *msg; |
| 9756 | void *hdr; |
| 9757 | |
| 9758 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9759 | if (!msg) |
| 9760 | return; |
| 9761 | |
| 9762 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9763 | if (!hdr) { |
| 9764 | nlmsg_free(msg); |
| 9765 | return; |
| 9766 | } |
| 9767 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9768 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9769 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9770 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9771 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9772 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9773 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9774 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9775 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9776 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9777 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9778 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9779 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9780 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9781 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9782 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9783 | |
| 9784 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9785 | nl80211_mlme_mcgrp.id, gfp); |
| 9786 | return; |
| 9787 | |
| 9788 | nla_put_failure: |
| 9789 | genlmsg_cancel(msg, hdr); |
| 9790 | nlmsg_free(msg); |
| 9791 | } |
| 9792 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9793 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 9794 | struct ieee80211_channel *chan, |
| 9795 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9796 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9797 | struct wiphy *wiphy = wdev->wiphy; |
| 9798 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9799 | |
| 9800 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9801 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9802 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9803 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9804 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9805 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9806 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9807 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 9808 | struct ieee80211_channel *chan, |
| 9809 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9810 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9811 | struct wiphy *wiphy = wdev->wiphy; |
| 9812 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9813 | |
| 9814 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9815 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9816 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9817 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9818 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9819 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9820 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 9821 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9822 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9823 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9824 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9825 | struct sk_buff *msg; |
| 9826 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9827 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 9828 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9829 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9830 | if (!msg) |
| 9831 | return; |
| 9832 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9833 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9834 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9835 | nlmsg_free(msg); |
| 9836 | return; |
| 9837 | } |
| 9838 | |
| 9839 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9840 | nl80211_mlme_mcgrp.id, gfp); |
| 9841 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9842 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9843 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9844 | 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] | 9845 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9846 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9847 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9848 | struct sk_buff *msg; |
| 9849 | void *hdr; |
| 9850 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9851 | trace_cfg80211_del_sta(dev, mac_addr); |
| 9852 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9853 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9854 | if (!msg) |
| 9855 | return; |
| 9856 | |
| 9857 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9858 | if (!hdr) { |
| 9859 | nlmsg_free(msg); |
| 9860 | return; |
| 9861 | } |
| 9862 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9863 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9864 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9865 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9866 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9867 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9868 | |
| 9869 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9870 | nl80211_mlme_mcgrp.id, gfp); |
| 9871 | return; |
| 9872 | |
| 9873 | nla_put_failure: |
| 9874 | genlmsg_cancel(msg, hdr); |
| 9875 | nlmsg_free(msg); |
| 9876 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9877 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9878 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9879 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 9880 | enum nl80211_connect_failed_reason reason, |
| 9881 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9882 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9883 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9884 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9885 | struct sk_buff *msg; |
| 9886 | void *hdr; |
| 9887 | |
| 9888 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9889 | if (!msg) |
| 9890 | return; |
| 9891 | |
| 9892 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9893 | if (!hdr) { |
| 9894 | nlmsg_free(msg); |
| 9895 | return; |
| 9896 | } |
| 9897 | |
| 9898 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9899 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9900 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9901 | goto nla_put_failure; |
| 9902 | |
| 9903 | genlmsg_end(msg, hdr); |
| 9904 | |
| 9905 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9906 | nl80211_mlme_mcgrp.id, gfp); |
| 9907 | return; |
| 9908 | |
| 9909 | nla_put_failure: |
| 9910 | genlmsg_cancel(msg, hdr); |
| 9911 | nlmsg_free(msg); |
| 9912 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9913 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9914 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9915 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9916 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9917 | { |
| 9918 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9919 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9920 | struct sk_buff *msg; |
| 9921 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9922 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9923 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9924 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9925 | return false; |
| 9926 | |
| 9927 | msg = nlmsg_new(100, gfp); |
| 9928 | if (!msg) |
| 9929 | return true; |
| 9930 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9931 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9932 | if (!hdr) { |
| 9933 | nlmsg_free(msg); |
| 9934 | return true; |
| 9935 | } |
| 9936 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9937 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9938 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9939 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9940 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9941 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 9942 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9943 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9944 | return true; |
| 9945 | |
| 9946 | nla_put_failure: |
| 9947 | genlmsg_cancel(msg, hdr); |
| 9948 | nlmsg_free(msg); |
| 9949 | return true; |
| 9950 | } |
| 9951 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9952 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 9953 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9954 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9955 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9956 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9957 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9958 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 9959 | |
| 9960 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9961 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 9962 | trace_cfg80211_return_bool(false); |
| 9963 | return false; |
| 9964 | } |
| 9965 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9966 | addr, gfp); |
| 9967 | trace_cfg80211_return_bool(ret); |
| 9968 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9969 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9970 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 9971 | |
| 9972 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 9973 | const u8 *addr, gfp_t gfp) |
| 9974 | { |
| 9975 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9976 | bool ret; |
| 9977 | |
| 9978 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 9979 | |
| 9980 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9981 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 9982 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 9983 | trace_cfg80211_return_bool(false); |
| 9984 | return false; |
| 9985 | } |
| 9986 | ret = __nl80211_unexpected_frame(dev, |
| 9987 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9988 | addr, gfp); |
| 9989 | trace_cfg80211_return_bool(ret); |
| 9990 | return ret; |
| 9991 | } |
| 9992 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9993 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9994 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9995 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9996 | int freq, int sig_dbm, |
| 9997 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9998 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9999 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10000 | struct sk_buff *msg; |
| 10001 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10002 | |
| 10003 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10004 | if (!msg) |
| 10005 | return -ENOMEM; |
| 10006 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10007 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10008 | if (!hdr) { |
| 10009 | nlmsg_free(msg); |
| 10010 | return -ENOMEM; |
| 10011 | } |
| 10012 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10013 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10014 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10015 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10016 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10017 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10018 | (sig_dbm && |
| 10019 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 10020 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10021 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10022 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10023 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10024 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10025 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10026 | |
| 10027 | nla_put_failure: |
| 10028 | genlmsg_cancel(msg, hdr); |
| 10029 | nlmsg_free(msg); |
| 10030 | return -ENOBUFS; |
| 10031 | } |
| 10032 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10033 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10034 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10035 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10036 | struct wiphy *wiphy = wdev->wiphy; |
| 10037 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10038 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10039 | struct sk_buff *msg; |
| 10040 | void *hdr; |
| 10041 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10042 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10043 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10044 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10045 | if (!msg) |
| 10046 | return; |
| 10047 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10048 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 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) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10055 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10056 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10057 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10058 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10059 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10060 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10061 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10062 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10063 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10064 | |
| 10065 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 10066 | return; |
| 10067 | |
| 10068 | nla_put_failure: |
| 10069 | genlmsg_cancel(msg, hdr); |
| 10070 | nlmsg_free(msg); |
| 10071 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10072 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10073 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10074 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10075 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10076 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10077 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10078 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10079 | struct wiphy *wiphy = wdev->wiphy; |
| 10080 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10081 | struct sk_buff *msg; |
| 10082 | struct nlattr *pinfoattr; |
| 10083 | void *hdr; |
| 10084 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10085 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10086 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10087 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10088 | if (!msg) |
| 10089 | return; |
| 10090 | |
| 10091 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10092 | if (!hdr) { |
| 10093 | nlmsg_free(msg); |
| 10094 | return; |
| 10095 | } |
| 10096 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10097 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10098 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10099 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10100 | |
| 10101 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10102 | if (!pinfoattr) |
| 10103 | goto nla_put_failure; |
| 10104 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10105 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10106 | rssi_event)) |
| 10107 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10108 | |
| 10109 | nla_nest_end(msg, pinfoattr); |
| 10110 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10111 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10112 | |
| 10113 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10114 | nl80211_mlme_mcgrp.id, gfp); |
| 10115 | return; |
| 10116 | |
| 10117 | nla_put_failure: |
| 10118 | genlmsg_cancel(msg, hdr); |
| 10119 | nlmsg_free(msg); |
| 10120 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10121 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10122 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10123 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10124 | struct net_device *netdev, const u8 *bssid, |
| 10125 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10126 | { |
| 10127 | struct sk_buff *msg; |
| 10128 | struct nlattr *rekey_attr; |
| 10129 | void *hdr; |
| 10130 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10131 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10132 | if (!msg) |
| 10133 | return; |
| 10134 | |
| 10135 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10136 | if (!hdr) { |
| 10137 | nlmsg_free(msg); |
| 10138 | return; |
| 10139 | } |
| 10140 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10141 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10142 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10143 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10144 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10145 | |
| 10146 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10147 | if (!rekey_attr) |
| 10148 | goto nla_put_failure; |
| 10149 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10150 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10151 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10152 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10153 | |
| 10154 | nla_nest_end(msg, rekey_attr); |
| 10155 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10156 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10157 | |
| 10158 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10159 | nl80211_mlme_mcgrp.id, gfp); |
| 10160 | return; |
| 10161 | |
| 10162 | nla_put_failure: |
| 10163 | genlmsg_cancel(msg, hdr); |
| 10164 | nlmsg_free(msg); |
| 10165 | } |
| 10166 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10167 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10168 | const u8 *replay_ctr, gfp_t gfp) |
| 10169 | { |
| 10170 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10171 | struct wiphy *wiphy = wdev->wiphy; |
| 10172 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10173 | |
| 10174 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10175 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10176 | } |
| 10177 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10178 | |
| 10179 | static void |
| 10180 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10181 | struct net_device *netdev, int index, |
| 10182 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10183 | { |
| 10184 | struct sk_buff *msg; |
| 10185 | struct nlattr *attr; |
| 10186 | void *hdr; |
| 10187 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10188 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10189 | if (!msg) |
| 10190 | return; |
| 10191 | |
| 10192 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10193 | if (!hdr) { |
| 10194 | nlmsg_free(msg); |
| 10195 | return; |
| 10196 | } |
| 10197 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10198 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10199 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10200 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10201 | |
| 10202 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10203 | if (!attr) |
| 10204 | goto nla_put_failure; |
| 10205 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10206 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10207 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10208 | (preauth && |
| 10209 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10210 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10211 | |
| 10212 | nla_nest_end(msg, attr); |
| 10213 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10214 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10215 | |
| 10216 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10217 | nl80211_mlme_mcgrp.id, gfp); |
| 10218 | return; |
| 10219 | |
| 10220 | nla_put_failure: |
| 10221 | genlmsg_cancel(msg, hdr); |
| 10222 | nlmsg_free(msg); |
| 10223 | } |
| 10224 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10225 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10226 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10227 | { |
| 10228 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10229 | struct wiphy *wiphy = wdev->wiphy; |
| 10230 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10231 | |
| 10232 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10233 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10234 | } |
| 10235 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10236 | |
| 10237 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10238 | struct net_device *netdev, |
| 10239 | struct cfg80211_chan_def *chandef, |
| 10240 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10241 | { |
| 10242 | struct sk_buff *msg; |
| 10243 | void *hdr; |
| 10244 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10245 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10246 | if (!msg) |
| 10247 | return; |
| 10248 | |
| 10249 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10250 | if (!hdr) { |
| 10251 | nlmsg_free(msg); |
| 10252 | return; |
| 10253 | } |
| 10254 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10255 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10256 | goto nla_put_failure; |
| 10257 | |
| 10258 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10259 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10260 | |
| 10261 | genlmsg_end(msg, hdr); |
| 10262 | |
| 10263 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10264 | nl80211_mlme_mcgrp.id, gfp); |
| 10265 | return; |
| 10266 | |
| 10267 | nla_put_failure: |
| 10268 | genlmsg_cancel(msg, hdr); |
| 10269 | nlmsg_free(msg); |
| 10270 | } |
| 10271 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10272 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10273 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10274 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10275 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10276 | struct wiphy *wiphy = wdev->wiphy; |
| 10277 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10278 | |
| 10279 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10280 | |
| 10281 | wdev_lock(wdev); |
| 10282 | |
| 10283 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10284 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) |
| 10285 | goto out; |
| 10286 | |
| 10287 | wdev->channel = chandef->chan; |
| 10288 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10289 | out: |
| 10290 | wdev_unlock(wdev); |
| 10291 | return; |
| 10292 | } |
| 10293 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10294 | |
| 10295 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10296 | const u8 *peer, u32 num_packets, |
| 10297 | u32 rate, u32 intvl, gfp_t gfp) |
| 10298 | { |
| 10299 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10300 | struct wiphy *wiphy = wdev->wiphy; |
| 10301 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10302 | struct sk_buff *msg; |
| 10303 | struct nlattr *pinfoattr; |
| 10304 | void *hdr; |
| 10305 | |
| 10306 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10307 | if (!msg) |
| 10308 | return; |
| 10309 | |
| 10310 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10311 | if (!hdr) { |
| 10312 | nlmsg_free(msg); |
| 10313 | return; |
| 10314 | } |
| 10315 | |
| 10316 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10317 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10318 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10319 | goto nla_put_failure; |
| 10320 | |
| 10321 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10322 | if (!pinfoattr) |
| 10323 | goto nla_put_failure; |
| 10324 | |
| 10325 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10326 | goto nla_put_failure; |
| 10327 | |
| 10328 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10329 | goto nla_put_failure; |
| 10330 | |
| 10331 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10332 | goto nla_put_failure; |
| 10333 | |
| 10334 | nla_nest_end(msg, pinfoattr); |
| 10335 | |
| 10336 | genlmsg_end(msg, hdr); |
| 10337 | |
| 10338 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10339 | nl80211_mlme_mcgrp.id, gfp); |
| 10340 | return; |
| 10341 | |
| 10342 | nla_put_failure: |
| 10343 | genlmsg_cancel(msg, hdr); |
| 10344 | nlmsg_free(msg); |
| 10345 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10346 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10347 | |
| 10348 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10349 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 10350 | struct cfg80211_chan_def *chandef, |
| 10351 | enum nl80211_radar_event event, |
| 10352 | struct net_device *netdev, gfp_t gfp) |
| 10353 | { |
| 10354 | struct sk_buff *msg; |
| 10355 | void *hdr; |
| 10356 | |
| 10357 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10358 | if (!msg) |
| 10359 | return; |
| 10360 | |
| 10361 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10362 | if (!hdr) { |
| 10363 | nlmsg_free(msg); |
| 10364 | return; |
| 10365 | } |
| 10366 | |
| 10367 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10368 | goto nla_put_failure; |
| 10369 | |
| 10370 | /* NOP and radar events don't need a netdev parameter */ |
| 10371 | if (netdev) { |
| 10372 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10373 | |
| 10374 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10375 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10376 | goto nla_put_failure; |
| 10377 | } |
| 10378 | |
| 10379 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10380 | goto nla_put_failure; |
| 10381 | |
| 10382 | if (nl80211_send_chandef(msg, chandef)) |
| 10383 | goto nla_put_failure; |
| 10384 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10385 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10386 | |
| 10387 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10388 | nl80211_mlme_mcgrp.id, gfp); |
| 10389 | return; |
| 10390 | |
| 10391 | nla_put_failure: |
| 10392 | genlmsg_cancel(msg, hdr); |
| 10393 | nlmsg_free(msg); |
| 10394 | } |
| 10395 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10396 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10397 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10398 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10399 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10400 | struct wiphy *wiphy = wdev->wiphy; |
| 10401 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10402 | struct sk_buff *msg; |
| 10403 | struct nlattr *pinfoattr; |
| 10404 | void *hdr; |
| 10405 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10406 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10407 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10408 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10409 | if (!msg) |
| 10410 | return; |
| 10411 | |
| 10412 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10413 | if (!hdr) { |
| 10414 | nlmsg_free(msg); |
| 10415 | return; |
| 10416 | } |
| 10417 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10418 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10419 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10420 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10421 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10422 | |
| 10423 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10424 | if (!pinfoattr) |
| 10425 | goto nla_put_failure; |
| 10426 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10427 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10428 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10429 | |
| 10430 | nla_nest_end(msg, pinfoattr); |
| 10431 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10432 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10433 | |
| 10434 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10435 | nl80211_mlme_mcgrp.id, gfp); |
| 10436 | return; |
| 10437 | |
| 10438 | nla_put_failure: |
| 10439 | genlmsg_cancel(msg, hdr); |
| 10440 | nlmsg_free(msg); |
| 10441 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10442 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10443 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10444 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10445 | u64 cookie, bool acked, gfp_t gfp) |
| 10446 | { |
| 10447 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10448 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10449 | struct sk_buff *msg; |
| 10450 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10451 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10452 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10453 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10454 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10455 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10456 | if (!msg) |
| 10457 | return; |
| 10458 | |
| 10459 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10460 | if (!hdr) { |
| 10461 | nlmsg_free(msg); |
| 10462 | return; |
| 10463 | } |
| 10464 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10465 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10466 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10467 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10468 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10469 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10470 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10471 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10472 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10473 | |
| 10474 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10475 | nl80211_mlme_mcgrp.id, gfp); |
| 10476 | return; |
| 10477 | |
| 10478 | nla_put_failure: |
| 10479 | genlmsg_cancel(msg, hdr); |
| 10480 | nlmsg_free(msg); |
| 10481 | } |
| 10482 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 10483 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10484 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 10485 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10486 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10487 | { |
| 10488 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10489 | struct sk_buff *msg; |
| 10490 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10491 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10492 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10493 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 10494 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10495 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10496 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10497 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 10498 | if (!msg) { |
| 10499 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10500 | return; |
| 10501 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10502 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10503 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 10504 | if (!hdr) |
| 10505 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10506 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10507 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10508 | (freq && |
| 10509 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 10510 | (sig_dbm && |
| 10511 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 10512 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 10513 | goto nla_put_failure; |
| 10514 | |
| 10515 | genlmsg_end(msg, hdr); |
| 10516 | |
| 10517 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10518 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10519 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10520 | return; |
| 10521 | |
| 10522 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10523 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10524 | if (hdr) |
| 10525 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10526 | nlmsg_free(msg); |
| 10527 | } |
| 10528 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 10529 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10530 | #ifdef CONFIG_PM |
| 10531 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 10532 | struct cfg80211_wowlan_wakeup *wakeup, |
| 10533 | gfp_t gfp) |
| 10534 | { |
| 10535 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10536 | struct sk_buff *msg; |
| 10537 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10538 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10539 | |
| 10540 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 10541 | |
| 10542 | if (wakeup) |
| 10543 | size += wakeup->packet_present_len; |
| 10544 | |
| 10545 | msg = nlmsg_new(size, gfp); |
| 10546 | if (!msg) |
| 10547 | return; |
| 10548 | |
| 10549 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 10550 | if (!hdr) |
| 10551 | goto free_msg; |
| 10552 | |
| 10553 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10554 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10555 | goto free_msg; |
| 10556 | |
| 10557 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10558 | wdev->netdev->ifindex)) |
| 10559 | goto free_msg; |
| 10560 | |
| 10561 | if (wakeup) { |
| 10562 | struct nlattr *reasons; |
| 10563 | |
| 10564 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10565 | |
| 10566 | if (wakeup->disconnect && |
| 10567 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 10568 | goto free_msg; |
| 10569 | if (wakeup->magic_pkt && |
| 10570 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 10571 | goto free_msg; |
| 10572 | if (wakeup->gtk_rekey_failure && |
| 10573 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 10574 | goto free_msg; |
| 10575 | if (wakeup->eap_identity_req && |
| 10576 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 10577 | goto free_msg; |
| 10578 | if (wakeup->four_way_handshake && |
| 10579 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 10580 | goto free_msg; |
| 10581 | if (wakeup->rfkill_release && |
| 10582 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 10583 | goto free_msg; |
| 10584 | |
| 10585 | if (wakeup->pattern_idx >= 0 && |
| 10586 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 10587 | wakeup->pattern_idx)) |
| 10588 | goto free_msg; |
| 10589 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10590 | if (wakeup->tcp_match) |
| 10591 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 10592 | |
| 10593 | if (wakeup->tcp_connlost) |
| 10594 | nla_put_flag(msg, |
| 10595 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 10596 | |
| 10597 | if (wakeup->tcp_nomoretokens) |
| 10598 | nla_put_flag(msg, |
| 10599 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 10600 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10601 | if (wakeup->packet) { |
| 10602 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 10603 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 10604 | |
| 10605 | if (!wakeup->packet_80211) { |
| 10606 | pkt_attr = |
| 10607 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 10608 | len_attr = |
| 10609 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 10610 | } |
| 10611 | |
| 10612 | if (wakeup->packet_len && |
| 10613 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 10614 | goto free_msg; |
| 10615 | |
| 10616 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 10617 | wakeup->packet)) |
| 10618 | goto free_msg; |
| 10619 | } |
| 10620 | |
| 10621 | nla_nest_end(msg, reasons); |
| 10622 | } |
| 10623 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10624 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10625 | |
| 10626 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10627 | nl80211_mlme_mcgrp.id, gfp); |
| 10628 | return; |
| 10629 | |
| 10630 | free_msg: |
| 10631 | nlmsg_free(msg); |
| 10632 | } |
| 10633 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 10634 | #endif |
| 10635 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10636 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 10637 | enum nl80211_tdls_operation oper, |
| 10638 | u16 reason_code, gfp_t gfp) |
| 10639 | { |
| 10640 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10641 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10642 | struct sk_buff *msg; |
| 10643 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10644 | |
| 10645 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 10646 | reason_code); |
| 10647 | |
| 10648 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10649 | if (!msg) |
| 10650 | return; |
| 10651 | |
| 10652 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 10653 | if (!hdr) { |
| 10654 | nlmsg_free(msg); |
| 10655 | return; |
| 10656 | } |
| 10657 | |
| 10658 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10659 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10660 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 10661 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 10662 | (reason_code > 0 && |
| 10663 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 10664 | goto nla_put_failure; |
| 10665 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10666 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10667 | |
| 10668 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10669 | nl80211_mlme_mcgrp.id, gfp); |
| 10670 | return; |
| 10671 | |
| 10672 | nla_put_failure: |
| 10673 | genlmsg_cancel(msg, hdr); |
| 10674 | nlmsg_free(msg); |
| 10675 | } |
| 10676 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 10677 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10678 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 10679 | unsigned long state, |
| 10680 | void *_notify) |
| 10681 | { |
| 10682 | struct netlink_notify *notify = _notify; |
| 10683 | struct cfg80211_registered_device *rdev; |
| 10684 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10685 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10686 | |
| 10687 | if (state != NETLINK_URELEASE) |
| 10688 | return NOTIFY_DONE; |
| 10689 | |
| 10690 | rcu_read_lock(); |
| 10691 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10692 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10693 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10694 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10695 | |
| 10696 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10697 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 10698 | list) { |
| 10699 | if (reg->nlportid == notify->portid) { |
| 10700 | list_del(®->list); |
| 10701 | kfree(reg); |
| 10702 | break; |
| 10703 | } |
| 10704 | } |
| 10705 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10706 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10707 | |
| 10708 | rcu_read_unlock(); |
| 10709 | |
| 10710 | return NOTIFY_DONE; |
| 10711 | } |
| 10712 | |
| 10713 | static struct notifier_block nl80211_netlink_notifier = { |
| 10714 | .notifier_call = nl80211_netlink_notify, |
| 10715 | }; |
| 10716 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10717 | void cfg80211_ft_event(struct net_device *netdev, |
| 10718 | struct cfg80211_ft_event_params *ft_event) |
| 10719 | { |
| 10720 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 10721 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10722 | struct sk_buff *msg; |
| 10723 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10724 | |
| 10725 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 10726 | |
| 10727 | if (!ft_event->target_ap) |
| 10728 | return; |
| 10729 | |
| 10730 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10731 | if (!msg) |
| 10732 | return; |
| 10733 | |
| 10734 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 10735 | if (!hdr) { |
| 10736 | nlmsg_free(msg); |
| 10737 | return; |
| 10738 | } |
| 10739 | |
| 10740 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 10741 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 10742 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 10743 | if (ft_event->ies) |
| 10744 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 10745 | if (ft_event->ric_ies) |
| 10746 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 10747 | ft_event->ric_ies); |
| 10748 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10749 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10750 | |
| 10751 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10752 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 10753 | } |
| 10754 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 10755 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10756 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 10757 | { |
| 10758 | struct cfg80211_registered_device *rdev; |
| 10759 | struct sk_buff *msg; |
| 10760 | void *hdr; |
| 10761 | u32 nlportid; |
| 10762 | |
| 10763 | rdev = wiphy_to_dev(wdev->wiphy); |
| 10764 | if (!rdev->crit_proto_nlportid) |
| 10765 | return; |
| 10766 | |
| 10767 | nlportid = rdev->crit_proto_nlportid; |
| 10768 | rdev->crit_proto_nlportid = 0; |
| 10769 | |
| 10770 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10771 | if (!msg) |
| 10772 | return; |
| 10773 | |
| 10774 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 10775 | if (!hdr) |
| 10776 | goto nla_put_failure; |
| 10777 | |
| 10778 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10779 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10780 | goto nla_put_failure; |
| 10781 | |
| 10782 | genlmsg_end(msg, hdr); |
| 10783 | |
| 10784 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 10785 | return; |
| 10786 | |
| 10787 | nla_put_failure: |
| 10788 | if (hdr) |
| 10789 | genlmsg_cancel(msg, hdr); |
| 10790 | nlmsg_free(msg); |
| 10791 | |
| 10792 | } |
| 10793 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 10794 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10795 | /* initialisation/exit functions */ |
| 10796 | |
| 10797 | int nl80211_init(void) |
| 10798 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10799 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10800 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10801 | err = genl_register_family_with_ops(&nl80211_fam, |
| 10802 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10803 | if (err) |
| 10804 | return err; |
| 10805 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10806 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 10807 | if (err) |
| 10808 | goto err_out; |
| 10809 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10810 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 10811 | if (err) |
| 10812 | goto err_out; |
| 10813 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10814 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 10815 | if (err) |
| 10816 | goto err_out; |
| 10817 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10818 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 10819 | if (err) |
| 10820 | goto err_out; |
| 10821 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10822 | #ifdef CONFIG_NL80211_TESTMODE |
| 10823 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 10824 | if (err) |
| 10825 | goto err_out; |
| 10826 | #endif |
| 10827 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10828 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10829 | if (err) |
| 10830 | goto err_out; |
| 10831 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10832 | return 0; |
| 10833 | err_out: |
| 10834 | genl_unregister_family(&nl80211_fam); |
| 10835 | return err; |
| 10836 | } |
| 10837 | |
| 10838 | void nl80211_exit(void) |
| 10839 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10840 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10841 | genl_unregister_family(&nl80211_fam); |
| 10842 | } |